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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 22 08:46:28 PST 2013


Author: martinl
Date: 2013-11-22 08:46:28 -0800 (Fri, 22 Nov 2013)
New Revision: 58283

Modified:
   grass/trunk/lib/vector/Vlib/open_pg.c
   grass/trunk/lib/vector/Vlib/read_pg.c
Log:
vlib/pg: fix reading categories for centroids


Modified: grass/trunk/lib/vector/Vlib/open_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open_pg.c	2013-11-22 15:54:30 UTC (rev 58282)
+++ grass/trunk/lib/vector/Vlib/open_pg.c	2013-11-22 16:46:28 UTC (rev 58283)
@@ -52,7 +52,7 @@
 static void notice_processor(void *, const char *);
 static char **scan_array(const char *);
 static int remap_node(const struct Format_info_offset *, int);
-static int remap_line(const struct Plus_head*, int);
+static int remap_line(const struct Plus_head*, int, int);
 #endif
 
 /*!
@@ -948,7 +948,7 @@
     }
 
     /* set centroid */
-    area->centroid = remap_line(plus, centroid);
+    area->centroid = remap_line(plus, centroid, GV_CENTROID);
     
     G_free_tokens(lines);
     G_free_tokens(isles);
@@ -1567,15 +1567,16 @@
 /*!
   \brief Get line id from offset
 
-  \todo speed up
+  \todo Do it better, speed up
 
   \param plus pointer to Plus_head struct
   \param line line to find
+  \param type line type
 
   \return line id
   \return -1 not found
 */
-int remap_line(const struct Plus_head* plus, int line)
+int remap_line(const struct Plus_head* plus, int line, int type)
 {
     int i;
     
@@ -1584,7 +1585,7 @@
     for (i = 1; i <= plus->n_lines; i++) {
         Line = plus->Line[i];
         
-        if (!Line)
+        if (!Line || Line->type != type)
             continue;
         
         if ((int) Line->offset == line)

Modified: grass/trunk/lib/vector/Vlib/read_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read_pg.c	2013-11-22 15:54:30 UTC (rev 58282)
+++ grass/trunk/lib/vector/Vlib/read_pg.c	2013-11-22 16:46:28 UTC (rev 58283)
@@ -617,9 +617,13 @@
     
     /* cache also categories (only for PostGIS Topology) */
     if (pg_info->toposchema_name) {
-        if (!PQgetisnull(pg_info->res, pg_info->next_line, 3))
+        int col_idx;
+
+        col_idx = type & GV_POINTS ? 2 : 3;
+            
+        if (!PQgetisnull(pg_info->res, pg_info->next_line, col_idx))
             pg_info->cache.lines_cats[pg_info->cache.lines_next] =
-                atoi(PQgetvalue(pg_info->res, pg_info->next_line, 3)); 
+                atoi(PQgetvalue(pg_info->res, pg_info->next_line, col_idx)); 
         else
             pg_info->cache.lines_cats[pg_info->cache.lines_next] = -1; /* no cat */
     }
@@ -1364,19 +1368,33 @@
         }
         
         if (type & GV_POINTS) {
+            int topotype;
+            char *nodeid;
+            
+            if (type == GV_POINT) {
+                topotype = 1;
+                nodeid = pg_info->fid_column;
+            }
+            else { /* assuming GV_CENTROID */
+                topotype = 3;
+                nodeid = "containing_face";
+            }
+            
             sprintf(stmt,
-                    "SELECT tt.geom,tt.containing_face,ft.fid FROM \"%s\".node AS tt "
-                    "LEFT JOIN \"%s\" AS ft ON (%s).type = 1 and (%s).id = node_id "
+                    "SELECT tt.geom,tt.containing_face,ft.%s FROM \"%s\".node AS tt "
+                    "LEFT JOIN \"%s\" AS ft ON (%s).type = %d and (%s).id = %s "
                     "WHERE node_id = %d",
-                    pg_info->toposchema_name, pg_info->table_name, pg_info->topogeom_column,
-                    pg_info->topogeom_column, fid);
+                    pg_info->fid_column, pg_info->toposchema_name,
+                    pg_info->table_name, pg_info->topogeom_column,
+                    topotype, pg_info->topogeom_column, nodeid, fid);
         }
         else {
             sprintf(stmt,
-                    "SELECT tt.geom,tt.left_face,tt.right_face,ft.fid FROM \"%s\".edge AS tt "
+                    "SELECT tt.geom,tt.left_face,tt.right_face,ft.%s FROM \"%s\".edge AS tt "
                     "LEFT JOIN \"%s\" AS ft ON (%s).type = 2 and (%s).id = edge_id "
                     "WHERE edge_id = %d",
-                    pg_info->toposchema_name, pg_info->table_name, pg_info->topogeom_column,
+                    pg_info->fid_column,  pg_info->toposchema_name, 
+                    pg_info->table_name, pg_info->topogeom_column,
                     pg_info->topogeom_column, fid);
         }
     }



More information about the grass-commit mailing list