Oriented buffers

7993
28
Jump to solution
02-07-2015 07:58 PM
davesacco
New Contributor II

Hi there,

I am using arcview 9.3.1 and I need to create oriented buffers from points in a shapefile. The euclidean direction method almost works, but because it calculates to the nearest point, buffers associated with points within the maximum will be truncated. I need each point to have a complete buffer in a specific direction, regardless of overlap with other points.

 

Any ideas would be greatly appreciated.

Thanks,

Dave

28 Replies
DanPatterson_Retired
MVP Emeritus

flds = ("SHAPE@", fld_start, fld_end, fld_dist)

for the last 3, you provided numbers rather than the field names that contained the values

Hayley_DelMaynard
New Contributor II

Thanks Dan.  I really appreciate the quick response.  I changed the lines to include the field names, but I still receive the below error message:

Runtime error
Traceback (most recent call last):
File "<string>", line 40, in <module>
File "<string>", line 11, in main
AttributeError: DescribeData: Method spatialReference does not exist

>>> import arcpy
...
... def main():
... fc_in = "C:\Users\ihwm\Documents\ArcGIS\Flood_NT_WA.gdb\points"
... fc_out = "C:\Users\ihwm\Documents\ArcGIS\Flood_NT_WA.gdb\points2"
...
... fld_start = "fld_start"
... fld_end = "fld_end"
... fld_dist = "fld_dist"
...
... sr = arcpy.Describe(fc_in).spatialReference
... arcpy.env.overwriteOutput = True
...
... flds = ("SHAPE@", fld_start, fld_end, fld_dist)
... lst_polygons = [1]
... with arcpy.da.SearchCursor(fc_in, flds) as curs:
... for row in curs:
... pnt_g = row[0]
... start = row[1]
... end = row[2]
... length = row[3]
... circle = pnt_g.buffer(length)
... pnt = pnt_g.firstPoint
... arrPnts = arcpy.Array()
... arrPnts.add(pnt)
... for bearing in range(int(start), int(end) + 1):
... arrPnts.add(createPointAtAngleWithBearing(pnt, bearing, length))
... polygon = arcpy.Polygon(arrPnts, sr)
... lst_polygons.append(polygon)
...
... arcpy.CopyFeatures_management(lst_polygons, fc_out)
...
... def createPointAtAngleWithBearing(pnt, angle, distance):
... import math
... angle = math.radians(angle)
... dist_x, dist_y = (distance * math.cos(angle), distance * math.sin(angle))
... return arcpy.Point(pnt.X + dist_x, pnt.Y + dist_y)
...
... if __name__ == '__main__':
... main()
...
Runtime error
Traceback (most recent call last):
File "<string>", line 40, in <module>
File "<string>", line 11, in main
AttributeError: DescribeData: Method spatialReference does not exist

0 Kudos
DarrenWiens2
MVP Honored Contributor

It may be having issues with escape characters in the lines where you specify the paths. Try adding an 'r' to denote raw string notation:

e.g.

fc_in = r"C:\Users\ihwm\Documents\ArcGIS\Flood_NT_WA.gdb\points"
Hayley_DelMaynard
New Contributor II

Thanks, Darren!  I'm still getting the same message.  Could it be because I'm using Arcgis 10.4.1 and that code was written for an earlier version?

