[GRASS-SVN] r51049 - in grass/trunk: include/defs lib/vector/Vlib lib/vector/diglib

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Mar 12 10:50:43 EDT 2012


Author: martinl
Date: 2012-03-12 07:50:43 -0700 (Mon, 12 Mar 2012)
New Revision: 51049

Modified:
   grass/trunk/include/defs/vector.h
   grass/trunk/lib/vector/Vlib/build.c
   grass/trunk/lib/vector/Vlib/init_head.c
   grass/trunk/lib/vector/Vlib/map.c
   grass/trunk/lib/vector/Vlib/open.c
   grass/trunk/lib/vector/Vlib/write.c
   grass/trunk/lib/vector/Vlib/write_ogr.c
   grass/trunk/lib/vector/Vlib/write_pg.c
   grass/trunk/lib/vector/Vlib/write_sfa.c
   grass/trunk/lib/vector/diglib/spindex.c
Log:
vlib(pg): introduce V1_rewrite_line_pg() and V1_rewrite_line_sfa()
	  minor various updates


Modified: grass/trunk/include/defs/vector.h
===================================================================
--- grass/trunk/include/defs/vector.h	2012-03-12 11:42:23 UTC (rev 51048)
+++ grass/trunk/include/defs/vector.h	2012-03-12 14:50:43 UTC (rev 51049)
@@ -488,23 +488,23 @@
 int V2_close_ogr(struct Map_info *);
 int V2_close_pg(struct Map_info *);
 
-/* Read/write lines */
+/* Read/write lines (internal use only) */
 int V1_read_line_nat(struct Map_info *, struct line_pnts *,
 		     struct line_cats *, off_t);
 int V1_read_line_ogr(struct Map_info *, struct line_pnts *,
 		     struct line_cats *, off_t);
 int V1_read_line_pg(struct Map_info *, struct line_pnts *,
 		    struct line_cats *, off_t);
+int V2_read_line_nat(struct Map_info *, struct line_pnts *,
+		     struct line_cats *, int);
+int V2_read_line_sfa(struct Map_info *, struct line_pnts *,
+		     struct line_cats *, int);
 int V1_read_next_line_nat(struct Map_info *, struct line_pnts *,
 			  struct line_cats *);
 int V1_read_next_line_ogr(struct Map_info *, struct line_pnts *,
 			  struct line_cats *);
 int V1_read_next_line_pg(struct Map_info *, struct line_pnts *,
 			 struct line_cats *);
