The patch I just sent was slightly faulty in that it always produced
a warning about ignoring OGR dsco parameters in update mode even when
none were given. Sorry about that. Attached is a fixed version.
I have run some tests with a PostGIS database and that seemed to work
just fine (adding new layers as tables to an existing DB), so this
is an SQLite issue. However, since ogr2ogr manages to stuff features
into an SQLite DB just fine, there must be something wrong with
either the GRASS interface or my own installation.

Maybe someone else could do some quick SQLite testing just to
confirm I am not the only one for who things don't work?
That would make it much easier for me to narrow down the problem.

Thanks,

Ben

Benjamin Ducke wrote:
Dear all,

I have attached a very small patch to v.out.org against the
version in 6.4.SVN. It adds a "-u" flag that allows users
to update data in existing OGR sources. It's the same as
ogr2ogr's "-update" option and _very_ important for being able
to write layers as tables into existing spatial databases.
It should not be able to break any existing functionality.

If a data source does not support updates (like Shapefiles),
then Ogr_Dr_open() behaves the same as Ogr_Dr_CreateDataSource().

Despite the update, I have not been able to successfully
write OGR features to an existing (or new) SQLite DB.

OGR_L_CreateFeature() results in this error from the SQLite driver
after the first feature has been written:

ERROR 1: sqlite3_step() failed:
  SQL logic error or missing database

Strangely, the first feature is written into the table just fine,
but the error appears for all consecutive writes.

I will have to do more tests to see if this is an SQLite
and GRASS specific problem (ogr2ogr works fine).

Cheers,

Ben


------------------------------------------------------------------------

_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev


--
Benjamin Ducke
Senior Geospatial Consultant

Oxford Archaeology
Janus House
Osney Mead
OX2 0ES
Oxford, U.K.

Tel: +44 (0)1865 263 800 (switchboard)
Tel: +44 (0)1865 980 758 (direct)
Fax :+44 (0)1865 793 496
[email protected]





------
Files attached to this email may be in ISO 26300 format (OASIS Open Document 
Format). If you have difficulty opening them, please visit http://iso26300.info 
for more information.
--- old/main.c	2009-05-11 10:16:32.000000000 +0100
+++ new/main.c	2009-05-11 11:20:47.000000000 +0100
@@ -44,7 +44,7 @@
     struct GModule *module;
     struct Option *in_opt, *dsn_opt, *layer_opt, *type_opt, *frmt_opt,
 	*field_opt, *dsco, *lco;
-    struct Flag *cat_flag, *esristyle, *poly_flag;
+    struct Flag *cat_flag, *esristyle, *poly_flag, *update_flag;
     char buf[2000];
     char key1[200], key2[200];
     struct Key_Value *projinfo, *projunits;
@@ -161,6 +161,12 @@
     poly_flag->key = 'p';
     poly_flag->description = _("Export lines as polygons");
 
+
+    update_flag = G_define_flag();
+    update_flag->key = 'u';
+    update_flag->description = _("Update an existing data source");
+        
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -249,22 +255,39 @@
 	G_fatal_error(_("OGR driver <%s> not found"), frmt_opt->answer);
     Ogr_driver = OGRGetDriver(drn);
 
-    /* parse dataset creation options */
-    i = 0;
-    while (dsco->answers[i]) {
-	tokens = G_tokenize(dsco->answers[i], "=");
-	if (G_number_of_tokens(tokens))
-	    papszDSCO = CSLSetNameValue(papszDSCO, tokens[0], tokens[1]);
-	G_free_tokens(tokens);
-	i++;
+    if ( update_flag->answer && ( strlen (dsco->answer) > 0 ) ) {
+        G_warning (_("Running in update mode. Ignoring 'dsco' parameter"));
+    } else {
+        /* parse dataset creation options */
+        i = 0;
+        while (dsco->answers[i]) {
+	    tokens = G_tokenize(dsco->answers[i], "=");
+	    if (G_number_of_tokens(tokens))
+	        papszDSCO = CSLSetNameValue(papszDSCO, tokens[0], tokens[1]);
+	    G_free_tokens(tokens);
+	    i++;
+        }
     }
 
     papszDSCO = dsco->answers;
-    Ogr_ds = OGR_Dr_CreateDataSource(Ogr_driver, dsn_opt->answer, papszDSCO);
+    
+    if ( update_flag->answer ) {
+        Ogr_ds = 
+	    OGR_Dr_Open(Ogr_driver, dsn_opt->answer, TRUE);    
+    } else {
+        Ogr_ds = OGR_Dr_CreateDataSource(Ogr_driver, dsn_opt->answer, papszDSCO);
+    }
     CSLDestroy(papszDSCO);
-    if (Ogr_ds == NULL)
-	G_fatal_error(_("Unable to open OGR data source '%s'"),
-		      dsn_opt->answer);
+    if (Ogr_ds == NULL) {
+        if ( !update_flag->answer ) {
+	    G_fatal_error(_("Unable to create OGR data source '%s'. "
+	                    "Use the -u flag to update an existing data source"),
+	                  dsn_opt->answer);	
+	} else {
+	    G_fatal_error(_("Unable to open OGR data source '%s'"),
+		          dsn_opt->answer);
+        }	
+    }
 
     /* parse layer creation options */
     i = 0;
@@ -376,7 +399,6 @@
 	    if (keycol == -1)
 		G_fatal_error(_("Key column '%s' not found"), Fi->key);
 	}
-
     }
 
     Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to