I have a large sample of gps coordinates, and I would like to create a similar analytical visualization to that in Overlaying lines and aggregating their values for overlapping segments using R?

Does anyone know of some sample Python code to get me started?

The algorithm will iterate to compare shapes to determine the overlapping segments, split the original geometry into segments, and importantly count the number of times (amount of overlap) on each segment.

My first steps were (using NumPy):

  • Creating a list of all of the XY coordinates from all of the PolyLines creating an (n,2) array.(x,y)
  • Reshaping the array so each row contains an individual line segment:

    segs1 = np.reshape(array[:-1,:],(-1,4) ) segs2 = np.reshape(np.roll(array,1, axis=0)[:-1,:],(-1,4) ) segments = np.vstack((segs1,segs2))

  • Then I used np.unique() to find the unique line segments and a count of their occurrences:

    segs, counts = np.unique(segments,return_counts=True, axis=0)

Now I have a collection of all the unique line segments, I come to the issue that plotting lines defaults to drawing connections between neighboring points, coming from different polylines. This is the expected behavior, as I haven't defined a way to separate them.

I felt like I was off to a good start, but expect there may be a tool that already exists to accomplish the same goal, and make like a little easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.