Guest User

Untitled

a guest
Mar 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. import arcpy, math
  2. arcpy.env.overwriteOutput = True
  3.  
  4. #Change to match your data:
  5. arcpy.env.workspace = r'C:ArendenDefault.gdb'
  6. boundries = r'Boundries'
  7. points = r'bufferpoints'
  8. out_feature_class = r'GrowPoints'
  9.  
  10. #Change to match your desired size of polygon, ok difference and step in buffer radius increase
  11. size = 7500
  12. ok_diff = 500
  13. increment = 5
  14.  
  15.  
  16. arcpy.CreateFeatureclass_management(out_path=arcpy.env.workspace, out_name=out_feature_class,
  17. geometry_type='POLYGON',
  18. spatial_reference=arcpy.Describe(points).spatialReference)
  19.  
  20. arcpy.MakeFeatureLayer_management(in_features=boundries, out_layer='blyr')
  21.  
  22. with arcpy.da.SearchCursor(points,['OID@','SHAPE@']) as cursor:
  23. for row in cursor:
  24. bufferstart = math.sqrt((size/math.pi))
  25. sql = """{0} = {1}""".format(
  26. arcpy.AddFieldDelimiters(points,arcpy.Describe(points).OIDFieldName),row[0])
  27. arcpy.MakeFeatureLayer_management(in_features=points, out_layer='pointlyr',where_clause=sql)
  28. arcpy.SelectLayerByLocation_management(in_layer='blyr', overlap_type='INTERSECT',
  29. select_features='pointlyr')
  30. if [i[0] for i in arcpy.da.SearchCursor('blyr','SHAPE@AREA')][0] > size:
  31. area = 1
  32. while abs(size-area)>ok_diff:
  33. print area
  34. arcpy.Buffer_analysis(in_features='pointlyr', out_feature_class=r'in_memorypoint',
  35. buffer_distance_or_field="{0} Meters".format(bufferstart))
  36. arcpy.Clip_analysis(in_features=r'in_memorypoint', clip_features='blyr',out_feature_class=r'in_memoryclipbuffer')
  37. area = [i[0] for i in arcpy.da.SearchCursor(r'in_memoryclipbuffer','SHAPE@AREA')][0]
  38. bufferstart+=increment
  39.  
  40. arcpy.Append_management(inputs=r'in_memoryclipbuffer', target=out_feature_class, schema_type='NO_TEST')
  41. else:
  42. print 'Impossible to fit buffer inside boundry for point number: ',row[0]
Add Comment
Please, Sign In to add comment