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?
Solved! Go to Solution.
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])
Kevin can you format your code using syntax highlighting /blogs/dan_patterson/2016/08/14/script-formatting
EDIT What are the longitudes and latitude? some example? longitude first (X), latitude 2nd (Y)
this doesn't work:
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)
])
is the polygon ring (aka points) clockwise in orientation? and non-intersecting? (i'm not going to draw it out... the numbers just got weird)
I drew it out and it looks like it's clockwise, non-intersecting.
How does it fail? With an error? If so, what's the full error?
I suspect it's because you don't set a spatial reference anywhere, but we'll see.
Can you provide an example where it fails? Or does your given example fail?
when I pass in the -111.8256, 40.691085 as above a record is created in the table, but w/ empty geometry.
What is the spatial reference of your 'polygon' feature class?
GCS_WGS_1984 is the spref of the FC I'm inserting into.