[GRASS-SVN] r39555 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 18 05:13:13 EDT 2009


Author: martinl
Date: 2009-10-18 05:13:12 -0400 (Sun, 18 Oct 2009)
New Revision: 39555

Modified:
   grass/trunk/lib/vector/Vlib/build_ogr.c
   grass/trunk/lib/vector/Vlib/field.c
   grass/trunk/lib/vector/Vlib/open.c
Log:
vlib: switch to level1 if topology is not built for OGR layer
      * use table name for layer name if not defined


Modified: grass/trunk/lib/vector/Vlib/build_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build_ogr.c	2009-10-18 06:16:08 UTC (rev 39554)
+++ grass/trunk/lib/vector/Vlib/build_ogr.c	2009-10-18 09:13:12 UTC (rev 39555)
@@ -1,5 +1,5 @@
 /*!
-   \file build_ogr.c
+   \file lib/vector/Vlib/build_ogr.c
 
    \brief Vector library - Building topology for OGR
 
@@ -339,7 +339,8 @@
 
     /* test layer capabilities */
     if (!OGR_L_TestCapability(Map->fInfo.ogr.layer, OLCRandomRead)) {
-	G_warning(_("Random read is not supported by OGR for this layer, cannot build support"));
+	G_warning(_("Random read is not supported by OGR for this layer, "
+		    "unable to build topology"));
 	return 0;
     }
 

Modified: grass/trunk/lib/vector/Vlib/field.c
===================================================================
--- grass/trunk/lib/vector/Vlib/field.c	2009-10-18 06:16:08 UTC (rev 39554)
+++ grass/trunk/lib/vector/Vlib/field.c	2009-10-18 09:13:12 UTC (rev 39555)
@@ -70,7 +70,7 @@
 
   \param Map pointer to Map_info structure
   \param number layer number
-  \param name layer name
+  \param name layer name (if not given use table name)
   \param table table name
   \param key key name
   \param db database name
@@ -85,25 +85,26 @@
 {
     int ret;
 
-    if (number == 0) {
+    if (number < 1) {
 	G_warning(_("Layer number must be 1 or greater"));
 	return -1;
     }
 
     if (Map->mode != GV_MODE_WRITE && Map->mode != GV_MODE_RW) {
-	G_warning(_("Unable to add database link, map is not opened in WRITE mode"));
+	G_warning(_("Unable to add attribute link, vector map is "
+		    "not opened in WRITE mode"));
 	return -1;
     }
 
     ret = Vect_add_dblink(Map->dblnk, number, name, table, key, db, driver);
     if (ret == -1) {
-	G_warning(_("Unable to add database link"));
+	G_warning(_("Unable to add attribute link"));
 	return -1;
     }
     /* write it immediately otherwise it is lost if module crashes */
     ret = Vect_write_dblinks(Map);
     if (ret == -1) {
-	G_warning(_("Unable to write database links"));
+	G_warning(_("Unable to write attribute links"));
 	return -1;
     }
     return 0;
@@ -202,7 +203,7 @@
   
   \param[in,out] p pointer to existing dblinks structure
   \param number layer number (1 for OGR)
-  \param name   layer name (layer for OGR)
+  \param name   layer name (layer for OGR) - if not given use table name
   \param table  table name (layer for OGR)
   \param key    key name
   \param db     database name (datasource for OGR)
@@ -218,6 +219,10 @@
     int ret;
 
     G_debug(3, "Field number <%d>, name <%s>", number, name);
+    if (!name) {
+	/* if name is not given, use table name */
+	name = table;
+    }
     ret = Vect_check_dblink(p, number, name);
     if (ret == 1) {
 	G_warning(_("Layer number %d or name <%s> already exists"), number,
@@ -277,9 +282,8 @@
 
   \return pointer to new field_info structure
  */
-struct field_info
-    *Vect_default_field_info(struct Map_info *Map,
-			     int field, const char *field_name, int type)
+struct field_info *Vect_default_field_info(struct Map_info *Map,
+					   int field, const char *field_name, int type)
 {
     struct field_info *fi;
     char buf[1000], buf2[1000];
@@ -295,8 +299,7 @@
     db = G__getenv2("DB_DATABASE", G_VAR_MAPSET);
 
     G_debug(2, "drv = %s db = %s", drv, db);
-
-
+    
     if (!connection.driverName && !connection.databaseName) {
 	/* Set default values and create dbf db dir */
 	db_set_default_connection();

Modified: grass/trunk/lib/vector/Vlib/open.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open.c	2009-10-18 06:16:08 UTC (rev 39554)
+++ grass/trunk/lib/vector/Vlib/open.c	2009-10-18 09:13:12 UTC (rev 39555)
@@ -375,8 +375,9 @@
 	    G_message(_("Building topology for OGR layer <%s> from datasource '%s'..."),
 		      Map->fInfo.ogr.layer_name, Map->fInfo.ogr.dsn);
 	    G_set_verbose(0);
-	    Vect_build(Map);
-	    level = 2;
+	    if (Vect_build(Map)) {
+		level = 2;
+	    }
 	    G_set_verbose(verbose);
 	}
     }



More information about the grass-commit mailing list