[GRASS-dev] v.out.ogr and data source that do not support "creation" or "overwrite"

Benjamin Ducke benjamin.ducke at oxfordarch.co.uk
Fri May 8 09:00:58 EDT 2009


Dear all,

I am experimenting a bit with SQLite spatial data storage and have found
the following problem in v.out.ogr (main.c, starting at ca. line 263):

    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);

Now, the last bit aborts operation whenever a new OGR data source could
not be created or an existing one overwritten. Unfortunately, there
are many database storage drivers in OGR, that do not support creation
of new data sources (i.e. databases), but only layers (i.e. tables
inside existing databases). With the current code, that capability
can never be used!

Either I am doing something really stupid here, or nobody has noticed
that problem before.

Anyway, a quick fix that works for me (but is not exactly pretty) is to
blindly attempt connecting to an existing source in case one of the
drivers with that problem is used:

     Ogr_ds = OGR_Dr_CreateDataSource(Ogr_driver, dsn_opt->answer, 
papszDSCO);

     /* some OGR drivers do not support overwriting existing sources
        or creating new ones */
     if (Ogr_ds == NULL) {
         if (!strcmp (frmt_opt->answer, "SQLite") ||
	    !strcmp (frmt_opt->answer, "PostgreSQL")) ||
	    !strcmp (frmt_opt->answer, "MySQL")) {
	    G_message(_("Attempting to open existing OGR data source.\n"));
             Ogr_ds =
	        OGR_Dr_Open(Ogr_driver, dsn_opt->answer, TRUE);
         }
     }

     CSLDestroy(papszDSCO);


That way, things work for me using existing SQLite databases.
I am sure there are many more trouble candidates among the OGR
drivers, but those are the ones I could come up with at first
glance.

There seem to be more problems with v.out.ogr and database storage.
I'll try to give this some more testing now.

Cheers,

Ben


-- 
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
benjamin.ducke at oxfordarch.co.uk




------
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.



More information about the grass-dev mailing list