-
Notifications
You must be signed in to change notification settings - Fork 3
/
elevation.py
executable file
·51 lines (35 loc) · 1.53 KB
/
elevation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
"""
Simple program that prints the elevation in meters of a point referenced by its WGS 84 latitude and longitude.
"""
import argparse
import ConfigParser
import logging
import os
from osgeo import gdal
from gdalconst import GA_ReadOnly
import geods
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
LOGGER = logging.getLogger(os.path.basename(__file__))
def main():
"""Main entrypoint"""
config = ConfigParser.ConfigParser()
config.read('config.ini')
config_dem_location = config.get('dem', 'location')
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('lat', type=float, help="latitude, ex: 43.561725")
parser.add_argument('long', type=float, help="longitude, ex: 1.444796")
parser.add_argument('-d', '--dem', help="DEM file location, ex: '/path/to/file/EUD_CP-DEMS_3500025000-AA.tif'",
default=config_dem_location)
args = parser.parse_args()
LOGGER.debug("requesting elevation for wgs84 lat: %f, long: %f using the following DEM: %s", args.lat, args.long,
args.dem)
# register all of the drivers
gdal.AllRegister()
# open the image
data_source = gdal.Open(args.dem, GA_ReadOnly)
# get the value
value = geods.read_ds_value_from_wgs84(data_source, args.lat, args.long)
print "elevation for coordinates: %f, %f is %f" % (args.lat, args.long, value)
if __name__ == '__main__':
main()