Browse Source

vlib(pg): optimize V2_read_line_pg()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@55763 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 years ago
parent
commit
4d3e4e1c23
1 changed files with 14 additions and 17 deletions
  1. 14 17
      lib/vector/Vlib/read_pg.c

+ 14 - 17
lib/vector/Vlib/read_pg.c

@@ -311,7 +311,7 @@ int V2_read_line_pg(struct Map_info *Map, struct line_pnts *line_p,
                     struct line_cats *line_c, int line)
                     struct line_cats *line_c, int line)
 {
 {
 #ifdef HAVE_POSTGRES
 #ifdef HAVE_POSTGRES
-    int type, fid;
+    int fid;
     
     
     struct Format_info_pg *pg_info;
     struct Format_info_pg *pg_info;
     struct P_line *Line;
     struct P_line *Line;
@@ -335,14 +335,15 @@ int V2_read_line_pg(struct Map_info *Map, struct line_pnts *line_p,
     if (!line_p && !line_c)
     if (!line_p && !line_c)
         return Line->type;
         return Line->type;
 
 
-    if (line_p != NULL)
-        Vect_reset_line(line_p);
-    if (line_c != NULL)
+    if (line_c) {
         Vect_reset_cats(line_c);
         Vect_reset_cats(line_c);
-
-    if (line_c) 
         Vect_cat_set(line_c, 1, (int) Line->offset);
         Vect_cat_set(line_c, 1, (int) Line->offset);
+    }
+
+    if (!line_p)
+        return Line->type;
     
     
+    Vect_reset_line(line_p);
     if (Line->type == GV_CENTROID && !pg_info->toposchema_name) {
     if (Line->type == GV_CENTROID && !pg_info->toposchema_name) {
         /* simple features access: get centroid from sidx */
         /* simple features access: get centroid from sidx */
         return get_centroid(Map, line, line_p);
         return get_centroid(Map, line, line_p);
@@ -353,25 +354,21 @@ int V2_read_line_pg(struct Map_info *Map, struct line_pnts *line_p,
         fid = Line->offset;
         fid = Line->offset;
     else
     else
         fid = pg_info->offset.array[Line->offset];
         fid = pg_info->offset.array[Line->offset];
-    
+
+    /* read feature */
     get_feature(pg_info, fid, Line->type);
     get_feature(pg_info, fid, Line->type);
     
     
+    /* check sf type */
     if (pg_info->cache.sf_type == SF_NONE) {
     if (pg_info->cache.sf_type == SF_NONE) {
         G_warning(_("Feature %d without geometry skipped"), line);
         G_warning(_("Feature %d without geometry skipped"), line);
         return -1;
         return -1;
     }
     }
+    if (0 > (int)pg_info->cache.sf_type) /* -1 || - 2 */
+        return -1;
     
     
-    type = (int)pg_info->cache.sf_type;
-    if (type < 0)           /* -1 || - 2 */
-        return type;
-    
-    if (Line->type == GV_BOUNDARY && type == GV_LINE)
-        type = GV_BOUNDARY; /* feature is read as GV_LINE (linestring), force GV_BOUNDARY */
-    
-    if (line_p)
-        Vect_append_points(line_p, pg_info->cache.lines[0], GV_FORWARD);
+    Vect_append_points(line_p, pg_info->cache.lines[0], GV_FORWARD);
     
     
-    return type;
+    return Line->type;
 #else
 #else
     G_fatal_error(_("GRASS is not compiled with PostgreSQL support"));
     G_fatal_error(_("GRASS is not compiled with PostgreSQL support"));
     return -1;
     return -1;