[GRASS-dev] d.vect -a shows only some elements
Moritz Lennert
mlennert at club.worldonline.be
Mon Oct 23 12:04:26 EDT 2006
Martin Landa wrote:
> Hi Moritz,
>
> 2006/10/23, Moritz Lennert <mlennert at club.worldonline.be>:
>> Martin Landa wrote:
>> > Hi,
>> >
>> > 2006/10/21, Moritz Lennert <mlennert at club.worldonline.be>:
>> >
>> > [snip]
>> >
>> >> > you are right (if I understand well), adding
>> >> >
>> >> > db_CatValArray_sort (&cvarr_rgb);
>> >> >
>> >> > should solve the problem. I wonder why db_select_CatValArray sorts
>> >> > cvarr->value by category number only for data type int or double...
>> >> > (?), see
>> >> >
>> >> > 00300 if ( type == DB_C_TYPE_INT )
>> >> > 00301 qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal),
>> >> > cmpcat);
>> >> > 00302 else if ( type == DB_C_TYPE_DOUBLE )
>> >> > 00303 qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal),
>> >> > cmpcat);
>> >> >
>> >>
>> >> Applying below patch directly to db_select_CatValArray solves the
>> problem
>> >> for me, but I don't know if this might cause other problems, even
>> >> though I
>> >> doubt it.
>> >>
>> >> Any ideas ?
>> >>
>> >> Moritz
>> >>
>> >> Index: lib/db/dbmi_client/select.c
>> >> ===================================================================
>> >> RCS file: /grassrepository/grass6/lib/db/dbmi_client/select.c,v
>> >> retrieving revision 1.8
>> >> diff -u -r1.8 select.c
>> >> --- lib/db/dbmi_client/select.c 14 Jul 2006 16:41:22 -0000 1.8
>> >> +++ lib/db/dbmi_client/select.c 20 Oct 2006 23:22:26 -0000
>> >> @@ -297,10 +297,7 @@
>> >> db_close_cursor(&cursor);
>> >> db_free_string ( &stmt );
>> >>
>> >> - if ( type == DB_C_TYPE_INT )
>> >> - qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal),
>> cmpcat);
>> >> - else if ( type == DB_C_TYPE_DOUBLE )
>> >> - qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal),
>> cmpcat);
>> >> + db_CatValArray_sort ( cvarr );
>> >>
>> >> return (nrows);
>> >> }
>> >
>> > in this case the array is sorted twice for datatype DB_C_TYPE_INT and
>> > DB_C_TYPE_DOUBLE, I suggest
>> >
>> > Index: lib/db/dbmi_client/select.c
>> > ===================================================================
>> > RCS file:
>> /home/grass/grassrepository/grass6/lib/db/dbmi_client/select.c,v
>> > retrieving revision 1.8
>> > diff -u -r1.8 select.c
>> > --- lib/db/dbmi_client/select.c 14 Jul 2006 16:41:22 -0000 1.8
>> > +++ lib/db/dbmi_client/select.c 21 Oct 2006 07:43:35 -0000
>> > @@ -297,9 +297,8 @@
>> > db_close_cursor(&cursor);
>> > db_free_string ( &stmt );
>> >
>> > - if ( type == DB_C_TYPE_INT )
>> > - qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal),
>> cmpcat);
>> > - else if ( type == DB_C_TYPE_DOUBLE )
>> > + if ( type == DB_C_TYPE_INT || type == DB_C_TYPE_DOUBLE ||
>> > + type == DB_C_TYPE_STRING )
>> > qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal), cmpcat);
>> >
>> > return (nrows);
>> >
>> > Not sure if you need to check "type" here (what about
>> DB_C_TYPE_DATETIME)??
>>
>>
>> Don't know, either. The whole idea is to have the array sorted by cat
>> when it is returned. No reason that this should be any different
>> whatever the datatype of the attached data column.
>>
>> This is why I suggested replacing the whole thing by one simple call to
>>
>> db_CatValArray_sort ( cvarr );
>>
>> where db_CatValArray_sort simply contains:
>>
>> qsort( (void *) arr->value, arr->n_values, sizeof(dbCatVal), cmpcat);
>>
>> i.e. exactly the same sorting call.
>
> Personally I agree with you. I don't think you have to check data type
> of CatVal.value[].val for sorting of CatValArray array by cat.
>
>> So, why would that sort the array twice ?
>
> Sorry!, it was mistake. Please forget it:-)
Ok, have just committed my above proposal.
Thanks for the help !
Moritz
More information about the grass-dev
mailing list