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.

closed as off-topic by xunilk, PolyGeo Jan 12 at 20:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – xunilk, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • You have an answer for QGIS here: gis.stackexchange.com/questions/217218/…. You can try to adapt this code for arcpy. – xunilk Jan 12 at 15:41
  • Im gonna check this. Thank you! But if anyone has something more arcpy related please post your ideas. – JuniorPythonNewbie Jan 12 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 at 19:00
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.