Hello,
I am wondering how to reproject an arcpy.Extent object. I have a Python script toolboxes with a single GPExtent parameter. In the execute block, I have the following code:
ext = parameters[0].value
srs = arcpy.SpatialReference(4326)
ext.projectAs(srs)
When I run this, I get an error stating "RuntimeError: Object: CreateObject error creating spatial reference". Am I doing something wrong? Oddly, the above code runs fine in a notebook.
Thanks in advance!
Extent—ArcGIS Pro | Documentation
What is parameter 0? use an AddMessage to report it. Perhaps the extent object is non-existent or not in the correct form
Thanks Dan,
It is an Extent object, I can pluck the XMin, XMax et al. from it no problem. It also appears to have the correct .spatialReference.
You might want to have a look at this link
it uses the extent object to make a geometry object, project it, then get the extent... seems to contradict the projectAs in the help though if the source and destination spatial references are known and correct
You might need to assign a transformation, according to the docstring for Extent.projectAs():
If your projection requires a transformation, you can use ListTransformations to get a list of valid transformations and pass those to the call:
from arcpy import Extent, SpatialReference, ListTransformations
ext: Extent = parameters[0].value
srs = SpatialReference(4326)
transformation: str = ListTransformations(ext.spatialReference, srs, extent=ext)[0]
ext.projectAs(srs, transformation_name=transformation)