fail to build polygon geometry from Lat/Long

1873
11
Jump to solution
09-23-2016 01:00 PM
KevinBell
Occasional Contributor III
import arcpy
array = arcpy.Array([arcpy.Point(0, 0),
                     arcpy.Point(0, 1000),
                     arcpy.Point(1000, 1000),
                     arcpy.Point(1000, 0)
                     ])
polygon = arcpy.Polygon(array)
cursor = arcpy.da.InsertCursor(r'C:\path\to\your\geodatabase.gdb\polygon', ['SHAPE@'])
cursor.insertRow([polygon])

The code below works as expected, but fails if I substitute Lat/Longs in the arcpy.Point.  Is that expected?

Tags (2)
0 Kudos
11 Replies
DarrenWiens2
MVP Honored Contributor

Can you try this?


import arcpy
fc = r'C:\path\to\your\geodatabase.gdb\polygon'
sr = arcpy.Describe(fc).spatialReference # get spatial reference
array = arcpy.Array([arcpy.Point(-111.8256, 40.691085),
                     arcpy.Point(-111.825347, 40.691614),
                     arcpy.Point(-111.824706, 40.691896),
                     arcpy.Point(-111.825592, 40.68703)
                     ])
polygon = arcpy.Polygon(array,sr) # create polygon with spatial reference
cursor = arcpy.da.InsertCursor(fc, ['SHAPE@'] )
cursor.insertRow([polygon])‍‍‍‍‍‍‍‍‍‍‍
KevinBell
Occasional Contributor III

Much thanks!  I thought it'd pick up the sr on it's own!

0 Kudos