0

Is this possible to generate polygons from points (which are centroids of future polygon)? I got shapefile with ~250 points + they have got two attributes: length and width.

I don't need complete workaround I need tip on how this can be achieved.

Below is sketch picture of what I want to achieve.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
  • You have an answer for QGIS here: https://gis.stackexchange.com/questions/217218/how-to-create-rectangular-buffers-around-points-in-qgis-with-python/217239#217239. You can try to adapt this code for arcpy. – xunilk Jan 12 '19 at 15:41
  • Im gonna check this. Thank you! But if anyone has something more arcpy related please post your ideas. – JuniorPythonNewbie Jan 12 '19 at 15:49
  • Add geometry attributes and Create 2 copies of your points. Calculate Shape using arcpy.Point(pointx-w/2,pointy-L/2). This will create lower left points. Similarly calculate upper right points. Merge, dissolve to create multipoint, minimum bounding geometry envelope. – FelixIP Jan 12 '19 at 19:00

1 Answers1

2
import arcpy

fc = r'X:\centroids.shp'
heightfield = 'height'
widthfield = 'width'
outfile = r'X:\rectangles2.shp'

points = [i for i in arcpy.da.SearchCursor(fc,['SHAPE@XY',heightfield,widthfield])]
features = []

for point in points:
    lowerleft = arcpy.Point(point[0][0]-point[2]/2, point[0][1]-point[1]/2)
    lowerright = arcpy.Point(point[0][0]+point[2]/2, point[0][1]-point[1]/2)
    topleft = arcpy.Point(point[0][0]-point[2]/2, point[0][1]+point[1]/2)
    topright = arcpy.Point(point[0][0]+point[2]/2, point[0][1]+point[1]/2)
    features.append(arcpy.Polygon(arcpy.Array([lowerleft,lowerright,topright,topleft])))

arcpy.CopyFeatures_management(features,outfile)

enter image description here

BERA
  • 72,339
  • 13
  • 72
  • 161