I need to calculate the minimum distance (in meters) of two polygons which are defined in lat/long coordinates (EPSG:4326) using Python.
shapely geometries have
distance() method which almost does what I need but as I understand first I need to reproject my polygons to some other coordinate reference system (maybe using pyproj module) to get the distance in meters.
As I understand the coordinate reference system I should use depends on which region on earth my polygons are located, but how should I find the right projection I need given the polygon coordinates.
My two polygons might be located anywhere on the earth but they will be within 10km distance from each other and 0.5m accuracy is good enough.
I have found this code on Internet, which I suppose does what I need (I'm not sure), but I understand 'EPSG:26944' is meant to be used only in California, so wouldn't work let's say in Australia, right?
from functools import partial from shapely import ops import pyproj def reproject(geom, from_proj=None, to_proj=None): tfm = partial(pyproj.transform, pyproj.Proj(init=from_proj), pyproj.Proj(init=to_proj)) return ops.transform(tfm, geom) polygon1_m = reproject(shapely_polygon1, 'EPSG:4326', 'EPSG:26944') polygon2_m = reproject(shapely_polygon2, 'EPSG:4326', 'EPSG:26944') distance_in_meters = polygon1_m.distance(polygon2_m)