Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force UTM Zone to gracefully handle UTM boundaries #20

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions geodesy/src/geodesy/utm.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,36 @@ def valid(self):
and self.northing == self.northing
and self.band != ' ')

def fromLatLong(latitude, longitude, altitude=float('nan')):
def fromLatLong(latitude, longitude, altitude=float('nan'),zone=None,band=None):
"""Generate :class:`UTMPoint` from latitude, longitude and (optional) altitude.

Latitude and longitude are expressed in degrees, relative to the
WGS84 ellipsoid.

Optionally a UTM zone and band may be specified (e.g. zone = '19T' or
zone = 19, band = 'T'), which returns the UTM coordinates relative to
the specified zone/band combination regardless of location. This
facilitates robot movement across UTM zones. Users should generally
not apply this method beyond 2 UTM zones lest the projection error
exceed typical GPS uncertainty.

:param latitude: [degrees], negative is South.
:param longitude: [degrees], negative is West.
:param altitude: [meters], negative is below the ellipsoid.

:param zone: either string of combined zone and band ('19T') or interger value (1-60) of zone alone.
:param band: capital letter, (C-X), may be omitted if zone is in combined form.

:returns: :class:`UTMPoint` object.
"""
z, b = gridZone(latitude, longitude)

if zone and not band:
z = zone[:2]
b = zone[-1]
elif zone and band:
z = str(zone)
b = band
else:
z, b = gridZone(latitude, longitude)
utm_proj = pyproj.Proj(proj='utm', zone=z, datum='WGS84')
e, n = utm_proj(longitude, latitude)
return UTMPoint(easting=e, northing=n, altitude=altitude, zone=z, band=b)
Expand Down