[GRASS-SVN] r59627 - grass/trunk/vector/v.in.ogr
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Apr 7 04:07:34 PDT 2014
Author: martinl
Date: 2014-04-07 04:07:34 -0700 (Mon, 07 Apr 2014)
New Revision: 59627
Modified:
grass/trunk/vector/v.in.ogr/main.c
grass/trunk/vector/v.in.ogr/v.in.ogr.html
Log:
v.in.ogr: use default DB settings when dsn is omitted (see the manual `dsn=./` - it was not working) - pg driver only
manual updated
Modified: grass/trunk/vector/v.in.ogr/main.c
===================================================================
--- grass/trunk/vector/v.in.ogr/main.c 2014-04-07 10:44:44 UTC (rev 59626)
+++ grass/trunk/vector/v.in.ogr/main.c 2014-04-07 11:07:34 UTC (rev 59627)
@@ -9,7 +9,7 @@
*
* PURPOSE: Import OGR vectors
*
- * COPYRIGHT: (C) 2003, 2011-2013 by the GRASS Development Team
+ * COPYRIGHT: (C) 2003, 2011-2014 by the GRASS Development Team
*
* This program is free software under the GNU General
* Public License (>=v2). Read the file COPYING that
@@ -100,6 +100,7 @@
int OFTIntegerListlength;
+ char *dsn;
char *output;
char **layer_names; /* names of layers to be imported */
int *layers; /* layer indexes */
@@ -318,7 +319,46 @@
exit(EXIT_SUCCESS);
}
- if (param.dsn->answer == NULL) {
+ /* dsn not specified, check default connection settings */
+ dsn = NULL;
+ if (strcmp(db_get_default_driver_name(), "pg") == 0 &&
+ param.dsn->answer == NULL) {
+ 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);
+ }
+
+ if (dsn == NULL) {
G_fatal_error(_("Required parameter <%s> not set"), param.dsn->key);
}
@@ -358,10 +398,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) {
@@ -380,7 +420,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);
Modified: grass/trunk/vector/v.in.ogr/v.in.ogr.html
===================================================================
--- grass/trunk/vector/v.in.ogr/v.in.ogr.html 2014-04-07 10:44:44 UTC (rev 59626)
+++ grass/trunk/vector/v.in.ogr/v.in.ogr.html 2014-04-07 11:07:34 UTC (rev 59627)
@@ -217,49 +217,55 @@
<h3>PostGIS tables</h3>
-Area example:
+Import polygons as areas:
<div class="code"><pre>
v.in.ogr dsn="PG:host=localhost dbname=postgis user=postgres" layer=polymap \
output=polygons type=boundary,centroid
</pre></div>
-<h3>Oracle Spatial maps</h3>
+<h3>Default connection settings as datasource (PostgreSQL only)</h3>
-Note that you have to set the environment-variables <tt>ORACLE_BASE,
-ORACLE_SID, ORACLE_HOME</tt> and <tt>TNS_ADMIN</tt> accordingly.
+Datasource (<b>dsn</b>) can be omitted in the case that default DB
+driver is <a href="grass-pg.html">PostgreSQL</a> (<tt>pg</tt>), see
+examples below.
-<div class="code"><pre>
-v.in.ogr dsn=OCI:username/password at database_instance output=grasslayer layer=roads_oci
-</pre></div>
-
-<h3>Support of database schema</h3>
-
<p>
For schema support, first set a default schema with
<em><a href="db.connect.html">db.connect</a></em>. If schema support
-is used the schema name must be specified whenever a db.* module is
-called.
+is used the schema name must be specified whenever a <tt>db.*</tt>
+module is called. User and password for connection to the database can
+be specified by <em><a href="db.login.html">db.login</a></em>.
<p>
-Example:
+Example (with schema):
<div class="code"><pre>
-db.connect driver=pg database=test schema=user1 group=group1
-db.login driver=pg database=test user=user1 password=pwd1
-v.in.ogr dsn=./ layer=river output=river # -> table user1.river
+db.connect driver=pg database=test schema=user1
+db.login user=user1 password=pwd1
+v.in.ogr layer=river output=river # -> table user1.river
db.select table=user1.river
</pre></div>
+<p>
The user can ignore schemas, if desired:
<div class="code"><pre>
db.connect driver=pg database=test
-db.login driver=pg database=test user=user1 password=pwd1
-v.in.ogr dsn=./ layer=river output=river # -> table public.river
+db.login user=user1 password=pwd1
+v.in.ogr layer=river output=river # -> table public.river
db.select table=river
</pre></div>
+<h3>Oracle Spatial</h3>
+
+Note that you have to set the environment-variables <tt>ORACLE_BASE,
+ORACLE_SID, ORACLE_HOME</tt> and <tt>TNS_ADMIN</tt> accordingly.
+
+<div class="code"><pre>
+v.in.ogr dsn=OCI:username/password at database_instance output=grasslayer layer=roads_oci
+</pre></div>
+
<h2>WARNINGS</h2>
If a message like "WARNING: Area size 1.3e-06, area not
More information about the grass-commit
mailing list