[GRASS-SVN] r47912 - grass/trunk/lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Aug 27 13:39:32 EDT 2011
Author: martinl
Date: 2011-08-27 10:39:32 -0700 (Sat, 27 Aug 2011)
New Revision: 47912
Modified:
grass/trunk/lib/vector/Vlib/open_ogr.c
grass/trunk/lib/vector/Vlib/read_ogr.c
grass/trunk/lib/vector/Vlib/write_ogr.c
Log:
vlib: fix writting wkbPolygon (OGR write access)
Modified: grass/trunk/lib/vector/Vlib/open_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open_ogr.c 2011-08-27 16:39:22 UTC (rev 47911)
+++ grass/trunk/lib/vector/Vlib/open_ogr.c 2011-08-27 17:39:32 UTC (rev 47912)
@@ -279,6 +279,10 @@
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 @@
case GV_LINE:
Ogr_geom_type = wkbLineString;
break;
- case GV_AREA:
+ case GV_BOUNDARY:
Ogr_geom_type = wkbPolygon;
break;
default:
Modified: grass/trunk/lib/vector/Vlib/read_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read_ogr.c 2011-08-27 16:39:22 UTC (rev 47911)
+++ grass/trunk/lib/vector/Vlib/read_ogr.c 2011-08-27 17:39:32 UTC (rev 47912)
@@ -506,6 +506,7 @@
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);
}
Modified: grass/trunk/lib/vector/Vlib/write_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_ogr.c 2011-08-27 16:39:22 UTC (rev 47911)
+++ grass/trunk/lib/vector/Vlib/write_ogr.c 2011-08-27 17:39:32 UTC (rev 47912)
@@ -107,11 +107,18 @@
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,10 +133,33 @@
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);
More information about the grass-commit
mailing list