I am trying to calculate shortest distance from any ship position to coastline in nautical miles using this zip file.
I have tried using GeoPandas, shapely, geopy but I have not found a way that properly works. I tried using below code to spot the nearest point and then calculate the distance, but it's always reading the wrong linestring. I appreciate any help.
import pandas as pd
import geopandas as gpd
from geopandas import GeoSeries
from shapely.geometry import Point
p1=GeoSeries(Point(8.41655010639208, -83.11475151369626))
coastline=gpd.read_file('/Users/Danilo/Documents/Python/panama_coastline/panama_coastline.shp')
coastline=coastline[coastline['NATURAL']=='shoreline']
coastline=coastline['geometry']
coastline.reset_index(drop=True,inplace=True)
#coastline.geom_type
#coastline
#p1=Point(8.41655010639208, -83.11475151369626)
#coastline.to_crs(epsg=5368,inplace=True)
#coastline.crs
#coastline.geometry.distance(p1).min()
line=coastline[p1.distance(coastline)==p1.distance(coastline).min()]
line.reset_index
#type(ls1)
#line.geom_type
from shapely.ops import nearest_points
p=nearest_points(p1,line[0])
from geopy.distance import geodesic, Point
p0=Point(p[0].y,p[0].x)
p1=Point(p1.y,p1.x)
geodesic(p0,p1).nautical
coastline.plot()
p0
#geodesic(Point(8.41655010639208, -83.11475151369626),Point(8.41388, -83.11114)).nautical
coastline[0].distance(p1)