1

I have a CSV file with hundreds of records. Each record contains 2 matching coordinates, 1) top right corner of a rectangle, 2) bottom left corner of a rectangle.

Polygon ID, Lat 1,       Lat 2,       Long 1,       Long 2          
1,          27o 28' 28", 27o 33' 30", 86o 06' 04",  86o 15' 00"

Is there a method which I can use to automate the creation of these polygons? I anticipate there being a few steps.

  • What language are you planning on using to script this? – Vince Oct 30 '13 at 18:05
  • ArcPy/Python would be my go-to for ArcGIS. – Radar Oct 30 '13 at 18:06
  • After some consideration, I think just editing the CSV, plotting the 4 corners as points, and using Points to Polygon will be the easiest solution. Other solutions still welcome. – Radar Oct 30 '13 at 18:18
0

This works for me: CSV format(XTR,YTR,XBL,YBL)

gp.CreateFeatureclass(path,name, "POLYGON")
cur = gp.InsertCursor (path+name)
open csv file
for each line in csvFile:

coordinates=split.line(",")

x1=float(xpcoordinates[0])
y1=float(xpcoordinates[1])

x2=float(xpcoordinates[0])-float(deltaX)
y2=float(xpcoordinates[1])

x3=float(xpcoordinates[2])
y3=float(xpcoordinates[3])

x4=float(xpcoordinates[2])+float(deltaX)
y4=float(xpcoordinates[3])

x5=float(xpcoordinates[0])
y5=float(xpcoordinates[1])

xyarray.append(str(x1)+","+str((y1)))
xyarray.append(str(x2)+","+str((y2)))
xyarray.append(str(x3)+","+str((y3)))
xyarray.append(str(x4)+","+str((y4)))
xyarray.append(str(x5)+","+str((y5)))

row = cur.NewRow()

PolygonArray = gp.CreateObject ("Array")
pnt = gp.CreateObject ("Point")

pnt.x = x1
pnt.y = y1
PolygonArray.add(pnt)

pnt.x = x2
pnt.y = y2
PolygonArray.add(pnt)

pnt.x = x3
pnt.y = y3
PolygonArray.add(pnt)

pnt.x = x4
pnt.y = y4
PolygonArray.add(pnt)

row.shape = PolygonArray
cur.InsertRow(row)
0

For thoroughness, below I am providing the solution I implemented.

  1. Converted coordinates to decimal degrees in Excel using a simple macro.
  2. Added extra columns representing the 2 corners not present in the original file. Therefore, all 4 corners were stored in the file.
  3. Added an ID field (one ID for each set of 4 points (corners).
  4. Imported the CSV into ArcGIS and plotted the points.
  5. Converted the points to polygons using the ID field. This resulted in the final polygon 'footprint' layer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.