Select to view content in your preferred language

Using ArcPy Spatial Reference object as input to .net Geoprocessing Tool

1055
1
05-19-2014 06:01 PM
DavidWilton
Frequent Contributor
I am creating a custom .net geoprocessing tool. The ESRI geoprocessing tools accept Python SpatialReference Objects as input parameters for projection. How can this be achieved in a custom .net geoprocessing tool? I have tried specifying my parameter data type as both GPSpatialReferenceType and GPCoordinateSystemType and neither work, they give the error "Invalid value type for parameter out_projection" when used with a Python Spatial reference object. In order to use that object you have to call the exportToString() method which I would rather not do as it is not consistent with ESRI. There is no way to interecept the object and convert it to a string because within IGPFunction2.UpdateParameters the parameter value is null

Dim outputParameter As IGPParameterEdit3 = New GPParameterClass()
outputParameter.DataType = CType(New GPSpatialReferenceType(), IGPDataType)


Thanks
David
0 Kudos
1 Reply
DavidWilton
Frequent Contributor

I got a reply from ESRI support on this question so I'm posting for others. It is possible to have a python spatial reference as an input type. If you don't set the value of the output parameter it will only accept integers, string names, the spatial reference as a string or a string path of a prj file. However, setting the value allows you to pass in a python spatial reference object and the parameter will behave in exactly the same way as the ESRI ones (see project in data management for example)

Dim outputParameter As IGPParameterEdit3 = New GPParameterClass()

outputParameter = New GPParameterClass()

outputParameter.DataType = DirectCast(New GPSpatialReferenceType(), IGPDataType)

outputParameter.Value = DirectCast(New GPSpatialReferenceClass(), IGPValue)

outputParameter.Direction = esriGPParameterDirection.esriGPParameterDirectionInput

outputParameter.DisplayName = "Output File Projection"

outputParameter.Name = "out_projection"

outputParameter.ParameterType = esriGPParameterType.esriGPParameterTypeRequired

Dim pParameters As IArray = New ArrayClass()

pParameters.Add(outputParameter)

0 Kudos