def test_classification_filename(self): """ Test getting classification filename """ fname = get_classification_filename(None, outdir=self.tmpdir) self.assertEqual(os.path.dirname(fname), self.tmpdir) self.assertEqual(os.path.basename(fname)[0:4], 'l2d_') fname = get_classification_filename(self.features[0], outdir=self.tmpdir) self.assertEqual(os.path.dirname(fname), self.tmpdir) bname = os.path.splitext(os.path.basename(self.vfilename))[0] self.assertEqual(bname, bname[0:len(bname)])
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)