I want to create a script that iterates through feature classes with different projections in a geodatabase and exports them into a new geodatabase, all with the same projections.
What I want is to create a script in toolbox with four display names:
- Input Geodatabase:
- Output Location:
- Convert to Coord System:
- Transformation Method:
This script will allow the user to choose different coordinate systems. I have been able to piece together the code and this is what I have:
# Import modules
import arcpy
import os
# Set environment settings
arcpy.env.workspace = r"F:\abc...il.gdb"
# Set local variables. I want to take whats in arcpy.env.workspace and put it into a
# geodatabse with new coordinate systems
outWorkspace = r"F:\abc...ished.gdb"
# outCS will be the old coordinate system.
Problem 1: ArcMap 10.1 and above no longer # have a Coordinate System folder. # So coordinates have to be saved in Favorites. Therefore, coordinate systems # have to be sourced from a favorite folder where # coords have been manually added as favorites in the Shapefile Properties window.
outCS = r"C:\Users\User\AppData\Roaming\ESRI\Desktop10.1\ArcMap\Coordinate Systems\NAD 1983 HARN StatePlane Hawaii 3 FIPS 5103 (US Feet)"
# Use ListFeatureClasses to generate a list of shapefiles
fcList = arcpy.ListFeatureClasses()
# Copy shapefiles to a file geodatabase
for infc in fcList:
arcpy.CopyFeatures_management(infc, r"F:\abc...ished.gdb" + os.sep + fc.strip(".shp"))
# Determine if the input has a defined coordinate system, can't project if it does
# not, Problem 2: What I want is to create a script
# in toolbox with four display names: 1) Input Geodatabase: 2) Output Location:,
# 3) Convert to Coord System: , 4) Transformation Method: .
# I have to use Search Cursor I think to first find the coordinate system.
desc = arcpy.Describe(arcpy.env.workspace)
rows = arcpy.da.SearchCursor(arcpy.env.workspace, ["SHAPE@"],
spatial_reference = desc.spatialReference)
# Now, the problem is I want the user to be able to choose the coord system,
# so I can put it in the outFeatureClass below instead of typing "WGS 1984 UTM Zone 4N".
if desc.spatialReference.Name == "Unknown":
print('Undefined coordinate system: ' + infc)
elif:
# Determine the new output feature class path and name
outFeatureClass = os.path.join(outWorkspace, infc.strip(".shp") + "WGS 1984 UTM Zone 4N")
# Set transformation. Problem 4: I want is to allow the user to choose this
# from the script this not have to type it as code.
transform_method = "NAD_1983_To_WGS_1984_1"
# New coord system
arcpy.Project_management(infc, outFeatureClass, outCS, transform_method)
I am new at programming.
This is what I have :
# Import modules
import arcpy
import os
# Set environment settings
arcpy.env.workspace = r"F:\...Rail.gdb"
# Set local variables. I want to take whats in arcpy.env.workspace and put it into a geodatabse
# with new coordinate systems
inputWorkspace = arcpy.GetParameterAsText(0)
outputName = arcpy.GetParameterAsText(1)
outWorkspace = r"F:\...\Finished.gdb"
# n is index number for "Convert to Coord System" parameter
outCS = arcpy.GetParameterAsText(n)
cs_dict = {
"NAD 1983":r"path/to/NAD83/prj/file",
"WGS 1984":r"path/to/WGS84/prj/file"
}
outCSprj = cs_dict[outCSchoice]
# Use ListFeatureClasses to generate a list of shapefiles
fcList = arcpy.ListFeatureClasses()
# Copy shapefiles to a file geodatabase
for infc in fcList:
arcpy.CopyFeatures_management(infc, r"F:\...Final_output.gdb" + os.sep + fc.strip(".shp"))
# Describe a feature class
fc = "D:/St_Johns/data.gdb/roads"
desc = arcpy.Describe(fc)
# Get the spatial reference
sr = desc.spatialReference
# Check if the feature class is in projected space
if sr.type == "Projected":
arcpy.Copy_management(fc,"D:/St_Johns/data.gdb/roads_UTM")
elif:
# Determine the new output feature class path and name
outFeatureClass = os.path.join(outWorkspace, infc.strip(".shp") + "WGS 1984 UTM Zone 4N")
# New coord system
arcpy.Project_management(infc, outFeatureClass, outCS, transform_method)