Easy OpenStreetMap tile displaying for Python

后端 未结 7 728
野的像风
野的像风 2020-12-08 12:21

I want to include the open street map (OSM) in my python code.

I have read through lots of webpages regarding to OSM. But unfortunately I\'m a bit lost, regarding wh

7条回答
  •  长情又很酷
    2020-12-08 12:38

    The following is also based on BerndGit's wonderful answer. I had to do some modifications to get it working with Python 3.6.7. Posting them here in case it helps others.

    Set-up required Pillow, and replacing urllib with requests, and replacing io/StringIO with io/ByesIO

    import requests
    from io import BytesIO
    

    And then just needed to modify how the image is downloaded in the getImageCluster() function:

    imgstr = requests.get(imgurl)
    tile = Image.open(BytesIO(imgstr.content))
    

    Big thanks to BerndGit for going to the trouble of posting the original.

    Haven't managed to get Etna's modified Basemap version working yet. Had to add in an export path for the PROJ_LIB error for Basemap:

    export PROJ_LIB=/path/to/your/instalation/of/anaconda/share/proj/
    

    (solution at Basemap import error in PyCharm —— KeyError: 'PROJ_LIB')

    And getting a set attribute error when trying to plot. It occurs using the Basemap tutorial too (https://basemaptutorial.readthedocs.io/en/latest/plotting_data.html#plot) but with the difference that the scatter of data does still plot as a layer on top of the map despite the error. With the OSM tiles, cannot get the data layer to show on top of the map. Having to export each layer individually and then combine using image editing software.

提交回复
热议问题