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 arcpy
NWLongitude = 41.936811
NWLatitude = -88.754027
NELongitude = 41.936811
NELatitude = -88.750635
SWLongitude = 41.934087
SWLatitude = -88.754027
SELongitude = 41.934087
SELatitude = -88.750635
Item = "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 Geographic
print("{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 variables
cursorFC.insertRow(
[polygon, NWLatitude, NWLongitude, NELatitude, NELongitude, SWLatitude, SWLongitude, SELatitude, SELongitude,
Item])
# Delete cursor object
del cursorFC