Select to view content in your preferred language

Support Empty Geometries with ArcPy Geometry Class Constructors

1935
6
04-21-2015 07:06 PM
Status: Closed
Labels (1)
JoshuaBixby
MVP Esteemed Contributor

Constructing empty geometries isn't possible using the ArcPy Geometry classes. The only way to currently create an empty geometry in ArcPy is to use the arcpy.FromWKT as a geometry constructor. I propose the ArcPy Geometry classes support the construction of empty geometries.

Currently, calling any of the ArcPy Geometry constructors with no arguments, a 'None' argument, or an empty arcpy.Array throws an exception.

>>> arcpy.Polygon()
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\arcobjects\mixins.py", line 222, in __init__
    *gp_fixargs(args, True))
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\geoprocessing\_base.py", line 504, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: CreateObject cannot create geometry from inputs


Instead, the constructors should generate an empty geometry of the appropriate type similar to geometry constructors from other Python (Shapely) and DBMS (SQL Server) packages.

>>> pg = arcpy.Polygon()
>>> pg.type
u'polygon'
>>> pg.WKT
u'MULTIPOLYGON EMPTY'


 

6 Comments
DuncanHornby
When I saw your idea I thought surely that's not right but having looked at the help file I realised there is no mechanism or method that allows you to add points to a polygon. In ArcObjects there is an interface called IPointsCollection and you would use that to insert points into a geometry. So as there is no way of adding points to an existing polygon its not suprising that the constructor won't allow the creation of a Polygon without an array of points. So I'm guessing until ESRI expose some method to add points to a polygon this idea will never get of the ground...

Still voted for it!
DavidWynne
Can create an empty polygon this way:
p = arcpy.Polygon(arcpy.Array(None))
 
DuncanHornby
Ha! I had tried the following and had come to the conclusion it was not possible as this throws an error:

p = arcpy.Polygon(arcpy.Array([]))

Nice to see it's possible.
 
JoshuaBixby
Funny, I tried None, arcpy.Array(), and arcpy.Array([]); but I never thought to try arcpy.Array(None).  That said, arcpy.Polygon(arcpy.Array(None)) is a bit too baroque for my tastes.  In the context of Zen, there is nothing simple or beautiful about the current implementation.  What is problematic with arcpy.Polygon()?

I will leave this idea open to push for a more elegant and straightfoward way to construct empty geometries.
JoshuaBixby

Given empty geometries are actually/already supported by the geometry constructors, I think this idea should be merged with https://community.esri.com/ideas/10963‌ since what I am after is having the syntax for creating empty geometries be more intuitive and idiomatic.

SSWoodward
Status changed to: Closed

This Idea has been closed as a duplicate of an idea found on the ArcGIS Pro Ideas Exchange. 

If you would like to support this idea. Please comment and send your kudos to the idea linked below.

https://community.esri.com/t5/arcgis-pro-ideas/pythonic-arcpy-geometries/idi-p/940322