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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 25 06:45:39 EDT 2011


Author: martinl
Date: 2011-08-25 03:45:39 -0700 (Thu, 25 Aug 2011)
New Revision: 47881

Modified:
   grass/trunk/lib/vector/Vlib/area.c
   grass/trunk/lib/vector/Vlib/read.c
   grass/trunk/lib/vector/Vlib/read_nat.c
   grass/trunk/lib/vector/Vlib/read_ogr.c
   grass/trunk/lib/vector/Vlib/rewind.c
   grass/trunk/lib/vector/Vlib/rewind_nat.c
   grass/trunk/lib/vector/Vlib/rewind_ogr.c
Log:
vlib: don't use random access for V2_read_next_line_ogr()
      various minor changes (related to OGR support)


Modified: grass/trunk/lib/vector/Vlib/area.c
===================================================================
--- grass/trunk/lib/vector/Vlib/area.c	2011-08-25 10:42:48 UTC (rev 47880)
+++ grass/trunk/lib/vector/Vlib/area.c	2011-08-25 10:45:39 UTC (rev 47881)
@@ -5,12 +5,10 @@
 
    Higher level functions for reading/writing/manipulating vectors.
 
-   (C) 2001-2009 by the GRASS Development Team
+   (C) 2001-2009, 2011 by the GRASS Development Team
 
-   This program is free software under the 
-   GNU General Public License (>=v2). 
-   Read the file COPYING that comes with GRASS
-   for details.
+   This program is free software under the GNU General Public License
+   (>=v2).  Read the file COPYING that comes with GRASS for details.
 
    \author Original author CERL, probably Dave Gerdes or Mike Higgins.
    \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
@@ -21,18 +19,17 @@
 #include <grass/glocale.h>
 
 /*!
-   \brief Returns polygon array of points of given area
+   \brief Returns polygon array of points (outer ring) of given area
 
-   \param Map vector map
+   \param Map pointer to Map_info structure
    \param area area id
    \param[out] BPoints points array
 
    \return number of points
    \return -1 on error
  */
-int
-Vect_get_area_points(const struct Map_info *Map,
-		     int area, struct line_pnts *BPoints)
+int Vect_get_area_points(const struct Map_info *Map,
+			 int area, struct line_pnts *BPoints)
 {
     int i, line, aline, dir;
     const struct Plus_head *Plus;
@@ -63,7 +60,7 @@
 	G_debug(3, "  append line(%d) = %d", i, line);
 
 	if (0 > Vect_read_line(Map, Points, NULL, aline)) {
-	    G_fatal_error("Cannot read line %d", aline);
+	    G_fatal_error(_("Unable to read read line %d"), aline);
 	}
 
 	G_debug(3, "  line n_points = %d", Points->n_points);
@@ -79,7 +76,7 @@
 	G_debug(3, "  area n_points = %d", BPoints->n_points);
     }
 
-    return (BPoints->n_points);
+    return BPoints->n_points;
 }
 
 /*!
@@ -145,7 +142,7 @@
    \param Map vector map
    \param area area id
 
-   \return centroid number of area
+   \return centroid id of area
    \return 0 if no centroid found
  */
 int Vect_get_area_centroid(const struct Map_info *Map, int area)

Modified: grass/trunk/lib/vector/Vlib/read.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read.c	2011-08-25 10:42:48 UTC (rev 47880)
+++ grass/trunk/lib/vector/Vlib/read.c	2011-08-25 10:45:39 UTC (rev 47881)
@@ -5,7 +5,7 @@
 
    Higher level functions for reading/writing/manipulating vectors.
 
-   (C) 2001-2009 by the GRASS Development Team
+   (C) 2001-2009, 2011 by the GRASS Development Team
 
    This program is free software under the GNU General Public License
    (>=v2).  Read the file COPYING that comes with GRASS for details.
