def list_feature(gdb, dataset): #dir_name = os.getcwd(gdb) # env.workspace = r"D:\全生命周期" # D:\全生命周期\ # for fgdb in arcpy.ListWorkspaces("*gdb"): for fgdb in list( set(arcpy.ListWorkspaces("*gdb")) | set(arcpy.ListWorkspaces("*.mdb"))): # print fgdb wk = os.path.basename(fgdb) if str(wk) == gdb: # str("SPDM2_datasets.gdb"): print wk env.workspace = fgdb # print arcpy.env.workspace datasets = arcpy.ListDatasets() datasets = [''] + datasets if datasets is not None else [] ## if datasets is not None: #datasets = [''] + datasets #else: # datasets = [] # print datasets for ds in datasets: #print env.workspace if str(ds).strip() == str(dataset).strip(): # print ds # env.workspace = fgdb + os.sep + ds return fgdb + os.sep + ds
def SetDefaultSpatialIndex(self, p_InputWS): env.workspace = p_InputWS ds = [''] for fds in arcpy.ListDatasets(): ds.append("/" + str(fds)) for currentDS in ds: env.workspace = p_InputWS + currentDS messageText = str(p_InputWS + currentDS) + ":-----------------------------" self.Message(messageText, 0) for fc in arcpy.ListFeatureClasses(): desc = arcpy.Describe(fc) if desc.hasSpatialIndex == False: indexGrid = [] result = arcpy.GetCount_management(fc) count = int(result.getOutput(0)) try: resultIdx = arcpy.CalculateDefaultGridIndex_management( fc) for i in range(0, resultIdx.outputCount): indexGrid.append(float(resultIdx.getOutput(i))) spIdx = self.RulesForCalculateDefaultGridIndex( int(indexGrid[0]), count) arcpy.AddSpatialIndex_management(fc, spIdx) messageText = ( "Neuer Index def_array.append(['%s/%s' , '%s' , %s])" ) % (currentDS, fc, desc.shapeType, spIdx) self.Message(messageText, 0) except: messageText = ( "Index '%s/%s' , '%s' von Hand setzen! Vorschlag ArcGIS:%s" ) % (currentDS, fc, desc.shapeType, indexGrid) self.Message(messageText, 2)
def layer_block_points(self) -> arcpy._mp.Layer: """ Esri Business Analyst block points layer - useful for calculating weighted centroids. :return: Feature Layer """ # get the path to the geodatabase where the Esri demographics reside gdb_path = os.path.join(self.usa_data_path, 'Data', 'Demographic Data', 'block_data') arcpy.env.workspace = gdb_path fc_name = [ d for d in arcpy.ListDatasets(gdb_path, ) if re.match(r'USA_ESRI_\d{4}_blocks', d) ][0] fc_path = os.path.join(gdb_path, fc_name) # create layer map visible_fields = ['Shape', 'ID', 'NAME'] def _eval_visible(field_name): if field_name in visible_fields: return 'VISIBLE' else: return 'HIDDEN' field_map_lst = [ ' '.join([f.name, f.name, _eval_visible(f.name), 'NONE']) for f in arcpy.ListFields(fc_path) ] field_map = ';'.join(field_map_lst)
def tabArea(): # Set environment settings arcpy.env.workspace = 'C:/Users/bougie/Desktop/'+rootDir+'/usxp/'+gdb #select all the datasets with "_lcc" at the end of name wc = "*_lcc" # Set local variables for raster in arcpy.ListDatasets(wc, "Raster"): print 'raster: ', raster # Set the cell size environment using a raster dataset. arcpy.env.cellSize = raster # Set Snap Raster environment arcpy.env.snapRaster = raster inZoneData = 'C:/Users/bougie/Desktop/'+rootDir+'/usxp/ancillary.gdb/counties' zoneField = "atlas_stco" inClassData = raster classField = "Value" outTable = inClassData + 'ta' #get the resolution of each raster to get the coorect size to process res = arcpy.GetRasterProperties_management(raster, "CELLSIZEX") print 'res: ', res processingCellSize = res # Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension("Spatial") # Execute TabulateArea TabulateArea(inZoneData, zoneField, inClassData, classField, outTable,processingCellSize)
def main(workspace): env.workspace = workspace dsList = [] datasetlist = arcpy.ListDatasets("*", "Feature") for dataset in datasetlist: dsList.append(dataset) fcList = arcpy.ListFeatureClasses() for fc in fcList: dsList.append(fc) tableList = arcpy.ListTables() for table in tableList: dsList.append(table) #message(dsList) for ds in dsList: desc = arcpy.Describe(ds) if desc.isVersioned: try: message(("unregistering as versioned: " + "\"" + ds + "\""),0) arcpy.UnregisterAsVersioned_management(ds, "NO_KEEP_EDIT", "COMPRESS_DEFAULT") except: message(("problem with unregistering: " + "\"" + ds + "\"" + '\n' + arcpy.GetMessages(2)),2) else: message(("--- already unregistered as versioned: " + "\"" + ds + "\""),0)
def writeDatasets(): datasets = arcpy.ListDatasets() datasets.sort() for ds in datasets: for fc in arcpy.ListFeatureClasses(feature_dataset=ds): #fc.sort() path = os.path.join(workspace, ds, fc) print "\n" #print "Path: "+path print path.split("GISOWN.", 1)[1] fcName1 = path.split("GISOWN.", 1)[1] fcName2 = fcName1.split("GISOWN.", 1)[1] textFile.write(fcName2 + "\n") fields = arcpy.ListFields(path) for field in fields: print("{0}\t\t{1}\t\t{2}\t\t{3}\t{4}\t\t{5}\t{6}".format( field.name, field.type, field.isNullable, field.defaultValue, field.domain, field.precision, field.length)) textFile.write( "{0}\t\t{1}\t\t{2}\t\t{3}\t{4}\t\t{5}\t{6}".format( field.name, field.type, field.isNullable, field.defaultValue, field.domain, field.precision, field.length)) textFile.write("\n") textFile.write("\n") textFile.write("\n\n")
def BuildSpatialIndexParams(self, p_InputWS): env.workspace = p_InputWS ds = [''] for fds in arcpy.ListDatasets(): ds.append("/" + str(fds)) for currentDS in ds: env.workspace = p_InputWS + currentDS self.Message(p_InputWS + currentDS + ":-----------------------------") for fc in arcpy.ListFeatureClasses(): desc = arcpy.Describe(fc) indexGrid = [] try: resultIdx = arcpy.CalculateDefaultGridIndex_management(fc) for i in range(0, resultIdx.outputCount): indexGrid.append(resultIdx.getOutput(i)) except: pass result = arcpy.GetCount_management(fc) count = int(result.getOutput(0)) gridVal = self.RulesForCalculateDefaultGridIndex( int(indexGrid[0]), count) messageText = ("def_array.append(['%s/%s' , '%s' , %s, %s])" ) % (currentDS, fc, desc.shapeType, gridVal, count) self.Message(messageText, 1)
def exportTopoTINDXF(self, outFolder): """exports dxf file (and SHP files) containing tin components of topo tin in same folder as gdb""" from os import path, makedirs arcpy.CheckOutExtension("3D") arcpy.env.workspace = arcpy.Describe(self.filename).path topoTINs = arcpy.ListDatasets("TIN*", "Tin") topoTIN = topoTINs[0] outfile = path.join(outFolder, "TopoTin") + ".dxf" memTinPoints = "in_memory//tin_points" memTinLines = "in_memory//tin_lines" memTinArea = "in_memory//tin_area" # TODO Do actual breaklines need to be pulled into their own layer? listTINComponents = [memTinPoints, memTinLines, memTinArea] for item in listTINComponents: if arcpy.Exists(item): arcpy.Delete_management(item) arcpy.TinNode_3d(topoTIN, memTinPoints) arcpy.TinEdge_3d(topoTIN, memTinLines, "DATA") arcpy.TinDomain_3d(topoTIN, memTinArea, "POLYGON") # TODO Convert Line Type from eSRI code?? arcpy.ExportCAD_conversion(listTINComponents, "DXF_R2007", outfile) return outfile
def regionGroup(gdb_args_in, wc, region_combos): #define workspace arcpy.env.workspace=defineGDBpath(gdb_args_in) for k, v in region_combos.iteritems(): print k,v for raster in arcpy.ListDatasets(wc, "Raster"): print 'raster: ', raster raster_out=raster+'_'+k print 'raster_out', raster_out if arcpy.Exists(raster_out): print "{} exists, not copying".format(raster) else: output=defineGDBpath(['sensitivity_analysis','mmu'])+raster_out print 'output: ',output # Execute RegionGroup outRegionGrp = RegionGroup(raster, v[0], v[1],"NO_LINK") # Save the output print 'save the output' outRegionGrp.save(output) gen.buildPyramids(output)
def main(): buildZones(10,11) for zone in zoneres: arcpy.env.workspace = "H:/fireharmQAQC/zips/Event_Mode/%s_fh_grids" %(zone) datasetList = arcpy.ListDatasets("", "Raster") for dataset in datasetList: if dataset[:3] != zone:# if first 3 chars don't equal zone add the zone number on front. out_raster = '%s_' %(zone)+dataset print dataset[:3], zone renameRaster(dataset, out_raster) else: pass if daymetnames.has_key(dataset[4:]): try: out_raster = '%s_%s' %(zone, daymetnames[dataset[4:]]) print dataset, 'switch ', out_raster renameRaster(dataset, out_raster) except:pass else: pass if eventnames.has_key(dataset[4:]): try: out_raster = '%s_%s' %(zone, eventnames[dataset[4:]]) print dataset, 'switch ', out_raster renameRaster(dataset, out_raster) except:pass else: pass
def listFcsInGDB(gdb): try: wk = arcpy.env.workspace = gdb if not arcpy.Exists(wk): log_results("\n" + "Database DOES NOT EXIST!\n") else: fldCnt = 0 # Inside Feature datasets: fdList = arcpy.ListDatasets(feature_type="feature") for fds in fdList: log_results("\n ---- Feature dataset: {0} ---- \n".format(fds)) fcListInside = arcpy.ListFeatureClasses(feature_dataset=fds) print_fc(fcListInside) # Stand-alone feature classes: log_results("\n ---- Stand-alone feature classes ---- \n") fcListOutside = arcpy.ListFeatureClasses() print_fc(fcListOutside) log_results("\n\n COMPLETED!! \n") logfile.close() except arcpy.ExecuteError: log_results(arcpy.GetMessages(2)) except Exception as e: log_results(e[0])
def createSpecificLUCMask(): # Description: reclass cdl rasters based on the specific arc_reclassify_table # self.series = series # self.name = name # self.subname = subname # self.res = str(res) # self.mmu = str(mmu) # self.years = years # Set environment settings arcpy.env.workspace = defineGDBpath(['post', post.name]) cond = post.series+'_'+post.name+post.res+'_'+post.datarange+'_mmu'+post.mmu+'_nbl_'+post.subname print 'cond:', cond # print cond # #loop through each of the cdl rasters for raster in arcpy.ListDatasets(cond, "Raster"): print 'raster: ',raster outraster = raster+'_msk' print 'outraster: ', outraster myRemapVal = RemapValue(getReclassifyValuesString()) outReclassRV = Reclassify(raster, "VALUE", myRemapVal, "") # Save the output outReclassRV.save(outraster) #create pyraminds gen.buildPyramids(outraster)
def getDomainUnion(inws, gdbs): """ Get the union of all the sr.domain of all FeatureClasses and Datasets directly in every gdbs. Arg: a list of gdbs. Return: a tuple of (xmin, ymin, xmax, ymax) """ li_domain = [] for g in gdbs: arcpy.env.workspace = os.path.join(inws, g) dss = arcpy.ListDatasets() fcs = arcpy.ListFeatureClasses() # Get the domain of FeatureClasses first. for fc in fcs: desc = arcpy.Describe(fc) sr = desc.spatialReference # Notice that sr.domain get a string of (xmin, ymin, xmax, ymax) separated by a space. li_domain.append([float(x) for x in sr.domain.split(" ")]) # Get the domain of Datasets here. for ds in dss: desc = arcpy.Describe(ds) sr = desc.spatialReference # Notice that sr.domain get a string of (xmin, ymin, xmax, ymax) separated by a space. li_domain.append([float(x) for x in sr.domain.split(" ")]) df = pd.DataFrame(li_domain) return (df.iloc[:, 0].min(), df.iloc[:, 1].min(), df.iloc[:, 2].max(), df.iloc[:, 3].max())
def process_subtypes(self): print "\nProcessing subtypes ..." self.write_it(self.f_create_indexes, "\n-- Subtypes") self.write_it(self.f_create_constraints, "\n-- Subtypes") self.write_it(self.f_split_schemas, "\n-- Subtypes") # create subtypes table for tables tables_list = arcpy.ListTables() tables_list.sort() for table in tables_list: self.create_subtypes_table(table) # create subtypes table for stand-alone featureclasses fc_list = arcpy.ListFeatureClasses("*", "") fc_list.sort() for fc in fc_list: self.create_subtypes_table(fc) # create subtypes table for featureclasses in datasets fds_list = arcpy.ListDatasets("*", "Feature") fds_list.sort() for fds in fds_list: fc_list = arcpy.ListFeatureClasses("*", "", fds) fc_list.sort() for fc in fc_list: self.create_subtypes_table(fc)
def check_input(county_folder): # First check that the input is a folder and not a file if os.path.isdir(county_folder) == True: print("Input is a folder...continuing...") if os.path.isdir(county_folder) == False: print("Input must be a folder, exiting...") sys.exit() # Check the input folder to verify that there are subfolders with rasters # For all of the subfolders in the county folder, find the folder with the largest # raster cell size for name in os.listdir(county_folder): if os.path.isdir(os.path.join(county_folder, name)): if name != "Combined": arcpy.env.workspace = os.path.join(county_folder, name) list_of_rasters = arcpy.ListDatasets('*', "Raster") if len(list_of_rasters) == 0: print("Folders must contain rasters, exiting...") sys.exit() # Check that subfolders contain 5 rasters, one for each return period if len(list_of_rasters) != 5: print("Folders must contain depth grids for return periods 10, 25, 50, 100 and 500, exiting...") sys.exit() nonlocal subfolders nonlocal small_cell_rasters subfolders.append(name) small_cell_rasters.append(name) if len(subfolders) < 2: print("There must be at least two subfolders each with rasters, exiting...") sys.exit()
def replicateDatabase(dbConnection, targetGDB): if arcpy.Exists(dbConnection): featSDE, cntSDE = getDatabaseItemCount(dbConnection) utils.common.OutputMessage( logging.DEBUG, "{0} - ".format(time.ctime()) + "Geodatabase being copied: %s -- Feature Count: %s" % (dbConnection, cntSDE)) arcpy.env.workspace = dbConnection try: datasetList = [ arcpy.Describe(a).name for a in arcpy.ListDatasets() ] except Exception, e: datasetList = [] utils.common.OutputMessage(logging.DEBUG, e) try: featureClasses = [ arcpy.Describe(a).name for a in arcpy.ListFeatureClasses() ] except Exception, e: featureClasses = [] utils.common.OutputMessage(logging.DEBUG, e)
def raster_with_max_cell_size(raster_cell_size_dictionary): v = list(raster_cell_size_dictionary.values()) k = list(raster_cell_size_dictionary.keys()) large_cell_subfolder = k[v.index(max(v))] large_cell_rasters = os.path.join(county_folder, large_cell_subfolder) # add the large rasters to the lists of rasters to mosaic in the end arcpy.env.workspace = large_cell_rasters large_raster_list = arcpy.ListDatasets('*', "Raster") for large_raster in large_raster_list: return_period = str(large_raster) large_raster_name = os.path.join(large_cell_rasters, large_raster) if return_period == 'rpd10': rpd_10_rasters.append(large_raster_name) elif return_period == 'rpd25': rpd_25_rasters.append(large_raster_name) elif return_period == 'rpd50': rpd_50_rasters.append(large_raster_name) elif return_period == 'rpd100': rpd_100_rasters.append(large_raster_name) else: # return period must be 500 rpd_500_rasters.append(large_raster_name) nonlocal large_cell_size large_cell_size = max(v) small_cell_rasters.remove(large_cell_subfolder) print("Large cell size: " + str(large_cell_size)) return large_cell_size
def createGSconvBylcc(wc): arcpy.env.workspace = 'C:/Users/bougie/Desktop/' + rootDir + '/usxp/' + gdb print 'wc: ', wc for raster in arcpy.ListDatasets(wc, "Raster"): print 'raster: ', raster # Set the cell size environment using a raster dataset. arcpy.env.cellSize = raster # Set Snap Raster environment arcpy.env.snapRaster = raster lcc = 'C:/Users/bougie/Desktop/' + rootDir + '/usxp/ancillary.gdb/lcc_100m_reproject' output = 'C:/Users/bougie/Desktop/' + rootDir + '/usxp/' + gdb + '/' + wc + '_lcc' print 'output: ', output cond = "Value IS NULL" print cond OutRas = Con(raster, raster, Raster(lcc), cond) # # Save the output OutRas.save(output)
def createRefinedTrajectory(): ##### Set environment settings arcpy.env.workspace = defineGDBpath(['refine', 'v2', 'masks']) ##### loop through each of the cdl rasters and make sure nlcd is last condlist = ['36and61', refine.mask_dev, 'nlcd' + refine.nlcd_ven] ##### create a raster list to mosiac together make sure that the intial traj is first in list and nlcd mask is last in the list. filelist = [refine.traj_dataset_path] for cond in condlist: yo = '*' + refine.datarange + '*_' + cond print yo for raster in arcpy.ListDatasets('*' + refine.datarange + '*' + cond, "Raster"): print 'raster: ', raster filelist.append(raster) print 'filelist', filelist print 'lenght of list:', len(filelist) output = refine.traj_rfnd_dataset print "output:", output ##### mosaicRasters(): arcpy.MosaicToNewRaster_management( filelist, defineGDBpath(['pre', 'v2', 'traj_refined']), output, Raster(refine.traj_dataset_path).spatialReference, '16_BIT_UNSIGNED', refine.res, "1", "LAST", "FIRST")
def gdb_to_shp(workspace, outworkspace): """ Export all feature classes in a Geodatabase to a single file. Do this for all Geodatabases in workspace. """ import os from glass.mng.gen import copy_feat # List GeoDatabases lst_gdb = arcpy.ListWorkspaces(workspace_type="FileGDB") dic_gdb = {} for gdb in lst_gdb: arcpy.env.workspace = gdb dic_gdb[gdb] = {} dts = arcpy.ListDatasets() for dt in dts: dic_gdb[gdb][dt] = arcpy.ListFeatureClasses(feature_dataset=dt) for gdb in dic_gdb: for dt in dic_gdb[gdb]: for fc in dic_gdb[gdb][dt]: copy_feat(os.path.join(gdb, dt, fc), os.path.join( outworkspace, "{}_{}.shp".format( os.path.splitext(os.path.basename(gdb))[0], fc)), gisApi='arcpy')
def createGSconvByYearLCC(wc,yr_dset,years): arcpy.env.workspace = 'C:/Users/bougie/Desktop/'+rootDir+'/usxp/'+gdb print 'wc: ', wc for raster in arcpy.ListDatasets(wc, "Raster"): print 'raster: ',raster # Set the cell size environment using a raster dataset. arcpy.env.cellSize = raster # Set Snap Raster environment arcpy.env.snapRaster = raster #set up the 2 datasets that will be used in the Con() function below # yr_dset='C:/Users/bougie/Desktop/'+rootDir+'/usxp/'+gdb+'/'+fname lcc='C:/Users/bougie/Desktop/'+rootDir+'/usxp/ancillary.gdb/lcc_100m_reproject' for year in years: output = 'C:/Users/bougie/Desktop/'+rootDir+'/usxp/'+gdb+'/gsConv_'+year+'_lcc' print 'output: ', output # using 3 rasters in this condtion. only select pixels of year x, if true get the lcc value for that pixel if fale set to null!! OutRas=Con((Raster(yr_dset) == int(year)), Raster(lcc),(SetNull(raster, raster, "Value > 8"))) # OutRas=Con((Raster(yr_dset) == int(year)), Raster(lcc),raster) #Save the output OutRas.save(output)
def writeGdbDesc(gdb): desc = 'The geodatabase contains the following elements: ' arcpy.env.workspace = gdb for aTable in arcpy.ListTables(): addMsgAndPrint(aTable) desc = desc + 'non-spatial table ' + aTable + ' (' + str( numberOfRows(aTable)) + ' rows); ' for aRaster in arcpy.ListRasters(): addMsgAndPrint(aRaster) desc = desc + 'raster ' + aRaster + '; ' for anFds in arcpy.ListDatasets(feature_type="Feature"): addMsgAndPrint(anFds) desc = desc + 'feature dataset ' + anFds + ' which contains ' fcs = arcpy.ListFeatureClasses('', 'All', anFds) if len(fcs) == 1: desc = desc + 'feature class ' + fcs[0] + ' (' + str( numberOfRows(fcs[0])) + ' features); ' else: for n in range(0, len(fcs) - 1): desc = desc + 'feature class ' + fcs[n] + ' (' + str( numberOfRows(fcs[n])) + ' features), ' lastn = len(fcs) - 1 desc = desc + 'and feature class ' + fcs[lastn] + ' (' + str( numberOfRows(fcs[lastn])) + ' features); ' desc = desc[:-2] + '. ' return desc
def question_a4(): arcpy.env.workspace = 'C:/Users/bougie/Desktop/'+rootDir+'/'+production_type+'/rasters/post/ytc.gdb' wc='ytc_b_mosaic_traj_n8h_mtr_8w_msk45_nbl_fnl' print 'wc: ', wc for raster in arcpy.ListDatasets(wc, "Raster"): print 'raster: ',raster # Set the cell size environment using a raster dataset. arcpy.env.cellSize = wc # Set Snap Raster environment arcpy.env.snapRaster = wc lcc='C:/Users/bougie/Desktop/'+rootDir+'/usxp/ancillary.gdb/lcc_100m_reproject' # years=['13', '14', '15'] years=['13'] for year in years: output = 'C:/Users/bougie/Desktop/'+rootDir+'/usxp/a.gdb/ytc_'+year+'_lcc' print 'output: ', output cond="Value <> " + year print 'cond', cond outSetNull = SetNull(raster, Raster(lcc), cond) #Save the output outSetNull.save(output)
def listAllFeatureClasses(gdb, **kwargs): import arcpy ''' list all Feature Classes in a geodatabase or coverage recursively (normal listFeatureClasses does not recurse) import arcplus fcs = arcplus.listAllFeatureClasses('d:\default.gdb') for fc in fcs: print "magic happens with: ", fc Arcplus also adds wildcard filtering; to process only feature classes that start with "HD_" within feature datasets containing "Hydro" fcs = arcplus.listAllFeatureClasses(gdb, fd_filter='*Hydro*', fc_filter='HD_*') ''' arcpy.env.workspace = gdb if not kwargs.has_key('fc_filter'): fc_filter = '*' else: fc_filter = kwargs['fc_filter'] if not kwargs.has_key('fd_filter'): fd_filter = '*' else: fd_filter = kwargs['fd_filter'] print 'Looking in %s for "%s" ' % (arcpy.env.workspace, fc_filter) fcs = [] for fds in arcpy.ListDatasets(fd_filter, 'feature') + ['']: for fc in arcpy.ListFeatureClasses(fc_filter, '', fds): #print '%s\\%s' % (fds,fc) fcs.append(os.path.join(fds, fc)) return fcs
def getFeaturesdf(GDB): ''' # to get unique FDS, FC, and FIELDS across a geodatabase Parameters ---------- GDB = path to GDB Returns ------- pandas dataframe of with two columns: Feature Dataset, Feature Class for each fc in gdb. ''' d = pandas.DataFrame([]) arcpy.env.workspace = GDB for theFDS in arcpy.ListDatasets(): for theFC in arcpy.ListFeatureClasses(feature_dataset=theFDS): minFields = ( fld.name.upper() for fld in arcpy.ListFields(os.path.join(GDB, theFDS, theFC)) if str(fld.name) not in ['Shape', 'OBJECTID', 'Shape_Length', 'Shape_Area']) minFields = list(minFields) for FLD in minFields: d = d.append(pandas.DataFrame( { 'FDS': str(theFDS), 'FC': str(theFC), 'FLD': str(FLD.name) }, index=[0]), ignore_index=True) return (d)
def addRasterAttributeTable(gdb_path, wc): arcpy.env.workspace = defineGDBpath(gdb_path) for raster in arcpy.ListDatasets(wc, "Raster"): print 'raster: ', raster list_count = [] list_acres = [] #loop through each row and get the value for specified columns rows = arcpy.SearchCursor(raster) for row in rows: value = row.getValue('value') print value count = row.getValue('Count') print count cur = conn.cursor() query = "INSERT INTO qaqc.counts_rasters VALUES ('" + str( raster) + "' , " + str( sum(list_count)) + " , " + str(res) + " , " + str( sum(list_acres)) + ")" print query cur.execute(query) conn.commit()
def listFeatureClassDatasetNames(gdb): import arcpy arcpy.env.workspace=gdb datasets=arcpy.ListDatasets("*","Feature") for data in datasets: return data fcList=arcpy.ListFeatureClasses(data) for fc in fcList: return fc inFile="C:/Users/oc3512/Documents/ArcGIS/Projects/Python_practice/MMSP.kml" out_Location="C:/Users/oc3512/Documents/ArcGIS/Projects/Python_practice" baseName=os.path.splitext(os.path.basename(inFile))[0] # returns arcpy.conversion.KMLToLayer(inFile,out_Location) fcDataSetFile=out_Location + "/" + baseName + ".gdb" fcDataSets=ListNamesFeatureClass.listFeatureClassDatasetNames(fcDataSetFile) fcFeatureList=ListNamesFeatureClass.listFeatureClassNames(fcDataSets) currentCRS=arcpy.Describe(fcFeatureList).spatialReference.Name CRS1=arcpy.SpatialReference("WGS 1984 UTM Zone 51N") CRS2=arcpy.SpatialReference("PRS 1992 Philippines Zone III") outFiles=str(baseName + ".shp") TT=arcpy.CopyFeatures_management(fcFeatureList,outFiles) firstCRS=arcpy.Project_management(TT,baseName+"_reproject.shp",CRS1) arcpy.Project_management(firstCRS,baseName+"_reproject_PRS.shp",CRS2)
def _get_tables(sde): tables = arcpy.ListFeatureClasses() + arcpy.ListTables() for dataset in arcpy.ListDatasets('', 'Feature'): arcpy.env.workspace = os.path.join(sde, dataset) tables += arcpy.ListFeatureClasses() return tables
def listFcsInGDB(): ''' set your arcpy.env.workspace to viewer minimum attribution gdb before calling ''' for fds in arcpy.ListDatasets('','feature') + ['']: for fc in arcpy.ListFeatureClasses('','',fds): minFields = (fld.name for fld in arcpy.ListFields(fc) if str(fld.name) not in ['Shape', 'OBJECTID', 'Shape_Length', 'Shape_Area']) reqDomains = (fld.domain for fld in arcpy.ListFields(fc) if str(fld.name) not in ['Shape', 'OBJECTID', 'Shape_Length', 'Shape_Area']) for f, d in zip(minFields, reqDomains): yield os.path.join(fds, fc, f, d) # add arcpy.env.workspace at beginning of join if want to keep the viewer workspace in the file path
def ship(self): try: # Run commands as user SDE to compress and analyze database and system tables sdeconnection = join(self.garage, 'FFSL', 'DNR_sde@[email protected]') arcpy.Compress_management(sdeconnection) self.log.info('Compress Complete') arcpy.AnalyzeDatasets_management(sdeconnection, 'SYSTEM') self.log.info('Analyze System Tables Complete') userconnections = [join(self.garage, 'FFSL', 'DNR_Fire@[email protected]'), join(self.garage, 'FFSL', 'DNR_Forestry@[email protected]'), join(self.garage, 'FFSL', 'DNR_Lands@[email protected]')] for con in userconnections: # set workspace # the user in this workspace must be the owner of the data to analyze. workspace = con # set the workspace environment arcpy.env.workspace = workspace # NOTE: Analyze Datasets can accept a Python list of datasets. # Get a list of all the datasets the user has access to. # First, get all the stand alone tables, feature classes and rasters. dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters() # Next, for feature datasets get all of the datasets and featureclasses # from the list and add them to the master list. for dataset in arcpy.ListDatasets('', 'Feature'): arcpy.env.workspace = join(workspace, dataset) dataList += arcpy.ListFeatureClasses() + arcpy.ListDatasets('', 'Feature') # reset the workspace arcpy.env.workspace = workspace # Execute analyze datasets # Note: to use the 'SYSTEM' option the workspace user must be an administrator. if len(dataList) > 0: arcpy.AnalyzeDatasets_management(workspace, 'NO_SYSTEM', dataList, 'ANALYZE_BASE', 'ANALYZE_DELTA', 'ANALYZE_ARCHIVE') self.log.info('Analyze Complete') except Exception: self.send_email('*****@*****.**', 'Error with {}'.format(__file__), format_exc()) raise