# CrossCompute
longitude_latitude_wkt = 'LINESTRING (-73.935242 40.730610, -71.057083 42.361145)'
# pip install shapely
# pip install utm
# pip install geotable
from shapely import wkt
line_wkt = longitude_latitude_wkt
line_geometry = wkt.loads(line_wkt)
line_geometry
point_geometry = line_geometry.centroid
point_longitude = point_geometry.x
point_latitude = point_geometry.y
import utm
utm_zone_number, utm_zone_letter = utm.from_latlon(point_latitude, point_longitude)[-2:]
utm_zone_number
utm_zone_letter
from geotable.projections import get_utm_proj4
utm_proj4 = get_utm_proj4(utm_zone_number, utm_zone_letter)
utm_proj4
from geotable.projections import get_transform_shapely_geometry, LONGITUDE_LATITUDE_PROJ4
f = get_transform_shapely_geometry(LONGITUDE_LATITUDE_PROJ4, utm_proj4)
f(line_geometry).wkt
utm_line_geometry = f(line_geometry)
line_length_in_meters = utm_line_geometry.length
line_length_in_meters
from geopy.distance import geodesic
geodesic((40.730610, -73.935242), (42.361145, -71.057083)).meters
# UTM is accurate only for local distances
print(f'utm_zone_number = {utm_zone_number}')
print(f'utm_zone_letter = {utm_zone_letter}')
print(f'utm_proj4 = {utm_proj4}')
print(f'line_utm_wkt = {utm_line_geometry.wkt}')
print(f'line_length_in_meters = {line_length_in_meters}')