def test0_classify(self): """ Test classification """ fnames = find_lasfiles(self.lasdir) self.assertTrue(len(fnames) == 4) for f in self.features: fout = get_classification_filename(f, self.testdir) slope, cellsize = class_params(f) classify(fnames, fout, site=f, slope=slope, cellsize=cellsize) fouts = find_classified_lasfile(self.testdir, site=f) self.assertTrue(len(fouts) == 1)
def main(): dhf = argparse.ArgumentDefaultsHelpFormatter parser = argparse.ArgumentParser(description='Classify LAS file(s)', formatter_class=dhf) parser.add_argument('lasdir', help='Directory of LAS file(s) to classify') parser.add_argument('-s', '--site', help='Polygon(s) to process', default=None) h = 'Amount to buffer out site polygons when merging LAS files' parser.add_argument('-b', '--buff', help=h, default=20) parser.add_argument('--slope', help='Slope (override)', default=None) parser.add_argument('--cellsize', help='Cell Size (override)', default=None) parser.add_argument('--maxWindowSize', help='Max Window Size (override)', default=None) parser.add_argument('--maxDistance', help='Max Distance (override)', default=None) parser.add_argument('--outdir', help='Output directory location', default='./') h = 'Decimate the points (steps between points, 1 is no pruning' parser.add_argument('--decimation', help=h, default=None) parser.add_argument( '-o', '--overwrite', default=False, action='store_true', help='Overwrite any existing output files') parser.add_argument('-v', '--verbose', help='Print additional info', default=False, action='store_true') args = parser.parse_args() start = datetime.now() if not os.path.exists(args.outdir): os.makedirs(args.outdir) if args.site is not None: site = gippy.GeoVector(args.site) else: site = [None] fouts = [] for feature in site: # get output filename fout = get_classification_filename(feature, args.outdir, args.slope, args.cellsize) # retrieve parameters from input site slope, cellsize = class_params(feature, args.slope, args.cellsize) if not os.path.exists(fout) or args.overwrite: try: filenames = find_lasfiles(args.lasdir, site=feature, checkoverlap=True) fout = classify(filenames, fout, slope=slope, cellsize=cellsize, site=feature, buff=args.buff, decimation=args.decimation, verbose=args.verbose) except Exception as e: print "Error creating %s: %s" % (os.path.relpath(fout), e) if args.verbose: import traceback print traceback.format_exc() fouts.append(fout) print 'l2d_classify completed in %s' % (datetime.now() - start)
def main(): parser = l2dParser(description='Create DEM(s) from LiDAR files', commands=True) parser.add_input_parser() parser.add_output_parser() parser.add_filter_parser() # parser.add_argument('--vendor_classified', # help='Files are not classified by l2d, the l2d naming scheme was not used for classified files', # default=False) args = parser.parse_args() start0 = datetime.now() lasdir = args.lasdir # open site vector if args.site is not None: try: site = GeoVector(args.site) except: print 'Error opening %s' % args.site exit(2) else: site = [None] # make sure outdir exists args.outdir = os.path.abspath(args.outdir) if not os.path.exists(args.outdir): os.makedirs(args.outdir) args.lasdir = os.path.abspath(args.lasdir) # the final filenames products = dem_products(args.demtype) bnames = {p: '%s%s.%s' % (args.demtype, args.suffix, p) for p in products} prefix = '' # if args.site is None else site.Basename() + '_' fouts = {p: os.path.join(args.outdir, '%s%s%s.%s.vrt' % (prefix, args.demtype, args.suffix, p)) for p in products} # pull out the arguments to pass to create_dems keys = ['radius', 'decimation', 'maxsd', 'maxz', 'maxangle', 'returnnum', 'outdir', 'suffix', 'verbose', 'overwrite'] vargs = vars(args) kwargs = {k: vargs[k] for k in vargs if k in keys} # run if any products are missing exists = all([os.path.exists(f) for f in fouts.values()]) if exists and not args.overwrite: print 'Already created %s in %s' % (args.demtype, os.path.relpath(args.outdir)) exit(0) # loop through features pieces = [] for feature in site: try: # find las files if args.demtype == 'density': lasfiles = find_lasfiles(args.lasdir, site=feature, checkoverlap=True) else: if args.vendor_classified == False: parameters = class_params(feature, args.slope, args.cellsize) lasfiles = find_classified_lasfile(args.lasdir, site=feature, params=parameters) else: lasfiles = find_lasfiles(args.lasdir, site=feature, checkoverlap=True) # create dems pouts = create_dems(lasfiles, args.demtype, site=feature, gapfill=args.gapfill, **kwargs) # NOTE - if gapfill then fouts is dict, otherwise is list of dicts (1 for each radius) pieces.append(pouts) except Exception, e: print "Error creating %s %s: %s" % (args.demtype, '' if feature is None else feature.Basename(), e) if args.verbose: import traceback print traceback.format_exc()
def main(): parser = l2dParser(description='Create DEM(s) from LiDAR files', commands=True) parser.add_input_parser() parser.add_output_parser() parser.add_filter_parser() # parser.add_argument('--vendor_classified', # help='Files are not classified by l2d, the l2d naming scheme was not used for classified files', # default=False) args = parser.parse_args() start0 = datetime.now() lasdir = args.lasdir # open site vector if args.site is not None: try: site = GeoVector(args.site) except: print 'Error opening %s' % args.site exit(2) else: site = [None] # make sure outdir exists args.outdir = os.path.abspath(args.outdir) if not os.path.exists(args.outdir): os.makedirs(args.outdir) args.lasdir = os.path.abspath(args.lasdir) # the final filenames products = dem_products(args.demtype) bnames = {p: '%s%s.%s' % (args.demtype, args.suffix, p) for p in products} prefix = '' # if args.site is None else site.Basename() + '_' fouts = { p: os.path.join(args.outdir, '%s%s%s.%s.vrt' % (prefix, args.demtype, args.suffix, p)) for p in products } # pull out the arguments to pass to create_dems keys = [ 'radius', 'decimation', 'maxsd', 'maxz', 'maxangle', 'returnnum', 'outdir', 'suffix', 'verbose', 'overwrite', 'resolution' ] vargs = vars(args) kwargs = {k: vargs[k] for k in vargs if k in keys} # run if any products are missing exists = all([os.path.exists(f) for f in fouts.values()]) if exists and not args.overwrite: print 'Already created %s in %s' % (args.demtype, os.path.relpath(args.outdir)) exit(0) # loop through features pieces = [] for feature in site: try: # find las files if args.demtype == 'density': lasfiles = find_lasfiles(args.lasdir, site=feature, checkoverlap=True) else: if args.vendor_classified == False: parameters = class_params(feature, args.slope, args.cellsize) lasfiles = find_classified_lasfile(args.lasdir, site=feature, params=parameters) else: lasfiles = find_lasfiles(args.lasdir, site=feature, checkoverlap=True) # create dems pouts = create_dems(lasfiles, args.demtype, site=feature, gapfill=args.gapfill, **kwargs) # NOTE - if gapfill then fouts is dict, otherwise is list of dicts (1 for each radius) pieces.append(pouts) except Exception, e: print "Error creating %s %s: %s" % ( args.demtype, '' if feature is None else feature.Basename(), e) if args.verbose: import traceback print traceback.format_exc()
def main(): dhf = argparse.ArgumentDefaultsHelpFormatter desc = 'Voxelize lidar data to output rasters' parser = argparse.ArgumentParser(description=desc, formatter_class=dhf) parser.add_argument( 'lasdir', help='Directory holding classified LAS files') parser.add_argument( 'demdir', help='Directory holding DEMs (including DSM and DTM for each feature)') parser.add_argument( '--voxtypes', help='Type of return data in output voxels (e.g. counts, intensity); option to output new CHM with "chm"', nargs='*', default=['count','intensity']) parser.add_argument( '-s', '--site', default=None, help='Site shapefile name (use if used for DTM/DSM creation); if area of interest is smaller than whole scene, l2d_dems should be run again using voxel region of interest shapefile') parser.add_argument( '--vendor_classified', help='Files are not classified by l2d, the l2d naming scheme was not used for classified files', default=False) parser.add_argument('--slope', help='Slope (override)', default=None) parser.add_argument('--cellsize', help='Cell Size (override)', default=None) parser.add_argument( '--outdir', help='Directory to output voxel rasters') parser.add_argument( '-o', '--overwrite', default=False, action='store_true', help='Overwrite any existing output files') parser.add_argument( '-v', '--verbose', default=False, action='store_true', help='Print additional info') args = parser.parse_args() start0 = datetime.now() # open site vector if args.site is not None: try: site = GeoVector(args.site) except: print 'Error opening %s' % args.site exit(2) else: site = [None] # make sure outdir exists args.outdir = os.path.abspath(args.outdir) if not os.path.exists(args.outdir): os.makedirs(args.outdir) args.lasdir = os.path.abspath(args.lasdir) # the final filenames products = args.voxtypes fouts = {p: os.path.join(args.outdir, '%s.voxels.vrt' % (p)) for p in products} # run if any products are missing exists = all([os.path.exists(f) for f in fouts.values()]) if exists and not args.overwrite: print 'Already created %s in %s' % (args.voxtypes, os.path.relpath(args.outdir)) exit(0) # loop through features pieces = [] for feature in site: try: # find las files if args.vendor_classified == False: parameters = class_params(feature, args.slope, args.cellsize) lasfiles = find_classified_lasfile(args.lasdir, site=feature, params=parameters) else: lasfiles = find_lasfiles(args.lasdir, site=feature, checkoverlap=True) # create voxels - perhaps not loop over features, but instead voxelize each tile...for loop over lasfiles here. would need to determine output image dimensions though since they could no longer be pulled from existing feature geotiff. pouts = create_voxels(lasfiles, voxtypes=args.voxtypes, demdir=args.demdir, site=feature, outdir=args.outdir, overwrite=args.overwrite) pieces.append(pouts) except Exception, e: print "Error creating voxels: %s" % e if args.verbose: import traceback print traceback.format_exc()
def main(): dhf = argparse.ArgumentDefaultsHelpFormatter desc = 'Voxelize lidar data to output rasters' parser = argparse.ArgumentParser(description=desc, formatter_class=dhf) parser.add_argument('lasdir', help='Directory holding classified LAS files') parser.add_argument( 'demdir', help='Directory holding DEMs (including DSM and DTM for each feature)') parser.add_argument( '--voxtypes', help= 'Type of return data in output voxels (e.g. counts, intensity); option to output new CHM with "chm"', nargs='*', default=['count', 'intensity']) parser.add_argument( '-s', '--site', default=None, help= 'Site shapefile name (use if used for DTM/DSM creation); if area of interest is smaller than whole scene, l2d_dems should be run again using voxel region of interest shapefile' ) parser.add_argument( '--vendor_classified', help= 'Files are not classified by l2d, the l2d naming scheme was not used for classified files', default=False) parser.add_argument('--slope', help='Slope (override)', default=None) parser.add_argument('--cellsize', help='Cell Size (override)', default=None) parser.add_argument('--outdir', help='Directory to output voxel rasters') parser.add_argument('-o', '--overwrite', default=False, action='store_true', help='Overwrite any existing output files') parser.add_argument('-v', '--verbose', default=False, action='store_true', help='Print additional info') args = parser.parse_args() start0 = datetime.now() # open site vector if args.site is not None: try: site = GeoVector(args.site) except: print 'Error opening %s' % args.site exit(2) else: site = [None] # make sure outdir exists args.outdir = os.path.abspath(args.outdir) if not os.path.exists(args.outdir): os.makedirs(args.outdir) args.lasdir = os.path.abspath(args.lasdir) # the final filenames products = args.voxtypes fouts = { p: os.path.join(args.outdir, '%s.voxels.vrt' % (p)) for p in products } # run if any products are missing exists = all([os.path.exists(f) for f in fouts.values()]) if exists and not args.overwrite: print 'Already created %s in %s' % (args.voxtypes, os.path.relpath(args.outdir)) exit(0) # loop through features pieces = [] for feature in site: try: # find las files if args.vendor_classified == False: parameters = class_params(feature, args.slope, args.cellsize) lasfiles = find_classified_lasfile(args.lasdir, site=feature, params=parameters) else: lasfiles = find_lasfiles(args.lasdir, site=feature, checkoverlap=True) # create voxels - perhaps not loop over features, but instead voxelize each tile...for loop over lasfiles here. would need to determine output image dimensions though since they could no longer be pulled from existing feature geotiff. pouts = create_voxels(lasfiles, voxtypes=args.voxtypes, demdir=args.demdir, site=feature, outdir=args.outdir, overwrite=args.overwrite) pieces.append(pouts) except Exception, e: print "Error creating voxels: %s" % e if args.verbose: import traceback print traceback.format_exc()