-int V2_read_line_nat(struct Map_info *, struct line_pnts *,
-		     struct line_cats *, int);
-int V2_read_line_sfa(struct Map_info *, struct line_pnts *,
-		     struct line_cats *, int);
 int V2_read_next_line_nat(struct Map_info *, struct line_pnts *,
 			  struct line_cats *);
 int V2_read_next_line_ogr(struct Map_info *, struct line_pnts *,
@@ -512,30 +512,32 @@
 int V2_read_next_line_pg(struct Map_info *, struct line_pnts *,
 			 struct line_cats *);
 int V1_delete_line_nat(struct Map_info *, off_t);
-int V2_delete_line_nat(struct Map_info *, int);
 int V1_delete_line_ogr(struct Map_info *, off_t);
 int V1_delete_line_pg(struct Map_info *, off_t);
+int V2_delete_line_nat(struct Map_info *, int);
 int V2_delete_line_sfa(struct Map_info *, int);
 int V1_restore_line_nat(struct Map_info *, off_t);
 int V2_restore_line_nat(struct Map_info *, int, off_t);
 off_t V1_write_line_nat(struct Map_info *, int, const struct line_pnts *,
 			const struct line_cats *);
-off_t V2_write_line_nat(struct Map_info *, int, const struct line_pnts *,
-			const struct line_cats *);
 off_t V1_write_line_ogr(struct Map_info *, int, const struct line_pnts *,
 			const struct line_cats *);
 off_t V1_write_line_pg(struct Map_info *, int, const struct line_pnts *,
 		       const struct line_cats *);
+off_t V2_write_line_nat(struct Map_info *, int, const struct line_pnts *,
+			const struct line_cats *);
 off_t V2_write_line_sfa(struct Map_info *, int, const struct line_pnts *,
 			const struct line_cats *);
 off_t V1_rewrite_line_nat(struct Map_info *, int, int, off_t,
 			  const struct line_pnts *, const struct line_cats *);
+off_t V1_rewrite_line_ogr(struct Map_info *, int, int, off_t,
+			  const struct line_pnts *, const struct line_cats *);
+off_t V1_rewrite_line_pg(struct Map_info *, int, int, off_t,
+			 const struct line_pnts *, const struct line_cats *);
 off_t V2_rewrite_line_nat(struct Map_info *, int, int, off_t,
 			  const struct line_pnts *, const struct line_cats *);
-off_t V1_rewrite_line_ogr(struct Map_info *, int, int, off_t,
+off_t V2_rewrite_line_sfa(struct Map_info *, int, int, off_t,
 			  const struct line_pnts *, const struct line_cats *);
-off_t V2_rewrite_line_ogr(struct Map_info *, int, int, off_t,
-			  const struct line_pnts *, const struct line_cats *);
 
     /* Build topology */
 int Vect_build_nat(struct Map_info *, int);

Modified: grass/trunk/lib/vector/Vlib/build.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build.c	2012-03-12 11:42:23 UTC (rev 51048)
+++ grass/trunk/lib/vector/Vlib/build.c	2012-03-12 14:50:43 UTC (rev 51049)
@@ -1075,14 +1075,13 @@
 
     plus = &(Map->plus);
 
-    if (plus->Spidx_built == 0) {
+    if (plus->Spidx_built == FALSE) {
 	G_warning("Spatial index not available, can not be saved");
 	return 0;
     }
 
     /* new or update mode ? */
-    if (plus->Spidx_new == 1) {
-
+    if (plus->Spidx_new == TRUE) {
 	/*  write out rtrees to sidx file  */
 	sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
 	G_file_name(fname, buf, GV_SIDX_ELEMENT, Map->mapset);
@@ -1103,12 +1102,12 @@
 	    return 0;
 	}
 	dig_spidx_free(plus);
-	Map->plus.Spidx_new = 0;
+	Map->plus.Spidx_new = FALSE;
     }
 
     fclose(Map->plus.spidx_fp.file);
 
-    Map->plus.Spidx_built = 0;
+    Map->plus.Spidx_built = FALSE;
 
     return 1;
 }

Modified: grass/trunk/lib/vector/Vlib/init_head.c
===================================================================
--- grass/trunk/lib/vector/Vlib/init_head.c	2012-03-12 11:42:23 UTC (rev 51048)
+++ grass/trunk/lib/vector/Vlib/init_head.c	2012-03-12 14:50:43 UTC (rev 51049)
@@ -65,9 +65,9 @@
     Vect_set_zone(Map, -1);
 
     /* support variables */
-    Map->plus.Spidx_built = 0;
-    Map->plus.release_support = 0;
-    Map->plus.update_cidx = 0;
+    Map->plus.Spidx_built = FALSE;
+    Map->plus.release_support = FALSE;
+    Map->plus.update_cidx = FALSE;
 }
 
 /*!

Modified: grass/trunk/lib/vector/Vlib/map.c
===================================================================
--- grass/trunk/lib/vector/Vlib/map.c	2012-03-12 11:42:23 UTC (rev 51048)
+++ grass/trunk/lib/vector/Vlib/map.c	2012-03-12 14:50:43 UTC (rev 51049)
@@ -842,7 +842,7 @@
  */
 void Vect_set_release_support(struct Map_info *Map)
 {
-    Map->plus.release_support = 1;
+    Map->plus.release_support = TRUE;
 }
 
 /*!
@@ -858,5 +858,5 @@
  */
 void Vect_set_category_index_update(struct Map_info *Map)
 {
-    Map->plus.update_cidx = 1;
+    Map->plus.update_cidx = TRUE;
 }

Modified: grass/trunk/lib/vector/Vlib/open.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open.c	2012-03-12 11:42:23 UTC (rev 51048)
+++ grass/trunk/lib/vector/Vlib/open.c	2012-03-12 14:50:43 UTC (rev 51049)
@@ -996,7 +996,7 @@
     G_debug(1, "Vect_open_sidx(): name = %s mapset= %s mode = %s", Map->name,
 	    Map->mapset, mode == 0 ? "old" : (mode == 1 ? "update" : "new"));
 
-    if (Map->plus.Spidx_built == 1) {
+    if (Map->plus.Spidx_built == TRUE) {
 	G_warning("Spatial index already opened");
 	return 0;
     }
@@ -1026,7 +1026,7 @@
 	Vect_coor_info(Map, &CInfo);
 
 	/* initialize spatial index */
-	Map->plus.Spidx_new = 0;
+	Map->plus.Spidx_new = FALSE;
 
 	/* load head */
 	if (dig_Rd_spidx_head(&(Map->plus.spidx_fp), Plus) == -1) {
@@ -1060,7 +1060,7 @@
 
     if (mode) {
 	/* open new spatial index */
-	Map->plus.Spidx_new = 1;
+	Map->plus.Spidx_new = TRUE;
 	
 	/* file based or memory based */
 	if (getenv("GRASS_VECTOR_LOWMEM")) {
@@ -1082,7 +1082,7 @@
 	}
     }
 
-    Map->plus.Spidx_built = 1;
+    Map->plus.Spidx_built = TRUE;
 
     return 0;
 }

Modified: grass/trunk/lib/vector/Vlib/write.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write.c	2012-03-12 11:42:23 UTC (rev 51048)
+++ grass/trunk/lib/vector/Vlib/write.c	2012-03-12 14:50:43 UTC (rev 51049)
@@ -93,9 +93,9 @@
 	rewrite_dummy, V1_rewrite_line_nat, V2_rewrite_line_nat}
 #ifdef HAVE_OGR
     , {
-	rewrite_dummy, V1_rewrite_line_ogr, V2_rewrite_line_ogr}
+	rewrite_dummy, V1_rewrite_line_ogr, V2_rewrite_line_sfa}
     , {
-	rewrite_dummy, V1_rewrite_line_ogr, V2_rewrite_line_ogr}
+	rewrite_dummy, V1_rewrite_line_ogr, V2_rewrite_line_sfa}
 #else
     , {
 	rewrite_dummy, format_l, format_l}
