[GRASS-SVN] r43312 - grass/trunk/vector/v.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 27 14:10:24 EDT 2010


Author: mmetz
Date: 2010-08-27 18:10:24 +0000 (Fri, 27 Aug 2010)
New Revision: 43312

Modified:
   grass/trunk/vector/v.in.ogr/geom.c
Log:
fix bug for min_area

Modified: grass/trunk/vector/v.in.ogr/geom.c
===================================================================
--- grass/trunk/vector/v.in.ogr/geom.c	2010-08-27 18:09:52 UTC (rev 43311)
+++ grass/trunk/vector/v.in.ogr/geom.c	2010-08-27 18:10:24 UTC (rev 43312)
@@ -25,12 +25,13 @@
 #include "ogr_api.h"
 #include "global.h"
 
-int split_line(struct Map_info *Map, int otype, struct line_pnts *Points, struct line_cats *Cats);
+int split_line(struct Map_info *Map, int otype, struct line_pnts *Points,
+	       struct line_cats *Cats);
 
 /* Add categories to centroids inside polygon */
 int
-centroid(OGRGeometryH hGeom, CENTR * Centr, struct spatial_index * Sindex, int field,
-	 int cat, double min_area, int type)
+centroid(OGRGeometryH hGeom, CENTR * Centr, struct spatial_index *Sindex,
+	 int field, int cat, double min_area, int type)
 {
     int i, valid_isles, j, np, nr, ret;
     static int first = 1;
@@ -98,16 +99,26 @@
 	    if ((np = OGR_G_GetPointCount(hRing)) > 0) {
 		IPoints[valid_isles] = Vect_new_line_struct();
 		for (j = 0; j < np; j++) {
-		    Vect_append_point(IPoints[valid_isles], OGR_G_GetX(hRing, j),
-				      OGR_G_GetY(hRing, j), OGR_G_GetZ(hRing, j));
+		    Vect_append_point(IPoints[valid_isles],
+				      OGR_G_GetX(hRing, j),
+				      OGR_G_GetY(hRing, j),
+				      OGR_G_GetZ(hRing, j));
 		}
-		valid_isles++;
+		size =
+		    G_area_of_polygon(IPoints[valid_isles]->x,
+				      IPoints[valid_isles]->y,
+				      IPoints[valid_isles]->n_points);
+		if (size < min_area)
+		    Vect_destroy_line_struct(IPoints[valid_isles]);
+		else
+		    valid_isles++;
 	    }
 	}
 
 	/* Find centroids */
 	if (Points->n_points >= 4) {
 	    int centr, in;
+
 	    double x, y;
 
 	    Vect_line_box(Points, &box);
@@ -159,13 +170,11 @@
 }
 
 /* count polygons and isles */
-int
-poly_count(OGRGeometryH hGeom)
+int poly_count(OGRGeometryH hGeom)
 {
     int i, nr, ret;
     OGRwkbGeometryType eType;
     OGRGeometryH hRing;
-
     eType = wkbFlatten(OGR_G_GetGeometryType(hGeom));
 
     if (eType == wkbPolygon) {
@@ -283,7 +292,7 @@
 
 	size = G_area_of_polygon(Points->x, Points->y, Points->n_points);
 	if (size < min_area) {
-	    G_warning(_("Area size [%.1e], area not imported"), size);
+	    G_debug(2, "Area size [%.1e], area not imported", size);
 	    return 0;
 	}
 
@@ -314,17 +323,23 @@
 		IPoints[valid_isles] = Vect_new_line_struct();
 
 		for (j = 0; j < np; j++) {
-		    Vect_append_point(IPoints[valid_isles], OGR_G_GetX(hRing, j),
-				      OGR_G_GetY(hRing, j), OGR_G_GetZ(hRing, j));
+		    Vect_append_point(IPoints[valid_isles],
+				      OGR_G_GetX(hRing, j),
+				      OGR_G_GetY(hRing, j),
+				      OGR_G_GetZ(hRing, j));
 		}
 
 		if (IPoints[valid_isles]->n_points < 4)
 		    G_warning(_("Degenerate island ([%d] vertices)"),
 			      IPoints[i - 1]->n_points);
 
-		size = G_area_of_polygon(Points->x, Points->y, Points->n_points);
+		size =
+		    G_area_of_polygon(IPoints[valid_isles]->x,
+				      IPoints[valid_isles]->y,
+				      IPoints[valid_isles]->n_points);
 		if (size < min_area) {
-		    G_warning(_("Island size [%.1e], island not imported"), size);
+		    G_debug(2, "Island size [%.1e], island not imported",
+			      size);
 		}
 		else {
 		    if (type & GV_LINE)
@@ -334,19 +349,20 @@
 		    if (split_distance > 0 && otype == GV_BOUNDARY)
 			split_line(Map, otype, IPoints[valid_isles], BCats);
 		    else
-			Vect_write_line(Map, otype, IPoints[valid_isles], BCats);
+			Vect_write_line(Map, otype, IPoints[valid_isles],
+					BCats);
 		}
 		valid_isles++;
 	    }
-	}	/* inner rings done */
+	}			/* inner rings done */
 
 	/* Centroid */
 	/* Vect_get_point_in_poly_isl() would fail for degenerate polygon */
 	if (mk_centr) {
 	    if (Points->n_points >= 4) {
 		ret =
-		    Vect_get_point_in_poly_isl(Points, IPoints, valid_isles, &x,
-					       &y);
+		    Vect_get_point_in_poly_isl(Points, IPoints, valid_isles,
+					       &x, &y);
 		if (ret == -1) {
 		    G_warning(_("Cannot calculate centroid"));
 		}
@@ -412,7 +428,8 @@
     return 0;
 }
 
-int split_line(struct Map_info *Map, int otype, struct line_pnts *Points, struct line_cats *Cats)
+int split_line(struct Map_info *Map, int otype, struct line_pnts *Points,
+	       struct line_cats *Cats)
 {
     int i;
     double dist = 0., seg_dist, dx, dy;
@@ -421,12 +438,12 @@
     /* don't write zero length boundaries */
     Vect_line_prune(Points);
     if (Points->n_points < 2)
-    	return 0;
+	return 0;
 
     /* can't split boundaries with only 2 vertices */
     if (Points->n_points == 2) {
 	Vect_write_line(Map, otype, Points, Cats);
-    	return 0;
+	return 0;
     }
 
     OutPoints = Vect_new_line_struct();
@@ -447,9 +464,11 @@
 	    Vect_write_line(Map, otype, OutPoints, Cats);
 	    Vect_reset_line(OutPoints);
 	    dist = seg_dist;
-	    Vect_append_point(OutPoints, Points->x[i - 1], Points->y[i - 1], Points->z[i - 1]);
+	    Vect_append_point(OutPoints, Points->x[i - 1], Points->y[i - 1],
+			      Points->z[i - 1]);
 	}
-	Vect_append_point(OutPoints, Points->x[i], Points->y[i], Points->z[i]);
+	Vect_append_point(OutPoints, Points->x[i], Points->y[i],
+			  Points->z[i]);
     }
     Vect_write_line(Map, otype, OutPoints, Cats);
 



More information about the grass-commit mailing list