Hi there, I just ran this script and it worked great for what I required; However, it wasn't perfect. I did get square buffers around the coordinates I supplied but the buffer distance wasn't accurate. I entered "375" for bufDist to create a 750m x 750m rectangle but the output created a 739m x 739m rectangle instead. An equal difference of 10.5m in each direction.Do you have any suggestions as to what happened??Thanks!p.s. the script is fantastic, I just don't understand Python all that well to troubleshoot!
This works for me... just a simple python script...import arcpy, os from arcpy import env env.overwriteOutput = True # Get arguments: # Input point feature class # Output polygon feature class # Buffer distance # Boolean type: Maintain fields and field values of the input in the output print "initializing" inPoints = "C://YourDataDirectory//yourPoint.shp" outPath = "C://YourDataDirectory" outName = "SqBuffer" bufDist = 15000 #in meters outPolys = outPath+"//"+outName+".shp" print "creating new blank feature" arcpy.CreateFeatureclass_management(outPath, outName,"POLYGON","","","", "", "","","","") print "created" # Open searchcursor inRows = arcpy.SearchCursor(inPoints) # Open insertcursor outRows = arcpy.InsertCursor(outPolys) # Create point and array objects pntObj = arcpy.Point() arrayObj = arcpy.Array() print "writing geomety" for inRow in inRows: # One output feature for each input point feature inShape = inRow.shape pnt = inShape.getPart(0) # Need 5 vertices for square buffer: upper right, upper left, lower left, # lower right, upper right. Add and subtract distance from coordinates of # input point as appropriate. for vertex in [0,1,2,3,4]: pntObj.ID = vertex if vertex in [0,3,4]: pntObj.X = pnt.X + bufDist else: pntObj.X = pnt.X - bufDist if vertex in [0,1,5]: pntObj.Y = pnt.Y + bufDist else: pntObj.Y = pnt.Y - bufDist arrayObj.add(pntObj) # Create new row for output feature feat = outRows.newRow() # Assign array of points to output feature feat.shape = arrayObj # Insert the feature outRows.insertRow(feat) # Clear array of points arrayObj.removeAll() # Delete inputcursor del outRows print "done Is this what you are looking for?
import arcpy, os from arcpy import env env.overwriteOutput = True # Get arguments: # Input point feature class # Output polygon feature class # Buffer distance # Boolean type: Maintain fields and field values of the input in the output print "initializing" inPoints = "C://YourDataDirectory//yourPoint.shp" outPath = "C://YourDataDirectory" outName = "SqBuffer" bufDist = 15000 #in meters outPolys = outPath+"//"+outName+".shp" print "creating new blank feature" arcpy.CreateFeatureclass_management(outPath, outName,"POLYGON","","","", "", "","","","") print "created" # Open searchcursor inRows = arcpy.SearchCursor(inPoints) # Open insertcursor outRows = arcpy.InsertCursor(outPolys) # Create point and array objects pntObj = arcpy.Point() arrayObj = arcpy.Array() print "writing geomety" for inRow in inRows: # One output feature for each input point feature inShape = inRow.shape pnt = inShape.getPart(0) # Need 5 vertices for square buffer: upper right, upper left, lower left, # lower right, upper right. Add and subtract distance from coordinates of # input point as appropriate. for vertex in [0,1,2,3,4]: pntObj.ID = vertex if vertex in [0,3,4]: pntObj.X = pnt.X + bufDist else: pntObj.X = pnt.X - bufDist if vertex in [0,1,5]: pntObj.Y = pnt.Y + bufDist else: pntObj.Y = pnt.Y - bufDist arrayObj.add(pntObj) # Create new row for output feature feat = outRows.newRow() # Assign array of points to output feature feat.shape = arrayObj # Insert the feature outRows.insertRow(feat) # Clear array of points arrayObj.removeAll() # Delete inputcursor del outRows print "done
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.