>>> import arcpy
...
... def main():
... fc_in = r"C:\Users\ihwm\Documents\ArcGIS\Flood_NT_WA.gdb\points"
... fc_out = r"C:\Users\ihwm\Documents\ArcGIS\Flood_NT_WA.gdb\points2"
...
... fld_start = "fld_start"
... fld_end = "fld_end"
... fld_dist = "fld_dist"
...
... sr = arcpy.Describe(fc_in).spatialReference
... arcpy.env.overwriteOutput = True
...
... flds = ("SHAPE@", fld_start, fld_end, fld_dist)
... lst_polygons = [1]
... with arcpy.da.SearchCursor(fc_in, flds) as curs:
... for row in curs:
... pnt_g = row[0]
... start = row[1]
... end = row[2]
... length = row[3]
... circle = pnt_g.buffer(length)
... pnt = pnt_g.firstPoint
... arrPnts = arcpy.Array()
... arrPnts.add(pnt)
... for bearing in range(int(start), int(end) + 1):
... arrPnts.add(createPointAtAngleWithBearing(pnt, bearing, length))
... polygon = arcpy.Polygon(arrPnts, sr)
... lst_polygons.append(polygon)
...
... arcpy.CopyFeatures_management(lst_polygons, fc_out)
...
... def createPointAtAngleWithBearing(pnt, angle, distance):
... import math
... angle = math.radians(angle)
... dist_x, dist_y = (distance * math.cos(angle), distance * math.sin(angle))
... return arcpy.Point(pnt.X + dist_x, pnt.Y + dist_y)
...
... if __name__ == '__main__':
... main()
...
Runtime error
Traceback (most recent call last):
File "<string>", line 40, in <module>
File "<string>", line 11, in main
AttributeError: DescribeData: Method spatialReference does not exist

0 Kudos
DanPatterson_Retired
MVP Emeritus

I just tried your code reference to the spatial reference object and it worked... you have a file issue or a disconnect to arcpy for some reason.

inFC
'C:\\Data\\points\\fishnet_label.shp'
sr = arcpy.Describe(inFC).spatialReference
sr.name
'NAD_1983_CSRS_MTM_9'
DarrenWiens2
MVP Honored Contributor

Are you sure 'points' is a feature class and not a nonspatial table, that wouldn't have a spatial reference?

Hayley_DelMaynard
New Contributor II

Hi Darren,

Thanks again for all your help.  I started over, taking a subset of my data and creating a feature class layer of 500 points saved in the Default gdb (FloodTestFC).  

This is the code I use:

import arcpy
...
... def main():
... fc_in = r"C:\Users\ihwm\Documents\ArcGIS\Default.gdb\FloodTestFC"
... fc_out = r"C:\Users\ihwm\Documents\ArcGIS\Default.gdb\FloodTestFC2"
...
... fld_start = "fld_start"
... fld_end = "fld_end"
... fld_dist = "fld_dist"
...
... sr = arcpy.Describe(fc_in).spatialReference
... arcpy.env.overwriteOutput = True
...
... flds = ("SHAPE@", fld_start, fld_end, fld_dist)
... lst_polygons = [1]
... with arcpy.da.SearchCursor(fc_in, flds) as curs:
... for row in curs:
... pnt_g = row[0]
... start = row[1]
... end = row[2]
... length = row[3]
... circle = pnt_g.buffer(length)
... pnt = pnt_g.firstPoint
... arrPnts = arcpy.Array()
... arrPnts.add(pnt)
... for bearing in range(int(start), int(end) + 1):
... arrPnts.add(createPointAtAngleWithBearing(pnt, bearing, length))
... polygon = arcpy.Polygon(arrPnts, sr)
... lst_polygons.append(polygon)
...
... arcpy.CopyFeatures_management(lst_polygons, fc_out)
...
... def createPointAtAngleWithBearing(pnt, angle, distance):
... import math
... angle = math.radians(angle)
... dist_x, dist_y = (distance * math.cos(angle), distance * math.sin(angle))
... return arcpy.Point(pnt.X + dist_x, pnt.Y + dist_y)
...
... if __name__ == '__main__':
... main()
...

And this is the error message:

Runtime error
Traceback (most recent call last):
File "<string>", line 40, in <module>
File "<string>", line 31, in main
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 2335, in CopyFeatures
raise e
RuntimeError: Object: Error in executing tool

0 Kudos
DarrenWiens2
MVP Honored Contributor

Shouldn't it be 'lst_polygons = []'? The way it is now, I think it's getting hung up trying to make a polygon out of the number 1.

Hayley_DelMaynard
New Contributor II

IT WORKED!!!!  Thank you SOOOO much!!  I can't believe how quickly you responded and how helpful your advice was.  Honestly, thanks again so much!

0 Kudos