How do I combine all three workspaces?
Only 1 workspace is being read while exporting data.
import os
import arcpy
# Set environment settings
arcpy.env.workspace = "C:/eis/eis shape/UPDM.gdb/P_PipeSystem"
arcpy.env.workspace = "C:/eis/eis shape/UPDM.gdb/OtherCompanies"
arcpy.env.workspace = "C:/eis/eis shape/UPDM.gdb/NEO"
arcpy.env.overwriteOutput = True
# Set local variables
outWorkspace = "C:/data"
try:
# Use ListFeatureClasses to generate a list of inputs
for infc in arcpy.ListFeatureClasses():
# Determine if the input has a defined coordinate system, can't project it if it does not
dsc = arcpy.Describe(infc)
if dsc.spatialReference.Name == "Unknown":
print ('skipped this fc due to undefined coordinate system: ' + infc)
else:
# Determine the new output feature class path and name
outfc = os.path.join(outWorkspace, infc)
# Set output coordinate system
outCS = arcpy.SpatialReference('WGS 1984')
# run project tool
arcpy.Project_management(infc, outfc, outCS)
# check messages
print(arcpy.GetMessages())
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
except Exception as ex:
print(ex.args[0])
1 Answer 1
You can have only one 'current' or 'active' workspace. The ListFeatureClasses() function is similar to 'dir' command in windows command line - you can list only one 'current' dir at time and if you need more, you need to switch.
Use for cycle to iterate over workspaces:
import os
import arcpy
# Set environment settings
workspaces = [
"C:/eis/eis shape/UPDM.gdb/P_PipeSystem",
"C:/eis/eis shape/UPDM.gdb/OtherCompanies",
"C:/eis/eis shape/UPDM.gdb/NEO"
]
arcpy.env.overwriteOutput = True
# Set local variables
outWorkspace = "C:/data"
try:
for ws in workspaces:
arcpy.env.workspace = ws
# Use ListFeatureClasses to generate a list of inputs
for infc in arcpy.ListFeatureClasses():
# Determine if the input has a defined coordinate system, can't project it if it does not
dsc = arcpy.Describe(infc)
if dsc.spatialReference.Name == "Unknown":
print ('skipped this fc due to undefined coordinate system: ' + infc)
else:
# Determine the new output feature class path and name
outfc = os.path.join(outWorkspace, infc)
# Set output coordinate system
outCS = arcpy.SpatialReference('WGS 1984')
# run project tool
arcpy.Project_management(infc, outfc, outCS)
# check messages
print(arcpy.GetMessages())
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
except Exception as ex:
print(ex.args[0])
lang-py
arcpy
can only have one current workspace, turn your code into function that takes a workspace then call it three times, one for each input workspace.