PMTiles file cannot be loaded when URL has URI parameters.
james-willis opened this issue · 3 comments
james-willis commented
Environment Information
- leafmap version: 0.31.8
- Python version: 3.10
- Operating System: MacOS
Description
I am trying to read a PMTiles file from s3 using signed URLs
I expect this to allow the pmtiles to be read through leafmap and rendered, but instead I got a validation that the file path must ending .pmtiles.
What I Did
import leafmap.foliumap as leafmap
import boto3
s3_client = boto3.client('s3')
signed_url = s3_client.generate_presigned_url(
'get_object',
Params={'Bucket': myBucket, 'Key': "somePrefix/filename.pmtiles"},
ExpiresIn=60 * 60 * 4 # 4 hours
)
m = leafmap.Map()
m.add_pmtiles(
signed_url, name="PMTiles", style=leafmap.pmtiles_style(signed_url), overlay=True, show=True, zoom_to_layer=True
)
m
gives:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_128/88315447.py in ?()
1 import leafmap.foliumap as leafmap
2
3 m = leafmap.Map()
4 m.add_pmtiles(
----> 5 signed_url, name="PMTiles", style=leafmap.pmtiles_style(signed_url), overlay=True, show=True, zoom_to_layer=True
6 )
7 m
/opt/conda/lib/python3.10/site-packages/leafmap/common.py in ?(url, layers, cmap, n_class, opacity, circle_radius, line_width, attribution, **kwargs)
11640 palette = ["#" + c for c in get_palette(cmap, n_class)]
11641
11642 n_class = len(palette)
11643
> 11644 metadata = pmtiles_metadata(url)
11645 layer_names = metadata["layer_names"]
11646
11647 style = {
/opt/conda/lib/python3.10/site-packages/leafmap/common.py in ?(input_file)
11549 )
11550 return
11551
11552 if not input_file.endswith(".pmtiles"):
> 11553 raise ValueError("Input file must be a .pmtiles file.")
11554
11555 header = pmtiles_header(input_file)
11556 metadata_offset = header["metadata_offset"]
ValueError: Input file must be a .pmtiles file.
james-willis commented
my work around until we merge and release this:
signed_url = get_signed_url(s3_uri) + "&extension=.pmtiles"
giswqs commented
Thanks for the fix. I will release a new version tonight