# Creating polyline buffer with ArcPy?

I'm trying to write a python script with ArcPy that draws arcs and I've achieved something with creating a buffer and then clipping it with a bounding box so I only keep the length I need (I thought it was easier that way than calculating from my center point and radius, vertex by vertex from my start angle to my end angle). The problem is that the buffer too creates polygon buffers and since I only have ArcVIew (soon ArcEditor) and I can't use the polygon to line tool (licenced to ArcInfo).

Is there a way to convert a polygon to a polyline somehow with ArcPy or create directly a polyline buffer?

-
What is your end goal? Are you really just trying to create polylines that are offset (displaced) from the original polylines by a specific distance? – RyanDalton Apr 30 '12 at 19:51

You could go about this in a few ways. One way to do it without Zero_Qualms' suggestion of ET_GeoWizards and with only an ArcView licence is to create your buffer polygons just as you have done. Then iterate over the buffer polygons, pulling out their geometry and build a new feature class using the geometry but cast it as a polyline instead. See these sections of the documentation to help you (if needed) with reading and writing geometries in ArcPy (scroll down for examples).

The alternative is to write a script to create the line without creating a buffer to copy first. You will need to read the geometries of your lines and progress from point to point, calculating the bearing at each step and then calculating the offset location of your buffer-line. This should be straightforward with a bit of basic vector maths and trig. You can calculate bother the left and right side of the line at the same time. You just need to ensure that the right-side (assuming a clockwise winding) points are added to your polyline so they are in sequential order following the entire set of left-hand points and in the reverse direction. You could do this by having two lists of points and then reverse the order of your right-hand point list before appending it to the lefthand points list to make your line.

-
That's where I'm heading now. I used Shapely and OGR because that's what was in the example I had. The only thing is that shapely's buffer don't have enough points to create its circle, but I'll find something. Thanks! – fgcartographix May 3 '12 at 17:37
The Shapely buffer takes the form: object.buffer(distance, resolution=16). The second parameter (resolution) is usually omitted and defaults to 16 segments. If you want something that approximates more closely to a circle, increase the resolution setting (say to 32). – MappaGnosis May 3 '12 at 19:54
Didn't know that one. Thanks!! – fgcartographix May 4 '12 at 15:07
Any idea how to reverse the order of my point? I tried to use a simple python feature (reversed()) to reverse my iterator, but it still start from my first point and then backward. In can't access directly (or haven't found a way) a point in my linestring (as in line(i) or line[i]), so I can't read for the end to rewrite my line... I – fgcartographix May 8 '12 at 14:05
Unfortunately, ArcPy's cursors go in one direction only. You have a couple of options. One would be to read all your points into a list first and then use the reversed() function on that list. The other would be to use OGR, which would give you access to all the geometry in one go (but you may prefer to stick just with arcpy). – MappaGnosis May 9 '12 at 9:41

One of the free functions in the ET_GeoWizards addon for ArcGIS supposedly has the ability to convert Polygons to Polylines:

http://www.ian-ko.com/ET_GeoWizards/gw_NoRestrictions.htm