def project(geom, from_proj=None, to_proj=None):
"""
Project a ``shapely`` geometry, and returns a new geometry of the same type from the transformed coordinates.
Default input projection is `WGS84 <https://en.wikipedia.org/wiki/World_Geodetic_System>`_, default output projection is `Mollweide <http://spatialreference.org/ref/esri/54009/>`_.
Inputs:
*geom*: A ``shapely`` geometry.
*from_proj*: A ``PROJ4`` string. Optional.
*to_proj*: A ``PROJ4`` string. Optional.
Returns:
A ``shapely`` geometry.
"""
from_proj = wgs84(from_proj)
if to_proj is None:
to_proj = MOLLWEIDE
else:
to_proj = wgs84(to_proj)
to_proj, from_proj = pyproj.Proj(to_proj), pyproj.Proj(from_proj)
if ((to_proj == from_proj) or
(to_proj.is_latlong() and from_proj.is_latlong())):
return geom
projection_func = partial(pyproj.transform, from_proj, to_proj)
return transform(projection_func, geom)
评论列表
文章目录