Square buffers for point feature

1727
6
02-29-2012 08:20 PM
AnandRao
Occasional Contributor
Hi,

I have a single point feature and I want to create a square buffer for it. Please let me know how to do this.

Thanks,
Anand
0 Kudos
6 Replies
J_B__K_
New Contributor III
This works for me... just a simple python script...

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   = "C://YourDataDirectory//yourPoint.shp"
outPath   = "C://YourDataDirectory"
outName   = "SqBuffer"
bufDist    = 15000 #in meters
outPolys   = outPath+"//"+outName+".shp"

print "creating new blank feature"
                             
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 + bufDist
        else:
            pntObj.X = pnt.X - bufDist
        if vertex in [0,1,5]:
            pntObj.Y = pnt.Y + bufDist
        else:
            pntObj.Y = pnt.Y - bufDist
        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


Is this what you are looking for?
0 Kudos
bodoMalowerschnig
New Contributor
Hello there

I have the same problem, but could not solve it for 100%
I have a grid of points, they build squares but the whole matrix is rotated for about 5 degrees (I am not allowed to change that)
I need to make squares around those points.
What I used was the BUFFER Wizard to create a circle polygon and then I used the Feature envelope to polygon tool to create squares out of those circles.
The result was a matrix of squares but they are not rotated at 5 degrees, so they build a step and a small part on every edge is blank.
See this image to understand it better.
http://oi41.tinypic.com/3481thw.jpg

Any help?
0 Kudos
RobertKirkwood
Occasional Contributor III
what is your projection you are using? This might be why they do not align...
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
If your points are equally spaced in both directions, only a bit "rotated" (5 degrees), you can try the Create Fishnet tool with that rotation angle to create regular squares. You need to figure out the corner coordinates though in order to have the points perfectly centered inside the fishnet polygons.
0 Kudos
AnnaBuchheit
New Contributor III
This works for me... just a simple python script...

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   = "C://YourDataDirectory//yourPoint.shp"
outPath   = "C://YourDataDirectory"
outName   = "SqBuffer"
bufDist    = 15000 #in meters
outPolys   = outPath+"//"+outName+".shp"

print "creating new blank feature"
                             
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 + bufDist
        else:
            pntObj.X = pnt.X - bufDist
        if vertex in [0,1,5]:
            pntObj.Y = pnt.Y + bufDist
        else:
            pntObj.Y = pnt.Y - bufDist
        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


Is this what you are looking for?



Hi there, 
I just ran this script and it worked great for what I required; However, it wasn't perfect.  I did get square buffers around the coordinates I supplied but the buffer distance wasn't accurate.  I entered "375" for bufDist to create a 750m x 750m rectangle but the output created a 739m x 739m rectangle instead.  An equal difference of 5.5m in each direction.

Do you have any suggestions as to what happened??

Thanks!
p.s. the script is fantastic, I just don't understand Python all that well to troubleshoot!
0 Kudos
MathewCoyle
Frequent Contributor
Hi there, 
I just ran this script and it worked great for what I required; However, it wasn't perfect.  I did get square buffers around the coordinates I supplied but the buffer distance wasn't accurate.  I entered "375" for bufDist to create a 750m x 750m rectangle but the output created a 739m x 739m rectangle instead.  An equal difference of 10.5m in each direction.

Do you have any suggestions as to what happened??

Thanks!
p.s. the script is fantastic, I just don't understand Python all that well to troubleshoot!


What projection are you working in? Are you working in different projections that might have an erroneous transformation?
0 Kudos