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)
def test_read_ds_value_from_wgs84(): expected = 151.0 gdal.AllRegister() data_source = gdal.Open(DS_FILENAME, GA_ReadOnly) actual = geods.read_ds_value_from_wgs84(data_source, 43.602091, 1.441183) assert abs(expected - actual) <= EPSILON
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)
def profile(data_source, wgs84_lat1, wgs84_long1, wgs84_lat2, wgs84_long2, height1=0, height2=0, above_ground1=True, above_ground2=True, definition=512): """ Generates a profile with the given parameters and elevation data source. :param data_source: the data_source to read elevation data from :param wgs84_lat1: the latitude of the starting point :param wgs84_long1: the longitude of the starting point :param wgs84_lat2: the latitude of the ending point :param wgs84_long2: the longitude of the ending point :param height1: the sight height for the starting point, defaults to 0 :param height2: the sight height for the ending point, defaults to 0 :param above_ground1: is sight height fir the starting point above the ground (True) or above the sea (False), defaults to True :param above_ground2: is sight height fir the ending point above the ground (True) or above the sea (False), defaults to True :param definition: the number of points to sample including the starting point and the ending point :return: the profile data composed of numpy arrays for latitudes, longitudes, sights, elevations, distances and overheads (correction of the rounded earth profile) """ profile_data = {} profile_data['latitudes'] = latitudes = np.linspace(wgs84_lat1, wgs84_lat2, definition) profile_data['longitudes'] = longitudes = np.linspace(wgs84_long1, wgs84_long2, definition) profile_data['elevations'] = geods.read_ds_value_from_wgs84(data_source, latitudes, longitudes) start_sight = float(height1) if above_ground1: start_sight += float(profile_data['elevations'][0]) end_sight = float(height2) if above_ground2: end_sight += float(profile_data['elevations'][-1]) profile_data['sights'] = np.linspace(start_sight, end_sight, definition) profile_data['distances'] = geometry.distance_between_wgs84_coordinates(wgs84_lat1, wgs84_long1, latitudes, longitudes) profile_data['overheads'] = compute_curved_earth_correction(wgs84_lat1, wgs84_long1, wgs84_lat2, wgs84_long2, latitudes, longitudes) return profile_data