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

utils0.latlon2utm(): ensure a single output UTM zone #1177

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/mintpy/objects/coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def lalo2yx(self, lat_in, lon_in):
and 'UTM_ZONE' in self.src_metadata
and np.max(np.abs(lat_in)) <= 90
and np.max(np.abs(lon_in)) <= 360):
lat_in, lon_in = ut0.latlon2utm(np.array(lat_in), np.array(lon_in))
lat_in, lon_in = ut0.latlon2utm(self.src_metadata, np.array(lat_in), np.array(lon_in))

# convert coordinates
y_out = []
Expand Down Expand Up @@ -292,7 +292,7 @@ def geo2radar(self, lat, lon, print_msg=True, debug_mode=False):
if ('UTM_ZONE' in self.src_metadata
and np.max(np.abs(lat)) <= 90
and np.max(np.abs(lon)) <= 360):
lat, lon = ut0.latlon2utm(np.array(lat), np.array(lon))
lat, lon = ut0.latlon2utm(self.src_metadata, np.array(lat), np.array(lon))

self.open()
if self.geocoded:
Expand Down
2 changes: 1 addition & 1 deletion src/mintpy/utils/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ def plot_gps(ax, SNWE, inps, metadata=dict(), print_msg=True):

# post-query: convert lat/lon to UTM for plotting
if 'UTM_ZONE' in metadata.keys():
site_lats, site_lons = ut0.latlon2utm(site_lats, site_lons)
site_lats, site_lons = ut0.latlon2utm(metadata, site_lats, site_lons)

# mask out stations not coincident with InSAR data
if inps.mask_gps and inps.msk is not None:
Expand Down
12 changes: 9 additions & 3 deletions src/mintpy/utils/utils0.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,22 @@ def utm2latlon(meta, easting, northing):
return lat, lon


def latlon2utm(lat, lon):
def latlon2utm(meta, lat, lon):
"""Convert latitude/longitude in degrees to UTM easting/northing in meters.

Parameters: lat - scalar/list/tuple/1-2D np.ndarray, WGS 84 coordinates in y direction
Parameters: meta - dict, mintpy attributes that includes:
UTM_ZONE
lat - scalar/list/tuple/1-2D np.ndarray, WGS 84 coordinates in y direction
lon - scalar/list/tuple/1-2D np.ndarray, WGS 84 coordinates in x direction
Returns: easting - scalar/list/tuple/1-2D np.ndarray, UTM coordinates in x direction
northing - scalar/list/tuple/1-2D np.ndarray, UTM coordinates in y direction
"""
import utm
easting, northing = utm.from_latlon(np.array(lat), np.array(lon))[:2]

# invoke zone_num to ensure all coordinates are converted into the same single UTM zone,
# even if they cross a UTM boundary.
zone_num = int(meta['UTM_ZONE'][:-1])
easting, northing = utm.from_latlon(np.array(lat), np.array(lon), force_zone_number=zone_num)[:2]

# output format
if any(isinstance(x, (list, tuple)) for x in [lat, lon]):
Expand Down