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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 6 06:54:09 PDT 2012


Author: martinl
Date: 2012-06-06 06:54:08 -0700 (Wed, 06 Jun 2012)
New Revision: 51985

Modified:
   grass/trunk/lib/vector/Vlib/close.c
   grass/trunk/lib/vector/Vlib/close_pg.c
Log:
vlib/pg: remove topo file for PG-links (full 2D topology)


Modified: grass/trunk/lib/vector/Vlib/close.c
===================================================================
--- grass/trunk/lib/vector/Vlib/close.c	2012-06-06 13:26:09 UTC (rev 51984)
+++ grass/trunk/lib/vector/Vlib/close.c	2012-06-06 13:54:08 UTC (rev 51985)
@@ -60,6 +60,8 @@
 #endif
 };
 
+static void unlink_file(const struct Map_info *, const char *);
+
 /*!
    \brief Close vector map
 
@@ -80,29 +82,15 @@
     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);
+        unlink_file(Map, GV_TOPO_ELEMENT); /* topo */
 
-	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_SIDX_ELEMENT); /* sidx */
 
-	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_CIDX_ELEMENT); /* cidx */
 
-	G_file_name(file_path, buf, GV_CIDX_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) {
-	    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 @@
         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 @@
 
     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);
+}

Modified: grass/trunk/lib/vector/Vlib/close_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/close_pg.c	2012-06-06 13:26:09 UTC (rev 51984)
+++ grass/trunk/lib/vector/Vlib/close_pg.c	2012-06-06 13:54:08 UTC (rev 51985)
@@ -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 @@
     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>"),



More information about the grass-commit mailing list