[GRASS-SVN] r60748 - grass/branches/releasebranch_7_0/vector/v.in.ogr
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jun 8 03:49:09 PDT 2014
Author: hcho
Date: 2014-06-08 03:49:09 -0700 (Sun, 08 Jun 2014)
New Revision: 60748
Modified:
grass/branches/releasebranch_7_0/vector/v.in.ogr/main.c
Log:
v.in.ogr: pg driver check and datetime types merged from trunk
Modified: grass/branches/releasebranch_7_0/vector/v.in.ogr/main.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.in.ogr/main.c 2014-06-08 09:59:35 UTC (rev 60747)
+++ grass/branches/releasebranch_7_0/vector/v.in.ogr/main.c 2014-06-08 10:49:09 UTC (rev 60748)
@@ -102,6 +102,9 @@
int OFTIntegerListlength;
+ char *dsn;
+ const char *driver_name;
+ const char *datetime_type;
char *output;
char **layer_names; /* names of layers to be imported */
int *layers; /* layer indexes */
@@ -335,6 +338,54 @@
G_fatal_error(_("Required parameter <%s> not set"), param.dsn->key);
}
+ driver_name = db_get_default_driver_name();
+
+ if (strcmp(driver_name, "pg") == 0)
+ datetime_type = "timestamp";
+ else if (strcmp(driver_name, "dbf") == 0)
+ datetime_type = "varchar(22)";
+ else
+ datetime_type = "datetime";
+
+ /* dsn is 'PG:', check default connection settings */
+ dsn = NULL;
+ if (strcmp(driver_name, "pg") == 0 &&
+ G_strcasecmp(param.dsn->answer, "PG:") == 0) {
+ const char *dbname;
+ dbConnection conn;
+
+ dbname = db_get_default_database_name();
+ if (!dbname)
+ G_fatal_error(_("Database not defined, please check default "
+ " connection settings by db.connect"));
+
+ dsn = (char *) G_malloc(GPATH_MAX);
+ /* -> dbname */
+ sprintf(dsn, "PG:dbname=%s", dbname);
+
+ /* -> user/passwd */
+ if (DB_OK == db_get_connection(&conn) &&
+ strcmp(conn.driverName, "pg") == 0 &&
+ strcmp(conn.databaseName, dbname) == 0) {
+ if (conn.user) {
+ strcat(dsn, " user=");
+ strcat(dsn, conn.user);
+ }
+ if (conn.password) {
+ strcat(dsn, " passwd=");
+ strcat(dsn, conn.password);
+ }
+ /* TODO: host/port... */
+ }
+ else {
+ G_debug(1, "unable to get connection");
+ }
+ G_debug(1, "Using dsn=%s", dsn);
+ }
+ else if (param.dsn->answer) {
+ dsn = G_store(param.dsn->answer);
+ }
+
min_area = atof(param.min_area->answer);
snap = atof(param.snap->answer);
type = Vect_option_to_types(param.type);
@@ -371,10 +422,10 @@
/* open OGR DSN */
Ogr_ds = NULL;
- if (strlen(param.dsn->answer) > 0)
- Ogr_ds = OGROpen(param.dsn->answer, FALSE, NULL);
+ if (strlen(dsn) > 0)
+ Ogr_ds = OGROpen(dsn, FALSE, NULL);
if (Ogr_ds == NULL)
- G_fatal_error(_("Unable to open data source <%s>"), param.dsn->answer);
+ G_fatal_error(_("Unable to open data source <%s>"), dsn);
/* check encoding for given driver */
if (param.encoding->answer) {
@@ -393,7 +444,7 @@
if (flag.list->answer)
G_message(_("Data source <%s> (format '%s') contains %d layers:"),
- param.dsn->answer,
+ dsn,
OGR_Dr_GetName(OGR_DS_GetDriver(Ogr_ds)), navailable_layers);
for (i = 0; i < navailable_layers; i++) {
Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
@@ -815,7 +866,10 @@
/* open output vector */
/* strip any @mapset from vector output name */
G_find_vector(output, G_mapset());
- Vect_open_new(&Map, output, with_z);
+
+ if (Vect_open_new(&Map, output, with_z) < 0)
+ G_fatal_error(_("Unable to create vector map <%s>"), output);
+
Out = ⤅
if (!flag.no_clean->answer) {
@@ -824,7 +878,9 @@
* at the end copy alive lines to output vector
* in case of polygons this reduces the coor file size by a factor of 2 to 5
* only needed when cleaning polygons */
- Vect_open_tmp_new(&Tmp, NULL, with_z);
+ if (Vect_open_tmp_new(&Tmp, NULL, with_z) < 0)
+ G_fatal_error(_("Unable to create temporary vector map"));
+
G_verbose_message(_("Using temporary vector <%s>"), Vect_get_name(&Tmp));
Out = &Tmp;
}
@@ -965,7 +1021,7 @@
sprintf(buf, ", %s time", Ogr_fieldname);
}
else if (Ogr_ftype == OFTDateTime) {
- sprintf(buf, ", %s datetime", Ogr_fieldname);
+ sprintf(buf, ", %s %s", Ogr_fieldname, datetime_type);
#endif
}
else if (Ogr_ftype == OFTString) {
More information about the grass-commit
mailing list