On Tue, 7 Oct 2008, Dylan Beaudette wrote:

On Tue, Oct 7, 2008 at 6:26 PM, Hamish <[EMAIL PROTECTED]> wrote:
Dylan:
It looks like the limiting factor in this equation is the
code used in v.out.ogr.

Following Dylan's posting on the GDAL list, and Frank's response, I suggest the following simple patch to vector/v.out.ogr/main.c (here 6.3):

$ diff -u main.c_old main.c
--- main.c_old  2008-10-09 10:54:19.000000000 +0200
+++ main.c      2008-10-09 11:30:34.000000000 +0200
@@ -625,7 +625,9 @@
                        colsqltype = db_get_column_sqltype(Column);
                        colctype = db_sqltype_to_Ctype ( colsqltype );
                        G_debug (2, "  colctype = %d", colctype );
-                       switch ( colctype ) {
+/* RSB 081009 emit unset fields */
+                        if (!db_test_value_isnull(Value)) {
+                         switch ( colctype ) {
                             case DB_C_TYPE_INT:
                                OGR_F_SetFieldInteger( Ogr_feature, j, db_get_va
lue_int(Value) );
                                break;
@@ -639,7 +641,8 @@
db_convert_column_value_to_string (Column, &dbst
ring);
                                OGR_F_SetFieldString( Ogr_feature, j, db_get_str
ing (&dbstring) );
                                break;
-                       }
+                         }
+                        } /* RSB */
                    }
                }
            }

In 6.4 this is after line 717. Essentially it just uses db_test_value_isnull() not to set values in OGR fields if the DB field value is NULL, and follows Frank's suggestion.

This matches code near line 939 in OGRGRASSLayer::SetAttributes()
gdal/ogr/ogr_frmts/grass/ogrgrasslayer.cpp in the vector plugin, which uses:

if ( !db_test_value_isnull(value) )

I'm sure the patch needs checking, but with changes in the R rgdal package to support vector null data correctly, it ought to improve the interface.

Best wishes,

Roger


maybe a silly question, but is a 3rd party format even needed here?

$ ogrinfo --formats | grep -i grass
 -> "GRASS" (readonly)

at least in the one direction.


Excellent question. I had also wondered about this. It looks like
there is a new argument in readVECT():

# read in directly with GDAL/OGR -- no intermediate file:
x <- readVECT6('xxx', plugin=TRUE)

This is quite fast and depends on the GDAL-GRASS plugin... However,
NULL data in a GRASS table is not imported correctly-- character
fields are imported as '', and numeric fields as 0.

So... Is the error in GDAL itself?

I tried inspecting a vector from GRASS with NULL data in some of the
columns from the table, using ogrinfo -al
location/mapset/vector/xxx/head

OGRFeature(1):23
 cat (Integer) = 24
 cat_ (Integer) = 24
 str1 (String) = (null)
 xyz (Real) = (null)
 abc (Integer) = (null)
 POINT (591583 4925280 0)

... which seems to correctly report the NULL values.

This leads me to suspect that something in readOGR() and writeOGR are
at fault in handling of NULL values.

Unfortunately looking at the rgdal source code wasn't very productive
(my fault).

Cheers,

Dylan


--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [EMAIL PROTECTED]

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to