[GRASS-dev] d.vect -a shows only some elements

Moritz Lennert mlennert at club.worldonline.be
Fri Oct 20 19:26:16 EDT 2006


On Fri, October 20, 2006 21:37, Martin Landa wrote:
> Hi Moritz,
>
> 2006/10/20, Moritz Lennert <mlennert at club.worldonline.be>:
>
> [snip]
>
>> I have done some testing, and the problem seems to be in line 224 of
>> display/d.vect/area.c:
>>
>> if (db_CatValArray_get_value (&cvarr_rgb, cat, &cv_rgb) != DB_OK)
>>
>> db_CatValArray_get_value returns 'not found' for many of the cat values.
>>
>> I am wondering whether this might be due to the fact that the bsearch in
>> db_CatValArray_get_value needs a sorted array, but that the array is not
>> sorted as db_select_CatValArray() which creates the array on line 67 of
>> the same file only sorts lists of ints or doubles, but not of strings...
>
> 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);
 }






More information about the grass-dev mailing list