[GRASS-SVN] r48947 - in grass/trunk: include include/vect lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Oct 26 05:05:20 EDT 2011


Author: martinl
Date: 2011-10-26 02:05:20 -0700 (Wed, 26 Oct 2011)
New Revision: 48947

Modified:
   grass/trunk/include/vect/dig_defines.h
   grass/trunk/include/vector.h
   grass/trunk/lib/vector/Vlib/field.c
Log:
vlib: add Vect_copy_map_dblinks()
      fix Vect_get_field2() for -1 (all layers)


Modified: grass/trunk/include/vect/dig_defines.h
===================================================================
--- grass/trunk/include/vect/dig_defines.h	2011-10-25 21:16:24 UTC (rev 48946)
+++ grass/trunk/include/vect/dig_defines.h	2011-10-26 09:05:20 UTC (rev 48947)
@@ -117,27 +117,24 @@
 /*! \brief Vector map close code */
 #define VECT_CLOSED_CODE 0x22AA2255
 
-/*! \brief Vector level
-
-  - 1 without topology
-  - 2 topology
-  - 3 ?
-*/
+/*! \brief Vector level - without topology */
 #define LEVEL_1  1
+/*! \brief Vector level - with topology */
 #define LEVEL_2  2
+/*! \brief Vector level - ? */
 #define LEVEL_3  3
 
-/*! \brief Topology level details */
-/*! \brief Nothing to build */
+/*! \brief Topology levels - nothing to build */
 #define GV_BUILD_NONE         0
-/*! \brief Basic level */
+/*! \brief Topology levels - basic level (without areas and isles) */
 #define GV_BUILD_BASE         1
-/*! \brief Build areas */
+/*! \brief Topology levels - build areas */
 #define GV_BUILD_AREAS        2
-/*! \brief Attach islands to areas */
+/*! \brief Topology levels - attach islands to areas */
 #define GV_BUILD_ATTACH_ISLES 3
-/*! \brief Assign centroids to areas */
+/*! \brief Topology levels - assign centroids to areas */
 #define GV_BUILD_CENTROIDS    4
+/*! \brief Topology levels - build everything (currently same as GV_BUILD_CENTROIDS) */
 #define GV_BUILD_ALL          GV_BUILD_CENTROIDS
 
 /*! \brief Check if vector map is open */

Modified: grass/trunk/include/vector.h
===================================================================
--- grass/trunk/include/vector.h	2011-10-25 21:16:24 UTC (rev 48946)
+++ grass/trunk/include/vector.h	2011-10-26 09:05:20 UTC (rev 48947)
@@ -103,6 +103,7 @@
 			const char *, const char *, const char *,
 			const char *);
 int Vect_map_del_dblink(struct Map_info *, int);
+void Vect_copy_map_dblinks(const struct Map_info *, struct Map_info *, int);
 int Vect_map_check_dblink(const struct Map_info *, int, const char *);
 int Vect_read_dblinks(struct Map_info *);
 int Vect_write_dblinks(struct Map_info *);

Modified: grass/trunk/lib/vector/Vlib/field.c
===================================================================
--- grass/trunk/lib/vector/Vlib/field.c	2011-10-25 21:16:24 UTC (rev 48946)
+++ grass/trunk/lib/vector/Vlib/field.c	2011-10-26 09:05:20 UTC (rev 48947)
@@ -155,11 +155,41 @@
 }
 
 /*!
+  \brief Copy DB links from input vector map to output vector map
+
+  \param In pointer to Map_info structure (input)
+  \param Out pointer to Map_info structure (output)
+  \param first_only copy only first link
+*/
+void Vect_copy_map_dblinks(const struct Map_info *In, struct Map_info *Out,
+			   int first_only)
+{
+    int i, ndblinks;
+    struct field_info *Fi;
+    
+    ndblinks = Vect_get_num_dblinks(In);
+    for (i = 0; i < ndblinks; i++) {
+	Fi = Vect_get_dblink(In, 0);
+	if (!Fi) {
+	    G_warning(_("Database connection not defined. Skipping."));
+	    continue;
+	}
+	Vect_map_add_dblink(Out, Fi->number, Fi->name, Fi->table, Fi->key,
+			    Fi->database, Fi->driver);
+	
+	if (first_only && ndblinks > 1)
+	    G_warning(_("More DB links defined for input vector map. "
+			"Using only first DB link for output."));
+    }
+}
+
+/*!
   \brief Check if DB connection exists in dblinks structure
 
   \param Map pointer to Map_info structure
   \param field layer number
-
+  \param name layer name
+  
   \return 1 dblink for field exists
   \return 0 dblink does not exist for field
  */
@@ -453,6 +483,9 @@
 /*!
   \brief Get information about link to database (by layer number or layer name)
   
+  Note: if <em>field</em> is -1 then the function returns the first
+  dblink or NULL
+  
   \param Map pointer to Map_info structure
   \param field layer number or name
   
@@ -474,8 +507,16 @@
 	if (fi)
 	    return fi;
     }
+    else if (ifield == -1) {
+      if (Vect_get_num_dblinks(Map) > 0)
+	  return Vect_get_dblink(Map, 0); /* return first */
+      else
+	  return NULL;
+    }
+    else if (ifield == 0)
+	return Vect_get_field_by_name(Map, field);
 
-    return Vect_get_field_by_name(Map, field);
+    return NULL;
 }
 
 /*!



More information about the grass-commit mailing list