-
Notifications
You must be signed in to change notification settings - Fork 9
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
UTM Conversion Utility #321
base: master
Are you sure you want to change the base?
Changes from 30 commits
4f1888a
699ee8e
3731a3b
99c826c
fc789d5
5a194ee
26a933f
5c06647
504892e
d3e5cd2
26e9ee4
4942cff
bcb902b
18fba3e
e3b18fe
bfc83fd
0d51891
d3a9664
b1c2ae8
984e95b
b91119c
ddaf759
9c77f13
c5b72c3
3e5cd61
ade0cf9
d83bc1c
98b5ff0
c258a02
3e62af5
8a07b8b
91452e9
d5d9453
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,18 @@ | |
# version: 2019.032 | ||
# author: Lan Dam | ||
# add inday_breakup() function | ||
# Dave Thomas added UTM / Lat Long routines,consolidated all pyproj here | ||
|
||
import fnmatch | ||
from datetime import datetime, timedelta | ||
from obspy.geodetics import locations2degrees | ||
from ph5.core.timedoy import epoch2passcal, passcal2epoch, TimeDOY, TimeError | ||
import time | ||
import re | ||
from pyproj import Transformer, Geod | ||
import math | ||
|
||
PROG_VERSION = "2019.81" | ||
PROG_VERSION = "2020.066" | ||
|
||
|
||
class PH5Response(object): | ||
|
@@ -68,6 +71,76 @@ def get_n_i(self, sensor_keys, datalogger_keys): | |
return ph5_resp.n_i | ||
|
||
|
||
def lat_long_to_utm(lat, lon): | ||
|
||
epsg_wgs84 = "EPSG:4326" | ||
|
||
if lat < 0.0: | ||
epsgroot = "327" | ||
hemisphere = 'S' | ||
elif lat >= 0.0: | ||
epsgroot = "326" | ||
hemisphere = 'N' | ||
|
||
utm_zone = int(math.floor((float(lon) + 180.)/6.0) % 60) + 1 | ||
epsg_utm = "EPSG:" + epsgroot + str(utm_zone) | ||
transformer = Transformer.from_crs(epsg_wgs84, | ||
epsg_utm, | ||
always_xy=True) | ||
easting, northing = transformer.transform(lon, lat) | ||
|
||
return (easting, northing, utm_zone, hemisphere) | ||
|
||
|
||
def geod_to_utm(lat, lon, elev): | ||
|
||
easting, northing, utm_zone, hemisphere = lat_long_to_utm(lat, lon) | ||
|
||
return (northing, easting, elev) | ||
|
||
|
||
def utm_to_lat_long(easting, northing, hemisphere, zone): | ||
|
||
epsg_wgs84 = "EPSG:4326" | ||
|
||
if hemisphere == "S": | ||
epsgroot = "327" | ||
elif hemisphere == "N": | ||
epsgroot = "326" | ||
|
||
epsg_utm = "EPSG:" + epsgroot + str(zone) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good, will implement this syntax. |
||
|
||
transformer = Transformer.from_crs(epsg_utm, epsg_wgs84, always_xy=True) | ||
lon, lat = transformer.transform(float(easting), float(northing)) | ||
return (lat, lon) | ||
|
||
|
||
def tspc_lat_long(easting, northing): | ||
# Texas State Plane Coords, in US FEET | ||
epsg_wgs84 = "EPSG:4326" | ||
epsg_sp4202 = "EPSG:2276" | ||
transformer = Transformer.from_crs(epsg_sp4202, epsg_wgs84, | ||
always_xy=True) | ||
lon, lat = transformer.transform(easting, northing) | ||
return (lon, lat) | ||
|
||
|
||
def latlon2geod(lat0, lon0, lat1, lon1, scalar=1.0): | ||
# Return azimuth, back azimuth, geodetic distance | ||
ELLIPSOID = 'WGS84' | ||
|
||
config = "+ellps={0}".format(ELLIPSOID) | ||
|
||
g = Geod(config) | ||
|
||
az, baz, dist = g.inv(lon0, lat0, lon1, lat1) | ||
|
||
if dist: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this conditional is to test ==0, then |
||
dist /= scalar | ||
|
||
return az, baz, dist | ||
|
||
|
||
""" | ||
=============== | ||
Utility methods | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a single blank line between functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK