Add flip direction method to Polyline class

958
5
12-03-2022 08:57 AM
Status: Open
DuncanHornby
MVP Notable Contributor

It would be very useful to add to the Polyline geometry class in arcpy a method that flips the direction of vertices. This could be done in situ or the method generates a new Polyline geometry (my preferred option). ArcObjects allows you to call such a method. Currently one has to program this logic which is tiresome when it seems such an obvious thing that one might want to do to a Polyline, reverse its direction.

5 Comments
RPGIS
by

I believe it already exists. I don't know if this is what you are looking for but here is something akin to it.

Flip Line via Python 

DuncanHornby

@RPGIS , I am aware of this geo-processing tool, that requires at least a standard license. I'm suggesting that the list of methods on the geometry polyline class be expanded to include a "flip" method. This would allow for cleaner easier coding and would compliment the long list of existing methods and frankly I'm surprised it does not exist already as reversing the direction of a polyline is a very common task. This should not be a task only accessible to higher license level tools.

RPGIS
by

I've ran across something similar, but the way I've handled it was to simply convert the polyline into an array of points and then use the reverse method to basically flip the line and then recreate the original polyline.

That's the only method I can think of that will do that using the geometries. 

DuncanHornby

That was my solution, but it just seems like overkill to me, having to create new arrays, inserting points in reverse then rebuilding a new polyline. Exposing it as a method of a polyline would make for simpler and cleaner code. It would probably be more efficient too as I understand that arcpy is often a wrapper to some uber fast c++ code.

RPGIS
by

That would be simpler,  however you could also do a couple of things to make it easier:

  • Write a function that reverses the polyline direction
  • Create a script and write it a class to then be called by any script as a module that can be imported into any script
  • Make a copy of the python library and modify the geometries portion of the newly copied library to include the line reversal

Aside from those suggestions you would have to see if Esri would be willing to implement your idea.