Skip to content
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

PMTiles file cannot be loaded when URL has URI parameters. #720

Closed
james-willis opened this issue Apr 15, 2024 · 3 comments
Closed

PMTiles file cannot be loaded when URL has URI parameters. #720

james-willis opened this issue Apr 15, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@james-willis
Copy link
Contributor

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
Copy link
Contributor Author

my work around until we merge and release this:

signed_url = get_signed_url(s3_uri) + "&extension=.pmtiles"

@giswqs
Copy link
Member

giswqs commented Apr 15, 2024

Thanks for the fix. I will release a new version tonight

@giswqs
Copy link
Member

giswqs commented Apr 16, 2024

Fixed in v0.31.9

@giswqs giswqs closed this as completed Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants