Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Creating buffered rectangle for single point

$
0
0
I am creating a 200m buffered rectangle around a selected feature layer of points. Sometimes tere are many points, in which case I appear to create a correct rectangle.

However, if there is only one point, the buffer does not appear to create a rectangle. I think this may be because the polygon array I create has the same co-ordinate for lowerleft/right etc so the initial shape the buffer is based on may not be a valid rectangle.

My code is below:

Code:

        AddressPointsCopy = AddressPointsLayerName + str(rowcount)
        arcpy.CopyFeatures_management(AddressPointsLayerName, AddressPointsCopy)
        # A good idea to limit the number of RoadLinks to a sensible area around the address points
        # Will stick to 200 metres just to ensure we don't miss anything
        desc = arcpy.Describe(AddressPointsCopy).extent
        array = arcpy.Array()
        # Create the bounding box
        array.add(desc.lowerLeft)
        array.add(desc.lowerRight)
        array.add(desc.upperRight)
        array.add(desc.upperLeft)
        # ensure the polygon is closed
        array.add(desc.lowerLeft)
        # Create the polygon object
        message = "ARRAY " + str(array[0]) + " " + str(array[1]) + " " +str(array[2]) + " " +str(array[3]) + " " + str(array[4])
        print message
        polygon = arcpy.Polygon(array)
        array.removeAll()
        # buffer
        extentPoly = layerMemory + os.sep + "RoadlinkBuffer"  + str(rowcount)
        arcpy.Buffer_analysis(polygon, extentPoly, "200 meters", "OUTSIDE_ONLY", "FLAT", "NONE")

How can I tailor this to deal with a single point and create a rectangle buffered by 200m in this case?

Viewing all articles
Browse latest Browse all 2485

Trending Articles