I am trying to batch project feature classes from one GDB to another in a stand alone script. This script also includes field mapping from a csv file to a new GDB but that portion of the script works fine. I have ArcMap 10.6.1 installed with Python 2.7.14. I started with with ESRI sample for BatchProject stand alone example.
import csv
import sys
import os
import arcpy
from arcpy import env
import BatchProject.py
arcpy.env.workspace = "C:\Data\Pennsylvania\Washington County\MCPExport.gdb" # Set workspace environment
out_workspace = "C:\\Data\\Pennsylvania\\NG911_TEST.gdb" # Output workspace
input_features = arcpy.ListFeatureClasses()
template = "C:\Data\Pennsylvania\NG911_TEST.gdb\ESZ_EMS"
out_cs = '' transformation = 'NAD_1983_To_WGS_1984_5' # Geographic transformation, if needed
res = arcpy.BatchProject(input_features, out_workspace, out_cs, template, transformation)
Error I get:
Traceback (most recent call last):
File "C:\Data\Pennsylvania\ETL_Bat_November2020\ETL\washington\etl3.py", line 6, in <module>
import BatchProject.py
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcToolBox\Scripts\BatchProject.py", line 54, in <module>
raise ConversionUtils.GPError(msgCoordinateSystem)
GPError: Must Enter a Spatial Reference or Template Feature Class.
I have tried various templates and out_cs values but nothing works. I've added. Any help would be appreciated!!
Thanks!!!
Solved! Go to Solution.
Like @JoeBorgione mentioned below, run the tool from the geoprocessing toolbox (Data Management, Projections and Transformations). You can do the same thing in ArcMap 10.6.1 if you don't have ArcGIS Pro. If you can get it to work there, you can copy the geoprocessing result as a python snippet and paste it into a text editor. This will give you a starting place to work out from.
Hello,
When I see issues like this, one thing I like to try is to only run the code with the required parameters. If that works, I slowly build out from there so I can absolutely confirm which parameters are causing the issue. In regards to the crs parameter, have your tried pointing to a .prj file? I have had success with that in the past.
Going even further, try simplifying your parameters too. Instead of running it on everything with arcpy.ListFeatureClasses(), just specify one feature class you know should work (meaning it is in NAD_1983). Try different combinations of specifying a projection or using a template, and with or without the transformation.
Hi Blake,
I have tried one shapefile then one feature class, even though it's a batch project. I still get the same error.
Like @JoeBorgione mentioned below, run the tool from the geoprocessing toolbox (Data Management, Projections and Transformations). You can do the same thing in ArcMap 10.6.1 if you don't have ArcGIS Pro. If you can get it to work there, you can copy the geoprocessing result as a python snippet and paste it into a text editor. This will give you a starting place to work out from.
After this little tidbit from Blake about copying the results as a python snippet I could really see the correct tool and syntax. My code was off. Should have been using arcpy.BatchProject_management.
Thank you Blake and Joe
import arcpy
arcpy.BatchProject_management(Input_Feature_Class_or_Dataset="'C:/Data/Pennsylvania/Washington County/MCPExport.gdb/RCL'", Output_Workspace="C:/Data/Pennsylvania/NG911_TEST.gdb", Output_Coordinate_System="GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]", Template_dataset="", Transformation="NAD_1983_To_WGS_1984_5")
Hi there,
I have tried .prj files. And leaving the template blank and trying various versions of WGS84. One being out_cs=arcpy.SpatialReference(4326)
If you run the Project Tool in arcgis pro, you will get all the parameters you need from the tool itself. You can then fold them into a script as described in the help https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/project.htm