TransWikia.com

Extrapolating arc via Python function

Geographic Information Systems Asked by Julianno Sambatti on June 13, 2021

I am looking for a Python code/function that can extend an arc linestring up to a pre-defined length while maintaining the same arc of the original line. The idea is to repeat the configuration of the last 2 segments of a linestring n times. My first inclination was to get the angle between these 2 last segments and apply affinity.rotate using always this angle while updating the origin in a while loop, something like:

from shapely.geometry import LineString, affinity
import numpy as np

n=100
last2SegmentsOfaLinestring=[(3,0),(3,5),(7,8)]
angle = alpha #angle between[(3,0),(3,5)] and [(3,5),(7,8)]
line = LineString([(3,5),(7,8)])
newX, newy = 7, 8
i=0
listOfTuples = []
while i < n:
    rotated = affinity.rotate(line, angle, origin=(newX, newy))
    # convert rotated to list of tuples to get updated (newX, newy) - this is the line centroid
    listOfTuples.append((newX, newy))
    i+=1

If I am thinking this correctly, I will need to convert the list of tuples to linestring, apply affinity.rotate, and convert back to a list of tuples to get the new origin. However, this seems a bit computational expensive and I wonder if there is an optimized function or a better way to do this.

Another way I tried is to apply a rotation to the vector and keep track of the origins of the next segment, adding the new, coordinates. This seems a bit more straightforward.

orignalVector = np.array([0,5])
rot = np.array([[np.cos(rotAngle), -np.sin(rotAngle)], [np.sin(rotAngle), np.cos(rotAngle)] ] )

xx = np.dot(rot, orignalVector)

but the question remains. Is there an optimized function that does all that?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP