Changeset 62091
- Timestamp:
- Sep 26, 2014, 5:52:24 AM (10 years ago)
- Location:
- grass/trunk/vector/v.select
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
grass/trunk/vector/v.select/overlap.c
r52537 r62091 39 39 /* Returns 1 if line1 from Map1 overlaps area2 from Map2, 40 40 * 0 otherwise */ 41 int line_overlap_area(struct Map_info *LMap, int line, struct Map_info *AMap,42 int area , struct bound_box box)41 int line_overlap_area(struct line_pnts *LPoints, struct Map_info *AMap, 42 int area) 43 43 { 44 44 int i, nisles, isle; 45 static struct line_pnts *LPoints = NULL;46 45 static struct line_pnts *APoints = NULL; 46 static struct line_pnts **IPoints = NULL; 47 static int isles_alloc = 0; 47 48 48 G_debug(4, "line_overlap_area line = %d area = %d", line, area);49 G_debug(4, "line_overlap_area area = %d", area); 49 50 50 if (!LPoints) { 51 LPoints = Vect_new_line_struct(); 51 if (!APoints) { 52 52 APoints = Vect_new_line_struct(); 53 isles_alloc = 10; 54 IPoints = G_malloc(isles_alloc * sizeof(struct line_pnts *)); 55 for (i = 0; i < isles_alloc; i++) 56 IPoints[i] = Vect_new_line_struct(); 53 57 } 54 58 55 /* Read line coordinates */ 56 Vect_read_line(LMap, LPoints, NULL, line); 59 Vect_get_area_points(AMap, area, APoints); 60 nisles = Vect_get_area_num_isles(AMap, area); 61 62 if (nisles >= isles_alloc) { 63 IPoints = G_realloc(IPoints, (nisles + 10) * sizeof(struct line_pnts *)); 64 for (i = isles_alloc; i < nisles + 10; i++) 65 IPoints[i] = Vect_new_line_struct(); 66 isles_alloc = nisles + 10; 67 } 68 69 for (i = 0; i < nisles; i++) { 70 isle = Vect_get_area_isle(AMap, area, i); 71 Vect_get_isle_points(AMap, isle, IPoints[i]); 72 } 57 73 58 74 /* Try if any of line vertices is within area */ 59 75 for (i = 0; i < LPoints->n_points; i++) { 60 if (Vect_point_in_area(LPoints->x[i], LPoints->y[i], AMap, area, &box)) { 61 G_debug(4, " -> line vertex inside area"); 62 return 1; 76 77 if (Vect_point_in_poly(LPoints->x[i], LPoints->y[i], APoints)) { 78 int inside = 1; 79 80 for (isle = 0; isle < nisles; isle++) { 81 if (Vect_point_in_poly(LPoints->x[i], LPoints->y[i], IPoints[isle])) { 82 inside = 0; 83 break; 84 } 85 } 86 if (inside) { 87 G_debug(4, " -> line vertex inside area"); 88 return 1; 89 } 63 90 } 64 91 } … … 70 97 /* Try intersections of line with area/isles boundary */ 71 98 /* Outer boundary */ 72 Vect_get_area_points(AMap, area, APoints);73 99 74 if (Vect_line_check_intersection (LPoints, APoints, 0)) {100 if (Vect_line_check_intersection2(LPoints, APoints, 0)) { 75 101 G_debug(4, " -> line intersects outer area boundary"); 76 102 return 1; 77 103 } 78 104 79 nisles = Vect_get_area_num_isles(AMap, area);105 for (i = 0; i < nisles; i++) { 80 106 81 for (i = 0; i < nisles; i++) { 82 isle = Vect_get_area_isle(AMap, area, i); 83 Vect_get_isle_points(AMap, isle, APoints); 84 85 if (Vect_line_check_intersection(LPoints, APoints, 0)) { 107 if (Vect_line_check_intersection2(LPoints, IPoints[i], 0)) { 86 108 G_debug(4, " -> line intersects area island boundary"); 87 109 return 1; -
grass/trunk/vector/v.select/proto.h
r51088 r62091 43 43 /* overlap.c */ 44 44 void add_aarea(struct Map_info *, int, int *); 45 int line_overlap_area(struct Map_info *, int, struct Map_info *, int, struct bound_box);45 int line_overlap_area(struct line_pnts *, struct Map_info *, int); 46 46 47 47 /* write.c */ -
grass/trunk/vector/v.select/select.c
r62067 r62091 35 35 36 36 nalines = Vect_get_num_lines(aIn); 37 if (operator == OP_OVERLAP)38 G_message("Using GRASS GIS operator...");39 else40 G_message("Using GEOS operator...");41 37 42 38 /* Lines in A. Go through all lines and mark those that meets condition */ … … 44 40 G_message(_("Processing features...")); 45 41 42 G_percent(0, nalines, 2); 46 43 for (aline = 1; aline <= nalines; aline++) { 47 44 struct bound_box abox; … … 110 107 Vect_read_line(bIn, BPoints, NULL, bline); 111 108 112 if (Vect_line_check_intersection (APoints, BPoints, 0)) {109 if (Vect_line_check_intersection2(APoints, BPoints, 0)) { 113 110 found = 1; 114 111 break; … … 148 145 } 149 146 else { 150 if (line_overlap_area( aIn, aline, bIn, barea, List->box[i])) {147 if (line_overlap_area(APoints, bIn, barea)) { 151 148 ALines[aline] = 1; 152 149 break; … … 172 169 naareas = Vect_get_num_areas(aIn); 173 170 171 G_percent(0, naareas, 2); 174 172 for (aarea = 1; aarea <= naareas; aarea++) { 175 173 struct bound_box abox; 176 174 177 G_percent(aarea, naareas, 2); /* must be before any continue */175 G_percent(aarea, naareas, 1); 178 176 179 177 if (Vect_get_area_cat(aIn, aarea, afield) < 0) { … … 220 218 } 221 219 else { 222 if (line_overlap_area(bIn, bline, aIn, aarea, abox)) { 220 Vect_read_line(bIn, BPoints, NULL, bline); 221 222 if (line_overlap_area(BPoints, aIn, aarea)) { 223 223 add_aarea(aIn, aarea, ALines); 224 224 continue; … … 262 262 263 263 aline = abs(LList->value[i]); 264 Vect_read_line(aIn, APoints, NULL, aline); 264 265 265 266 for (j = 0; j < TmpList->n_values; j++) { … … 303 304 304 305 /* Check intersectin of lines from List with area B */ 305 if (line_overlap_area(aIn, aline, 306 bIn, barea, TmpList->box[j])) { 306 if (line_overlap_area(APoints, bIn, barea)) { 307 307 found = 1; 308 308 break;
Note:
See TracChangeset
for help on using the changeset viewer.
