import arcpy pointFC = r"c:\My.gdb\points" # input point fc polygonFC = r"c:\My.gdb\polys" # output polygon FC # make a list of the point coords as pairs pointList = [] with arcpy.da.SearchCursor(pointFC, "SHAPE@XY") as cursor: for row in cursor: shortList = list(row[0]) pointList.append(shortList) # insert cursor to add polygons c = arcpy.da.InsertCursor(polygonFC, ["SHAPE@"]) for pnt in pointList: # start with the lower left lowX = pnt[0] lowY = pnt[1] # find the upper right highX = lowX + sideLen highY = lowY + sideLen # create polygon array of points array = arcpy.Array([arcpy.Point(lowX, lowY), arcpy.Point(lowX, highY), arcpy.Point(highX, highY), arcpy.Point(highX, lowY), arcpy.Point(lowX, lowY)]) polyline = arcpy.Polyline(array) # insert the array as a polygon c.insertRow([polyline]) del c del arcpy
import arcpy from arcpy import env env.overwriteOutput = True pointFC = "C:/Scratch/testpnts.shp" pointList=[] featureList= [] with arcpy.da.SearchCursor(pointFC, ["SHAPE@XY"]) as cursor: for row in cursor: shortList = list(row[0]) pointList.append(shortList) for pnt in pointList: lowX = pnt[0] lowY = pnt[1] highX = lowX + .5 highY = lowY + .5 array = arcpy.Array([arcpy.Point(lowX, lowY), arcpy.Point(lowX, highY), arcpy.Point(highX, highY), arcpy.Point(highX, lowY), arcpy.Point(lowX, lowY)]) polygon = arcpy.Polygon(array) featureList.append(polygon) arcpy.CopyFeatures_management(featureList, "Z:/Scratch/polys.shp") print arcpy.GetMessages()
Well, if you have the lower left xy point, and know the dimensions of the squares,
Then it is pretty straightforward to calculate each other corner in order
and then feed the whole list to an insert cursor.
# your given point coords
lowX = 1
lowY= 1
# the far corner coords
highX = lowX + 2
highY = lowY + 2
# all the corners as pairs
theList = [[lowX, lowY], [highX, lowY], [highX, highY], [lowX, highY], [lowX, lowY]]
I don't offhand recall the correct syntax for supplying the coords,
but they should be in an array, not a nested list like above, but this is the idea...
.. later, he added:import arcpy pointFC = r"c:\My.gdb\points" # input point fc polygonFC = r"c:\My.gdb\polys" # output polygon FC # make a list of the point coords as pairs pointList = [] with arcpy.da.SearchCursor(pointFC, "SHAPE@XY") as cursor: for row in cursor: shortList = list(row[0]) pointList.append(shortList) # insert cursor to add polygons c = arcpy.da.InsertCursor(polygonFC, ["SHAPE@"]) for pnt in pointList: # start with the lower left lowX = pnt[0] lowY = pnt[1] # find the upper right highX = lowX + sideLen highY = lowY + sideLen # create polygon array of points array = arcpy.Array([arcpy.Point(lowX, lowY), arcpy.Point(lowX, highY), arcpy.Point(highX, highY), arcpy.Point(highX, lowY), arcpy.Point(lowX, lowY)]) polyline = arcpy.Polyline(array) # insert the array as a polygon c.insertRow([polyline]) del c del arcpy
... Not tested, no warranties expressed or implied ...
import arcpy pointFC = r"C:\Users\whitley-wayne\Desktop\summary\data.gdb\funds" polygonFC = r"C:\Users\whitley-wayne\Desktop\summary\data.gdb\hab60" pointList = [] with arcpy.da.SearchCursor(pointFC, "SHAPE@XY") as cursor: for row in cursor: shortList = list(row[0]) pointList.append(shortList) with arcpy.da.InsertCursor(polygonFC, ["SHAPE@"]) as c: for pnt in pointList: # start with the lower left lowX = pnt[0] lowY = pnt[1] # find the upper right highX = lowX + 20 highY = lowY + 20 array = arcpy.Array([arcpy.Point(lowX, lowY), arcpy.Point(lowX, highY), arcpy.Point(highX, highY), arcpy.Point(highX, lowY), arcpy.Point(lowX, lowY)]) polygon = arcpy.Polygon(array) c.insertRow([polygon])
import arcpy fc= r"U:\\Tax\\Special Projects\\JEFitzgerald\\CUVA\\Test\\Points.shp" polygonFC= r"U:\\Tax\\Special Projects\\JEFitzgerald\\CUVA\Test\\Polygon.shp" pointList=[] ####CODE VERSION#### # Source: "http://resources.arcgis.com/en/help/main/10.1/index.html#/ # Reading_geometries/002z0000001t000000/" #for row in arcpy.da.SearchCursor (fc, [ "OID@", "SHAPE@XY"]): #print ("feature {0}:".format(row[0])) #print row[1] #**** CODE ****# #Sourc: "http://forums.arcgis.com/threads/96860-Create-multiple-polygons-in-ArcGIS-using-Python- #and-an-XY-table?highlight=create+multiple+polygons" with arcpy.da.SearchCursor (fc, ["SHAPE@XY"]) as cursor: for row in cursor: xy = row[0] pointList.append(xy) #print ("{0}, {1}".format(x,y)) with arcpy.da.InsertCursor (polygonFC, ["SHAPE@"]) as U: for pnt in pointList: lowX = pnt[0] lowY = pnt[1] # find the upper right highX = lowX + 163.1935 highY = lowY + 183.831 array = arcpy.Array([arcpy.Point(lowX, lowY), arcpy.Point(lowX, highY), arcpy.Point(highX, highY), arcpy.Point(highX, lowY), arcpy.Point(lowX, lowY)]) polygon = arcpy.Polygon(array) U.insertRow([polygon])
Hi,
How would be the script to generate a polygon with four corners from a table where i have all 4 pairs of XY?
It is a bit tedious to build hundreds of polygons using the absolute path and I can't see any tool such as XY to polygon in Arctoolbox. I could only see XY to point and XY to polyline.
Thank you for your help.
Ciprian, through the GUI:
1.) Create points from XY (Make XY Event Layer)
2.) Create line from points (this or this)
3.) Create polygons from lines (requires Advanced license)
If you want to do this using Arcpy (certainly possible and done many times before), please post what you've got so far.
I would like to try the Arcpy way to automate the process, but I am really novice at this and hoped I could alter the code above. At this moment, I have a gdb table that contains the columns: x_F1, y_F1, x_F2, y_F2, x_F3, y_F3, x_F4, y_F4.
You can write such a script using a Geometry Polygon object and some search cursors.
See the code sample at the bottom of this page: ArcGIS Help (10.2, 10.2.1, and 10.2.2)