浏览代码

vlib/geos: determine feature type (work in progress)
(merge from devbr6, https://trac.osgeo.org/grass/changeset/37319)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@37320 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 16 年之前
父节点
当前提交
62ef4c400b
共有 2 个文件被更改,包括 28 次插入21 次删除
  1. 1 1
      include/Vect.h
  2. 27 20
      lib/vector/Vlib/geos.c

+ 1 - 1
include/Vect.h

@@ -470,7 +470,7 @@ int Vect_attach_centroids(struct Map_info *, const BOUND_BOX *);
 
 
     /* GEOS support */
     /* GEOS support */
 #ifdef HAVE_GEOS
 #ifdef HAVE_GEOS
-GEOSGeometry *Vect_read_line_geos(struct Map_info *, int);
+GEOSGeometry *Vect_read_line_geos(struct Map_info *, int, int*);
 GEOSGeometry *Vect_line_to_geos(struct Map_info *, const struct line_pnts*, int);
 GEOSGeometry *Vect_line_to_geos(struct Map_info *, const struct line_pnts*, int);
 GEOSGeometry *Vect_read_area_geos(struct Map_info *, int);
 GEOSGeometry *Vect_read_area_geos(struct Map_info *, int);
 GEOSCoordSequence *Vect_get_area_points_geos(struct Map_info *, int);
 GEOSCoordSequence *Vect_get_area_points_geos(struct Map_info *, int);

+ 27 - 20
lib/vector/Vlib/geos.c

@@ -21,8 +21,8 @@
 #ifdef HAVE_GEOS
 #ifdef HAVE_GEOS
 #include <geos_c.h>
 #include <geos_c.h>
 
 
-static GEOSGeometry *Vect__read_line_geos(struct Map_info *, long);
-static GEOSCoordSequence *V1_read_line_geos(struct Map_info *, long);
+static GEOSGeometry *Vect__read_line_geos(struct Map_info *, long, int *);
+static GEOSCoordSequence *V1_read_line_geos(struct Map_info *, long, int *);
 static GEOSCoordSequence *V2_read_line_geos(struct Map_info *, int);
 static GEOSCoordSequence *V2_read_line_geos(struct Map_info *, int);
 
 
 /*!
 /*!
@@ -37,12 +37,13 @@ static GEOSCoordSequence *V2_read_line_geos(struct Map_info *, int);
 
 
    \param Map pointer to Map_info structure
    \param Map pointer to Map_info structure
    \param line feature id
    \param line feature id
-
+   \param[out] type feature type or NULL
+   
    \return pointer to GEOSGeometry instance
    \return pointer to GEOSGeometry instance
    \return empty GEOSGeometry for unsupported feature type
    \return empty GEOSGeometry for unsupported feature type
    \return NULL on error
    \return NULL on error
  */
  */
-GEOSGeometry *Vect_read_line_geos(struct Map_info *Map, int line)
+GEOSGeometry *Vect_read_line_geos(struct Map_info *Map, int line, int *type)
 {
 {
     P_LINE *Line;
     P_LINE *Line;
     
     
@@ -64,7 +65,7 @@ GEOSGeometry *Vect_read_line_geos(struct Map_info *Map, int line)
 	G_fatal_error("Vect_read_line_geos(): %s %d",
 	G_fatal_error("Vect_read_line_geos(): %s %d",
 		      _("Attempt to read dead line"), line);
 		      _("Attempt to read dead line"), line);
     
     
-    return Vect__read_line_geos(Map, Line->offset);
+    return Vect__read_line_geos(Map, Line->offset, type);
 }
 }
 
 
 /*!
 /*!
@@ -122,8 +123,8 @@ GEOSGeometry *Vect_read_area_geos(struct Map_info * Map, int area)
    \return pointer to GEOSGeometry instance
    \return pointer to GEOSGeometry instance
    \return NULL on error
    \return NULL on error
  */
  */
-GEOSGeometry *Vect_line_to_geos(struct Map_info * Map,
-				const struct line_pnts * points, int type)
+GEOSGeometry *Vect_line_to_geos(struct Map_info *Map,
+				const struct line_pnts *points, int type)
 {
 {
     int i, with_z;
     int i, with_z;
     GEOSGeometry *geom;
     GEOSGeometry *geom;
@@ -181,29 +182,30 @@ GEOSGeometry *Vect_line_to_geos(struct Map_info * Map,
 
 
   \param Map pointer to Map_info
   \param Map pointer to Map_info
   \param offset line offset
   \param offset line offset
- 
+  \param[out] type feature type or NULL
+
   \return pointer to GEOSGeometry
   \return pointer to GEOSGeometry
   \return NULL on error
   \return NULL on error
   \return NULL dead line
   \return NULL dead line
   \return NULL end of file
   \return NULL end of file
 */
 */
-GEOSGeometry *Vect__read_line_geos(struct Map_info *Map, long offset)
+GEOSGeometry *Vect__read_line_geos(struct Map_info *Map, long offset, int *type)
 {
 {
-    int type;
+    int ftype;
     double *x, *y, *z;
     double *x, *y, *z;
     
     
     GEOSGeometry *geom;
     GEOSGeometry *geom;
     GEOSCoordSequence *pseq;
     GEOSCoordSequence *pseq;
     
     
-    pseq = V1_read_line_geos(Map, offset);
+    pseq = V1_read_line_geos(Map, offset, &ftype);
     if (!pseq)
     if (!pseq)
 	G_fatal_error(_("Unable to read line offset %ld"), offset);
 	G_fatal_error(_("Unable to read line offset %ld"), offset);
     
     
-    if (type & GV_POINT) {
+    if (ftype & GV_POINT) {
 	G_debug(3, "    geos_type = point");
 	G_debug(3, "    geos_type = point");
 	geom = GEOSGeom_createPoint(pseq);
 	geom = GEOSGeom_createPoint(pseq);
     }
     }
-    else if (type & GV_LINE) {
+    else if (ftype & GV_LINE) {
 	G_debug(3, "    geos_type = linestring");
 	G_debug(3, "    geos_type = linestring");
 	geom = GEOSGeom_createLineString(pseq);
 	geom = GEOSGeom_createLineString(pseq);
     }
     }
@@ -226,6 +228,9 @@ GEOSGeometry *Vect__read_line_geos(struct Map_info *Map, long offset)
     
     
     /* GEOSCoordSeq_destroy(pseq); */
     /* GEOSCoordSeq_destroy(pseq); */
     
     
+    if (type)
+      *type = ftype;
+    
     return geom;
     return geom;
 }
 }
 
 
@@ -243,6 +248,7 @@ GEOSGeometry *Vect__read_line_geos(struct Map_info *Map, long offset)
 */
 */
 GEOSCoordSequence *V2_read_line_geos(struct Map_info *Map, int line)
 GEOSCoordSequence *V2_read_line_geos(struct Map_info *Map, int line)
 {
 {
+    int ftype;
     P_LINE *Line;
     P_LINE *Line;
     
     
     G_debug(3, "V2_read_line_geos(): line = %d", line);
     G_debug(3, "V2_read_line_geos(): line = %d", line);
@@ -253,7 +259,7 @@ GEOSCoordSequence *V2_read_line_geos(struct Map_info *Map, int line)
 	G_fatal_error("V2_read_line_geos(): %s %d",
 	G_fatal_error("V2_read_line_geos(): %s %d",
 		      _("Attempt to read dead line"), line);
 		      _("Attempt to read dead line"), line);
     
     
-    return V1_read_line_geos(Map, Line->offset);
+    return V1_read_line_geos(Map, Line->offset, &ftype);
 }
 }
 
 
 
 
@@ -267,14 +273,15 @@ GEOSCoordSequence *V2_read_line_geos(struct Map_info *Map, int line)
   
   
   \param Map pointer to Map_info
   \param Map pointer to Map_info
   \param offset line offset
   \param offset line offset
- 
+  \param[out] type feature type
+  
   \return pointer to GEOSCoordSequence
   \return pointer to GEOSCoordSequence
   \return empty GEOSCoordSequence for dead line or unsuppored feature type
   \return empty GEOSCoordSequence for dead line or unsuppored feature type
   \return NULL end of file
   \return NULL end of file
 */
 */
-GEOSCoordSequence *V1_read_line_geos(struct Map_info *Map, long offset)
+GEOSCoordSequence *V1_read_line_geos(struct Map_info *Map, long offset, int *type)
 {
 {
-    int i, n_points, type;
+    int i, n_points;
     char rhead;
     char rhead;
     double *x, *y, *z;
     double *x, *y, *z;
     
     
@@ -296,13 +303,13 @@ GEOSCoordSequence *V1_read_line_geos(struct Map_info *Map, long offset)
 	return GEOSCoordSeq_create(0, (Map->head.with_z) ? 3 : 2);
 	return GEOSCoordSeq_create(0, (Map->head.with_z) ? 3 : 2);
     
     
     rhead >>= 2;
     rhead >>= 2;
-    type = dig_type_from_store((int)rhead);
+    *type = dig_type_from_store((int) rhead);
     
     
     /* read only points / lines / boundaries */
     /* read only points / lines / boundaries */
-    if (!(type & (GV_POINT | GV_LINES)))
+    if (!(*type & (GV_POINT | GV_LINES)))
 	return GEOSCoordSeq_create(0, (Map->head.with_z) ? 3 : 2);
 	return GEOSCoordSeq_create(0, (Map->head.with_z) ? 3 : 2);
     
     
-    if (type & GV_POINTS) {
+    if (*type & GV_POINTS) {
 	n_points = 1;
 	n_points = 1;
     }
     }
     else {
     else {