Python Script: Create a polygon (rectangle) using a single point feature

5286
1
11-28-2013 02:49 AM
PeterWilson
Occasional Contributor III
I've got 563 photos that have been taken as part of a survey. I've also got a GPS location for each Photograph that has been taken.
Jake Skinner from ESRI provided me with a starting point: http://forums.arcgis.com/threads/97398-Python-Insert-Photographs-into-ArcMap-Data-View-Programattica...

What I would like to do is rather specify the width and height, instead of using the current data frame extent. So I'm looking for a way to generate a polygon around each point feature that represents the location of the photographs, based on a specified height and width.

Regards
Tags (2)
1 Reply
XanderBakker
Esri Esteemed Contributor
Hi Peter,

I changed my code from this thread a bit and this should create the rectangles:


import arcpy

# input point file
fc = r'C:\Project\_Forums\pointInterpol\fgdb\test.gdb\points' # edit this
fields = ("SHAPE@XY")

# size of rectangle
h = 1000 # height, edit this
w = 1500 # width, edit this

# output feature class
fcout = r'C:\Project\_Forums\pointInterpol\fgdb\test.gdb\diamonds01' # edit this

features = []
with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:
        arrPnts = arcpy.Array()
        X = row[0][0]
        Y = row[0][1]

        # point 1
        pnt = arcpy.Point(X-w/2,Y-h/2)
        arrPnts.add(pnt)

        # point 2
        pnt = arcpy.Point(X-w/2,Y+h/2)
        arrPnts.add(pnt)

        # point 3
        pnt = arcpy.Point(X+w/2,Y+h/2)
        arrPnts.add(pnt)

        # point 4
        pnt = arcpy.Point(X+w/2,Y-h/2)
        arrPnts.add(pnt)

        # point 5 (close diamond)
        pnt = arcpy.Point(X-w/2,Y-h/2)
        arrPnts.add(pnt)

        pol = arcpy.Polygon(arrPnts)
        features.append(pol)


# write to output
arcpy.CopyFeatures_management(features, fcout)


Kind regards,

Xander