[GRASS-SVN] r64871 - grass/branches/releasebranch_7_0/vector/v.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 15 13:15:31 PDT 2015


Author: mmetz
Date: 2015-03-15 13:15:31 -0700 (Sun, 15 Mar 2015)
New Revision: 64871

Modified:
   grass/branches/releasebranch_7_0/vector/v.in.ogr/geom.c
   grass/branches/releasebranch_7_0/vector/v.in.ogr/main.c
Log:
v.in.ogr: fix r64353, backport 64476

Modified: grass/branches/releasebranch_7_0/vector/v.in.ogr/geom.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.in.ogr/geom.c	2015-03-15 20:14:38 UTC (rev 64870)
+++ grass/branches/releasebranch_7_0/vector/v.in.ogr/geom.c	2015-03-15 20:15:31 UTC (rev 64871)
@@ -140,7 +140,7 @@
 		in = 1;
 		for (j = 0; j < valid_isles; j++) {
 		    ret = Vect_point_in_poly(x, y, IPoints[j]);
-		    if (ret == 1) {	/* centroid in inner ring */
+		    if (ret > 0) {	/* centroid in inner ring */
 			in = 0;
 			break;	/* inside isle */
 		    }
@@ -305,7 +305,6 @@
 	    return 0;
 	}
 
-	n_polygons++;
 	nr = OGR_G_GetGeometryCount(hGeom);
 
 	Vect_reset_line(Points);
@@ -327,6 +326,8 @@
 	    return 0;
 	}
 
+	n_polygons++;
+
 	if (type & GV_LINE)
 	    otype = GV_LINE;
 	else

Modified: grass/branches/releasebranch_7_0/vector/v.in.ogr/main.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.in.ogr/main.c	2015-03-15 20:14:38 UTC (rev 64870)
+++ grass/branches/releasebranch_7_0/vector/v.in.ogr/main.c	2015-03-15 20:15:31 UTC (rev 64871)
@@ -180,7 +180,7 @@
     param.min_area->required = NO;
     param.min_area->answer = "0.0001";
     param.min_area->label =
-	_("Minimum size of area to be imported (square units)");
+	_("Minimum size of area to be imported (square meters)");
     param.min_area->guisection = _("Selection");
     param.min_area->description = _("Smaller areas and "
 				  "islands are ignored. Should be greater than snap^2");
@@ -204,7 +204,7 @@
     param.snap->type = TYPE_DOUBLE;
     param.snap->required = NO;
     param.snap->answer = "-1";
-    param.snap->label = _("Snapping threshold for boundaries");
+    param.snap->label = _("Snapping threshold for boundaries (map units)");
     param.snap->description = _("'-1' for no snap");
 
     param.outloc = G_define_option();
@@ -533,8 +533,44 @@
     proj_units = NULL;
     Ogr_projection = OGR_L_GetSpatialRef(Ogr_layer);	/* should not be freed later */
 
+
+    /* fetch boundaries */
+    G_get_window(&cellhd);
+    if ((OGR_L_GetExtent(Ogr_layer, &oExt, 1)) == OGRERR_NONE) {
+	cellhd.north = ymax = oExt.MaxY;
+	cellhd.south = ymin = oExt.MinY;
+	cellhd.west = xmin = oExt.MinX;
+	cellhd.east = xmax = oExt.MaxX;
+	cellhd.rows = 20;	/* TODO - calculate useful values */
+	cellhd.cols = 20;
+	cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows;
+	cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols;
+
+	/* use OGR extents if possible, needed to skip corrupted data
+	 * in OGR dsn/layer */
+	have_ogr_extent = 1;
+    }
+    
+    if (!have_ogr_extent) {
+	cellhd.north = 1.;
+	cellhd.south = 0.;
+	cellhd.west = 0.;
+	cellhd.east = 1.;
+	cellhd.top = 1.;
+	cellhd.bottom = 1.;
+	cellhd.rows = 1;
+	cellhd.rows3 = 1;
+	cellhd.cols = 1;
+	cellhd.cols3 = 1;
+	cellhd.depths = 1;
+	cellhd.ns_res = 1.;
+	cellhd.ns_res3 = 1.;
+	cellhd.ew_res = 1.;
+	cellhd.ew_res3 = 1.;
+	cellhd.tb_res = 1.;
+    }
+
     /* Do we need to create a new location? */
-    G_get_window(&cellhd);
     if (param.outloc->answer != NULL) {
 	/* Convert projection information non-interactively as we can't
 	 * assume the user has a terminal open */
@@ -555,9 +591,8 @@
 	    G_get_window(&cellhd);
 	}
 
-        /* If the i flag is set, clean up? and exit here */
-        if(flag.no_import->answer)
-        {
+        /* If the i flag is set, clean up and exit here */
+        if (flag.no_import->answer) {
 	    OGR_DS_Destroy(Ogr_ds);
             exit(EXIT_SUCCESS);
         }
@@ -667,47 +702,8 @@
 	}
     }
 
