Search code examples
pythondictionarylayerfoliumwms

Adding a WMS layer using folium


I am using folium package in Python to construct the map in this link: GeoAdmin Map Link

For basic map creation I am using:

map_geo = folium.Map(location=[47.46901, 9.36688], zoom_start=13)

And then try to add the layer as wms layer:

folium.raster_layers.WmsTileLayer(url = 'https://wms.geo.admin.ch/?',
                                  layers = 'ch.bfe.fernwaerme-nachfrage_wohn_dienstleistungsgebaeude',
                                  transparent = False, 
                                  control = True, 
                                  name = 'energy',
                                  overlay=True,
                                  show = True,
                                  ).add_to(map_geo)
folium.LayerControl().add_to(map_geo)

In the end the final map looks like: map created If I choose the base layer alone from the layer control then I can see it. But if I activate the energy usage layer, background layer is going all white. What am I doing wrong?

Thanks


Solution

  • I did not know that such layers could be laid on top of each other. I went through trial and error with your code, looking at the examples in the reference. To solve the problem, I formatted the image of the layer and it improved.

    import folium
    
    map_geo = folium.Map(location=[47.46901, 9.36688], zoom_start=13)
    
    folium.raster_layers.WmsTileLayer(url = 'https://wms.geo.admin.ch/?',
                                      layers = 'ch.bfe.fernwaerme-nachfrage_wohn_dienstleistungsgebaeude',
                                      transparent = True, 
                                      control = True,
                                      fmt="image/png",
                                      name = 'energy',
                                      overlay = True,
                                      show = True,
                                      ).add_to(map_geo)
    folium.LayerControl().add_to(map_geo)
    
    map_geo
    

    enter image description here