瀏覽代碼

Simple Features API: Vect_sfa_write_line_wkt() -> Vect_sfa_line_astext()
* various minor changes


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

Martin Landa 15 年之前
父節點
當前提交
d554428909
共有 3 個文件被更改,包括 105 次插入15 次删除
  1. 6 3
      include/vector.h
  2. 3 3
      lib/vector/Vlib/ascii.c
  3. 96 9
      lib/vector/Vlib/simple_features.c

+ 6 - 3
include/vector.h

@@ -416,10 +416,13 @@ int Vect_write_ascii(FILE *, FILE *, struct Map_info *, int,
 void Vect_write_ascii_head(FILE *, struct Map_info *);
 void Vect_write_ascii_head(FILE *, struct Map_info *);
 
 
 /* Simple Features */
 /* Simple Features */
-void Vect_sfa_write_line_wkt(const struct line_pnts *, int, int, int, FILE *);
-int Vect_sfa_check_line_type(const struct line_pnts *, int, int, int);
 int Vect_sfa_get_line_type(const struct line_pnts *, int, int);
 int Vect_sfa_get_line_type(const struct line_pnts *, int, int);
-int Vect_sfa_is_line_closed(const struct line_pnts *, int, int);
+int Vect_sfa_check_line_type(const struct line_pnts *, int, int, int);
+int Vect_sfa_line_dimension(int);
+char *Vect_sfa_line_geometry_type(const struct line_pnts *, int);
+int Vect_sfa_line_astext(const struct line_pnts *, int, int, int, FILE *);
+int Vect_sfa_is_line_is_simple(const struct line_pnts *, int, int);
+int Vect_sfa_is_line_is_closed(const struct line_pnts *, int, int);
 
 
 /*
 /*
  * Internal functions, MUST NOT be used in modules
  * Internal functions, MUST NOT be used in modules

+ 3 - 3
lib/vector/Vlib/ascii.c

@@ -563,7 +563,7 @@ int Vect_write_ascii(FILE *ascii,
 	    if (type & (GV_BOUNDARY | GV_CENTROID | GV_FACE | GV_KERNEL))
 	    if (type & (GV_BOUNDARY | GV_CENTROID | GV_FACE | GV_KERNEL))
 		continue;
 		continue;
 	    /* Well-Known Text */
 	    /* Well-Known Text */
-	    Vect_sfa_write_line_wkt(Points, type, Vect_is_3d(Map), dp, ascii);
+	    Vect_sfa_line_astext(Points, type, Vect_is_3d(Map), dp, ascii);
 	}
 	}
 	else {
 	else {
 	    G_fatal_error(_("Unknown format"));
 	    G_fatal_error(_("Unknown format"));
@@ -593,7 +593,7 @@ int Vect_write_ascii(FILE *ascii,
 	    }
 	    }
 	    fprintf(ascii, "POLYGON(");
 	    fprintf(ascii, "POLYGON(");
 	    /* write outter ring */
 	    /* write outter ring */
-	    Vect_sfa_write_line_wkt(Points, GV_BOUNDARY, 0, dp, ascii); /* boundary is always 2D */
+	    Vect_sfa_line_astext(Points, GV_BOUNDARY, 0, dp, ascii); /* boundary is always 2D */
 	    /* get isles (holes) -> inner rings */
 	    /* get isles (holes) -> inner rings */
 	    nisles = Vect_get_area_num_isles(Map, area);
 	    nisles = Vect_get_area_num_isles(Map, area);
 	    for (i = 0; i < nisles; i++) {
 	    for (i = 0; i < nisles; i++) {
@@ -605,7 +605,7 @@ int Vect_write_ascii(FILE *ascii,
 		}
 		}
 		fprintf(ascii, ", ");
 		fprintf(ascii, ", ");
 		/* write inner ring */
 		/* write inner ring */
-		Vect_sfa_write_line_wkt(Points, GV_BOUNDARY, 0, dp, ascii); /* boundary is always 2D */
+		Vect_sfa_line_astext(Points, GV_BOUNDARY, 0, dp, ascii); /* boundary is always 2D */
 	    }
 	    }
 	    fprintf(ascii, ")\n");
 	    fprintf(ascii, ")\n");
 	}
 	}

+ 96 - 9
lib/vector/Vlib/simple_features.c

@@ -3,10 +3,22 @@
  
  
   \brief Vector library - OGC Simple Features Access
   \brief Vector library - OGC Simple Features Access
 
 
-  Note: In progress. Currently on GV_POINT, GV_LINE are supported.
+  Note: In progress! Currently on GV_POINT, GV_LINE, GV_AREA are supported.
   
   
   Higher level functions for reading/writing/manipulating vectors.
   Higher level functions for reading/writing/manipulating vectors.
-  
+
+  \todo
+   - Vect_sfa_line_is_simple()
+   - Vect_sfa_line_srid()
+   - Vect_sfa_line_envelope()
+   - Vect_sfa_line_asbinary()
+   - Vect_sfa_line_is_empty()
+   - Vect_sfa_line_is_3d()
+   - Vect_sfa_line_is_measured()
+   - Vect_sfa_line_boundary()
+
+  Reference: http://www.opengeospatial.org/standards/sfa
+
   (C) 2009 by the GRASS Development Team
   (C) 2009 by the GRASS Development Team
   
   
   This program is free software under the GNU General Public License
   This program is free software under the GNU General Public License
@@ -30,7 +42,8 @@ static void print_point(const struct line_pnts *, int, int, int, FILE *);
   List of supported feature types:
   List of supported feature types:
    - GV_POINT    -> SF_POINT
    - GV_POINT    -> SF_POINT
    - GV_LINE     -> SF_LINE / SF_LINESTRING / SF_LINEARRING
    - GV_LINE     -> SF_LINE / SF_LINESTRING / SF_LINEARRING
