TileToolkitDocumentation
Tile toolkit
The tiletoolkit is used to plot raster from a raster server.
Imports
from hera import toolkitHome
import matplotlib.pyplot as plt
tk = toolkitHome.getToolkit(toolkitHome.GIS_TILES)
When using the toolkit we can use the default server or a specified server.
For checking the default server, use the following command:
tk.getConfig().get('defaultTileServer', 'Not set - call setDefaultTileServer() first')
The default server is Google maps.
When ploting a region, we specify the region points coordinates (down left and upper right) using minx,miny,maxx,maxy.
The default input coordinates are WSG84.
We can get the image using the getImageFromCorners() by passing the dictionary of the region using the following example:
# Set Google Maps as the default tile server
tk.setDefaultTileServer("http://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}")
minx = 34.775
maxx = 34.8
maxy = 32.1
miny = 32.05
region = dict(minx=minx,maxx=maxx,maxy=maxy,miny=miny,zoomlevel=17,tileServer=None)
img = tk.getImageFromCorners(**region)
For using a default tile server, we specify the tileServer=None, as seen above.
Note that IMS coordinates can also be used.
We specify the inputCRS argument as ITM:
from hera.measurements.GIS.utils import WSG84,ITM,convertCRS
minx = 178898.481
maxx = 181280.365
maxy = 667478.9
miny = 661943.482
region = dict(minx=minx,maxx=maxx,maxy=maxy,miny=miny,zoomlevel=17,tileServer=None,inputCRS=ITM)
img = tk.getImageFromCorners(**region)
We can plot the image using the presentation layer of the toolkit. We do this with the plot() function. One can also control the output coordinates (WSG84 or ITM) using the outputCRS argument (default is ITM):
fig,ax = plt.subplots(1,1,figsize=(28,28))
tk.presentation.plot(img,ax=ax)
Output with WSG64 coordinates:
fig,ax = plt.subplots(1,1,figsize=(28,28))
tk.presentation.plot(img,outputCRS=WSG84,ax=ax)
For setting a new default server we can use the setDefaultTileServer() function:
tk.setDefaultTileServer("https://tile.openstreetmap.org/{z}/{x}/{y}.png")
tk.getConfig()
We can also pass the server argument without changing the default server each time:
region = dict(minx=minx,maxx=maxx,maxy=maxy,miny=miny,zoomlevel=17,tileServer="http://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}",inputCRS=ITM)
img = tk.getImageFromCorners(**region)
In addition, if we have a tile server datasource in our projet repository, we can only define the name of the datasource:
tk.getDataSourceList()
region = dict(minx=minx,maxx=maxx,maxy=maxy,miny=miny,zoomlevel=17,tileServer="localTileServer",inputCRS=ITM)
img = tk.getImageFromCorners(**region)