Get a geotiff from an ESRI REST server
Kaufmann, 2022-2024.
[1]:
import matplotlib.pyplot as plt
from geometron.utils.geoservices import esri_rest_server_metadata, esri_rest_server_geotiff, geotiff_from_esri_rest_server, esri_rest_server_request
import rasterio
from rasterio.plot import show
Set ESRI REST API server and service
[2]:
host = 'geoservices.wallonie.be'
folder = 'IMAGERIE' # 'RELIEF'
service = 'ORTHO_2022_ETE' # 'WALLONIE_MNT_2013_2014'
service_type = 'MapServer'
Define request parameters (extent, crs…)
[3]:
xmin, xmax, ymin, ymax = 120400.0, 120600.0, 126700.0, 127000.0 # map extent in epsg:31370
size_width, size_height = 768, 768
epsg = 31370
[4]:
# Parameters
params = {'bbox': f'{xmin},{ymin},{xmax},{ymax}',
'size': f'{size_width}, {size_height}',
'bboxSR':{"wkid" : epsg},
'imageSR':{"wkid" : epsg},
'format': 'png32',
'transparent': 'false',
'layerDefs': '',
'layers' : '',
'dpi' : '100',
'time':'',
'f':'image'
}
[5]:
image_file='tmp_files/test.tif'
[6]:
esri_rest_server_geotiff(image_file=image_file, host=host,folder=folder, service=service, service_type=service_type, parameter=params, verbose=True)
url:
https://geoservices.wallonie.be/arcgis/rest/services/IMAGERIE/ORTHO_2022_ETE/MapServer/export?bbox=120400.0%2C126700.0%2C120600.0%2C127000.0&size=768%2C+768&bboxSR=%7B%27wkid%27%3A+31370%7D&imageSR=%7B%27wkid%27%3A+31370%7D&format=png32&transparent=false&layerDefs=&layers=&dpi=100&time=&f=pjson
url:
https://geoservices.wallonie.be/arcgis/rest/services/IMAGERIE/ORTHO_2022_ETE/MapServer/export?bbox=120400.0%2C126700.0%2C120600.0%2C127000.0&size=768%2C+768&bboxSR=%7B%27wkid%27%3A+31370%7D&imageSR=%7B%27wkid%27%3A+31370%7D&format=png32&transparent=false&layerDefs=&layers=&dpi=100&time=&f=image
/home/su530201/.local/share/virtualenvs/geometron-VhFx4lLH/lib/python3.10/site-packages/rasterio/__init__.py:304: NotGeoreferencedWarning: Dataset has no geotransform, gcps, or rpcs. The identity matrix will be returned.
dataset = DatasetReader(path, driver=driver, sharing=sharing, **kwargs)
[7]:
src = rasterio.open(image_file)
[8]:
fig, ax = plt.subplots(figsize=(10,10))
show(src, transform=src.transform, ax=ax)
[8]:
<Axes: >