We have been trying (for days) to create a polygon features from a CSV of min xy and max xy, held as GDA94 (lat,long) and it does not work for the majority of records. Only one works.
I have added both the code and data. We are creating the corresponding points to ensure the correct import and that works but when we Append to create the polygon it works but a feature of zero area is created. There is no reported error in the script.
Python code
import arcpy, fileinput, os
from arcpy import env
env.overwriteOutput = True
infile = "C:/temp/M80/Metadata_RP.csv"
pt1 = arcpy.Point()
pt2 = arcpy.Point()
pt3 = arcpy.Point()
pt4 = arcpy.Point()
ptGeoms = []
point = arcpy.Point()
array = arcpy.Array()
featureList= []
curXY = arcpy.da.SearchCursor(infile, ["o_minx","o_miny","o_maxx","o_maxy"])
for row in curXY:
message = "{0}, {1}, {2}, {3}".format(row[0], row[1], row[2], row[3])
arcpy.AddMessage(message)
o_minx= row[0]
o_miny=row[1]
o_maxx=row[2]
o_maxy=row[3]
message = "{0}, {1}, {2}, {3}".format(o_minx,o_miny,o_maxx,o_maxy)
pt1.X = o_minx
pt1.Y = o_miny
ptGeoms.append(arcpy.PointGeometry(pt1))
pt2.X = o_maxx
pt2.Y = o_miny
ptGeoms.append(arcpy.PointGeometry(pt2))
pt3.X = o_maxx
pt3.Y = o_maxy
ptGeoms.append(arcpy.PointGeometry(pt3))
pt4.X = o_minx
pt4.Y = o_maxy
ptGeoms.append(arcpy.PointGeometry(pt4))
arcpy.AddMessage(message)
array = arcpy.Array([pt1,pt2,pt3,pt4,pt1])
polygon = arcpy.Polygon(array)
featureList.append(polygon)
arcpy.CopyFeatures_management(featureList, r"C:/temp/M80/polys.shp")
arcpy.CopyFeatures_management(ptGeoms, r"C:/temp/M80/points.shp")
print arcpy.GetMessages()
CSV data
o_minx,o_miny,o_maxx,o_maxy
144.820900,-37.757700,144.827300,-37.755800
144.818700,-37.762200,144.823400,-37.759100
144.81900,-37.760800,144.824500,-37.758400
144.823800,-37.755800,144.829200,-37.753300
144.825500,-37.753400,144.832200,-37.75200
144.8209,-37.7577,144.8273,-37.7558
144.8187,-37.7622,144.8234,-37.7591
144.8268,-37.7524,144.8331,-37.7517
144.8292,-37.7506,144.8367,-37.7502
144.8203,-37.7621,144.8201,-37.761
144.8187,-37.7622,144.8234,-37.7591
144.8214,-37.7615,144.8224,-37.761
144.8192,-37.7622,144.8225,-37.7608
144.8209,-37.7577,144.8273,-37.7558
144.8187,-37.7622,144.8234,-37.7591