[GRASS-SVN] r64341 - grass/branches/releasebranch_7_0/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 27 14:24:25 PST 2015


Author: mmetz
Date: 2015-01-27 14:24:24 -0800 (Tue, 27 Jan 2015)
New Revision: 64341

Modified:
   grass/branches/releasebranch_7_0/lib/vector/Vlib/find.c
Log:
Vlib: fix Vect_find_area()

Modified: grass/branches/releasebranch_7_0/lib/vector/Vlib/find.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/vector/Vlib/find.c	2015-01-27 22:24:10 UTC (rev 64340)
+++ grass/branches/releasebranch_7_0/lib/vector/Vlib/find.c	2015-01-27 22:24:24 UTC (rev 64341)
@@ -263,11 +263,13 @@
  */
 int Vect_find_area(struct Map_info *Map, double x, double y)
 {
-    int i, ret, area;
+    int i, j, ret, area, isle;
     struct bound_box box;
     static struct boxlist *List = NULL;
     static BOX_SIZE *size_list;
     static int alloc_size_list = 0;
+    const struct Plus_head *Plus;
+    struct P_area *Area;
 
     G_debug(3, "Vect_find_area() x = %f y = %f", x, y);
 
@@ -277,6 +279,8 @@
 	size_list = G_malloc(alloc_size_list * sizeof(BOX_SIZE));
     }
 
+    Plus = &(Map->plus);
+
     /* select areas by box */
     box.E = x;
     box.W = x;
@@ -320,14 +324,31 @@
 
     for (i = 0; i < List->n_values; i++) {
 	area = size_list[i].i;
-	/* testing only the outer ring is sufficient because 
-	 * inner rings have been tested earlier (sorted list) */
+	/* outer ring */
 	ret = Vect_point_in_area_outer_ring(x, y, Map, area, &size_list[i].box);
 
-	G_debug(3, "    area = %d Vect_point_in_area() = %d", area, ret);
+	G_debug(3, "    area = %d Vect_point_in_area_outer_ring() = %d", area, ret);
 
-	if (ret >= 1)
+	if (ret >= 1) {
+	    /* check if in islands */
+	    Area = Plus->Area[area];
+	    for (j = 0; j < Area->n_isles; j++) {
+		isle = Area->isles[j];
+		Vect_get_isle_box(Map, isle, &box);
+		ret = Vect_point_in_island(x, y, Map, isle, &box);
+
+		G_debug(3, "    area = %d Vect_point_in_island() = %d", area, ret);
+
+		if (ret >= 1) {
+		    /* point is not in area
+		     * point is also not in any inner area, those have 
+		     * been tested before (sorted list) 
+		     * -> area inside island could not be built */
+		    return 0;
+		}
+	    }
 	    return (area);
+	}
     }
 
     return 0;



More information about the grass-commit mailing list