Why I am getting Infinity infity in LineString?
I am try get linestring so I can measure the distance and time. Here in this linestring I am getting nan
distance and time.
Also, pleased to hear any of your suggestion on my code or logic. Thanks
data:
[[29.87819, 121.54944999999998], [24.23111845, 119.02311485000001], [5.402576549999999, 106.87891215000002], [1.367889, 104.27658300000002], [4.65750565, 98.40456015000001], [5.93498595, 82.50298040000001], [6.895460999999999, 75.83849285000002], [11.087761, 55.21659015], [11.986111, 50.79761100000002], [12.57124165, 44.563427950000005], [15.262399899999998, 41.828814550000004], [27.339266099999996, 34.20131845], [29.927166, 32.566855000000004], [32.36497615, 28.787162800000004], [36.25582884999999, 14.171143199999989], [37.089583, 11.039139000000006], [36.98901405, 4.773231850000002], [36.139162799999994, -4.182775300000003], [36.86918755, -8.487389949999994], [42.41353785, -9.331828900000005], [47.68888635, -5.458406800000006], [50.7011586, 1.0547821000000113], [52.84235105, -6.168939849999987], [53.33306, -6.248889999999989]]
Code:
import pyproj
from shapely.geometry import Point, LineString, Polygon
from shapely import geometry, ops
from shapely.ops import transform
from functools import partial
from shapely.ops import split
from itertools import chain
import itertools
import math
def get_route(positions):
tmp=0
for i in range(len(positions['data']['route'])):
if positions['data']['route'][i]['type'] == 'SEA':
if tmp==0:
t = positions['data']['route'][i]['path']
tmp=1
else:
t = t + positions['data']['route'][i]['path'][1:]
return t
def process(input_list, threshold=3):
combos = itertools.combinations(input_list, 2)
points_to_remove = [point2 for point1, point2 in combos if math.dist(point1, point2)=threshold]
points_to_keep = [point for point in input_list if point not in points_to_remove]
return points_to_keep
def get_ls(line):
project = partial(
pyproj.transform,
pyproj.Proj('EPSG:4326'),
pyproj.Proj('EPSG:32633'))
return transform(project, line)
def get_distance(p):
route = get_route(p)
total_path = process(route)
total_path.append(route[-1])
print(total_path)
total_line = LineString(total_path)
print(total_line)
total_ls = get_ls(total_line)
print(total_ls)
total_dis = total_ls.length/1852
total_hr = total_dis/13
current_pin = (1.754978395187126, 104.52625140784272)
position = Point(current_pin)
all_points_coords = chain(total_line.coords,position.coords)
all_points = map(Point, all_points_coords)
new_line = LineString(sorted(all_points, key=total_line.project))
new_ls = get_ls(new_line)
remain = LineString(new_line.coords[new_line.coords[:].index(current_pin):])
remain = get_ls(remain)
remain_dis = remain.length/1852
remain_hr= remain_dis/13
return total_dis,total_hr, remain_dis, remain_hr, total_ls
Topic python
Category Data Science