चूंकि हारून के कोड के अंत में लिंक की गई स्क्रिप्ट का उपयोग केवल स्क्वायर बफ़र्स के लिए किया जा सकता है और नए arcpy.da मॉड्यूल का उपयोग नहीं करता है, इसलिए मैंने एक स्क्रिप्ट लिखी है जिसका उपयोग आयत बफ़र्स बनाने के लिए किया जा सकता है। 10k यादृच्छिक बिंदु डेटासेट पर, यह 10 सेकंड में पूरा हुआ:
import os, arcpy
point_FC = arcpy.GetParameterAsText(0)
w = float(arcpy.GetParameterAsText(1))
h = float(arcpy.GetParameterAsText(2))
output_FC = arcpy.GetParameterAsText(3)
def rect(coord, w, h):
#Given XY coordinates and rectangle dimensions,
#return a polygon object of a rectangle centered about the point
x,y = coord
w *= 0.5
h *= 0.5
xmin,xmax = x-w, x+w
ymin,ymax = y-h, y+h
poly = ((xmin, ymax), (xmax, ymax), (xmax, ymin), (xmin, ymin))
return arcpy.Polygon(arcpy.Array(arcpy.Point(*p) for p in poly))
#Create output feature class.
spatref = arcpy.Describe(point_FC).spatialReference
folder, base = os.path.split(output_FC)
arcpy.CreateFeatureclass_management(folder, base, "POLYGON", spatial_reference=spatref)
#Get field object for every field in input except OID and Shape.
fields = [f for f in arcpy.ListFields(point_FC) if f.type not in ("OID", "Geometry")]
for field in fields:
arcpy.AddField_management(output_FC, field.name, field.type, field.precision,
field.scale, field.length, field.aliasName,
field.isNullable, field.required, field.domain)
#Get field names to be inputted to cursors.
#Need SHAPE@XY token to read point coords and SHAPE@ token to write polygon coords.
fnames = [f.name for f in fields]
fields_in = fnames[::]
fields_out = fnames[::]
fields_in.append("SHAPE@XY")
fields_out.append("SHAPE@")
#Create buffers and write attributes to output FC, if any.
count = int(arcpy.GetCount_management(point_FC)[0])
arcpy.SetProgressor("step", "Buffering...", 0, count, 1)
with arcpy.da.SearchCursor(point_FC, fields_in) as Scursor, arcpy.da.InsertCursor(output_FC, fields_out) as Icursor:
for i,row_in in enumerate(Scursor):
#"Convert" point to rectangle
arcpy.SetProgressorPosition(i)
feature = list(row_in)
feature[-1] = rect(feature[-1], w, h)
Icursor.insertRow(feature)