# Problem - Zero length and area for polygon generated with Python script using insert cursor to ArcPro map

1129
5
09-28-2021 07:40 AM
New Contributor II

I'm having a problem with the following script.  It writes the feature successfully with all of the attributes, but it does not draw the polygon, as the shape length and area are both zero.  This script worked previously with ArcPro 2.5, but that project became corrupted so I re-created it in ArcPro 2.8.  I'm not sure that has anything to do with the issue.

In reading other posts, it appears the two most significant factors for this script to work are setting the spatial reference and also using "Shape@" to write the polygon coordinates from the array.  The spatial reference of the map and the feature class are the same- "NAD 1983 (2011) StatePlane Illinois East FIPS 1201 (US Feet)."

Any help is very much appreciated.

`import arcpyNWLongitude = 41.936811NWLatitude = -88.754027NELongitude = 41.936811NELatitude = -88.750635SWLongitude = 41.934087SWLatitude = -88.754027SELongitude = 41.934087SELatitude = -88.750635Item = "Test Area"fc = r'G:\Arc\ArcPro\Public Works\MyProject6\MyProject6.gdb\Test_Polygon'# Important: the spatial reference must be set, or the geometry will not locate properly.sr = arcpy.Describe(fc).spatialReference  # ***Since Lat/Long Coordinates are provided, need Geographicprint("{0} : {1}".format(fc, sr.name))# Define the coordinate array for the 4-point polygon that is passed to the feature to map it.# Note that the feature is plotted with the 4 points in a clockwise direction - NW, NE, SE, SW.coordinateArray = arcpy.Array([arcpy.Point(NWLongitude, NWLatitude),                               arcpy.Point(NELongitude, NELatitude),                               arcpy.Point(SELongitude, SELatitude),                               arcpy.Point(SWLongitude, SWLatitude)])polygon = arcpy.Polygon(coordinateArray, sr)# Create Insert Cursor to write feature using polygon coordinateArray above.# "SHAPE@" is a special designation that passes through the polygon geometry statement directly above.# Note that these are the exact field names in the Test_Polygon feature.cursorFC = arcpy.da.InsertCursor(fc, ["SHAPE@", "NWlat", "NWlong", "NElat", "NElong", "SWlat", "SWlong", "SElat",                                      "SElong", "Item"])# Loading the variablescursorFC.insertRow(    [polygon, NWLatitude, NWLongitude, NELatitude, NELongitude, SWLatitude, SWLongitude, SELatitude, SELongitude,     Item])#  Delete cursor object del cursorFC`

Tags (2)
1 Solution

Accepted Solutions
Occasional Contributor III

Your code worked OK for me when I ran it against a feature class with a spatial reference whose unit of measure was degrees (NAD 1983).  At least the polygon that it generated looks correct.

5 Replies
MVP Frequent Contributor

Sorry I've not checked the script thoroughly, but it seems that you've not closed the polygon (clockwise array should end with a repeat of the first coordinates).

New Contributor II

Thank you for the suggestion David.  I changed the code to add the first coordinate pair again at the end, however I am getting the same result.

MVP Frequent Contributor

Oh wait, what's up with the projection? The geometry has to be in the same units as the projection, you cant just use lat longs, or am I missing something?

Occasional Contributor III

Your code worked OK for me when I ran it against a feature class with a spatial reference whose unit of measure was degrees (NAD 1983).  At least the polygon that it generated looks correct.

New Contributor II

David and Don, you are right.  I was using a State Plane Coordinate System, which is a projected coordinate system, but using Lat/Long coordinates I need a geographic coordinate system like NAD 83.  Thank you!