-    G_begin_polygon_area_calculations();	/* Used in geom() */
+    G_begin_polygon_area_calculations();	/* Used in geom() and centroid() */
 
-    /* TODO: threshold might be recalculated with optional geodesic support to meters */
-    if (G_projection() == PROJECTION_LL)
-        G_important_message(_("Note: In latitude-longitude coordinate system specify threshold in degree unit"));
-
-    /* fetch boundaries */
-    if ((OGR_L_GetExtent(Ogr_layer, &oExt, 1)) == OGRERR_NONE) {
-	cellhd.north = ymax = oExt.MaxY;
-	cellhd.south = ymin = oExt.MinY;
-	cellhd.west = xmin = oExt.MinX;
-	cellhd.east = xmax = oExt.MaxX;
-	cellhd.rows = 20;	/* TODO - calculate useful values */
-	cellhd.cols = 20;
-	cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows;
-	cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols;
-
-	/* use OGR extents if possible, needed to skip corrupted data
-	 * in OGR dsn/layer */
-	have_ogr_extent = 1;
-    }
-    
-    if (!have_ogr_extent) {
-	cellhd.north = 1.;
-	cellhd.south = 0.;
-	cellhd.west = 0.;
-	cellhd.east = 1.;
-	cellhd.top = 1.;
-	cellhd.bottom = 1.;
-	cellhd.rows = 1;
-	cellhd.rows3 = 1;
-	cellhd.cols = 1;
-	cellhd.cols3 = 1;
-	cellhd.depths = 1;
-	cellhd.ns_res = 1.;
-	cellhd.ns_res3 = 1.;
-	cellhd.ew_res = 1.;
-	cellhd.ew_res3 = 1.;
-	cellhd.tb_res = 1.;
-    }
-
     /* set spatial filter */
     if (flag.region->answer) {
 	if (param.spat->answer)
@@ -715,6 +711,9 @@
 	if (nlayers > 1)
 	    G_warning(_("The region flag is applied only to the first OGR layer"));
 
+	/* TODO: does not make sense if a new location has been created:
+	 * the current window has been set from the extents of the first
+	 * OGR layer */
 	G_get_window(&cur_wind);
 	if (have_ogr_extent) {
 	    /* check for any overlap */
@@ -1576,19 +1575,45 @@
 	    max_snap = pow(10, max_snap);
 
 	    G_important_message("%s", separator);
-	    G_warning(_("Errors were encountered during the import"));
-	    G_important_message(_("Estimated range of snapping threshold: [%g, %g]"), min_snap, max_snap);
+	    if (n_overlaps) {
+		G_important_message(_("Some input polygons are overlapping each other."));
+		G_important_message(_("If overlapping is not desired, the data need to be cleaned."));
 
-	    if (snap < min_snap) {
-		G_important_message(_("Try to import again, snapping with at least %g: 'snap=%g'"), min_snap, min_snap);
+		if (snap < max_snap) {
+		    G_important_message(_("The input could be cleaned by snapping vertices to each other."));
+		    G_important_message(_("Estimated range of snapping threshold: [%g, %g]"), min_snap, max_snap);
+		}
+
+		if (snap < min_snap) {
+		    G_important_message(_("Try to import again, snapping with at least %g: 'snap=%g'"), min_snap, min_snap);
+		}
+		else if (snap < max_snap) {
+		    min_snap = snap * 10;
+		    G_important_message(_("Try to import again, snapping with %g: 'snap=%g'"), min_snap, min_snap);
+		}
+		else
+		    /* assume manual cleaning is required */
+		    G_important_message(_("Manual cleaning may be needed."));
 	    }
-	    else if (snap < max_snap) {
-		min_snap = snap * 10;
-		G_important_message(_("Try to import again, snapping with %g: 'snap=%g'"), min_snap, min_snap);
+	    else {
+		if (ncentr < n_polygons) {
+		    G_important_message(_("%d input polygons got lost during import."), n_polygons - ncentr);
+		}
+		if (ncentr > n_polygons) {
+		    G_important_message(_("%d additional areas where created during import."), ncentr - n_polygons);
+		}
+		if (snap > 0) {
+		    G_important_message(_("The snapping threshold %g might be too large."), snap);
+		    G_important_message(_("Estimated range of snapping threshold: [%g, %g]"), min_snap, max_snap);
+		    /* assume manual cleaning is required */
+		    G_important_message(_("Manual cleaning may be needed."));
+		}
+		else {
+		    G_important_message(_("The input could be cleaned by snapping vertices to each other."));
+		    G_important_message(_("Estimated range of snapping threshold: [%g, %g]"), min_snap, max_snap);
+		}
 	    }
-	    else
-		/* assume manual cleaning is required */
-		G_important_message(_("Manual cleaning may be needed"));
+
 	}
     }
 



More information about the grass-commit mailing list