@@ -61,6 +61,8 @@
 /*!
    \brief Read next vector feature (level 1 and 2)
 
+   This function implements sequential access.
+     
    \param Map pointer vector map
    \param[out] line_p feature geometry
    \param[out] line_c feature categories
@@ -83,8 +85,10 @@
 }
 
 /*!
-   \brief Read vector feature
+   \brief Read vector feature  (level 2 only)
 
+   This function implements random access.
+
    \param Map pointer to vector map
    \param[out] line_p feature geometry
    \param[out] line_c feature categories

Modified: grass/trunk/lib/vector/Vlib/read_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read_nat.c	2011-08-25 10:42:48 UTC (rev 47880)
+++ grass/trunk/lib/vector/Vlib/read_nat.c	2011-08-25 10:45:39 UTC (rev 47881)
@@ -10,7 +10,7 @@
    - Vect_read_constraint_type()
    - Vect_remove_constraints()
 
-   (C) 2001-2009 by the GRASS Development Team
+   (C) 2001-2009, 2011 by the GRASS Development Team
 
    This program is free software under the GNU General Public License
    (>=v2).  Read the file COPYING that comes with GRASS for details.
@@ -23,46 +23,47 @@
 #include <grass/vector.h>
 #include <grass/glocale.h>
 
-static int
-Vect__Read_line_nat(struct Map_info *,
-		    struct line_pnts *, struct line_cats *, off_t);
+static int read_line_nat(struct Map_info *,
+			 struct line_pnts *, struct line_cats *, off_t);
 
 /*!
- * \brief Read line from coor file on given offset.
- *
- * \param Map vector map 
- * \param[out] Points container used to store line points within
- * \param[out] Cats container used to store line categories within
- * \param offset given offset 
- *
- * \return line type
- * \return 0 dead line
- * \return -2 end of table (last row)
- * \return -1 out of memory
- */
-int
-V1_read_line_nat(struct Map_info *Map,
-		 struct line_pnts *Points,
-		 struct line_cats *Cats, off_t offset)
+  \brief Read line from coor file on given offset (level 1)
+  
+  This function implements random access on level 1.
+
+  \param Map vector map 
+  \param[out] Points container used to store line points within
+  \param[out] Cats container used to store line categories within
+  \param offset given offset 
+  
+  \return line type
+  \return 0 dead line
+  \return -2 end of table (last row)
+  \return -1 out of memory
+*/
+int V1_read_line_nat(struct Map_info *Map,
+		     struct line_pnts *Points,
+		     struct line_cats *Cats, off_t offset)
 {
-    return Vect__Read_line_nat(Map, Points, Cats, offset);
+    return read_line_nat(Map, Points, Cats, offset);
 }
 
 /*!
- * \brief Read next line from coor file.
- *
- * \param Map vector map layer
- * \param[out] line_p container used to store line points within
- * \param[out] line_c container used to store line categories within
- *
- * \return line type
- * \return 0 dead line
- * \return -2 end of table (last row)
- * \return -1 out of memory
- */
-int
-V1_read_next_line_nat(struct Map_info *Map,
-		      struct line_pnts *line_p, struct line_cats *line_c)
+  \brief Read next line from coor file.
+  
+  This function implements sequential access on level 1.
+    
+  \param Map vector map layer
+  \param[out] line_p container used to store line points within
+  \param[out] line_c container used to store line categories within
+  
+  \return line type
+  \return 0 dead line
+  \return -2 end of table (last row)
+  \return -1 out of memory
+*/
+int V1_read_next_line_nat(struct Map_info *Map,
+			  struct line_pnts *line_p, struct line_cats *line_c)
 {
     int itype;
     off_t offset;
@@ -75,7 +76,7 @@
 
     while (1) {
 	offset = dig_ftell(&(Map->dig_fp));
-	itype = Vect__Read_line_nat(Map, line_p, line_c, offset);
+	itype = read_line_nat(Map, line_p, line_c, offset);
 	if (itype < 0)
 	    return (itype);
 
@@ -104,21 +105,22 @@
 }
 
 /*!
- * \brief Reads any specified line, this is NOT affected by constraints
- *
- * \param Map vector map layer
- * \param[out] line_p container used to store line points within
- * \param[out] line_c container used to store line categories within
- * \param line line id
- *
- * \return line type ( > 0 )
- * \return 0 dead line
- * \return -1 out of memory
- * \return -2 end of file
- */
-int
-V2_read_line_nat(struct Map_info *Map,
-		 struct line_pnts *line_p, struct line_cats *line_c, int line)
+  \brief Reads any specified line, this is NOT affected by constraints
+ 
+  This function implements random access on level 2.
+ 
+  \param Map vector map layer
+  \param[out] line_p container used to store line points within
+  \param[out] line_c container used to store line categories within
+  \param line line id
+  
+  \return line type ( > 0 )
+  \return 0 dead line
+  \return -1 out of memory
+  \return -2 end of file
+*/
+int V2_read_line_nat(struct Map_info *Map,
+		     struct line_pnts *line_p, struct line_cats *line_c, int line)
 {
     struct P_line *Line;
 
@@ -131,24 +133,25 @@
 	G_fatal_error("V2_read_line_nat(): %s %d",
 		      _("Attempt to read dead line"), line);
 
-    return Vect__Read_line_nat(Map, line_p, line_c, Line->offset);
+    return read_line_nat(Map, line_p, line_c, Line->offset);
 }
 
 /*!
- * \brief Reads next unread line each time called.  Use Vect_rewind to reset.
- *
- * \param Map vector map layer
- * \param[out] line_p container used to store line points within
- * \param[out] line_c container used to store line categories within
- * 
- * \return line type ( > 0 )
- * \return 0 dead line
- * \return -1 out of memory
- * \return -2 end of file
- */
-int
-V2_read_next_line_nat(struct Map_info *Map,
-		      struct line_pnts *line_p, struct line_cats *line_c)
+  \brief Reads next unread line each time called.  Use Vect_rewind to reset.
+  
+  This function implements sequential access on level 2.
+
+  \param Map vector map layer
+  \param[out] line_p container used to store line points within
+  \param[out] line_c container used to store line categories within
+  
+  \return line type ( > 0 )
+  \return 0 dead line
+  \return -1 out of memory
+  \return -2 end of file
+*/
+int V2_read_next_line_nat(struct Map_info *Map,
+			  struct line_pnts *line_p, struct line_cats *line_c)
 {
     register int line, ret;
     register struct P_line *Line;
@@ -192,21 +195,20 @@
 
 
 /*!  
- * \brief Read line from coor file 
- *
- * \param Map vector map layer
- * \param[out] p container used to store line points within
- * \param[out] c container used to store line categories within
- * \param offset given offset
- *
- * \return line type ( > 0 )
- * \return 0 dead line
- * \return -1 out of memory
- * \return -2 end of file
- */
-int
-Vect__Read_line_nat(struct Map_info *Map,
-		    struct line_pnts *p, struct line_cats *c, off_t offset)
+  \brief Read line from coor file 
+  
+  \param Map vector map layer
+  \param[out] p container used to store line points within
+  \param[out] c container used to store line categories within
+  \param offset given offset
+  
+  \return line type ( > 0 )
+  \return 0 dead line
+  \return -1 out of memory
+  \return -2 end of file
+*/
+int read_line_nat(struct Map_info *Map,
+		  struct line_pnts *p, struct line_cats *c, off_t offset)
 {
     register int i, dead = 0;
     int n_points;
@@ -334,5 +336,5 @@
     if (dead)
 	return 0;
 
-    return (type);
+    return type;
 }

Modified: grass/trunk/lib/vector/Vlib/read_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read_ogr.c	2011-08-25 10:42:48 UTC (rev 47880)
+++ grass/trunk/lib/vector/Vlib/read_ogr.c	2011-08-25 10:45:39 UTC (rev 47881)
@@ -5,7 +5,7 @@
 
    Higher level functions for reading/writing/manipulating vectors.
 
-   (C) 2001-2010 by the GRASS Development Team
+   (C) 2001-2011 by the GRASS Development Team
 
    This program is free software under the GNU General Public License
    (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -21,17 +21,17 @@
 #include <ogr_api.h>
 
 /*!
- * \brief Recursively read feature and add all elements to points_cache and types_cache.
- *
- * ftype: if > 0 use this type (because parts of Polygon are read as wkbLineString)
- *
- * \param Map pointer to Map_info structure
- * \param[out] hGeom OGR geometry
- * \param ftype feature type
- * 
- * \return 0 on success
- * \return 1 on error
- */
+  \brief Recursively read feature and add all elements to points_cache and types_cache.
+  
+  ftype: if > 0 use this type (because parts of Polygon are read as wkbLineString)
+  
+  \param Map pointer to Map_info structure
+  \param[out] hGeom OGR geometry
+  \param ftype feature type
+  
+  \return 0 on success
+  \return 1 on error
+*/
 static int cache_feature(struct Map_info *Map, OGRGeometryH hGeom, int ftype)
 {
     int line, i, np, ng, tp;
@@ -119,21 +119,23 @@
 }
 
 /*!
- * \brief Read next feature from OGR layer. Skip empty features. (level 1)
- *
- *  The action of this routine can be modified by:
- *   - Vect_read_constraint_region()
- *   - Vect_read_constraint_type()
- *   - Vect_remove_constraints()
- *
- * \param Map pointer to Map_info structure
- * \param[out] line_p container used to store line points within
- * \param[out] line_c container used to store line categories within
- *
- * \return feature type
- * \return -2 no more features (EOF)
- * \return -1 out of memory
- */
+  \brief Read next feature from OGR layer. Skip empty features (level 1)
+  
+  This function implements sequential access.
+  
+  The action of this routine can be modified by:
+   - Vect_read_constraint_region()
+   - Vect_read_constraint_type()
+   - Vect_remove_constraints()
+  
+  \param Map pointer to Map_info structure
+  \param[out] line_p container used to store line points within
+  \param[out] line_c container used to store line categories within
+  
+  \return feature type
+  \return -2 no more features (EOF)
+  \return -1 out of memory
+*/
 int V1_read_next_line_ogr(struct Map_info *Map, struct line_pnts *line_p,
 			  struct line_cats *line_c)
 {
@@ -152,7 +154,7 @@
     if (Map->Constraint_region_flag)
 	Vect_get_constraint_box(Map, &mbox);
 
-    while (1) {
+    while (TRUE) {
 	/* Read feature to cache if necessary */
 	while (Map->fInfo.ogr.lines_next == Map->fInfo.ogr.lines_num) {
 	    hFeature = OGR_L_GetNextFeature(Map->fInfo.ogr.layer);
@@ -223,42 +225,45 @@
 }
 
 /*!
- * \brief Read next feature from OGR layer (topology level).
- *
- * \param Map pointer to Map_info structure
- * \param[out] line_p container used to store line points within
- * \param[out] line_c container used to store line categories within
- *
- * \return feature type
- * \return -2 no more features (EOF)
- * \return -1 out of memory
- */
-int
-V2_read_next_line_ogr(struct Map_info *Map, struct line_pnts *line_p,
-		      struct line_cats *line_c)
+  \brief Read next feature from OGR layer (topology level).
+
+  This function implements sequential access.
+
+  \param Map pointer to Map_info structure
+  \param[out] line_p container used to store line points within
+  \param[out] line_c container used to store line categories within
+  
+  \return feature type
+  \return -2 no more features (EOF)
+  \return -1 out of memory
+*/
+int V2_read_next_line_ogr(struct Map_info *Map, struct line_pnts *line_p,
+			  struct line_cats *line_c)
 {
     if (Map->next_line > Map->plus.n_lines)
 	return -2;
 
-    return V2_read_line_ogr(Map, line_p, line_c, Map->next_line++);
+    Map->next_line++;
+
+    return V1_read_next_line_ogr(Map, line_p, line_c);
 }
 
 /*!
- * \brief Recursively descend to feature and read the part
- *
- * \param Map pointer to Map_info structure
- * \param hGeom OGR geometry
- * \param offset given offset
- * \param[out] Points container used to store line pointes within
- *
- * \return feature type
- * \return -1 on error
- */
+  \brief Recursively descend to feature and read the part
+  
+  \param Map pointer to Map_info structure
+  \param hGeom OGR geometry
+  \param offset given offset
+  \param[out] Points container used to store line pointes within
+  
+  \return feature type
+  \return -1 on error
+*/
 static int read_line(const struct Map_info *Map, OGRGeometryH hGeom, long offset,
 		     struct line_pnts *Points)
 {
     int i, nPoints;
-    int eType;
+    int eType, line;
     OGRGeometryH hGeom2;
 
     /* Read coors if hGeom is a simple element (wkbPoint, wkbLineString) otherwise
@@ -298,11 +303,19 @@
     case wkbGeometryCollection:
 	G_debug(4, " more geoms -> part %d", Map->fInfo.ogr.offset[offset]);
 	hGeom2 = OGR_G_GetGeometryRef(hGeom, Map->fInfo.ogr.offset[offset]);
-	return (read_line(Map, hGeom2, offset + 1, Points));
+	line = read_line(Map, hGeom2, offset + 1, Points);
+	if (eType == wkbPolygon || wkbMultiPolygon)
+	    return GV_BOUNDARY;
+	if (eType == wkbMultiPoint)
+	    return GV_POINT;
+	if (eType == wkbMultiLineString)
+	    return GV_LINE;
+	return line;
 	break;
 
     default:
-	G_warning(_("OGR feature type %d not supported"), eType);
+	G_warning(_("OGR feature type '%s' not supported"),
+		  OGRGeometryTypeToName(eType));
 	break;
     }
 
@@ -310,16 +323,16 @@
 }
 
 /*!
- * \brief Recursively descend to feature and read the part
- *
- * \param Map pointer to Map_info structure
- * \param hGeom OGR geometry
- * \param offset given offset
- * \param[out] Points container used to store line pointes within
- *
- * \return feature type
- * \return -1 on error
- */
+  \brief Recursively descend to feature and read the part
+  
+  \param Map pointer to Map_info structure
+  \param hGeom OGR geometry
+  \param offset given offset
+  \param[out] Points container used to store line pointes within
+  
+  \return feature type
+  \return -1 on error
+*/
 static int get_line_type(const struct Map_info *Map, long FID)
 {
     int eType;
@@ -368,18 +381,20 @@
 }
 
 /*!
- * \brief Read feature from OGR layer at given offset (level 1)
- *
- * \param Map pointer to Map_info structure 
- * \param[out] line_p container used to store line points within
- * \param[out] line_c container used to store line categories within
- * \param offset given offset 
- *
- * \return line type
- * \return 0 dead line
- * \return -2 no more features
- * \return -1 out of memory
- */
+  \brief Read feature from OGR layer at given offset (level 1)
+  
+  This function implements random access on level 1.
+
+  \param Map pointer to Map_info structure 
+  \param[out] line_p container used to store line points within
+  \param[out] line_c container used to store line categories within
+  \param offset given offset 
+  
+  \return line type
+  \return 0 dead line
+  \return -2 no more features
+  \return -1 out of memory
+*/
 int V1_read_line_ogr(struct Map_info *Map,
 		     struct line_pnts *line_p, struct line_cats *line_c, off_t offset)
 {
@@ -438,17 +453,19 @@
 }
 
 /*!
- * \brief Reads feature from OGR layer (topology level)
- *
- * \param Map pointer to Map_info structure
- * \param[out] line_p container used to store line points within
- * \param[out] line_c container used to store line categories within
- * \param line feature id
- *
- * \return feature type
- * \return -2 no more features
- * \return -1 out of memory
- */
+  \brief Reads feature from OGR layer (topology level)
+ 
+  This function implements random access on level 2.
+  
+  \param Map pointer to Map_info structure
+  \param[out] line_p container used to store line points within
+  \param[out] line_c container used to store line categories within
+  \param line feature id
+  
+  \return feature type
+  \return -2 no more features
+  \return -1 out of memory
+*/
 int V2_read_line_ogr(struct Map_info *Map, struct line_pnts *line_p,
 		     struct line_cats *line_c, int line)
 {
@@ -458,8 +475,7 @@
     Line = Map->plus.Line[line];
     
     if (Line == NULL)
-	G_fatal_error("V2_read_line_ogr(): %s %d",
-		      _("Attempt to read dead line"), line);
+	G_fatal_error(_("Attempt to read dead feature %d"), line);
 
     if (Line->type == GV_CENTROID) {
 	G_debug(4, "Centroid");
@@ -484,6 +500,7 @@
 		}
 	    }
 
+	    Vect_reset_line(line_p);
 	    Vect_append_point(line_p, list.box[found].E, list.box[found].N, 0.0);
 	}
 

Modified: grass/trunk/lib/vector/Vlib/rewind.c
===================================================================
--- grass/trunk/lib/vector/Vlib/rewind.c	2011-08-25 10:42:48 UTC (rev 47880)
+++ grass/trunk/lib/vector/Vlib/rewind.c	2011-08-25 10:45:39 UTC (rev 47881)
@@ -5,7 +5,7 @@
 
    Higher level functions for reading/writing/manipulating vectors.
 
-   (C) 2001-2009 by the GRASS Development Team
+   (C) 2001-2009, 2011 by the GRASS Development Team
 
    This program is free software under the GNU General Public License
    (>=v2).  Read the file COPYING that comes with GRASS for details.
@@ -55,7 +55,7 @@
 /*!
    \brief Rewind vector data file to cause reads to start at beginning
 
-   \param Map vector map
+   \param Map pointer to Map_info structure
 
    \return 0 on success
    \return -1 on error

Modified: grass/trunk/lib/vector/Vlib/rewind_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/rewind_nat.c	2011-08-25 10:42:48 UTC (rev 47880)
+++ grass/trunk/lib/vector/Vlib/rewind_nat.c	2011-08-25 10:45:39 UTC (rev 47881)
@@ -5,7 +5,7 @@
 
    Higher level functions for reading/writing/manipulating vectors.
 
-   (C) 2001-2009 by the GRASS Development Team
+   (C) 2001-2009, 2011 by the GRASS Development Team
 
    This program is free software under the GNU General Public License
    (>=v2).  Read the file COPYING that comes with GRASS for details.

Modified: grass/trunk/lib/vector/Vlib/rewind_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/rewind_ogr.c	2011-08-25 10:42:48 UTC (rev 47880)
+++ grass/trunk/lib/vector/Vlib/rewind_ogr.c	2011-08-25 10:45:39 UTC (rev 47881)
@@ -22,9 +22,8 @@
   \brief Rewind vector data file to cause reads to start at beginning (level 1)
 
   \param Map vector map
-  
-  \return 0 on success
-  \return -1 on error
+
+  \return 0
  */
 int V1_rewind_ogr(struct Map_info *Map)
 {
@@ -41,10 +40,9 @@
 /*!
   \brief Rewind vector data file to cause reads to start at beginning (level 2)
 
-  \param Map vector map
+  \param Map pointer to Map_info structure
 
-  \return 0 on success
-  \return -1 on error
+  \return 0
  */
 int V2_rewind_ogr(struct Map_info *Map)
 {
@@ -52,6 +50,8 @@
 
     Map->next_line = 1;
 
+    V1_rewind_ogr(Map);
+
     return 0;
 }
 



More information about the grass-commit mailing list