Generate polygon plot boundaries around random points

1912
11
03-19-2019 02:58 PM
DennisMarks
New Contributor II

Hi,

In past years, I've used the Geospatial Modeling Environment software (with R) to generate rectangular plot boundaries around a set of random points. It was a simple script (below) but it doesn't look like the last GME software is compatible with ArcMap 10.6.  I've seen some older solutions given on these pages but didn't suit this problem, in that I need to input GROUND dimensions (in feet, meters, miles, etc.) and have ArcMap draw rectangle polygons around all points in the layer. I've also seen some Python solutions but used coordinates as input (and I don't know Python). Are there any other possibilities? Does ArcGIS Pro have any feature to do this?

Thank you! 

genshapes(in="C:\randompoints2017.shp", shape="RECTANGLE", dim=c(402.35, 201.175), out="C:\randomplotpolys2017.shp");

0 Kudos
11 Replies
DanPatterson_Retired
MVP Esteemed Contributor

check the builtin tools Minimum Bounding Geometry—Data Management toolbox | ArcGIS Desktop (available in *map and *Pro)

DennisMarks
New Contributor II

Thanks Dan, I did play around a bit with the min bounding geometry prior to posting. As far as I can see, it doesn't allow me to enter rectangle dimensions, and it wants to build a rectangle using all the points in my feature. I need something to take each point in that feature and build a specified (ht + width) rectangle around each.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

python it is

https://community.esri.com/thread/119885?commentID=449371#comment-449371 

you will have a little work to do, but Xander Bakker‌ options and code are great

DennisMarks
New Contributor II

We've been playing around with Python codes off these pages and are having some success! It's been a little clunky in that you adjust the lat/long coordinate, check rectangle side distance, and repeat. This is working, the problem now is something with the projection isn't spot on and the rectangle is slightly tilted in our project and we're having problems figuring out why from the code. The code you gave us the link to looks a little different...we'll give it another shot tomorrow. Thanks!

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

longitude latitude coordinates  and rectangles around them aren't going to be truly rectangular because of the differences in the width of a line of latitude as you head polewards.  You should be working with data in a projected coordinate system (eg. UTM or similar... definitely not web Mercator) and specify your rectangle width and height in the same units as the projection (eg. meters) 

DennisMarks
New Contributor II

Still tinkering. Yes, when we apply the Python code in an unprojected ArcMap, we get the rectangle, but with the angle issue. When we run Python in a projected project (we're using NAD83 UTM3N), Python doesn't create anything.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Open a new dataframe devoid of anything other than the points.

Make sure that there are no points selected in the table etc.

And the obvious and most important, the code needs to be adjusted to account for your coordinate system and the cell size, since the examples were specific to those conditions.  Check the code for the appropriate lines.

MatthewDriscoll
MVP Regular Contributor

Here is a solution I found on here many years ago, which I cannot find now.  This is for ArcMap.    

import arcpy, os
from arcpy import env
env.overwriteOutput = True
# Get arguments: 
#   Input point feature class
#   Output polygon feature class
#   Buffer distance
#   Boolean type: Maintain fields and field values of the input in the output

print "initializing"
inPoints   = arcpy.GetParameterAsText(0)    # Feature Class
outPath   = arcpy.GetParameterAsText(1)     # Folder
outName   = arcpy.GetParameterAsText(2)     # Variant
buf1    = float(arcpy.GetParameterAsText(3))    # String
buf2    = float(arcpy.GetParameterAsText(4))    # String
bufDist1    = buf1/2
bufDist2    = buf2/2
outPolys   = outPath+"//"+outName+".shp"

print "creating new blank feature"

arcpy.env.outputCoordinateSystem = arcpy.GetParameterAsText(5)  # Coordinate System
                             
arcpy.CreateFeatureclass_management(outPath, outName,"POLYGON","","","", "", "","","","")
print "created"

# Open searchcursor
inRows = arcpy.SearchCursor(inPoints)

# Open insertcursor
outRows = arcpy.InsertCursor(outPolys)

# Create point and array objects
pntObj = arcpy.Point()
arrayObj = arcpy.Array()

print "writing geomety"
for inRow in inRows: # One output feature for each input point feature
    inShape = inRow.shape
    pnt = inShape.getPart(0)

    # Need 5 vertices for square buffer: upper right, upper left, lower left,
    #   lower right, upper right. Add and subtract distance from coordinates of
    #   input point as appropriate.
    for vertex in [0,1,2,3,4]:
        pntObj.ID = vertex
        if vertex in [0,3,4]:
            pntObj.X = pnt.X + bufDist1
        else:
            pntObj.X = pnt.X - bufDist1
        if vertex in [0,1,5]:
            pntObj.Y = pnt.Y + bufDist2
        else:
            pntObj.Y = pnt.Y - bufDist2
        arrayObj.add(pntObj)

    # Create new row for output feature
    feat = outRows.newRow()
    
    # Assign array of points to output feature
    feat.shape = arrayObj

    # Insert the feature
    outRows.insertRow(feat)

    # Clear array of points
    arrayObj.removeAll()

# Delete inputcursor
del outRows
print "done"‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
DennisMarks
New Contributor II

Fantastic! When we ran Python on a projected arcmap, the measurements were created in meters, not degrees. At first we just didn't see it draw because we left the dimensions in (fraction) degrees, which were tiny on the .mxd. Changing the projection changed the measurements. It all lined up and is working perfectly. 

Thank you Dan...and Matthew!

0 Kudos