ArcGIS Pro – Accessing Built-in Coordinate Systems via Python Toolbox Tool

arcgis-proarcpycoordinate systemparameterspython-toolbox

I am attempting to create a custom ArcGIS Pro Python Toolbox tool and some of the geoprocessing tools I use run slowly or not at all if the input DEM or environment is not projected first. I would like to make the tool have the option of selecting the projection with the built in tools like in the Project Raster tool where you have the option to select the coordinate system, but I cannot figure out how to call that.

Select coordinate System button circled in red

The current work around I have discovered is creating a .prj file of the coordinate system you wish to project into and using that file as a parameter to feed into your script like so.

        projection = arcpy.Parameter(
        displayName="Projection for DEM",
        name="projection",
        datatype="DEPrjFile",
        parameterType="Required",
        direction="Input")

Then using arcpy.management.ProjectRaster() to project using the .prj file.

I believe there must be a better way to access the built in Coordinate systems.

Best Answer

See Defining parameter data types in a Python toolbox.

I would use either GPCoordinateSystem or GPSpatialReference.

class Tool(object):

    def getParameterInfo(self):
        """Define parameter definitions"""
        param0 = arcpy.Parameter(
            displayName="GPCoordinateSystem",
            name="GPCoordinateSystem",
            datatype="GPCoordinateSystem",
            parameterType="Required",
            direction="Input")

        param1 = arcpy.Parameter(
            displayName="GPSpatialReference",
            name="GPSpatialReference",
            datatype="GPSpatialReference",
            parameterType="Required",
            direction="Input")

        return [param0, param1]

enter image description here

Related Question