def dem_generator(): arcpy.env.workspace = "C:\\Users\\michal\\Desktop\\_BP" arcpy.env.overwriteOutput = 1 print("Creating list of las files...") las_pasy = [] for root, dirs, files in os.walk( r'C:\Users\michal\Desktop\_BP\Krkonose\LiDAR\area_81'): for file in files: if file.endswith('.las'): pas = ("Krkonose\\LiDAR\\area_81\\" + file, "gis\\las_pasy_dem\\arcgis\\area_n81\\" + file[:-4] + "_dem.tif") las_pasy.append(pas) print("List of las files created!") for las in las_pasy: print("Rasterizing: ", las[0]) arcpy.env.snapRaster = "Krkonose\\2019_06_14_Lucni_2_DSM.tif" arcpy.env.cellSize = "Krkonose\\2019_06_14_Lucni_2_DSM.tif" arcpy.env.extent = "MAXOF" arcpy.LasDatasetToRaster_conversion( las[0], las[1], "ELEVATION", "TRIANGULATION LINEAR MINIMUM 0,05", "FLOAT", "CELLSIZE", 0.05, 1) arcpy.env.extent = "Krkonose\\area_n81.shp" arcpy.LasDatasetToRaster_conversion( las[0], las[2], "ELEVATION", "TRIANGULATION LINEAR MINIMUM 0,05", "FLOAT", "CELLSIZE", 0.05, 1) print("Done!") print("DEMs generated.")
def convert_LAS_to_TIFF(src, dst, sampling_value=(1000 / 2048)): result = arcpy.LasDatasetToRaster_conversion( in_las_dataset=src, out_raster=dst, value_field="ELEVATION", interpolation_type="BINNING MAXIMUM LINEAR", data_type="FLOAT", sampling_value=sampling_value)
def las_to_GandFrreturns(las_files, mask, name): '''This function takes a list of las files, creates a las dataset. Then it create a lasd for first and ground returns. After which it rasterizes the lasd and masks them to a specified area. las_files: a list of the paths for all the las files mask: ''' lasd = arcpy.CreateLasDataset_management(las_files, name) g_lasd = arcpy.MakeLasDatasetLayer_management(lasd, "ground", 2) g_ras = arcpy.LasDatasetToRaster_conversion( g_lasd, "g_rast.img", "ELEVATION", "BINNING AVERAGE NATURAL_NEIGHBOR", "FLOAT", "CELLSIZE", 0.5) g_mask = arcpy.sa.ExtractByMask(g_ras, mask) g_mask.save("g_mask" + name + ".img") f_lasd = arcpy.MakeLasDatasetLayer_management(lasd, "first", '', 1) f_ras = arcpy.LasDatasetToRaster_conversion( f_lasd, "f_rast.img", "ELEVATION", "BINNING MAXIMUM NATURAL_NEIGHBOR", "FLOAT", "CELLSIZE", 0.5) f_mask = arcpy.sa.ExtractByMask(f_ras, mask, name) f_mask.save("f_mask" + name + ".img") return f_mask, g_mask
def generate_raster(las, path, proc_dict): # Set Extent for Task Processing proc_ext = proc_dict[1] XMin = proc_ext[0] YMin = proc_ext[1] XMax = proc_ext[2] YMax = proc_ext[3] arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax) # Generate Raster try: arcpy.LasDatasetToRaster_conversion( las, os.path.join(path, str(proc_dict[0]) + '.tif'), 'ELEVATION', 'TRIANGULATION LINEAR NO_THINNING MINIMUM 0', 'FLOAT', 'CELLSIZE', 1.0) except Exception as e: print('Exception: ', e)
'name': 'intensity' } arcpy.AddMessage("Generating DSM") surfaceLyr = arcpy.CreateUniqueName('First Return Layer') arcpy.MakeLasDatasetLayer_management( in_las_dataset=inlasd, out_layer=surfaceLyr, class_code=None, return_values=['Single Return', 'First of Many']) arcpy.LasDatasetToRaster_conversion( in_las_dataset=surfaceLyr, out_raster=surface_files['rawraster'], value_field='ELEVATION', interpolation_type= "TRIANGULATION NATURAL_NEIGHBOR NO_THINNING CLOSEST_TO_MEAN 0", # 'TRIANGULATION Linear {point_thinning_type} {point_selection_method} {resolution}', data_type='FLOAT', sampling_type='CELLSIZE', sampling_value=cell_edge_length, z_factor=z_factor) arcpy.AddMessage("Generating DEM") groundLyr = arcpy.CreateUniqueName('Last Return Layer') arcpy.MakeLasDatasetLayer_management( in_las_dataset=inlasd, out_layer=groundLyr, class_code=None, return_values=['Single Return', 'Last of Many']) arcpy.LasDatasetToRaster_conversion( in_las_dataset=groundLyr,
def process(fldr, outFldr, outGdb, build): arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("Spatial") start = datetime.datetime.now() print(start) #fldr = r"C:\00_school\appChallenge" #outFldr = r"C:\00_school\appChallenge\output" #outGdb = os.path.join(outFldr, "output.gdb") outFinal = os.path.join(outFldr, os.path.basename(fldr) + "_all.shp") #build = r"C:\00_school\appChallenge\AllOttawa_Buildings\Buildings_polygon_MTM9.shp" coord = arcpy.Describe(build).spatialReference.exportToString() days = [355, 172, 80] lat = "45.3748" sky = "200" outList = [] extList = [] for f in os.listdir(fldr): if f.endswith(".zip"): code = f[:-4] extFldr = os.path.join(fldr, code) print("Starting " + code) print(" Extracting files") zipPath = zipfile.ZipFile(os.path.join(fldr, f), 'r') zipPath.extractall(extFldr) zipPath.close() extList.append(extFldr) las = os.path.join(extFldr, os.listdir(extFldr)[0]) ras = os.path.join(extFldr, "r" + code + ".tif") print(" Converting las to raster") arcpy.LasDatasetToRaster_conversion( in_las_dataset=las, out_raster=ras, value_field="ELEVATION", interpolation_type="BINNING AVERAGE NONE", data_type="FLOAT", sampling_type="CELLSIZE", sampling_value=1, z_factor=1) print(" Defining projection") arcpy.DefineProjection_management(in_dataset=ras, coor_system=coord) print(" Running solar analysis") solList = [] for d in days: if d == days[0]: sol = os.path.join(extFldr, "ws" + code + ".tif") elif d == days[1]: sol = os.path.join(extFldr, "ss" + code + ".tif") else: sol = os.path.join(extFldr, "eq" + code + ".tif") solList.append(sol) t = "WithinDay " + str(d) + " 0 24" arcpy.gp.AreaSolarRadiation(ras, sol, lat, sky, t) print(" Generating footprint") zeroExp = """\"""" + ras + """\" * 0 """ zeroRas = os.path.join(extFldr, "z" + code + ".tif") intRas = os.path.join(extFldr, "i" + code + ".tif") rasFp = os.path.join(extFldr, "fp" + code + ".shp") arcpy.gp.RasterCalculator_sa(zeroExp, zeroRas) arcpy.gp.Int_sa(zeroRas, intRas) arcpy.RasterToPolygon_conversion(intRas, rasFp, "SIMPLIFY", "VALUE") print(" Clipping Buildings") buildClip = os.path.join(extFldr, "build" + code + ".shp") arcpy.Clip_analysis(in_features=build, clip_features=rasFp, out_feature_class=buildClip) print(" Generating stats") field = arcpy.ListFields(dataset=buildClip, field_type="OID")[0] tblList = [] lyr = buildClip[:-4] + ".lyr" arcpy.MakeFeatureLayer_management(in_features=buildClip, out_layer=lyr) for s in solList: tbl = s[:-4] + "_tbl.dbf" tblList.append(tbl) arcpy.sa.ZonalStatisticsAsTable(in_zone_data=buildClip, zone_field=field.name, in_value_raster=s, out_table=tbl, statistics_type="MEAN") field2 = arcpy.ListFields(dataset=tbl, field_type="OID")[0] arcpy.AddJoin_management(in_layer_or_view=lyr, in_field=field.name, join_table=tbl, join_field=field2.name) print(" Exporting Data") output = os.path.join(outGdb, "out_" + code) outList.append(output) arcpy.CopyFeatures_management(in_features=lyr, out_feature_class=output) flds = arcpy.ListFields(dataset=output) for fld in flds: name = fld.name if name.endswith("MEAN"): if name.startswith("ws"): arcpy.AlterField_management(in_table=output, field=name, new_field_name="WS_MEAN", new_field_alias="WS_MEAN") elif name.startswith("ss"): arcpy.AlterField_management(in_table=output, field=name, new_field_name="SS_MEAN", new_field_alias="SS_MEAN") else: arcpy.AlterField_management(in_table=output, field=name, new_field_name="EQ_MEAN", new_field_alias="EQ_MEAN") for fld in flds: if fld.type != "OID" and not fld.name.startswith( "Shape") and not fld.name.endswith("MEAN"): arcpy.DeleteField_management(in_table=output, drop_field=fld.name) curr = datetime.datetime.now() elap = curr - start print(code + " complete. " + str(curr) + " Time elapsed: " + str(elap)) if len(os.listdir(fldr)) != 0: print("Merging output layers") arcpy.Merge_management(inputs=outList, output=outFinal) print("\nI AM INVINCIBLE") return (extList)
output_gdb_path = "E:\\Caitlin\\ROSETTA\\ROSETTA Database\\ROSETTA.gdb\\" # las_array is a list of lists, where each inner list represents one raster # las_array = [["output filename", "input file path", "input file path", ...], # ["output filename," "input file path", "input file path", ...] # ... ... ] las_array = [[ "AN03_F1004_1", "X:\\trunk\\icepod\\antarctica\\20162017\\lidar\\vq580\\pointcloud\\F1004\\las\\full_swath\AN03_F1004_20161127_204658_LIDAR_VQ580_Record1.las" ]] ####################################################### for las_list in las_array: name = las_list[0] path_list = las_list[1:] arcpy.CreateLasDataset_management(path_list, lasd_output_path + name + ".lasd", "NO_RECURSION", "", arcpy.SpatialReference(4326), "COMPUTE_STATS", "RELATIVE_PATHS", "NO_FILES") arcpy.LasDatasetToRaster_conversion(lasd_output_path + name + ".lasd", output_gdb_path + name, "ELEVATION", 'BINNING AVERAGE SIMPLE', 'FLOAT', 'CELLSIZE', 0.00001, 1) #arcpy.RasterToOtherFormat_conversion(output_gdb_path + name, raster_output_path, {"TIFF"})
def LASToDSM_Conversion(input_workspace, output_raster, coordinate_system, tile_index, cell_size, output_layer): """TODO: Add documentation about this function here""" try: # Local Variables class_codes = [2, 5, 6] # Class Codes for surfaces (reduces noise) return_values = [ '1' ] # The desired return value for surfaces (just the first returns) output_las_dataset = input_workspace + "\\LASDataset" arcpy.env.workspace = input_workspace arcpy.env.scratchWorkspace = input_workspace #FeatureClasses = arcpy.ListFeatureClasses() # Main Analysis # - Create LAS Dataset arcpy.AddMessage('Creating LAS Dataset...') arcpy.management.CreateLasDataset(input_workspace, output_las_dataset, "NO_RECURSION", "", coordinate_system, "NO_COMPUTE_STATS", "RELATIVE_PATHS") arcpy.AddMessage('...LAS Dataset Created') # - Make LAS Dataset Layer input_las_dataset = output_las_dataset + ".lasd" arcpy.management.MakeLasDatasetLayer(input_las_dataset, output_layer, class_codes, return_values) arcpy.AddMessage('...LAS Dataset Layer Created') # - - Set the workspace for ListFeatureClasses fields = ['ORTHO', 'Shape'] #values = [row[0] for row in arcpy.da.SearchCursor(tile_index, field)] # -= Extent Filtering and looping arcpy.AddMessage('Starting Raster Loop...') #for row in arcpy.da.SearchCursor(tile_index, fields): rows = arcpy.SearchCursor(tile_index, fields) arcpy.AddMessage('Search cursor assigned to ' + tile_index) # - Create input LAS layer for raster conversion input_las_layer = output_layer + ".lasd" arcpy.env.outputCOordinateSystem = coordinate_system for row in rows: feat = row.getValue('Shape') tile_name = row.getValue('ORTHO') arcpy.AddMessage('...Extent retrieved for ' + tile_name) # - Create Name tile_output = output_raster + tile_name # - Set Extent arcpy.env.extent = feat.extent arcpy.AddMessage('... set extent for to {0}, {1}, {2}, {3}'.format( arcpy.env.extent.XMin, arcpy.env.extent.YMin, arcpy.env.extent.XMax, arcpy.env.extent.YMax)) # - LASDataset to Raster arcpy.AddMessage('Creating output raster: ' + tile_output) arcpy.LasDatasetToRaster_conversion( input_las_layer, tile_output, 'ELEVATION', 'BINNING MAXIMUM NATURAL_NEIGHBOR', 'FLOAT', 'CELLSIZE', cell_size, '1') arcpy.AddMessage('... created raster tile: ' + tile_name) pass except arcpy.ExecuteError: print arcpy.GetMessages(2) except Exception as e: print e.args[0] finally: # Regardless of whether the script succeeds or not, delete # the row and cursor # if rows: del rows