1

I am working on vessel tracking. I have setup route path, and vessel current position. Now my aim is to add that current position point to the path and update it. and calculate the length of linestring and time duration of whole line(start to end) and remain line(from current position to end). Now my main question is how can add the point to the LineString in order to update the route? Below, I have provided the my input linestring and current point data. also output of line and point. Data:

p = {'route': [{'path': [[51.51309, 0.4836599999999862],
     [51.512222970577746, 0.4838196951935174],
     [51.50817683327391, 0.4845649394298732],
     .
     .
     [26.160997649670072, 56.29158290493038],
     [25.234004681463745, 55.29187512793891],
     [25.035363331133816, 55.07765203286928],
     [25.00255, 55.10811000000001]],
    'type': 'SEA'}]}

l_path=p['route'][0]['path']
path = LineString(l_path)

I want to connect this point to the linestring:

position = Point(13.752724664396988, 56.42578125)

Line and point output:

enter image description here

Thanks in advance.

R. Baraiya
  • 1,490
  • 1
  • 4
  • 17

1 Answers1

0

I have update the path my connecting with the point but still not getting the desire output. Because, using below code vessel taking long path which is causing me a issue in with wrong length and time.

from shapely.geometry import LineString
from shapely.ops import transform
from functools import partial
import pyproj
from shapely.ops import split
from itertools import chain

total_path=p['route'][0]['path'][1:-1] ##### Total path
total_line = LineString(total_path)

project = partial(
    pyproj.transform,
    pyproj.Proj('EPSG:4326'),
    pyproj.Proj('EPSG:32633'))
total_ls = transform(project, total_line)
total_ls

enter image description here

total_distance = total_ls.length/1852   ######Tortal distance in NM
print(total_distance, "Distance")

enter image description here

current_pin = (13.752724664396988, 56.42578125)
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 = transform(project, new_line)
new_distance = new_ls.length/1852
print(new_distance,"New distance")
new_ls

enter image description here

## remain distance from current position
remain = LineString(new_line.coords[new_line.coords[:].index(current_pin):]) 
remain = transform(project, remain)
r_distance = remain.length/1852
print(r_distance,"remain distance")
 remain

enter image description here

R. Baraiya
  • 1,490
  • 1
  • 4
  • 17