Ignore:
Timestamp:
May 15, 2014, 3:21:58 AM (10 years ago)
Author:
neteler
Message:

r.in.lidar: return filter added (from v.in.lidar)

Location:
grass/trunk/raster/r.in.lidar
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/raster/r.in.lidar/main.c

    r57951 r60247  
    2727#include <grass/gprojects.h>
    2828#include <grass/glocale.h>
     29#include <liblas/capi/liblas.h>
    2930#include "local_proto.h"
    3031
     
    4041struct node *nodes;
    4142
     43#define LAS_ALL 0
     44#define LAS_FIRST 1
     45#define LAS_LAST 2
     46#define LAS_MID 3
    4247
    4348int new_node(void)
     
    139144
    140145    struct GModule *module;
    141     struct Option *input_opt, *output_opt, *percent_opt, *type_opt;
     146    struct Option *input_opt, *output_opt, *percent_opt, *type_opt, *filter_opt;
    142147    struct Option *method_opt, *zrange_opt, *zscale_opt;
    143148    struct Option *trim_opt, *pth_opt, *res_opt;
     
    149154    LASSRSH LAS_srs;
    150155    LASPointH LAS_point;
     156    int return_filter;
    151157
    152158    struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;
     
    155161    struct Cell_head cellhd, loc_wind;
    156162
     163    unsigned int n_filtered;
    157164
    158165    G_gisinit(argv[0]);
     
    237244        _("Output raster resolution");
    238245
     246    filter_opt = G_define_option();
     247    filter_opt->key = "filter";
     248    filter_opt->type = TYPE_STRING;
     249    filter_opt->required = NO;
     250    filter_opt->label = _("Only import points of selected return type");
     251    filter_opt->description = _("If not specified, all points are imported");
     252    filter_opt->options = "first,last,mid";
     253
    239254    print_flag = G_define_flag();
    240255    print_flag->key = 'p';
     
    303318
    304319        exit(EXIT_SUCCESS);
     320    }
     321
     322    return_filter = LAS_ALL;
     323    if (filter_opt->answer) {
     324        if (strcmp(filter_opt->answer, "first") == 0)
     325            return_filter = LAS_FIRST;
     326        else if (strcmp(filter_opt->answer, "last") == 0)
     327            return_filter = LAS_LAST;
     328        else if (strcmp(filter_opt->answer, "mid") == 0)
     329            return_filter = LAS_MID;
     330        else
     331            G_fatal_error(_("Unknown filter option <%s>"), filter_opt->answer);
    305332    }
    306333
     
    322349        /* Does the projection of the current location match the dataset? */
    323350        /* G_get_window seems to be unreliable if the location has been changed */
    324         G_get_set_window(&loc_wind);
     351        G_get_set_window(&loc_wind); /* TODO: v.in.lidar uses G_get_default_window() */
    325352        /* fetch LOCATION PROJ info */
    326353        if (loc_wind.proj != PROJECTION_XY) {
     
    736763            y = LASPoint_GetY(LAS_point);
    737764            z = LASPoint_GetZ(LAS_point);
     765
     766        if (return_filter != LAS_ALL) {
     767            int return_no = LASPoint_GetReturnNumber(LAS_point);
     768            int n_returns = LASPoint_GetNumberOfReturns(LAS_point);
     769            int skipme = 1;
     770
     771            if (n_returns > 1) {
     772
     773                switch (return_filter) {
     774                case LAS_FIRST:
     775                    if (return_no == 1)
     776                        skipme = 0;
     777                    break;
     778                case LAS_LAST:
     779                    if (return_no == n_returns)
     780                        skipme = 0;
     781                    break;
     782                case LAS_MID:
     783                    if (return_no > 1 && return_no < n_returns)
     784                        skipme = 0;
     785                    break;
     786                }
     787            }
     788            if (skipme) {
     789                n_filtered++;
     790                continue;
     791            }
     792        }
    738793
    739794            if (y <= pass_south || y > pass_north) {
  • grass/trunk/raster/r.in.lidar/r.in.lidar.html

    r57949 r60247  
    8585<!-- explained: memory use for regular stats will be based solely on region size,
    8686 but for the aggregate fns it will also depend on the number of data points. (?) -->
    87 
     87<p>
     88A LiDAR pulse can have multiple returns. The first return values can be
     89used to obtain a digital surface model (DSM) where e.g. canopy cover is
     90represented. The last return values can be used to obtain a digital
     91terrain model (DTM) where e.g. the forest floor instead of canopy
     92cover is represented. The <b>filter</b> option allows to select one of
     93first, mid, or last returns.
    8894<p>
    8995The default map <b>type</b>=<tt>FCELL</tt> is intended as compromise between
Note: See TracChangeset for help on using the changeset viewer.