Changeset 62091


Ignore:
Timestamp:
Sep 26, 2014, 5:52:24 AM (10 years ago)
Author:
mmetz
Message:

v.select: speed up OP_OVERLAP

Location:
grass/trunk/vector/v.select
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/vector/v.select/overlap.c

    r52537 r62091  
    3939/* Returns 1 if line1 from Map1 overlaps area2 from Map2,
    4040 *         0 otherwise */
    41 int line_overlap_area(struct Map_info *LMap, int line, struct Map_info *AMap,
    42                       int area, struct bound_box box)
     41int line_overlap_area(struct line_pnts *LPoints, struct Map_info *AMap,
     42                      int area)
    4343{
    4444    int i, nisles, isle;
    45     static struct line_pnts *LPoints = NULL;
    4645    static struct line_pnts *APoints = NULL;
     46    static struct line_pnts **IPoints = NULL;
     47    static int isles_alloc = 0;
    4748
    48     G_debug(4, "line_overlap_area line = %d area = %d", line, area);
     49    G_debug(4, "line_overlap_area area = %d", area);
    4950
    50     if (!LPoints) {
    51         LPoints = Vect_new_line_struct();
     51    if (!APoints) {
    5252        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();
    5357    }
    5458
    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    }
    5773
    5874    /* Try if any of line vertices is within area */
    5975    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            }
    6390        }
    6491    }
     
    7097    /* Try intersections of line with area/isles boundary */
    7198    /* Outer boundary */
    72     Vect_get_area_points(AMap, area, APoints);
    7399
    74     if (Vect_line_check_intersection(LPoints, APoints, 0)) {
     100    if (Vect_line_check_intersection2(LPoints, APoints, 0)) {
    75101        G_debug(4, "  -> line intersects outer area boundary");
    76102        return 1;
    77103    }
    78104
    79     nisles = Vect_get_area_num_isles(AMap, area);
     105    for (i = 0; i < nisles; i++) {
    80106
    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)) {
    86108            G_debug(4, "  -> line intersects area island boundary");
    87109            return 1;
  • grass/trunk/vector/v.select/proto.h

    r51088 r62091  
    4343/* overlap.c */
    4444void add_aarea(struct Map_info *, int, int *);
    45 int line_overlap_area(struct Map_info *, int, struct Map_info *, int, struct bound_box);
     45int line_overlap_area(struct line_pnts *, struct Map_info *, int);
    4646
    4747/* write.c */
  • grass/trunk/vector/v.select/select.c

    r62067 r62091  
    3535
    3636    nalines = Vect_get_num_lines(aIn);
    37     if (operator == OP_OVERLAP)
    38         G_message("Using GRASS GIS operator...");
    39     else
    40         G_message("Using GEOS operator...");
    4137   
    4238    /* Lines in A. Go through all lines and mark those that meets condition */
     
    4440        G_message(_("Processing features..."));
    4541       
     42        G_percent(0, nalines, 2);
    4643        for (aline = 1; aline <= nalines; aline++) {
    4744            struct bound_box abox;
     
    110107                        Vect_read_line(bIn, BPoints, NULL, bline);
    111108
    112                         if (Vect_line_check_intersection(APoints, BPoints, 0)) {
     109                        if (Vect_line_check_intersection2(APoints, BPoints, 0)) {
    113110                            found = 1;
    114111                            break;
     
    148145                    }
    149146                    else {
    150                         if (line_overlap_area(aIn, aline, bIn, barea, List->box[i])) {
     147                        if (line_overlap_area(APoints, bIn, barea)) {
    151148                            ALines[aline] = 1;
    152149                            break;
     
    172169        naareas = Vect_get_num_areas(aIn);
    173170
     171        G_percent(0, naareas, 2);
    174172        for (aarea = 1; aarea <= naareas; aarea++) {
    175173            struct bound_box abox;
    176174
    177             G_percent(aarea, naareas, 2);       /* must be before any continue */
     175            G_percent(aarea, naareas, 1);
    178176
    179177            if (Vect_get_area_cat(aIn, aarea, afield) < 0) {
     
    220218                    }
    221219                    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)) {
    223223                            add_aarea(aIn, aarea, ALines);
    224224                            continue;
     
    262262
    263263                    aline = abs(LList->value[i]);
     264                    Vect_read_line(aIn, APoints, NULL, aline);
    264265
    265266                    for (j = 0; j < TmpList->n_values; j++) {
     
    303304                           
    304305                            /* 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)) {
    307307                                found = 1;
    308308                                break;
Note: See TracChangeset for help on using the changeset viewer.