-
Notifications
You must be signed in to change notification settings - Fork 42
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
Bing Maps view: no coordinates returned for GeoTIFF #59
Comments
Hi @ario101 The implementation for Bing maps coordinates is a bit dumb at the moment - there is no reading of the geotiff header info to find where an image is. Instead, we use a separate metadata file for each sample to specify the centroid. It would be nice to have an automatic mode for geotiffs but obviously sometimes people use non georeferenced image formats, so the metadata file is a way to normalise behaviour across different image file types. An example of the metadata file can be found here. You can also check out the demo config to see how to point to a metadata file for each sample. Let me know if problems persist. Ali |
Thanks for a prompt answer! import os
import json
import re
import rasterio
def centroid_to_metadata(path):
'''
Writes .json file with filename and centroid for each .gtiff file and converts coordinates from EPSG:3857 to EPSG:4326.
Metadata is written to every .json file which is named after image id (this is because IRIS has complicated metadata handling)
path: direrctory for all files to create metadata from
'''
try:
json_data = {}
for file_ in os.listdir(path):
# checking if file is TIFF file
if re.findall(".tif", file_):
filepath_ = os.path.join(path, file_)
with rasterio.open(filepath_) as src:
left, bottom, right, top = src.bounds
centroid_x = (left + right) / 2
centroid_y = (top + bottom) / 2
# converting CRS to epsg:4326
proj_from = Proj('epsg:3857')
proj_to = Proj('epsg:4326')
transformer = Transformer.from_proj(proj_from, proj_to, always_xy=True)
lon, lat = transformer.transform(centroid_x, centroid_y)
# creating dict of images and coordinates
json_data.update({"location":[lat, lon]})
# creating subfolder for metadata files if it doesn't exist
if not os.path.exists(os.path.join(path, "metadata")):
os.makedirs(os.path.join(path, "metadata"))
# writing to .json
with open(os.path.join(path, "metadata", f"{file_[:-4]}.json"), 'w') as json_file:
json.dump(json_data, json_file, indent=4)
else:
continue
print("Metadata write successful!")
print(f"Metadata files are in ", os.path.join(path, "metadata"))
except Exception as e:
print('Error:', e) |
Thanks, this is super helpful. I need to think more how this can be implemented automatically, because sometimes users will be using data that isn't in geotif files, in which case this would break. I think it might be best to have an option in the BingMaps view config to select where the location comes from (either the geotifs, or the metadata files). Then something like this function can run for each image when loaded, to find the location. Will look into it soon! |
When using Bing Maps view the coordinates with GeoTIFF images, the coordinates from GeoTIFF file are not returned correctly - for every image it is (0, 0).
The text was updated successfully, but these errors were encountered: