Sfoglia il codice sorgente

vlib(pg): introduce V1_rewrite_line_pg() and V1_rewrite_line_sfa()
minor various updates


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@51049 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 13 anni fa
parent
commit
1655b43918

+ 13 - 11
include/defs/vector.h

@@ -488,23 +488,23 @@ int V1_close_pg(struct Map_info *);
 int V2_close_ogr(struct Map_info *);
 int V2_close_ogr(struct Map_info *);
 int V2_close_pg(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 *,
 int V1_read_line_nat(struct Map_info *, struct line_pnts *,
 		     struct line_cats *, off_t);
 		     struct line_cats *, off_t);
 int V1_read_line_ogr(struct Map_info *, struct line_pnts *,
 int V1_read_line_ogr(struct Map_info *, struct line_pnts *,
 		     struct line_cats *, off_t);
 		     struct line_cats *, off_t);
 int V1_read_line_pg(struct Map_info *, struct line_pnts *,
 int V1_read_line_pg(struct Map_info *, struct line_pnts *,
 		    struct line_cats *, off_t);
 		    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 *,
 int V1_read_next_line_nat(struct Map_info *, struct line_pnts *,
 			  struct line_cats *);
 			  struct line_cats *);
 int V1_read_next_line_ogr(struct Map_info *, struct line_pnts *,
 int V1_read_next_line_ogr(struct Map_info *, struct line_pnts *,
 			  struct line_cats *);
 			  struct line_cats *);
 int V1_read_next_line_pg(struct Map_info *, struct line_pnts *,
 int V1_read_next_line_pg(struct Map_info *, struct line_pnts *,
 			 struct line_cats *);
 			 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 *,
 int V2_read_next_line_nat(struct Map_info *, struct line_pnts *,
 			  struct line_cats *);
 			  struct line_cats *);
 int V2_read_next_line_ogr(struct Map_info *, struct line_pnts *,
 int V2_read_next_line_ogr(struct Map_info *, struct line_pnts *,
@@ -512,29 +512,31 @@ int V2_read_next_line_ogr(struct Map_info *, struct line_pnts *,
 int V2_read_next_line_pg(struct Map_info *, struct line_pnts *,
 int V2_read_next_line_pg(struct Map_info *, struct line_pnts *,
 			 struct line_cats *);
 			 struct line_cats *);
 int V1_delete_line_nat(struct Map_info *, off_t);
 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_ogr(struct Map_info *, off_t);
 int V1_delete_line_pg(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 V2_delete_line_sfa(struct Map_info *, int);
 int V1_restore_line_nat(struct Map_info *, off_t);
 int V1_restore_line_nat(struct Map_info *, off_t);
 int V2_restore_line_nat(struct Map_info *, int, 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 *,
 off_t V1_write_line_nat(struct Map_info *, int, const struct line_pnts *,
 			const struct line_cats *);
 			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 *,
 off_t V1_write_line_ogr(struct Map_info *, int, const struct line_pnts *,
 			const struct line_cats *);
 			const struct line_cats *);
 off_t V1_write_line_pg(struct Map_info *, int, const struct line_pnts *,
 off_t V1_write_line_pg(struct Map_info *, int, const struct line_pnts *,
 		       const struct line_cats *);
 		       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 *,
 off_t V2_write_line_sfa(struct Map_info *, int, const struct line_pnts *,
 			const struct line_cats *);
 			const struct line_cats *);
 off_t V1_rewrite_line_nat(struct Map_info *, int, int, off_t,
 off_t V1_rewrite_line_nat(struct Map_info *, int, int, off_t,
 			  const struct line_pnts *, const struct line_cats *);
 			  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 V1_rewrite_line_ogr(struct Map_info *, int, int, off_t,
 			  const struct line_pnts *, const struct line_cats *);
 			  const struct line_pnts *, const struct line_cats *);
-off_t V2_rewrite_line_ogr(struct Map_info *, int, int, off_t,
+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 V2_rewrite_line_sfa(struct Map_info *, int, int, off_t,
 			  const struct line_pnts *, const struct line_cats *);
 			  const struct line_pnts *, const struct line_cats *);
 
 
     /* Build topology */
     /* Build topology */

+ 4 - 5
lib/vector/Vlib/build.c

@@ -1075,14 +1075,13 @@ int Vect_save_sidx(struct Map_info *Map)
 
 
     plus = &(Map->plus);
     plus = &(Map->plus);
 
 
-    if (plus->Spidx_built == 0) {
+    if (plus->Spidx_built == FALSE) {
 	G_warning("Spatial index not available, can not be saved");
 	G_warning("Spatial index not available, can not be saved");
 	return 0;
 	return 0;
     }
     }
 
 
     /* new or update mode ? */
     /* new or update mode ? */
-    if (plus->Spidx_new == 1) {
-
+    if (plus->Spidx_new == TRUE) {
 	/*  write out rtrees to sidx file  */
 	/*  write out rtrees to sidx file  */
 	sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
 	sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
 	G_file_name(fname, buf, GV_SIDX_ELEMENT, Map->mapset);
 	G_file_name(fname, buf, GV_SIDX_ELEMENT, Map->mapset);
@@ -1103,12 +1102,12 @@ int Vect_save_sidx(struct Map_info *Map)
 	    return 0;
 	    return 0;
 	}
 	}
 	dig_spidx_free(plus);
 	dig_spidx_free(plus);
-	Map->plus.Spidx_new = 0;
+	Map->plus.Spidx_new = FALSE;
     }
     }
 
 
     fclose(Map->plus.spidx_fp.file);
     fclose(Map->plus.spidx_fp.file);
 
 
-    Map->plus.Spidx_built = 0;
+    Map->plus.Spidx_built = FALSE;
 
 
     return 1;
     return 1;
 }
 }

