# Creating Polygons based on 2 XY points

I have an excel file with 2 x,y coordinates as columns. One set of coordinates is the top left vertex of a rectangle, the other set is the bottom right vertex of the rectangle.

Is there anyway to plot these coordinates and have Arcmap automatically draw rectangles connecting these vertexes? I've searched on here for the answer but kept getting hung up on some of the options. Preferably a solution without using arcpy.

• @ziggy not if you treat them as an extent. – mkennedy Feb 7 '17 at 18:56
• Not sure why this is on hold. Seems clear to me. Follow these steps: 1) add XY data from File menu. Then export data. (2) use the XY To Line geoprocessing tool to convert the XY Coordinates to a Line (3) Use the Line as input into the Minimum Bounding Geometry geoprocessing tool. All of the geoprocessing tools are under Data Management Tools\Features – Brad Feb 7 '17 at 19:03
• What license level is available? You can use @Brad 's solution with Advanced, but won't have access to the 'ENVELOPE' option with Basic/Standard. – phloem Feb 7 '17 at 19:08
• @Brad further up in that link you'll see (under Syntax > geometry_type) that `ENVELOPE` is only available under Advanced license – Midavalo Feb 7 '17 at 19:18
• The tool is available, but the output geometry type is limited by license level. – phloem Feb 7 '17 at 19:18

As suggested by @Brad convert pairs of points to lines.

``````arcpy.AddGeometryAttributes_management("LINES", "EXTENT")
arcpy.Buffer_analysis("LINES", "D:/Scratch/buffers.shp", "1 Meters")
``````

Apply this field calculator expression on field Shape of buffers:

``````def toExtent(xmin,ymin,xmax,ymax):
LL=arcpy.Point(xmin,ymin)
UL=arcpy.Point(xmin,ymax)
UR=arcpy.Point(xmax,ymax)
LR=arcpy.Point(xmax,ymin)
array=arcpy.Array([LL,UL,UR,LR])
polygon=arcpy.Polygon(array)
return polygon
#------------------------
toExtent( !EXT_MIN_X!, !EXT_MIN_Y!, !EXT_MAX_X!, !EXT_MAX_Y! )
``````

OUTPUT:

I know you prefer not to use arcpy, but I'm not sure how you can get around it with Basic/Standard license. After you've got your Excel spreadsheet into an ArcMap table view:

``````fc = 'my_table' # the table
fields = ['N_Lat','W_Lon','S_Lat','E_Lon'] # coordinate fields. Order is important.
sr = arcpy.SpatialReference(4326) # spatial reference. Assume WGS_1984.
out_recs = [] # placeholder
with arcpy.da.SearchCursor(fc,fields) as cursor: # loop through table
for row in cursor:
extent = arcpy.Extent(row[1],row[2],row[3],row[0]) # create extent object
extent_poly = arcpy.Polygon(arcpy.Array([extent.upperLeft,extent.upperRight,extent.lowerRight,extent.lowerLeft]),sr) # create polygon from extent. Define spatial reference.
out_recs.append(extent_poly) # add to polygon list
arcpy.CopyFeatures_management(out_recs,r'in_memory\out_recs') # write to disk
``````