@@ -104,7 +104,7 @@
 #endif
 #ifdef HAVE_POSTGRES
     , {
-	rewrite_dummy, rewrite_dummy, rewrite_dummy}
+	rewrite_dummy, V1_rewrite_line_pg, V2_rewrite_line_sfa}
 #else
     , {
 	rewrite_dummy, format_l, format_l}
@@ -222,21 +222,20 @@
 {
     off_t ret, offset;
     
-    G_debug(3, "Vect_rewrite_line(): name = %s, line = %d", Map->name, line);
-    
     if (!VECT_OPEN(Map))
 	G_fatal_error(_("Unable to rewrite feature, vector map is not opened"));
 
     if (!(Map->plus.update_cidx)) {
-	Map->plus.cidx_up_to_date = 0;
+	Map->plus.cidx_up_to_date = FALSE;
     }
 
     offset = Map->plus.Line[line]->offset;
-    G_debug(3, "   offset=%llu", Map->plus.Line[line]->offset);
-    ret =
-	(*Vect_rewrite_line_array[Map->format][Map->level]) (Map, line, type, offset,
-							     points, cats);
-
+    G_debug(3, "Vect_rewrite_line(): name = %s, line = %d offset = %llu",
+	    Map->name, line, offset);
+    ret = (*Vect_rewrite_line_array[Map->format][Map->level]) (Map, line, type,
+							       offset,
+							       points, cats);
+    
     if (ret == -1)
 	G_fatal_error(_("Unable to rewrite feature %d"), line);
 

Modified: grass/trunk/lib/vector/Vlib/write_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_ogr.c	2012-03-12 11:42:23 UTC (rev 51048)
+++ grass/trunk/lib/vector/Vlib/write_ogr.c	2012-03-12 14:50:43 UTC (rev 51049)
@@ -239,40 +239,6 @@
 }
 
 /*!
-  \brief Rewrites feature to 'coor' file (topology level) - internal use only
-  
-  \param Map pointer to Map_info structure
-  \param line feature id
-  \param type feature type (GV_POINT, GV_LINE, ...)
-  \param offset unused
-  \param points feature geometry
-  \param cats feature categories
-  
-  \return offset where line was rewritten
-  \return -1 on error
-*/
-off_t V2_rewrite_line_ogr(struct Map_info *Map, int line, int type, off_t offset,
-			  const struct line_pnts *points, const struct line_cats *cats)
-{
-    G_debug(3, "V2_rewrite_line_ogr(): line=%d type=%d offset=%llu",
-	    line, type, offset);
-
-#ifdef HAVE_OGR
-    if (type != V2_read_line_sfa(Map, NULL, NULL, line)) {
-	G_warning(_("Unable to rewrite feature (incompatible feature types)"));
-	return -1;
-    }
-
-    V2_delete_line_sfa(Map, line);
-
-    return V2_write_line_sfa(Map, type, points, cats);
-#else
-    G_fatal_error(_("GRASS is not compiled with OGR support"));
-    return -1;
-#endif
-}
-
-/*!
   \brief Deletes feature at the given offset (level 1)
   
   \param Map pointer Map_info structure

Modified: grass/trunk/lib/vector/Vlib/write_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_pg.c	2012-03-12 11:42:23 UTC (rev 51048)
+++ grass/trunk/lib/vector/Vlib/write_pg.c	2012-03-12 14:50:43 UTC (rev 51049)
@@ -187,6 +187,40 @@
 }
 
 /*!
+  \brief Rewrites feature at the given offset (level 1) (PostGIS interface)
+  
+  \param Map pointer to Map_info structure
+  \param offset feature offset
+  \param type feature type (GV_POINT, GV_LINE, ...)
+  \param points feature geometry
+  \param cats feature categories
+  
+  \return feature offset (rewriten feature)
+  \return -1 on error
+*/
+off_t V1_rewrite_line_pg(struct Map_info *Map,
+			 int line, int type, off_t offset,
+			 const struct line_pnts *points, const struct line_cats *cats)
+{
+    G_debug(3, "V1_rewrite_line_pg(): line=%d type=%d offset=%llu",
+	    line, type, offset);
+#ifdef HAVE_POSTGRES
+    if (type != V1_read_line_pg(Map, NULL, NULL, offset)) {
+	G_warning(_("Unable to rewrite feature (incompatible feature types)"));
+	return -1;
+    }
+
+    /* delete old */
+    V1_delete_line_pg(Map, offset);
+
+    return V1_write_line_pg(Map, type, points, cats);
+#else
+    G_fatal_error(_("GRASS is not compiled with PostgreSQL support"));
+    return -1;
+#endif
+}
+
+/*!
   \brief Deletes feature at the given offset (level 1)
   
   \param Map pointer Map_info structure

Modified: grass/trunk/lib/vector/Vlib/write_sfa.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_sfa.c	2012-03-12 11:42:23 UTC (rev 51048)
+++ grass/trunk/lib/vector/Vlib/write_sfa.c	2012-03-12 14:50:43 UTC (rev 51049)
@@ -124,6 +124,40 @@
 }
 
 /*!
+  \brief Rewrites feature to 'coor' file (topology level) - internal use only
+  
+  \param Map pointer to Map_info structure
+  \param line feature id
+  \param type feature type (GV_POINT, GV_LINE, ...)
+  \param offset unused
+  \param points feature geometry
+  \param cats feature categories
+  
+  \return offset where line was rewritten
+  \return -1 on error
+*/
+off_t V2_rewrite_line_sfa(struct Map_info *Map, int line, int type, off_t offset,
+			  const struct line_pnts *points, const struct line_cats *cats)
+{
+    G_debug(3, "V2_rewrite_line_sfa(): line=%d type=%d offset=%llu",
+	    line, type, offset);
+
+#if defined HAVE_OGR || defined HAVE_POSTGRES
+    if (type != V2_read_line_sfa(Map, NULL, NULL, line)) {
+	G_warning(_("Unable to rewrite feature (incompatible feature types)"));
+	return -1;
+    }
+
+    V2_delete_line_sfa(Map, line);
+
+    return V2_write_line_sfa(Map, type, points, cats);
+#else
+    G_fatal_error(_("GRASS is not compiled with OGR/PostgreSQL support"));
+    return -1;
+#endif
+}
+
+/*!
   \brief Deletes feature (topology level) -- internal use only
   
   \todo Update fidx

Modified: grass/trunk/lib/vector/diglib/spindex.c
===================================================================
--- grass/trunk/lib/vector/diglib/spindex.c	2012-03-12 11:42:23 UTC (rev 51048)
+++ grass/trunk/lib/vector/diglib/spindex.c	2012-03-12 14:50:43 UTC (rev 51049)
@@ -85,7 +85,7 @@
     Plus->Volume_spidx_offset = 0L;
     Plus->Hole_spidx_offset = 0L;
 
-    Plus->Spidx_built = 0;
+    Plus->Spidx_built = FALSE;
     
     return 1;
 }



More information about the grass-commit mailing list