+ 3 - 3
lib/vector/Vlib/init_head.c

@@ -65,9 +65,9 @@ void Vect__init_head(struct Map_info *Map)
     Vect_set_zone(Map, -1);
     Vect_set_zone(Map, -1);
 
 
     /* support variables */
     /* 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;
 }
 }
 
 
 /*!
 /*!

+ 2 - 2
lib/vector/Vlib/map.c

@@ -842,7 +842,7 @@ Vect_copy_table_by_cats(const struct Map_info *In, struct Map_info *Out,
  */
  */
 void Vect_set_release_support(struct Map_info *Map)
 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_release_support(struct Map_info *Map)
  */
  */
 void Vect_set_category_index_update(struct Map_info *Map)
 void Vect_set_category_index_update(struct Map_info *Map)
 {
 {
-    Map->plus.update_cidx = 1;
+    Map->plus.update_cidx = TRUE;
 }
 }

+ 4 - 4
lib/vector/Vlib/open.c

@@ -996,7 +996,7 @@ int Vect_open_sidx(struct Map_info *Map, int mode)
     G_debug(1, "Vect_open_sidx(): name = %s mapset= %s mode = %s", Map->name,
     G_debug(1, "Vect_open_sidx(): name = %s mapset= %s mode = %s", Map->name,
 	    Map->mapset, mode == 0 ? "old" : (mode == 1 ? "update" : "new"));
 	    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");
 	G_warning("Spatial index already opened");
 	return 0;
 	return 0;
     }
     }
@@ -1026,7 +1026,7 @@ int Vect_open_sidx(struct Map_info *Map, int mode)
 	Vect_coor_info(Map, &CInfo);
 	Vect_coor_info(Map, &CInfo);
 
 
 	/* initialize spatial index */
 	/* initialize spatial index */
-	Map->plus.Spidx_new = 0;
+	Map->plus.Spidx_new = FALSE;
 
 
 	/* load head */
 	/* load head */
 	if (dig_Rd_spidx_head(&(Map->plus.spidx_fp), Plus) == -1) {
 	if (dig_Rd_spidx_head(&(Map->plus.spidx_fp), Plus) == -1) {
@@ -1060,7 +1060,7 @@ int Vect_open_sidx(struct Map_info *Map, int mode)
 
 
     if (mode) {
     if (mode) {
 	/* open new spatial index */
 	/* open new spatial index */
-	Map->plus.Spidx_new = 1;
+	Map->plus.Spidx_new = TRUE;
 	
 	
 	/* file based or memory based */
 	/* file based or memory based */
 	if (getenv("GRASS_VECTOR_LOWMEM")) {
 	if (getenv("GRASS_VECTOR_LOWMEM")) {
@@ -1082,7 +1082,7 @@ int Vect_open_sidx(struct Map_info *Map, int mode)
 	}
 	}
     }
     }
 
 
-    Map->plus.Spidx_built = 1;
+    Map->plus.Spidx_built = TRUE;
 
 
     return 0;
     return 0;
 }
 }

