Hi,
I,m trying to to write a backend that can generate tiles folder structure and images based on the example that We can find here
Maybe the example is little bit outdated, but essentially it just works as expected with minimal changes like new loader for my datasource, parquet files hosted in S3 buckets, that are downloaded and converted to dataframe.
The problem is the next, when I run my script and everything just seems to be normal, the folders and image tiles start to popping inside the output dir and then Iβm able to run a simple python http server on this folder and connect leaflet to this XYZ source layer. Then when I go from 0 zoom level to greater zoom levels everything works fine, but Iβm not be able to update my map layer beyond 5 zoom level. Leaflet is simply querying for unexistent zoom level folders, well, to be more precise, this level folders exists but seems to have different numeric names rather than expected by leaflet.
Versions:
Python 3.7.9
datashader==0.13.0
holoviews==1.14.5
Script sample:
from datashader.tiles import render_tiles
import pandas as pd
import datashader as ds
import datashader.transfer_functions as tf
from datashader.colors import viridis
import holoviews as hv
from kpi.tta.maps.config.country_bounding_boxes import country_bounding_boxes
# extent_of_area_i_want_to_tile = (-500000, -500000, 500000, 500000) # xmin, ymin, xmax, ymax
bbox = country_bounding_boxes['MX'][1]
def load_data_func(x_range, y_range):
df = pd.read_parquet(
path='s3://xxx/coverage/334/202007/MX.ATT/LTE/coverage_334_202007_MX.ATT_LTE/')
df['longitude'] = pd.to_numeric(df.longitude, errors='coerce')
df['latitude'] = pd.to_numeric(df.latitude, errors='coerce')
df.dropna(subset=['longitude', 'latitude'], inplace=True)
df["longitude"], df["latitude"] = hv.Tiles.lon_lat_to_easting_northing(
df["longitude"], df["latitude"]
)
df = df[['longitude', 'latitude', 'value']].rename(columns={'longitude': 'x', 'latitude': 'y'})
# df = df.loc[df['x'].between(*x_range) & df['y'].between(*y_range)]
return df
def rasterize_func(df, x_range, y_range, height, width):
cvs = ds.Canvas(x_range=x_range, y_range=y_range,
plot_height=height, plot_width=width)
agg = cvs.points(df, 'x', 'y')
return agg
def shader_func(agg, span=None):
# img = tf.shade(agg, cmap=reversed(viridis), span=span, how='log')
img = tf.shade(agg, cmap=viridis, span=span, how='log')
return img
def post_render_func(img, **kwargs):
return img
if __name__ == "__main__":
render_tiles(
full_extent=bbox,
levels=range(0, 16),
output_path='example_tileset_output_directory',
load_data_func=load_data_func,
rasterize_func=rasterize_func,
shader_func=shader_func,
post_render_func=post_render_func
)
Sample of the script output, seems normal, no error:
calculating statistics for level 0
rendering 1 supertiles for zoom level 0 with span=(0, 1767208)
calculating statistics for level 1
rendering 1 supertiles for zoom level 1 with span=(0, 861200)
calculating statistics for level 2
rendering 1 supertiles for zoom level 2 with span=(0, 736715)
calculating statistics for level 3
rendering 1 supertiles for zoom level 3 with span=(0, 473304)
calculating statistics for level 4
rendering 1 supertiles for zoom level 4 with span=(0, 223669)
calculating statistics for level 5
rendering 4 supertiles for zoom level 5 with span=(0, 96105)
calculating statistics for level 6
rendering 4 supertiles for zoom level 6 with span=(0, 3950)
calculating statistics for level 7
rendering 4 supertiles for zoom level 7 with span=(0, 6)
calculating statistics for level 8
rendering 4 supertiles for zoom level 8 with span=(0, 0)
calculating statistics for level 9
rendering 4 supertiles for zoom level 9 with span=(0, 0)
calculating statistics for level 10
rendering 4 supertiles for zoom level 10 with span=(0, 0)
Sample of tiles output dir:
example_tileset_output_directory/
βββ 0
β βββ 0
βββ 1
β βββ 0
β βββ 1
βββ 10
β βββ 496
β βββ 497
β βββ 498
β βββ 499
β βββ 500
β βββ 501
β βββ 502
β βββ 503
β βββ 504
β βββ 505
β βββ 506
β βββ 507
β βββ 508
β βββ 509
β βββ 510
β βββ 511
β βββ 512
β βββ 513
β βββ 514
β βββ 515
β βββ 516
β βββ 517
β βββ 518
β βββ 519
β βββ 520
β βββ 521
β βββ 522
β βββ 523
β βββ 524
β βββ 525
β βββ 526
β βββ 527
βββ 11
β βββ 1000
β βββ 1001
β βββ 1002
β βββ 1003
β βββ 1004
β βββ 1005
β βββ 1006
β βββ 1007
β βββ 1008
β βββ 1009
β βββ 1010
β βββ 1011
β βββ 1012
β βββ 1013
β βββ 1014
β βββ 1015
β βββ 1016
β βββ 1017
β βββ 1018
β βββ 1019
β βββ 1020
β βββ 1021
β βββ 1022
β βββ 1023
β βββ 1024
β βββ 1025
β βββ 1026
β βββ 1027
β βββ 1028
β βββ 1029
β βββ 1030
β βββ 1031
β βββ 1032
β βββ 1033
β βββ 1034
β βββ 1035
β βββ 1036
β βββ 1037
β βββ 1038
β βββ 1039
β βββ 1040
β βββ 1041
β βββ 1042
β βββ 1043
β βββ 1044
β βββ 1045
β βββ 1046
β βββ 1047
β βββ 1048
β βββ 1049
β βββ 1050
β βββ 1051
β βββ 1052
β βββ 1053
β βββ 1054
β βββ 1055
β βββ 992
β βββ 993
β βββ 994
β βββ 995
β βββ 996
β βββ 997
β βββ 998
β βββ 999
βββ 2
β βββ 0
β βββ 1
β βββ 2
β βββ 3
βββ 3
β βββ 0
β βββ 1
β βββ 2
β βββ 3
β βββ 4
β βββ 5
β βββ 6
β βββ 7
βββ 4
β βββ 0
β βββ 1
β βββ 10
β βββ 11
β βββ 12
β βββ 13
β βββ 14
β βββ 15
β βββ 2
β βββ 3
β βββ 4
β βββ 5
β βββ 6
β βββ 7
β βββ 8
β βββ 9
βββ 5
β βββ 0
β βββ 1
β βββ 10
β βββ 11
β βββ 12
β βββ 13
β βββ 14
β βββ 15
β βββ 16
β βββ 17
β βββ 18
β βββ 19
β βββ 2
β βββ 20
β βββ 21
β βββ 22
β βββ 23
β βββ 24
β βββ 25
β βββ 26
β βββ 27
β βββ 28
β βββ 29
β βββ 3
β βββ 30
β βββ 31
β βββ 4
β βββ 5
β βββ 6
β βββ 7
β βββ 8
β βββ 9
βββ 6
β βββ 16
β βββ 17
β βββ 18
β βββ 19
β βββ 20
β βββ 21
β βββ 22
β βββ 23
β βββ 24
β βββ 25
β βββ 26
β βββ 27
β βββ 28
β βββ 29
β βββ 30
β βββ 31
β βββ 32
β βββ 33
β βββ 34
β βββ 35
β βββ 36
β βββ 37
β βββ 38
β βββ 39
β βββ 40
β βββ 41
β βββ 42
β βββ 43
β βββ 44
β βββ 45
β βββ 46
β βββ 47
βββ 7
β βββ 48
β βββ 49
β βββ 50
β βββ 51
β βββ 52
β βββ 53
β βββ 54
β βββ 55
β βββ 56
β βββ 57
β βββ 58
β βββ 59
β βββ 60
β βββ 61
β βββ 62
β βββ 63
β βββ 64
β βββ 65
β βββ 66
β βββ 67
β βββ 68
β βββ 69
β βββ 70
β βββ 71
β βββ 72
β βββ 73
β βββ 74
β βββ 75
β βββ 76
β βββ 77
β βββ 78
β βββ 79
βββ 8
β βββ 112
β βββ 113
β βββ 114
β βββ 115
β βββ 116
β βββ 117
β βββ 118
β βββ 119
β βββ 120
β βββ 121
β βββ 122
β βββ 123
β βββ 124
β βββ 125
β βββ 126
β βββ 127
β βββ 128
β βββ 129
β βββ 130
β βββ 131
β βββ 132
β βββ 133
β βββ 134
β βββ 135
β βββ 136
β βββ 137
β βββ 138
β βββ 139
β βββ 140
β βββ 141
β βββ 142
β βββ 143
βββ 9
βββ 240
βββ 241
βββ 242
βββ 243
βββ 244
βββ 245
βββ 246
βββ 247
βββ 248
βββ 249
βββ 250
βββ 251
βββ 252
βββ 253
βββ 254
βββ 255
βββ 256
βββ 257
βββ 258
βββ 259
βββ 260
βββ 261
βββ 262
βββ 263
βββ 264
βββ 265
βββ 266
βββ 267
βββ 268
βββ 269
βββ 270
βββ 271
Sample of leaflet requesting unexisting images in resulting tiles output:
127.0.0.1 - - [10/Sep/2021 10:23:47] "GET /6/15/26.png HTTP/1.1" 404 -
127.0.0.1 - - [10/Sep/2021 10:23:47] "GET /6/11/28.png HTTP/1.1" 404 -
127.0.0.1 - - [10/Sep/2021 10:23:47] "GET /6/11/26.png HTTP/1.1" 404 -
If you look carefully to the server log and compare that 404 to the previous output, You will realize that there is no /6/11/ structure dir and the same structure mismatch is the similar to every zoom level beyond 5.
Iβve spent some time testing with other XYZ layer client, like OpenLayers and just obtained the same result.
Iβm not sure if Iβm not using the tiling tool in a proper way or Iβm missing some previous adjustements to data or method params to get the desired output or at least the one required by leaflet or similar XYZ web clients.
I hope that someone can help me a little bit to find the problem. Thank You.
Regards,
Javier.