I often download data that comes in 30 minutes to 1-hour windows and then have to compile that data manually into one feature class, from multiple GDBs. I am trying to iterate through the separate GDBs and store each point feature class in an object. Here's what I have so far (Python 2.7.14):
import arcpy
import os
from arcpy import env
outputOverwrite = True
print('imported')
arcpy.env.workspace = r'C:\Vector\20190902'
print('ws set')
workspaces = arcpy.ListWorkspaces(workspace_type = 'FileGDB')
for workspace in workspaces:
datasets = arcpy.ListDatasets(feature_type = 'All')
for ds in datasets:
arcpy.env.workspace = ds
fc = arcpy.ListFeatureClasses(feature_type = 'Point')
print(fc)
I am unable to post pictures or copy and paste my code, as the system is on a totally different network.
Edited to reflect changes made by @BERA.
This code outputs
imported
ws set
>>>
It doesn't print the feature classes like i expected it to.
I traced this back to the line of code
for workspace in workspaces:
datasets = arcpy.ListDatasets(feature_type='All')
When I tried to do
print(datasets)
It gave me blank lists
[]
[]
[]
[]
...
Hope this clears up the ambiguity on my end.
Answer
ListFeatureClasses will search in current workspace, which is r'C:\Vector\20190902'
. You need to change it to point at each gdb when listing feature classes.
I dont know why you are listing datasets, are you sure that is what you want?
If you have a structure like this, code below will work:
import arcpy, os
arcpy.env.workspace = r'C:\GIS\ArcMap_default_folder'
fclist = []
for ws in arcpy.ListWorkspaces(workspace_type='FileGDB'):
arcpy.env.workspace = ws
for fc in arcpy.ListFeatureClasses(feature_type='POINT'):
fclist.append(os.path.join(ws, fc))
print (fclist)
#arcpy.Merge_management(inputs=fclist,...
['C:\\GIS\\ArcMap_default_folder\\Default.gdb\\point1', 'C:\\GIS\\ArcMap_default_folder\\test.gdb\\point2']
No comments:
Post a Comment