+ 10 - 11
lib/vector/Vlib/write.c

@@ -93,9 +93,9 @@ static off_t (*Vect_rewrite_line_array[][3]) () = {
 	rewrite_dummy, V1_rewrite_line_nat, V2_rewrite_line_nat}
 	rewrite_dummy, V1_rewrite_line_nat, V2_rewrite_line_nat}
 #ifdef HAVE_OGR
 #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
 #else
     , {
     , {
 	rewrite_dummy, format_l, format_l}
 	rewrite_dummy, format_l, format_l}
@@ -104,7 +104,7 @@ static off_t (*Vect_rewrite_line_array[][3]) () = {
 #endif
 #endif
 #ifdef HAVE_POSTGRES
 #ifdef HAVE_POSTGRES
     , {
     , {
-	rewrite_dummy, rewrite_dummy, rewrite_dummy}
+	rewrite_dummy, V1_rewrite_line_pg, V2_rewrite_line_sfa}
 #else
 #else
     , {
     , {
 	rewrite_dummy, format_l, format_l}
 	rewrite_dummy, format_l, format_l}
@@ -222,21 +222,20 @@ off_t Vect_rewrite_line(struct Map_info *Map, int line, int type,
 {
 {
     off_t ret, offset;
     off_t ret, offset;
     
     
-    G_debug(3, "Vect_rewrite_line(): name = %s, line = %d", Map->name, line);
-    
     if (!VECT_OPEN(Map))
     if (!VECT_OPEN(Map))
 	G_fatal_error(_("Unable to rewrite feature, vector map is not opened"));
 	G_fatal_error(_("Unable to rewrite feature, vector map is not opened"));
 
 
     if (!(Map->plus.update_cidx)) {
     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;
     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)
     if (ret == -1)
 	G_fatal_error(_("Unable to rewrite feature %d"), line);
 	G_fatal_error(_("Unable to rewrite feature %d"), line);
 
 

+ 0 - 34
lib/vector/Vlib/write_ogr.c

@@ -239,40 +239,6 @@ off_t V1_rewrite_line_ogr(struct Map_info *Map,
 }
 }
 
 
 /*!
 /*!
-  \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)
   \brief Deletes feature at the given offset (level 1)
   
   
   \param Map pointer Map_info structure
   \param Map pointer Map_info structure

+ 34 - 0
lib/vector/Vlib/write_pg.c

@@ -187,6 +187,40 @@ off_t V1_write_line_pg(struct Map_info *Map, int type,
 }
 }
 
 
 /*!
 /*!
+  \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)
   \brief Deletes feature at the given offset (level 1)
   
   
   \param Map pointer Map_info structure
   \param Map pointer Map_info structure

+ 34 - 0
lib/vector/Vlib/write_sfa.c

@@ -124,6 +124,40 @@ off_t V2_write_line_sfa(struct Map_info *Map, int type,
 }
 }
 
 
 /*!
 /*!
+  \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
   \brief Deletes feature (topology level) -- internal use only
   
   
   \todo Update fidx
   \todo Update fidx

+ 1 - 1
lib/vector/diglib/spindex.c

@@ -85,7 +85,7 @@ int dig_spidx_init(struct Plus_head *Plus)
     Plus->Volume_spidx_offset = 0L;
     Plus->Volume_spidx_offset = 0L;
     Plus->Hole_spidx_offset = 0L;
     Plus->Hole_spidx_offset = 0L;
 
 
-    Plus->Spidx_built = 0;
+    Plus->Spidx_built = FALSE;
     
     
     return 1;
     return 1;
 }
 }