def get_elevation(latlng_coord): """Gets the elevation at a given lat-lng coord """ coordstring = get_coordstring(latlng_coord) coord_zipfile = coordstring + ".zip" coord_folder_name = coordstring + "/" url = USGS_FTP_PATH + coord_zipfile download_directory = config.CWD + USGS_FOLDER zip_file_path = download_directory + coord_zipfile unzip_directory = download_directory + coord_folder_name img_file_name = get_img_file_name(coordstring) img_file_path = unzip_directory + img_file_name geotiff_file_path = unzip_directory + coordstring + ".tif" if file_exists(geotiff_file_path): pass else: if file_exists(img_file_path): pass else: if file_exists(zip_file_path): pass else: util.smart_print("Not yet downloaded.") util.smart_print("Now downloading " + coord_zipfile + "...") util.smart_print("From " + str(url)) urllib.urlretrieve(url, zip_file_path) unzip_zipfile(zip_file_path, unzip_directory, img_file_name) remove_file(zip_file_path) img_to_geotiff(img_file_name, unzip_directory, coordstring) remove_file(img_file_path) lonlat_coord = util.swap_pair(latlng_coord) pixel_val = geotiff_pixel_val(geotiff_file_path, lonlat_coord) return pixel_val
def geospatial_to_latlng(geospatial, proj): """Converts geospatial coordinates to latitude longitude coordinates""" lonlat = proj(geospatial[0], geospatial[1], inverse=True) return util.swap_pair(lonlat)