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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 29 02:06:46 PST 2012


Author: martinl
Date: 2012-11-29 02:06:45 -0800 (Thu, 29 Nov 2012)
New Revision: 54101

Modified:
   grass/trunk/lib/vector/Vlib/build_pg.c
   grass/trunk/lib/vector/Vlib/open_pg.c
   grass/trunk/lib/vector/Vlib/write_pg.c
Log:
vlib/PostGIS Topology: report correct number of centroids and isles (work in progress)


Modified: grass/trunk/lib/vector/Vlib/build_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build_pg.c	2012-11-29 09:35:33 UTC (rev 54100)
+++ grass/trunk/lib/vector/Vlib/build_pg.c	2012-11-29 10:06:45 UTC (rev 54101)
@@ -122,7 +122,8 @@
 */
 int build_topo(struct Map_info *Map, int build)
 {
-    int line, type, topo_id, area, nareas, s;
+    int line, type, topo_id, s;
+    int area, nareas, isle, nisles;
     int face[2];
     char stmt[DB_SQL_MAX];
     
@@ -180,7 +181,7 @@
 
         /* delete faces */        
         sprintf(stmt, "DELETE FROM \"%s\".face WHERE "
-                "face_id > 0", pg_info->toposchema_name);
+                "face_id != 0", pg_info->toposchema_name);
         G_debug(2, "SQL: %s", stmt);
         if(Vect__execute_pg(pg_info->conn, stmt) == -1) {
             Vect__execute_pg(pg_info->conn, "ROLLBACK");
@@ -215,6 +216,15 @@
         }
     }
     
+    if (build >= GV_BUILD_ATTACH_ISLES) {
+        /* insert isles as faces with negative face_id */
+        nisles = Vect_get_num_islands(Map);
+        for(isle = 1; isle <= nisles; isle++) {
+            Isle = plus->Isle[isle];
+            Vect__insert_face_pg(Map, -isle);
+        }
+    }
+
     G_message(_("Updating TopoGeometry data..."));
     for (line = 1; line <= plus->n_lines; line++) {
         type = Vect_read_line(Map, NULL, NULL, line); 

Modified: grass/trunk/lib/vector/Vlib/open_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open_pg.c	2012-11-29 09:35:33 UTC (rev 54100)
+++ grass/trunk/lib/vector/Vlib/open_pg.c	2012-11-29 10:06:45 UTC (rev 54101)
@@ -1389,9 +1389,11 @@
     plus->n_areas = Vect__execute_get_value_pg(pg_info->conn, stmt);
     G_debug(3, "Vect_open_topo_pg(): n_areas=%d", plus->n_areas);
 
-    /* isles (faces with face_id <=0 in PostGIS Topology model) */
+    /* isles (faces with face_id <=0 in PostGIS Topology model)
+       note: universal face is represented in GRASS Topology model as isle (area=0)
+    */
     sprintf(stmt,
-            "SELECT COUNT(*) FROM \"%s\".face WHERE face_id < 1",
+            "SELECT COUNT(*) FROM \"%s\".face WHERE face_id < 0",
             pg_info->toposchema_name);
     plus->n_isles = Vect__execute_get_value_pg(pg_info->conn, stmt);
     G_debug(3, "Vect_open_topo_pg(): n_isles=%d", plus->n_isles);
@@ -1428,7 +1430,12 @@
 
     /* centroids */
     sprintf(stmt,
-            "SELECT COUNT(*) FROM \"%s\".face WHERE mbr IS NOT NULL",
+            "SELECT COUNT(*) FROM \"%s\".node WHERE containing_face "
+            "IS NOT NULL AND node_id NOT IN "
+            "(SELECT node FROM (SELECT start_node AS node FROM \"%s\".edge "
+            "GROUP BY start_node UNION ALL SELECT end_node AS node FROM "
+            "\"%s\".edge GROUP BY end_node) AS foo)",
+            pg_info->toposchema_name, pg_info->toposchema_name,
             pg_info->toposchema_name);
     plus->n_clines = Vect__execute_get_value_pg(pg_info->conn, stmt);
     G_debug(3, "Vect_open_topo_pg(): n_clines=%d", plus->n_clines);
@@ -1599,7 +1606,7 @@
     G_debug(2, "SQL: %s", stmt);
     res = PQexec(pg_info->conn, stmt);
     if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
-        PQntuples(res) > plus->n_clines) {
+        PQntuples(res) != plus->n_clines) {
         G_warning(_("Inconsistency in topology: number of "
                     "centroids %d (should be %d)"),
                   PQntuples(res), plus->n_clines);

Modified: grass/trunk/lib/vector/Vlib/write_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_pg.c	2012-11-29 09:35:33 UTC (rev 54100)
+++ grass/trunk/lib/vector/Vlib/write_pg.c	2012-11-29 10:06:45 UTC (rev 54101)
@@ -1354,7 +1354,7 @@
   \brief Insert new face to the 'face' table (topo only)
 
   \param Map pointer to Map_info struct
-  \param area area id
+  \param area area id (negative id for isles)
 
   \return 0 on error
   \return area id on success (>0)
@@ -1366,7 +1366,7 @@
     struct Format_info_pg *pg_info;
     struct bound_box box;
     
-    if (area <= 0)
+    if (area == 0)
         return 0; /* universal face has id '0' in PostGIS Topology */
 
     stmt = NULL;
@@ -1375,7 +1375,10 @@
     /* check if face exists */
     
     /* get mbr of the area */
-    Vect_get_area_box(Map, area, &box);
+    if (area > 0)
+        Vect_get_area_box(Map, area, &box);
+    else
+        Vect_get_isle_box(Map, abs(area), &box);
     
     /* insert face if not exists */
     G_asprintf(&stmt, "INSERT INTO \"%s\".face (face_id, mbr) VALUES "



More information about the grass-commit mailing list