square buffer

9338
12
Jump to solution
01-24-2015 02:40 PM
MahmoudMdookh
New Contributor II

for people who know about using python scripting in ArcMap, I'm a GIS student and I have a small project about python. I'm beginner in python language I need some help in my python script. it's about square buffer around a points feature in GIS ArcMap 10.1? and I have tried all my best to do this but it's not working .. Hope you'll help me If you don't know "Just tag this post to anyone who know about this" Thanks in advance.

This is my script:

    import arcpy
    import math
    import os
    from arcpy import env
    env
.overwriteOutput=False

    #Point Feature Class that the square buffers will be created around
    Input_Points= arcpy.GetParameterAsText(0)
    #Path and name for Output Polygon Feature Class
    out_Feature_Class
=arcpy.GetParameterAsText(1)
    Out_Path=os.path.dirname(out_Feature_Class)
    out_Name
=os.path.basename(out_Feature_Class)
    #Height
    h
= arcpy.GetParameterAsText(2)
    h
=float(h)
    #Width
    w
= arcpy.GetParameterAsText(3)
    w
=float(w)
    cursor
=arcpy.da.SearchCursor(Input_Points,"Shape")
    fields
=cursor.fields
    for field in fields:
      m
=cursor.next()
      x
=m[0][0]
      y
=m[0][1]
      x1
=x-(w/2)
      x2
=x+(w/2)
      x3
=x+(w/2)
      x4
=x-(w/2)
      y1
=y-(h/2)
      y2
=y-(h/2)
      y3
=y-(h/2)
      y4
=y-(h/2)
      pnt1
=arcpy.Point(x1,y1)
      pnt2
=arcpy.Point(x2,y2)
      pnt3
=arcpy.Point(x3,y3)
      pnt4
=arcpy.Point(x4,y4)
      arr
=arcpy.Array([pnt1,pnt2,pnt3,pnt4,pnt1])
      square_buffer
=arcpy.Polygon(arr)

    arcpy
.CopyFeatures_management(square_buffer,"square_buffer")

    arcpy
.CreateFeatureclass_management(Out_Path,out_Name,"POINT")
    arcpy
.AddField_management(out_Feature_Class,"x","FLOAT")
    arcpy
.AddField_management(out_Feature_Class,"y","FLOAT")
    arcpy
.AddField_management(out_Feature_Class,"POI","TEXT")
    arcpy
.AddField_management(out_Feature_Class,"Height","DOUBLE")
    arcpy
.AddField_management(out_Feature_Class,"Width","DOUBLE")

    with arcpy.da.InsertCursor(out_Feature_Class,("SHAPE@xy","x","y","POI","Height","Width"))as cursor:
     
for line in cursor:
      attributes
=line.split(",")
      x
=attributes[0]
      x
=float(x)
      y
=attributes[1]
      y
=float(y)
      POI
=attributes[3]
     
Height=attributes[4]
     
Width=attributes[4]
      row
=((x,y),x,y,POI,Height,Width)
     
#arcpy.Add massege(row)
      cursor
.insertRow(row)

Tags (2)
0 Kudos
12 Replies
FilipKrál
Occasional Contributor III

The link Xander Bakker‌ provided above is the solution, I just want to note that truly square (special case of rectangular) buffers with sides of equal length can be created using arcpy.analysis.Buffer and then arcpy.management.FeatureEnvelopeToPolygon

That is if the squares can be aligned with your coordinate system and wouldn't need to rotating‌. Also arcpy.management.MinimumBoundingGeometry can be useful for these kinds of tasks.

MahmoudMdookh
New Contributor II

Thanks so much to everybody who helped me in this ...

0 Kudos
XanderBakker
Esri Esteemed Contributor

Glad it worked for you!

0 Kudos