Bläddra i källkod

vlib: fix writting wkbPolygon (OGR write access)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47912 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 år sedan
förälder
incheckning
2c2907aeeb
3 ändrade filer med 40 tillägg och 5 borttagningar
  1. 5 1
      lib/vector/Vlib/open_ogr.c
  2. 1 0
      lib/vector/Vlib/read_ogr.c
  3. 34 4
      lib/vector/Vlib/write_ogr.c

+ 5 - 1
lib/vector/Vlib/open_ogr.c

@@ -279,6 +279,10 @@ int V1_open_new_ogr(struct Map_info *Map, const char *name, int with_z)
 
    V1_open_new_ogr() is required to be called before this function.
 
+   List of currently supported types:
+    - GV_POINT     (wkbPoint)
+    - GV_LINE      (wkbLineString)
+    - GV_BOUNDARY  (wkb_Polygon)
    \param[in,out] Map pointer to Map_info structure
    \param type feature type (GV_POINT, GV_LINE, ...)
 
@@ -312,7 +316,7 @@ int V2_open_new_ogr(struct Map_info *Map, int type)
     case GV_LINE:
 	Ogr_geom_type = wkbLineString;
 	break;
-    case GV_AREA:
+    case GV_BOUNDARY:
 	Ogr_geom_type = wkbPolygon;
 	break;
     default:

+ 1 - 0
lib/vector/Vlib/read_ogr.c

@@ -506,6 +506,7 @@ int V2_read_line_ogr(struct Map_info *Map, struct line_pnts *line_p,
 
 	if (line_c != NULL) {
 	  /* cat = FID and offset = FID for centroid */
+	  Vect_reset_cats(line_c);
 	  Vect_cat_set(line_c, 1, (int) Line->offset);
 	}
 	

+ 34 - 4
lib/vector/Vlib/write_ogr.c

@@ -107,11 +107,18 @@ off_t V1_write_line_ogr(struct Map_info *Map, int type,
     else if (type & GV_LINE) {
 	if (Ogr_geom_type != wkbLineString &&
 	    Ogr_geom_type != wkbLineString25D) {
-	    G_warning(_("Feature is not a line Skipping."));
+	    G_warning(_("Feature is not a line. Skipping."));
 	    return -1;
 	}
 	Ogr_geometry = OGR_G_CreateGeometry(wkbLineString);
     }
+    else if (type & GV_BOUNDARY) {
+	if (Ogr_geom_type != wkbPolygon) {
+	    G_warning(_("Feature is not a polygon. Skipping."));
+	    return -1;
+	}
+	Ogr_geometry = OGR_G_CreateGeometry(wkbPolygon);
+    }
     else if (type & GV_FACE) {
 	if (Ogr_geom_type != wkbPolygon25D) {
 	    G_warning(_("Feature is not a face. Skipping."));
@@ -126,9 +133,32 @@ off_t V1_write_line_ogr(struct Map_info *Map, int type,
 
     G_debug(3, "V1_write_line_ogr(): type = %d", type);
 
-    for (i = 0; i < points->n_points; i++) {
-	OGR_G_AddPoint(Ogr_geometry, points->x[i], points->y[i],
-		       points->z[i]);
+    if (Ogr_geom_type == wkbPolygon || Ogr_geom_type == wkbPolygon25D) {
+	/* create exterior ring */
+	OGRGeometryH Ogr_ring;
+	int npoints;
+	
+	npoints = points->n_points - 1;
+	Ogr_ring = OGR_G_CreateGeometry(wkbLinearRing);
+	if (points->x[0] != points->x[npoints] ||
+	    points->y[0] != points->y[npoints] ||
+	    points->z[0] != points->z[npoints]) {
+	    G_warning(_("Boundary is not closed. Skipping."));
+	    return -1;
+	}
+	
+	/* add points */
+	for (i = 0; i < points->n_points; i++) {
+	    OGR_G_AddPoint(Ogr_ring, points->x[i], points->y[i],
+			   points->z[i]);
+	}
+	OGR_G_AddGeometry(Ogr_geometry, Ogr_ring);
+    }
+    else {
+	for (i = 0; i < points->n_points; i++) {
+	    OGR_G_AddPoint(Ogr_geometry, points->x[i], points->y[i],
+			   points->z[i]);
+	}
     }
     
     G_debug(4, "   n_points = %d", points->n_points);