-  
+   - GV_AREA     -> SF_POLYGON
+
   \param Points  pointer to line_pnts structure
   \param Points  pointer to line_pnts structure
   \param type    feature type (GV_POINT, GV_LINE, ...)
   \param type    feature type (GV_POINT, GV_LINE, ...)
   \param with_z  non-zero value for 3D data
   \param with_z  non-zero value for 3D data
@@ -64,28 +77,79 @@ int Vect_sfa_check_line_type(const struct line_pnts *Points, int type, int sftyp
 }
 }
 
 
 /*!
 /*!
-  \brief Print feature in Well-Known Text format
+  \brief Get geometry dimension
+
+  \param Points pointer to line_pnts structure
+  \param type   feature type (GV_POINT, GV_LINE, ...)
+
+  \return 0
+  \return 1
+  \return 2
+  \return -1 unsupported feature type
+*/
+int Vect_sfa_line_dimension(int type)
+{
+    if (type == GV_POINT)
+	return 0;
+    if (type == GV_LINE)
+	return 1;
+    if (type == GV_AREA)
+	return 2;
+
+    return -1;
+}
+
+/*!
+  \brief Get geometry type (string)
+
+  \param Points pointer to line_pnts structure
+  \param type   feature type (GV_POINT, GV_LINE, ...)
+
+  \return geometry type string
+  \return NULL unsupported feature type
+*/
+char *Vect_sfa_line_geometry_type(const struct line_pnts *Points, int type)
+{
+    int sftype = Vect_sfa_get_line_type(Points, type, 0);
 
 
+    if (sftype == SF_POINT)
+	return G_store("POINT");
+    if (sftype == SF_LINESTRING)
+	return G_store("LINESTRING");
+    if (sftype == SF_LINE)
+	return G_store("LINE");
+    if (sftype == SF_LINEARRING)
+	return G_store("LINEARRING");
+
+    return NULL;
+}
+
+/*!
+  \brief Export geometry to Well-Known Text
+  
   \param Points    pointer to line_pnts structure
   \param Points    pointer to line_pnts structure
   \param type      feature type
   \param type      feature type
   \param with_z    non-zero value for 3D data
   \param with_z    non-zero value for 3D data
   \param precision floating number precision 
   \param precision floating number precision 
   \param[out] file file where to write the output
   \param[out] file file where to write the output
+
+  \return 0 on success
+  \return -1 unsupported feature type
 */
 */
-void Vect_sfa_write_line_wkt(const struct line_pnts *Points, int type, int with_z, int precision, FILE *file)
+int Vect_sfa_line_astext(const struct line_pnts *Points, int type, int with_z, int precision, FILE *file)
 {
 {
     int i, sftype;
     int i, sftype;
     
     
     sftype = Vect_sfa_get_line_type(Points, type, with_z);
     sftype = Vect_sfa_get_line_type(Points, type, with_z);
     
     
     switch(sftype) {
     switch(sftype) {
-    case SF_POINT: {
+    case SF_POINT: { /* point */
 	fprintf(file, "POINT(");
 	fprintf(file, "POINT(");
 	print_point(Points, 0, with_z, precision, file);
 	print_point(Points, 0, with_z, precision, file);
 	fprintf(file, ")\n");
 	fprintf(file, ")\n");
 	break;
 	break;
     }
     }
-    case SF_LINESTRING: case SF_LINE: case SF_LINEARRING: {
+    case SF_LINESTRING: case SF_LINE: case SF_LINEARRING: /* line */ {
 	if (sftype == SF_LINESTRING)
 	if (sftype == SF_LINESTRING)
 	    fprintf(file, "LINESTRING(");
 	    fprintf(file, "LINESTRING(");
 	else if (sftype ==  SF_LINE)
 	else if (sftype ==  SF_LINE)
@@ -100,7 +164,7 @@ void Vect_sfa_write_line_wkt(const struct line_pnts *Points, int type, int with_
 	fprintf(file, ")\n");
 	fprintf(file, ")\n");
 	break;
 	break;
     }
     }
-    case SF_POLYGON: {
+    case SF_POLYGON: /* polygon */ {
 	/* write only outter/inner ring */
 	/* write only outter/inner ring */
 	fprintf(file, "(");
 	fprintf(file, "(");
 	for (i = 0; i < Points->n_points; i++) {
 	for (i = 0; i < Points->n_points; i++) {
@@ -113,10 +177,33 @@ void Vect_sfa_write_line_wkt(const struct line_pnts *Points, int type, int with_
     }
     }
     default: {
     default: {
 	G_warning(_("Unknown Simple Features type (%d)"), sftype);
 	G_warning(_("Unknown Simple Features type (%d)"), sftype);
-	break;
+	return -1;
     }
     }
     }
     }
+    
     fflush(file);
     fflush(file);
+    return 0;
+}
+
+/*!
+  \brief Check if feature is simple
+
+  \param Points pointer to line_pnts structure
+  \param type   feature type (GV_POINT, GV_LINE, ...)
+  
+  \return 1  feature simple
+  \return 0  feature not simple
+  \return -1 feature type not supported (GV_POINT, GV_CENTROID, ...)
+*/
+int Vect_sfa_is_line_is_simple(const struct line_pnts *Points, int type, int with_z)
+{
+    int sftype;
+    
+    sftype = Vect_sfa_get_line_type(Points, type, with_z);
+
+    /* TODO */
+
+    return 0;
 }
 }
 
 
 /*!
 /*!