WG: [GRASS-user] OGR Import Error for shapes with Fieldtype DATE

Markus Neteler neteler at itc.it
Fri Jun 30 19:05:25 EDT 2006


Horst, Frank,

On Fri, Jun 30, 2006 at 10:25:15AM -0400, Frank Warmerdam wrote:
> Düster Horst wrote:
> >Column type not supported (NEW_DATE)
> >
> >Column type not supported (ARCHIVE_DA)
> >DBMI-DBF driver error:
> >Incompatible value type.
> >Error in db_execute_immediate()
> >
> >
> >The reason of this error seems to be the fields NEW_DATE and ARCHIVE_DA.
> >These two fields are of type DATE. The same problem appears with the ogr
> >Import functionality og QGIS 0.8. Datatype DATE is an approved type for 
> >ESRI
> >Shapefiles.
> >
> >Is it a known bug? Does exists a suitable workaround?
> 
> Duster,
> 
> I suspect that the OGR interface code in GRASS needs to either add explicit
> handling of OGR date fields (a recent addition for GDAL/OGR 1.3.2)

GRASS is using OGR for SHAPE import, but (AFAIK) SHAPElib, not OGR for DBFs
storage. I recently updated grass61/lib/external/shapelib/ to the current
SHAPElib state.

Find attached a patch which now recognizes the new OGR date field type. No
more errors.

> or it  needs
> to at least treat them as string fields, which is essentially what happened
> before I think.

It also happens now. I suggested date support in SHAPELib but it
was rejected... So far I don't know how to hack SHAPELib for date support
or how to replace SHAPELib to OGR to handle DBFs. The latter probably makes
more sense.

With attached patch the file seems to be imported, but as before the
Dates are mapped to strings. If it also works for you, I can submit
the patch to CVS. Please verify it.

Best regards,

 Markus

-- 
Markus Neteler  <neteler itc it>  http://mpa.itc.it/markus/
ITC-irst -  Centro per la Ricerca Scientifica e Tecnologica
MPBA - Predictive Models for Biol. & Environ. Data Analysis
Via Sommarive, 18        -       38050 Povo (Trento), Italy
-------------- next part --------------
Index: vector/v.in.ogr/main.c
===================================================================
RCS file: /grassrepository/grass6/vector/v.in.ogr/main.c,v
retrieving revision 1.64
diff -u -r1.64 main.c
--- vector/v.in.ogr/main.c	14 Jun 2006 20:34:52 -0000	1.64
+++ vector/v.in.ogr/main.c	30 Jun 2006 23:02:49 -0000
@@ -618,6 +618,8 @@
 		    G_warning (_("Writing column <%s> with fixed length 40 chars (may be truncated)"), Ogr_fieldname);
 		} else if( Ogr_ftype == OFTReal ) {
 		    sprintf (buf, ", %s double precision", Ogr_fieldname );
+		} else if( Ogr_ftype == OFTDate ) {
+		    sprintf (buf, ", %s date", Ogr_fieldname );
 		} else if( Ogr_ftype == OFTString ) {
 		    int fwidth;
 		    fwidth = OGR_Fld_GetWidth(Ogr_field);
@@ -690,7 +692,7 @@
 		    if( OGR_F_IsFieldSet( Ogr_feature, i ) ) {
 			if( Ogr_ftype == OFTInteger || Ogr_ftype == OFTReal ) {
 			    sprintf (buf, ", %s", OGR_F_GetFieldAsString( Ogr_feature, i) );
-			} else if( Ogr_ftype == OFTString || Ogr_ftype == OFTIntegerList ) {
+			} else if( Ogr_ftype == OFTString || Ogr_ftype == OFTIntegerList || Ogr_ftype == OFTDate ) {
 			    db_set_string ( &strval,  (char *) OGR_F_GetFieldAsString( Ogr_feature, i) );
 			    db_double_quote_string (&strval);
 			    sprintf (buf, ", '%s'", db_get_string(&strval) );
@@ -702,7 +704,7 @@
 			/* TODO: change to 'NULL' once supported by dbf driver */
 			if( Ogr_ftype == OFTInteger || Ogr_ftype == OFTReal ) {
 			    sprintf (buf, ", 0" );
-			} else if( Ogr_ftype == OFTString || Ogr_ftype == OFTIntegerList ) {
+			} else if( Ogr_ftype == OFTString || Ogr_ftype == OFTIntegerList || Ogr_ftype == OFTDate ) {
 			    sprintf (buf, ", ''" );
 			}
 			/* sprintf (buf, ", NULL" ); */


More information about the grass-user mailing list