def test1_create_density(self): """ Test creating density """ fouts = [] for f in self.features: lasfiles = find_lasfiles(self.lasdir, site=f, checkoverlap=True) fout = create_dems(lasfiles, "density", site=f, outdir=self.testdir) fouts.append(fout["den"]) [self.assertTrue(os.path.exists(f)) for f in fouts] # create VRT fout = os.path.join(self.testdir, "density.vrt") create_vrt(fouts, fout, site=self.features)
def test3_create_dsm(self): """ Create DSM """ pieces = [] for f in self.features: lasfiles = find_classified_lasfile(self.testdir, site=f) pouts = create_dems(lasfiles, "dsm", site=f, gapfill=True, outdir=self.testdir) [self.assertTrue(os.path.exists(fout) for fout in pouts.items())] pieces.append(pouts) for product in pouts.keys(): # there will be mult if gapfill False and multiple radii....use 1st one fnames = [piece[product] for piece in pieces] fout = os.path.join(self.testdir, "dsm-%s.vrt" % product) create_vrt(fnames, fout, site=self.features) self.assertTrue(os.path.exists(fout))
def test1_create_density(self): """ Test creating density """ fouts = [] for f in self.features: lasfiles = find_lasfiles(self.lasdir, site=f, checkoverlap=True) fout = create_dems(lasfiles, 'density', site=f, outdir=self.testdir) fouts.append(fout['den']) [self.assertTrue(os.path.exists(f)) for f in fouts] # create VRT fout = os.path.join(self.testdir, 'density.vrt') create_vrt(fouts, fout, site=self.features)
def test3_create_dsm(self): """ Create DSM """ pieces = [] for f in self.features: lasfiles = find_classified_lasfile(self.testdir, site=f) pouts = create_dems(lasfiles, 'dsm', site=f, gapfill=True, outdir=self.testdir) [self.assertTrue(os.path.exists(fout) for fout in pouts.items())] pieces.append(pouts) for product in pouts.keys(): # there will be mult if gapfill False and multiple radii....use 1st one fnames = [piece[product] for piece in pieces] fout = os.path.join(self.testdir, 'dsm-%s.vrt' % product) create_vrt(fnames, fout, site=self.features) self.assertTrue(os.path.exists(fout))
def test4_create_chm(self): """ Create CHM """ fouts = [] for f in self.features: prefix = os.path.join(self.testdir, f.Basename() + "_") fdtm = os.path.join(self.testdir, prefix + "dtm.idw.tif") fdsm = os.path.join(self.testdir, prefix + "dsm.max.tif") fout = create_chm(fdtm, fdsm, prefix + "chm.tif") fouts.append(fout) self.assertTrue(os.path.exists(fout)) fout = create_vrt(fouts, os.path.join(self.testdir, "chm.vrt"), site=self.features) self.assertTrue(os.path.exists(fout))
def test4_create_chm(self): """ Create CHM """ fouts = [] for f in self.features: prefix = os.path.join(self.testdir, f.Basename() + '_') fdtm = os.path.join(self.testdir, prefix + 'dtm.idw.tif') fdsm = os.path.join(self.testdir, prefix + 'dsm.max.tif') fout = create_chm(fdtm, fdsm, prefix + 'chm.tif') fouts.append(fout) self.assertTrue(os.path.exists(fout)) fout = create_vrt(fouts, os.path.join(self.testdir, 'chm.vrt'), site=self.features) self.assertTrue(os.path.exists(fout))
def main(): dhf = argparse.ArgumentDefaultsHelpFormatter desc = 'Calculate and create CHM from a DSM and DTM' parser = argparse.ArgumentParser(description=desc, formatter_class=dhf) parser.add_argument( 'demdir', help='Directory holding DEMs (and used to store CHM output') parser.add_argument( '-s', '--site', default=None, help='Site shapefile name (use if used for DTM/DSM creation') parser.add_argument( '--dsm', default='dsm.max.tif', help='Filename of DSM input (will be preceded by feature name if using shapefile') parser.add_argument( '--dtm', default='dtm.idw.tif', help='Filename of DTM input (will be preceded by feature name if using shapefile') parser.add_argument( '--fout', default='chm.tif', help='Output filename (created in demdir)') parser.add_argument( '--hillshade', default=False, action='store_true', help='Generate hillshade') parser.add_argument( '-v', '--verbose', default=False, action='store_true', help='Print additional info') args = parser.parse_args() start = dt.datetime.now() print 'Creating CHM from DEMS in %s' % (os.path.relpath(args.demdir)) if args.site is not None: site = gippy.GeoVector(args.site) else: site = [None] fout_final = os.path.join(args.demdir, os.path.splitext(args.fout)[0] + '.vrt') fouts = [] hillfouts = [] for feature in site: prefix = os.path.join(args.demdir, '' if feature is None else feature.Basename() + '_') fdtm = prefix + args.dtm fdsm = prefix + args.dsm if not os.path.exists(fdtm) or not os.path.exists(fdsm): print "No valid input files found (%s)" % prefix continue try: fout = create_chm(fdtm, fdsm, prefix + args.fout) fouts.append(fout) except Exception as e: print "Error creating %s: %s" % (fout, e) if args.verbose: import traceback print traceback.format_exc() if args.hillshade: hillfouts.append(create_hillshade(fout)) # if multiple file output then combine them together if len(fouts) > 0 and site[0] is not None: create_vrt(fouts, fout_final, site=site) if args.hillshade: fout = os.path.splitext(fout_final)[0] + '_hillshade.tif' create_vrt(hillfouts, fout, site=site) print 'Completed %s in %s' % (fout_final, dt.datetime.now() - start)
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() # combine all features into single file and align to site for product in products: # there will be mult if gapfill False and multiple radii....use 1st one fnames = [piece[product] for piece in pieces] if len(fnames) > 0: create_vrt(fnames, fouts[product], site=site) print 'l2d_dems %s completed (%s) in %s' % (args.demtype, os.path.relpath(args.outdir), datetime.now() - start0) if __name__ == '__main__': main()
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() # combine all features into single file and align to site for product in products: # there will be mult if gapfill False and multiple radii....use 1st one fnames = [piece[product] for piece in pieces] if len(fnames) > 0: create_vrt(fnames, fouts[product], site=site) print 'l2d_dems %s completed (%s) in %s' % ( args.demtype, os.path.relpath(args.outdir), datetime.now() - start0) if __name__ == '__main__': main()
def main(): dhf = argparse.ArgumentDefaultsHelpFormatter desc = 'Calculate and create CHM from a DSM and DTM' parser = argparse.ArgumentParser(description=desc, formatter_class=dhf) parser.add_argument( 'demdir', help='Directory holding DEMs (and used to store CHM output') parser.add_argument( '-s', '--site', default=None, help='Site shapefile name (use if used for DTM/DSM creation') parser.add_argument( '--dsm', default='dsm.max.tif', help= 'Filename of DSM input (will be preceded by feature name if using shapefile' ) parser.add_argument( '--dtm', default='dtm.idw.tif', help= 'Filename of DTM input (will be preceded by feature name if using shapefile' ) parser.add_argument('--fout', default='chm.tif', help='Output filename (created in demdir)') parser.add_argument('--hillshade', default=False, action='store_true', help='Generate hillshade') parser.add_argument('-v', '--verbose', default=False, action='store_true', help='Print additional info') args = parser.parse_args() start = dt.datetime.now() print 'Creating CHM from DEMS in %s' % (os.path.relpath(args.demdir)) if args.site is not None: site = gippy.GeoVector(args.site) else: site = [None] fout_final = os.path.join(args.demdir, os.path.splitext(args.fout)[0] + '.vrt') fouts = [] hillfouts = [] for feature in site: prefix = os.path.join( args.demdir, '' if feature is None else feature.Basename() + '_') fdtm = prefix + args.dtm fdsm = prefix + args.dsm if not os.path.exists(fdtm) or not os.path.exists(fdsm): print "No valid input files found (%s)" % prefix continue try: fout = create_chm(fdtm, fdsm, prefix + args.fout) fouts.append(fout) except Exception as e: print "Error creating %s: %s" % (fout, e) if args.verbose: import traceback print traceback.format_exc() if args.hillshade: hillfouts.append(create_hillshade(fout)) # if multiple file output then combine them together if len(fouts) > 0 and site[0] is not None: create_vrt(fouts, fout_final, site=site) if args.hillshade: fout = os.path.splitext(fout_final)[0] + '_hillshade.tif' create_vrt(hillfouts, fout, site=site) print 'Completed %s in %s' % (fout_final, dt.datetime.now() - start)
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() # combine all features into single file and align to site for chm if 'chm' in products: fnames = [piece['chm'] for piece in pieces] if len(fnames) > 0: create_vrt(fnames, fouts['chm'], site=site) print 'l2d_voxelize completed (%s) in %s' % (os.path.relpath(args.outdir), datetime.now() - start0) if __name__ == '__main__': main()
print 'clipping image to feature' clip_by_site(out,feature) pieces.append(out) except Exception, e: print "Error creating metric: %s" % e if args.verbose: import traceback print traceback.format_exc() # combine all features into single file and align to site for chm create_vrt(pieces, fouts[product], site=site) print 'l2d_process_voxels completed (%s) in %s' % (os.path.relpath(args.outdir), datetime.now() - start0) if __name__ == '__main__': main()
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() # combine all features into single file and align to site for chm if 'chm' in products: fnames = [piece['chm'] for piece in pieces] if len(fnames) > 0: create_vrt(fnames, fouts['chm'], site=site) print 'l2d_voxelize completed (%s) in %s' % (os.path.relpath( args.outdir), datetime.now() - start0) if __name__ == '__main__': main()