فهرست منبع

vlib/pg: remove topo file for PG-links (full 2D topology)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@51985 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 سال پیش
والد
کامیت
c1277796ab
2فایلهای تغییر یافته به همراه39 افزوده شده و 22 حذف شده
  1. 21 20
      lib/vector/Vlib/close.c
  2. 18 2
      lib/vector/Vlib/close_pg.c

+ 21 - 20
lib/vector/Vlib/close.c

@@ -60,6 +60,8 @@ static int (*Close_array[][2]) () = {
 #endif
 };
 
+static void unlink_file(const struct Map_info *, const char *);
+
 /*!
    \brief Close vector map
 
@@ -80,29 +82,15 @@ int Vect_close(struct Map_info *Map)
     if (strcmp(Map->mapset, G_mapset()) == 0 &&
 	Map->support_updated &&
 	Map->plus.built == GV_BUILD_ALL) {
-	char buf[GPATH_MAX];
-	char file_path[GPATH_MAX];
-
-	/* delete old support files if available */
-	sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
 
-	G_file_name(file_path, buf, GV_TOPO_ELEMENT, G_mapset());
-	if (access(file_path, F_OK) == 0)	/* file exists? */
-	    unlink(file_path);
+        unlink_file(Map, GV_TOPO_ELEMENT); /* topo */
 
-	G_file_name(file_path, buf, GV_SIDX_ELEMENT, G_mapset());
-	if (access(file_path, F_OK) == 0)	/* file exists? */
-	    unlink(file_path);
+	unlink_file(Map, GV_SIDX_ELEMENT); /* sidx */
 
-	G_file_name(file_path, buf, GV_CIDX_ELEMENT, G_mapset());
-	if (access(file_path, F_OK) == 0)	/* file exists? */
-	    unlink(file_path);
+	unlink_file(Map, GV_CIDX_ELEMENT); /* cidx */
 
-	if (Map->format == GV_FORMAT_OGR ||
-	    Map->format == GV_FORMAT_POSTGIS) {
-	    G_file_name(file_path, buf, GV_FIDX_ELEMENT, G_mapset());
-	    if (access(file_path, F_OK) == 0)	/* file exists? */
-		unlink(file_path);
+	if (Map->format == GV_FORMAT_OGR || Map->format == GV_FORMAT_POSTGIS) {
+	    unlink_file(Map, GV_FIDX_ELEMENT); /* fidx */
 	}
 	
 	Vect_coor_info(Map, &CInfo);
@@ -113,7 +101,7 @@ int Vect_close(struct Map_info *Map)
         Vect_save_topo(Map);
         
 	/* write out sidx file */
-	Map->plus.Spidx_new = TRUE;
+	Map->plus.Spidx_new = TRUE; /* force writing */
 	Vect_save_sidx(Map);
 
 	/* write out cidx file */
@@ -171,3 +159,16 @@ int Vect_close(struct Map_info *Map)
 
     return 0;
 }
+
+void unlink_file(const struct Map_info *Map, const char *name)
+{
+    char buf[GPATH_MAX];
+    char file_path[GPATH_MAX];
+
+    /* delete old support files if available */
+    sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
+
+    G_file_name(file_path, buf, name, G_mapset());
+    if (access(file_path, F_OK) == 0) /* file exists? */
+        unlink(file_path);
+}

+ 18 - 2
lib/vector/Vlib/close_pg.c

@@ -14,6 +14,7 @@
  */
 
 #include <stdlib.h>
+#include <unistd.h>
 #include <grass/vector.h>
 #include <grass/dbmi.h>
 #include <grass/glocale.h>
@@ -109,9 +110,24 @@ int V2_close_pg(struct Map_info *Map)
     if (!VECT_OPEN(Map))
         return -1;
 
-    if (Map->fInfo.pg.toposchema_name) /* no fidx file for PostGIS topology */
+    if (Map->fInfo.pg.toposchema_name) {
+        /* no fidx file for PostGIS topology
+           
+           remove topo file (which was required for saving sidx file)
+        */
+        char buf[GPATH_MAX];
+        char file_path[GPATH_MAX];
+        
+        /* delete old support files if available */
+        sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
+        
+        G_file_name(file_path, buf, GV_TOPO_ELEMENT, G_mapset());
+        if (access(file_path, F_OK) == 0) /* file exists? */
+            unlink(file_path);
+        
         return 0;
-
+    }
+    
     /* write fidx for maps in the current mapset */
     if (Vect_save_fidx(Map, &(Map->fInfo.pg.offset)) != 1)
         G_warning(_("Unable to save feature index file for vector map <%s>"),