Skip to content

Commit

Permalink
utils0: add epsg_code2utm_zone() (insarlab#1159)
Browse files Browse the repository at this point in the history
+ utils.utils0.py: add `epsg_code2utm_zone()` to convert the EPSG code to the UTM zone string.

---------

Co-authored-by: Scott Staniewicz <scott.stanie@gmail.com>
  • Loading branch information
2 people authored and ehavazli committed Mar 19, 2024
1 parent 9644873 commit fe6f84b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/api/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ The following attributes vary for each interferogram:
+ SUBSET_XMIN/XMAX/YMIN/YMAX = start/end column/row number of subset in the original coverage
+ MODIFICATION_TIME = dataset modification time, exists in ifgramStack.h5 file for 3D dataset, used for "--update" option of unwrap error corrections.
+ NCORRLOOKS = number of independent looks, as explained in [SNAPHU](https://web.stanford.edu/group/radar/softwareandlinks/sw/snaphu/snaphu.conf.full)
+ UTM_ZONE = UTM zone, comprises a zone number and a hemisphere, e.g. 11N, 60S, for geocoded file with UTM projection only.
+ EPSG = EPSG code for coordinate systems, for geocoded files only.
+ UTM_ZONE = [UTM zone](https://docs.up42.com/data/reference/utm#utm-wgs84), comprises a zone number and a hemisphere, e.g. 11N, 60S, for geocoded file with UTM projection only.
+ EPSG = EPSG code for coordinate systems, for geocoded files only. Check [here] for its relationship with UTM zone.
+ CENTER_INCIDENCE_ANGLE = incidence angle in degrees at the scene center, read from the 2D incidence angle matrix, for isce2 files only.

### Reference ###
Expand Down
24 changes: 24 additions & 0 deletions src/mintpy/utils/utils0.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def touch(fname_list, times=None):
def utm_zone2epsg_code(utm_zone):
"""Convert UTM Zone string to EPSG code.
Reference: https://docs.up42.com/data/reference/utm#utm-wgs84
Parameters: utm_zone - str, atr['UTM_ZONE'], comprises a zone number
and a hemisphere, e.g. 11N, 36S, etc.
Returns: epsg_code - str, EPSG code
Expand All @@ -285,6 +287,28 @@ def utm_zone2epsg_code(utm_zone):
return epsg_code


def epsg_code2utm_zone(epsg_code):
"""Convert EPSG code to UTM Zone string.
Reference: https://docs.up42.com/data/reference/utm#utm-wgs84
Parameters: epsg_code - str / int, EPSG code
Returns: utm_zone - str, atr['UTM_ZONE'], comprises a zone number
and a hemisphere, e.g. 11N, 36S, etc. None for
a EPSG code not in a UTM coordnate system
Examples: utm_zone = epsg_code2utm_zone('32736')
"""
from pyproj import CRS

# link: https://pyproj4.github.io/pyproj/stable/examples.html#initializing-crs
# alternatively, use CRS.from_user_input(epsg_code) or CRS.from_string(f'EPSG:{epsg_code}')
crs = CRS.from_epsg(epsg_code)
utm_zone = crs.utm_zone
if not utm_zone:
print(f'WARNING: input EPSG code ({epsg_code}) is NOT a UTM zone, return None and continue.')
return utm_zone


def to_latlon(infile, x, y):
"""Convert x, y in the projection coordinates of the file to lat/lon in degree.
Expand Down

0 comments on commit fe6f84b

Please sign in to comment.