예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
    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))
예제 #4
0
    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))
예제 #5
0
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()
예제 #6
0
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()
예제 #7
0
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()
예제 #8
0
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()