sys.exit() filename = sys.argv[1] basename = os.path.splitext(filename)[0] extension = os.path.splitext(filename)[1] In = filename fn = basename+'_dsm.tif' # read point cloud x,y,z,c = getpoints(In) # intiate grid system (coordinates of center point grid cells) res = 1 xi, yi = np.arange(x.min(), x.max()+res/2, res), np.arange(y.min(), y.max()+res/2, res) extent = [xi.min(), xi.max(), yi.min(), yi.max()] # only used to set extent to plots grid = np.zeros((len(yi),len(xi)))*np.NaN # retreive gridcell border coordinates bx, by = gridcellborders(xi,yi,res) # georeferencing info geotransform = (x.min(), res, 0, y.max(), 0, -res) # used for georeference metadata in geotiff proj = '' # mandatory setting used to store projection information in metadata geotiff (not assigned as metadata is not stored in lidar txt) # create DSM dsm = createDSM(x,y,z,xi,yi,bx,by,res,geotransform, proj) # write tiff saveimg(np.flipud(dsm), fn, len(xi), len(yi), geotransform, proj)
# georeferencing info geotransform = (x.min(), res, 0, y.max(), 0, -res) # used for georeference metadata in geotiff proj = '' # mandatory setting used to store projection information in metadata geotiff (not assigned as metadata is not stored in lidar txt) # dtm if os.path.isfile(fn_dtm) == True: # load dtm from generic_tools import openimg dtm, _,_,_,_,_ = openimg(fn_dtm) dtm = np.flipud(dtm) else: # create dtm from dtm import createDTM g = c == 2 dtm = createDTM(x[g],y[g],z[g],xi,yi,res,geotransform, proj, method='idw') saveimg(np.flipud(dtm), fn_dtm , len(xi), len(yi), geotransform, proj) # dsm if os.path.isfile(fn_dsm) == True: # load dsm from generic_tools import openimg dsm, _,_,_,_,_ = openimg(fn_dsm) dsm = np.flipud(dsm) else: # create dsm from dsm import createDSM dsm = createDSM(x,y,z,xi,yi,bx,by,res,geotransform, proj) saveimg(np.flipud(dsm), fn_dsm, len(xi), len(yi), geotransform, proj) # create chm chm = createCHM(dtm,dsm)
res = 1 xi, yi = np.arange(x.min(), x.max()+res/2, res), np.arange(y.min(), y.max()+res/2, res) extent = [xi.min(), xi.max(), yi.min(), yi.max()] # only used to set extent to plots grid = np.zeros((len(yi),len(xi)))*np.NaN # retreive gridcell border coordinates bx, by = gridcellborders(xi,yi,res) # georeferencing info geotransform = (x.min(), res, 0, y.max(), 0, -res) # used for georeference metadata in geotiff proj = '' # mandatory setting used to store projection information in metadata geotiff (not assigned as metadata is not stored in lidar txt) # create dsm from dsm import createDSM dsm = createDSM(x,y,z,xi,yi,bx,by,res,geotransform, proj) saveimg(np.flipud(dsm), basename+"_dsm.tif", len(xi), len(yi), geotransform, proj) # calculate slope and aspect in radians slope_rad = np.core.umath.deg2rad(calcSlope(dsm)) asp_rad = np.core.umath.deg2rad(calcAspect(dsm)) slope_rad = np.flipud(slope_rad) asp_rad = np.flipud(asp_rad) # calculate solar radiation SR = calcSR(dsm, slope_rad, asp_rad, xi, yi, 0.2) # write tiff saveimg(SR, fn, len(xi), len(yi), geotransform, proj) plt.figure(figsize=(15,5))
# georeferencing info geotransform = (x.min(), res, 0, y.max(), 0, -res) # used for georeference metadata in geotiff proj = '+proj=utm +zone=21 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs ' # mandatory setting used to store projection information in metadata geotiff (not assigned as metadata is not stored in lidar txt) # create dtm from dtm import createDTM g = c == 2 dtm = createDTM(x[g],y[g],z[g],xi,yi,res,geotransform, proj, method='idw') # Calculate cover #from cover import Cover #cover = Cover(x,y,c,grid,bx,by) # Calculate RH50 from relativeheight import createRH rh50 = createRH(x,y,z,grid,dtm,bx,by,50) # Calculate biomass #agb = calcAGB(cover,rh50) agb = calcAGB(rh50) # write tiff saveimg(np.flipud(agb), fn, len(xi), len(yi), geotransform, proj) # write intermediate results fn = basename+'_dtm.tif' saveimg(np.flipud(dtm), fn, len(xi), len(yi), geotransform, proj) fn = basename+'_rh50.tif' saveimg(np.flipud(rh50), fn, len(xi), len(yi), geotransform, proj)
In = filename fn = basename+'_aspect.tif' # read point cloud x,y,z,c = getpoints(In) g = c==2 # ground points # intiate grid system (coordinates of center point grid cells) res = 1 xi, yi = np.arange(x.min(), x.max()+res/2, res), np.arange(y.min(), y.max()+res/2, res) extent = [xi.min(), xi.max(), yi.min(), yi.max()] # only used to set extent to plots grid = np.zeros((len(yi),len(xi)))*np.NaN # retreive gridcell border coordinates bx, by = gridcellborders(xi,yi,res) # georeferencing info geotransform = (x.min(), res, 0, y.max(), 0, -res) # used for georeference metadata in geotiff proj = '' # mandatory setting used to store projection information in metadata geotiff (not assigned as metadata is not stored in lidar txt) # create DTM from dtm import createDTM dtm = createDTM(x[g],y[g],z[g],xi,yi,res,geotransform, proj, method='idw') # calculate slope angle aspect = calcAspect(dtm) # write tiff saveimg(np.flipud(aspect), fn, len(xi), len(yi), geotransform, proj)
tree_x = Xi[coo[0], coo[1]] tree_y = Yi[coo[0], coo[1]] tree_z = chm[coo[0], coo[1]] else: # more peaks in one crown, determine highest peak=tree top tree_z = chm[coo[:, 0], coo[:, 1]] highest_peak = np.argwhere(tree_z == tree_z.max()) tree_x = Xi[coo[highest_peak, 0], coo[highest_peak, 1]] tree_y = Yi[coo[highest_peak, 0], coo[highest_peak, 1]] tree_z = chm[coo[highest_peak, 0], coo[highest_peak, 1]] tree_record = "%.2f, %.2f, %.2f\n" % (tree_x, tree_y, tree_z) f.write(tree_record) f.close() print "Tree coordinates and heights stored in", fn_heights # write tiff saveimg(np.flipud(crowns), fn_tree, len(xi), len(yi), geotransform, proj) saveimg(np.flipud(crowns == -999), fn_gaps, len(xi), len(yi), geotransform, proj) # polygonize tree crowns polygonize(fn_tree, fn_shape) # plot import pylab as plt fig = plt.figure(figsize=(15, 5)) ax = fig.add_subplot(131) plt.imshow(chm, extent=[Xi.min(), Xi.max(), Yi.min(), Yi.max()]) plt.scatter(peak_x, peak_y, c="k", marker="+", s=100) plt.xlim([Xi.min(), Xi.max()]) plt.ylim([Yi.min(), Yi.max()]) title = "local peaks (n=%d)" % (peak) plt.title(title)