Changeset 66823


Ignore:
Timestamp:
Nov 12, 2015, 2:51:02 PM (9 years ago)
Author:
wenzeslaus
Message:

v.in.lidar: import points only in selected areas [news]

It uses a vector map with areas as a mask to specify
where to import the points (ignores points outside
the mask, does the opposite with -i flag).

Cashing the bboxes seems to be slightly faster
than just creating them all over again. Otherwise,
this implementation is the simplest (not fastest) way possible.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/vector/v.in.lidar/main.c

    r66561 r66823  
    114114    struct Option *in_opt, *out_opt, *spat_opt, *filter_opt, *class_opt;
    115115    struct Option *id_layer_opt, *return_layer_opt, *class_layer_opt;
     116    struct Option *vector_mask_opt, *vector_mask_field_opt;
    116117    struct Option *skip_opt, *preserve_opt, *offset_opt, *limit_opt;
    117118    struct Option *outloc_opt;
     
    119120    struct Flag *nocats_flag;
    120121    struct Flag *over_flag, *extend_flag, *no_import_flag;
     122    struct Flag *invert_mask_flag;
    121123    char buf[2000];
    122124    struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;
     
    156158    unsigned long long points_imported; /* counter how much we have imported */
    157159    unsigned long long feature_count, n_outside,
    158         n_filtered, n_class_filtered, not_valid;
     160        n_outside_mask, n_filtered, n_class_filtered, not_valid;
    159161#else
    160162    unsigned long n_features;
    161163    unsigned long points_imported;
    162164    unsigned long feature_count, n_outside,
    163         n_filtered, n_class_filtered, not_valid;
     165        n_outside_mask, n_filtered, n_class_filtered, not_valid;
    164166#endif
    165167
     
    228230    class_opt->guisection = _("Selection");
    229231
     232    vector_mask_opt = G_define_standard_option(G_OPT_V_INPUT);
     233    vector_mask_opt->key = "mask";
     234    vector_mask_opt->required = NO;
     235    vector_mask_opt->label = _("Areas where to import points");
     236    vector_mask_opt->description = _("Name of vector map with areas where the points should be imported");
     237    vector_mask_opt->guisection = _("Selection");
     238
     239    vector_mask_field_opt = G_define_standard_option(G_OPT_V_FIELD);
     240    vector_mask_field_opt->key = "mask_layer";
     241    vector_mask_field_opt->label = _("Layer number or name for mask option");
     242    vector_mask_field_opt->guisection = _("Selection");
     243
    230244    skip_opt = G_define_option();
    231245    skip_opt->key = "skip";
     
    283297    region_flag->guisection = _("Selection");
    284298    region_flag->description = _("Limit import to the current region");
     299
     300    invert_mask_flag = G_define_flag();
     301    invert_mask_flag->key = 'i';
     302    invert_mask_flag->description = _("Invert mask when selecting points");
     303    invert_mask_flag->guisection = _("Selection");
    285304
    286305    extend_flag = G_define_flag();
     
    753772    }
    754773
     774    struct Map_info vector_mask;
     775    int naareas;
     776    int aarea;
     777    struct bound_box *mask_area_boxes;
     778    int invert_mask = 0;
     779    if (vector_mask_opt->answer) {
     780        if (Vect_open_old2(&vector_mask, vector_mask_opt->answer, "", vector_mask_field_opt->answer) < 2)
     781            G_fatal_error(_("Failed to open vector <%s>"), vector_mask_opt->answer);
     782        naareas = Vect_get_num_areas(&vector_mask);
     783        mask_area_boxes = G_malloc(naareas * sizeof(struct bound_box));
     784        for (aarea = 1; aarea <= naareas; aarea++) {
     785            Vect_get_area_box(&vector_mask, aarea, &mask_area_boxes[aarea - 1]);
     786        }
     787        if (invert_mask_flag->answer)
     788            invert_mask = 1;
     789    }
     790
    755791    /* Import feature */
    756792    points_imported = 0;
     
    761797    n_filtered = 0;
    762798    n_class_filtered = 0;
     799    n_outside_mask = 0;
    763800
    764801    Points = Vect_new_line_struct();
     
    818855            }
    819856        }
     857    if (vector_mask_opt->answer) {
     858        skipme = TRUE;
     859        for (aarea = 1; aarea <= naareas; aarea++) {
     860            if (Vect_point_in_area(x, y, &vector_mask, aarea, &mask_area_boxes[aarea - 1])) {
     861                skipme = FALSE;
     862                break;
     863            }
     864        }
     865        if (invert_mask ^ skipme) {
     866            n_outside_mask++;
     867            continue;
     868        }
     869    }
    820870        if (return_filter != LAS_ALL) {
    821871            int return_no = LASPoint_GetReturnNumber(LAS_point);
     
    9931043    }
    9941044   
     1045    if (vector_mask_opt->answer) {
     1046        Vect_close(&vector_mask);
     1047        G_free(mask_area_boxes);
     1048    }
     1049   
    9951050    LASSRS_Destroy(LAS_srs);
    9961051    LASHeader_Destroy(LAS_header);
     
    10051060    if (!limit_n && !cat_max_reached && points_imported != n_features
    10061061            - not_valid - n_outside - n_filtered - n_class_filtered
    1007             - offset_n_counter - n_count_filtered)
     1062            - n_outside_mask - offset_n_counter - n_count_filtered)
    10081063        G_warning(_("The underlying libLAS library is at its limits."
    10091064                    " Previously reported counts might have been distorted."
     
    10191074    if (n_outside)
    10201075        G_message(_("%llu input points were outside of the selected area"), n_outside);
     1076    if (n_outside_mask)
     1077        G_message(_("%llu input points were outside of the area specified by mask"), n_outside_mask);
    10211078    if (n_filtered)
    10221079        G_message(_("%llu input points were filtered out by return number"), n_filtered);
     
    10361093    if (n_outside)
    10371094        G_message(_("%lu input points were outside of the selected area"), n_outside);
     1095    if (n_outside_mask)
     1096        G_message(_("%lu input points were outside of the area specified by mask"), n_outside_mask);
    10381097    if (n_filtered)
    10391098        G_message(_("%lu input points were filtered out by return number"), n_filtered);
Note: See TracChangeset for help on using the changeset viewer.