Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    maimagdy
    @maimagdy
    Hello All ! , I was wondering is there any calendar search button to use filter on date ranges in folium map ..I want to enter from_Date: ,To_Date:
    harabat
    @harabat

    Hey guys,

    I wonder whether it's possible for DivIcon to have an automatic size.

    The context:
    On my map, hovering over a country will trigger a tooltip with the country's name.
    I also have several DivIcons, with the following code:

    folium.Marker(
        location=[lat, lon],
        icon=folium.DivIcon(
            html='''
                <div style="background-color: red; display: inline-block;">
                    <span>
                        {region_name}:
                        <br />{region_info}
                    </span>
                </div>
            ''',
            icon_size=(100, 100),
            icon_anchor=(0, 0),  
        )
    ).add_to(map)

    Because of the variation in region_names and region_infos, the width of the content varies between 50 and 90 pixels. I want my text to be displayed on two lines and the div to fit its content: the display: inline-block in the html allows me to do this, even if my icon_size is constant.

    But the problem is that the size of the DivIcon affects the tooltips: I can have a 70px-wide block with content, but an area of 30px next to it which doesn't display as a block but still counts as that block. So if I hover out of the visible block, instead of the tooltip appearing with some country's name, nothing happens. This is especially problematic when this area covers a bunch of small countries.

    What I'd like to happen is for the DivIcon to fit to the html within, or to have some kind of dynamic behaviour. I have tried doing icon_size=(10, 10) or removing icon_size, but the block just shrinks to fit to the longest word in the content. I have tried to go through the code for folium.DivIcon, branca.MacroElement, branca.Figure, etc., but wasn't able to get control of this behaviour.

    Any suggestions welcome.

    anuraghuram
    @anuraghuram
    Hi, I am designing a choropleth dashboard with multiple layers to toggle on/off. Two open questions: 1) first, is there any way to hide the legends? They are cluttering the map, so I wanted to hide them and display legend stats as a popup icon for each district I am mapping. 2) second, is there any functionality within the layer control selection that can reset/clear all selections on a map?
    Many thanks!
    anuraghuram
    @anuraghuram
    Relatedly (forgot to mention as third q above) - is there a parameter to adjust legend positions for choropleth maps? I see they run horizontally across the top of the map, but what if I want it vertically down one side of the window? Or even a minimizable option, similar to layer controls feature?
    M Powers
    @roadfoodr
    I know that a CRS representation changed between geopandas 0.6.1 and 0.7, and that folium 0.11.0 made changes (#1251) to support this. Question: is folium 0.11.0 backwards-compatible for geopandas 0.6.1, or must I upgrade to 0.7? (it seems that I can only do so with conda via the conda-forge channel, which will also change many of the dependent packages to conda-forge. I'm reluctant to do that if not necessary.)
    Here are some specific messages from the issue I am trying to work through:
    gpd.__version__
    '0.6.1'
    folium.__version__
    '0.11.0'
    
    gdf.crs  # gdf created via gpd.read_file()
    {'init': 'epsg:4326'}
    
    folium.GeoJson(gdf, name='gdf test').add_to(test_map)
    
    RuntimeError                              Traceback (most recent call last)
    <ipython-input-24-268ce60b1d50> in <module>
         35 
    ---> 36 folium.GeoJson(gdf, name='gdf test').add_to(test_map)
         37 
    . . . 
    S:\MDP\Programs\Anaconda3\lib\site-packages\pyproj\__init__.py in __new__(self, projparams, preserve_units, **kwargs)
        360         # on case-insensitive filesystems).
        361         projstring = projstring.replace('EPSG','epsg')
    --> 362         return _proj.Proj.__new__(self, projstring)
        363 
        364     def __call__(self, *args, **kw):
    
    _proj.pyx in _proj.Proj.__cinit__()
    
    RuntimeError: b'no arguments in initialization list'
    M Powers
    @roadfoodr
    (... or maybe my problem is something else altogether...)
    M Powers
    @roadfoodr
    Update: upgrading pyproj to 2.6.1 did the trick (although FutureWarnings are still produced. Presumably these would go away with geopandas 0.7.)
    Yves Moisan
    @ymoisan
    Hello all. I'm trrying to get a popup on a GeoJson layer. I can get a tooltip allright that fetches the fields in the GeoJSON attribute elements, but I can't get a popup with that information. Using 0.11. I thought popups behaved kind of like tooltips, e.g. folium.GeoJson(img_centroids, name="Centroïdes d'images", tooltip = tooltip, popup = popup) but whatever way I create my popup object does nothing. Pointers appreciated. TIA
    rupestre-campos
    @rupestre-campos
    @ymoisan you asked for some guideline. NOT sure if it works as it is between triple quotes lol But If I kept it is for some good reason ya ll tell
        fg = folium.FeatureGroup(name="tiles")
        with open(geojson_file) as geojson:
            tileDic = json.load(geojson)
        for feature in tileDic['features']:
            coords = [[y,x] for i in feature['geometry']['coordinates'] for x,y in i ]
            tileId = feature['properties']['tile_id']
            print(coords)
            print(tileId)
            fg.add_child(folium.Polygon(locations=coords,fill=True,popup=(folium.Popup(tileId))))
    lol
    Yves Moisan
    @ymoisan
    @rupestre-campos : thank you for your answer. I ended up monkey patching the code with a code bit I found in a PR. I have two remaining issues, if anyone has pointers :
    1) when I click on a Search result (plugins.Search) I defined a search_zoom and all works fine; however I can't get rid of the red circle that appears on the map; luckily, only the last search item red circle remains but still that is bothersome, especially since the circle doesn't scale so it's always apparent on the map, whatever zoom level
    2) I built a MarkerCluster Layer to manually loop through my folium.GeoJson object to build specific icons as a function of one attribute; I didn't find the way to do it in the GeoJson layer; so I tried pointing the Search box to that MarkerCluster Layer; the search box shows up, but searching never ends; so I pointed the Search control to the original GeoJson object and that works. Problem is, I have to add the GeoJson layer to my map. Even having the layer defined won't let me use the search on it. I have to add_to map. That destroys the nice clusters (in fact it goes on top of clusters) so I thought how can I set visibility to "off". control=False in the layer gets rid of it in the LayerControl object, but I can't tell the layer not to draw itself.
    Pointers appreciated. TIA
    Yves Moisan
    @ymoisan
    Erratum : show=False works on GeoJson layers
    I'd be happy if there was a "previous zoom" and/or "home" button. Thanx for this awesome library !|
    f-batiri
    @f-batiri
    Hi everyone,
    I'm Trying to use features.GeoJson Tooltip to add a tooltip which will show about 30 different information from geoJson file.
    Is there anyway to make the tooltip into 2 or more columns?
    Currently it only shows all of them in single column
    allenjack
    @allenjack
    Hi guys, I am trying to add some latex symbols to the choropleth legend. I tried the way of matplotlib (r'$ $') but it does not work. I am wondering is there any way to do this?
    Thank you.
    Tom Mueller
    @tgmueller

    I would like to publish information from an ArcGIS MapServer to Folium. I had some It looks like that can be done if a given api is configured to create tiles, but many are not. My first question is, does anyone know if this is possible?
    Some ArcGIS MapServer services are published in the WMS format but these are relative few. I tried to configure the api listed below as a Folium “wms_layer” but I am getting a driver error (also listed below). Anyone know if this is even possible?

    m.add_wms_layer(wms_name="Census Current (2020) WMS",wms_url="https://tigerweb.geo.census.gov/arcgis/services/TIGERweb/tigerWMS_Current/MapServer/WMSServer",
    wms_format="image/png",
    wms_layers='2010 Census Public Use Microdata Areas Labels')

    DriverError: D:\Dev\APS\aps\data\satskred\AvalDet_20190101_051134_ref_20181226_trno_095_VV\AvalDet_20190101_051134_ref_20181226_trno_095_VV.shp\AvalDet_20190101_051134_ref_20181226_trno_095_VV.shp: No such file or directory

    2 replies
    Michele Gentili
    @michelegentili93
    Hi everyone! Does someone know how to change Icon color in the geoJson dictionary when defining the points? Also how tom add a popup for those points. I saw how to do it with Marker, but then I cannot add a Search Bar! Thanks in advance. Here some code to play with:
    import folium
    from folium import features
    m = folium.Map([ 45.75345246,12.34117475], zoom_start=7)
    
    points_ = {'type': 'FeatureCollection',
     'features': [{'type': 'Feature',
       'properties': {'Codice': 500732, 'Categoria': 'D1', 'Cluster': 3},
       'geometry': {'type': 'Point', 'coordinates': [12.34117475, 45.75345246]},
       'id': '0'},
      {'type': 'Feature',
       'properties': {'Codice': 500732, 'Categoria': 'A2', 'Cluster': 3,'iconColor':'red'},
       'geometry': {'type': 'Point', 'coordinates': [14.34117475, 46.75345246]},
       'id': '1'}]}
    
    pp = folium.Popup("hello",fields=['Codice'])
    ic = features.Icon(iconColor="red")
    gj = folium.GeoJson(points_)#, tooltip=tooltip)
    
    gj.add_child(ic)
    gj.add_child(pp)
    m.add_child(gj).add_child(pp).add_child(ic)
    
    m
    Maarten van der Hoef
    @maartenvanderhoef
    image.png
    Hi Everyone, my map control has a huge line as i'm using mapbox with a manual http url.. Is there something possible here, I personally would love to hide the whole radio, happy with all suggestions! TIA.
    cyberdestroyer
    @cyberdestroyer:matrix.org
    [m]
    Hi everyone, Just wondering is there any way to plot markers on a specific date on a TimeSliderChoropleth map at all? Trying to plot a marker on a specific date and then removing it after that date has been passed on the slider. Any advice welcome!
    Cyril-Murat
    @Cyril-Murat
    Hi all. I'm new both to Github and to Gitter and I hope that my help request will not be a problem.
    Just in case someone reads...
    patty-olanterns
    @patty-olanterns
    Afternoon y'all. Wondering if any folks on here know how to add hyperlinks to a local directory file on the folium.html option. I'm trying to figure out how to add a hyperlink to a plotly chart and iterate by index position
    www2000
    @www2000
    Hi is there a way to add a symbol/marker to the center of the widget?
    I wand to mark the center for a moving map application.
    LummersGit
    @LummersGit

    Hi is there a way to add a symbol/marker to the center of the widget?
    I wand to mark the center for a moving map application.

    Could you use the centroid? I loaded data into a GeoDataFrame and then it's easy to determine the center geocode:

    for index, row in df.iterrows():
    centroid = row.geometry.centroid

    LummersGit
    @LummersGit

    Hi everyone. I've joined this Gitter in the hope of finding some active community that uses Folium. I just started using it this month.

    Can anyone share guidance on how to create 'labels' for folium.features.GeoJson? I have a lot of small polygons that I want to permanently label and the tooltip/popups are not working well for my use-case.

    I've been driving myself insane trying to come up with a solution. The main challenge I have is that all the labels resize with the map. I do not want this; I want a fixed size in meters.

    1) Tried using HTML in the DivIcon of a Marker. This works and I can create labels but they resize on zoom.

    2) I've tried permanent popups (permanent=True) on folium.GeoJsonTooltip. Same issue, the tooltip is resizing.

    3) I've even created custom text images using Python Image Library (PIL) to create PNG files that I add in using ImageOverlay. This is not resizing the images (yay) but several implementation issues: (i) the images are pixelated, the quality is poor, (ii) I am generating a lot of images (several hundred), and (iii) I want to size the labels depending on the polygon size; I want every label to stay inside its polygon but be as large as possible.

    The only element I can find in Folium that isn't resizing is folium.Circle.

    Thanks for anyone who can help me out. I can't help but feel I am missing obvious as labeling feels like it should be a basic requirement.

    Cheers!

    gmehta1996
    @gmehta1996

    Hi
    I am trying to plot some data using folium maps.
    Below is my python code and a screenshot(1st image).

        india_coord = [lat,long]
        my_map = folium.Map(location = india_coord,zoom_start=5,tiles=None,overlay=False)
        feature_group = folium.FeatureGroup(name='Central Region',overlay=True)
        feature_group2 = folium.FeatureGroup(name='South Region',overlay=True)
        feature_group3 = folium.FeatureGroup(name='East Region',overlay=True)
        feature_group4 = folium.FeatureGroup(name='West Region',overlay=True)
        feature_group5 = folium.FeatureGroup(name='North Region',overlay=True)
    
        feature_group.add_to(my_map)
        feature_group2.add_to(my_map)
        feature_group3.add_to(my_map)
        feature_group4.add_to(my_map)
        feature_group5.add_to(my_map)
    
        c1 = folium.Choropleth(
            geo_data = india,
            name = 'India',
            legend_name = 'India',
            fill_color = 'orange',
            fill_opacity = 0.3,
            highlight = True).add_to(my_map)
    
        folium.TileLayer('openstreetmap',overlay=False,name = f'SUMMARY {summ_date}').add_to(my_map)
    
    
        folium.LayerControl().add_to(my_map) 
    
        folium.Marker(location,tooltip = data1,popup = popup, icon=folium.Icon(color='cadetblue',icon = 'fa-industry', prefix='fa')).add_to(feature_group)
        ...
        ...
        ...
        folium.Marker(location,tooltip = data1,popup = popup, icon=folium.Icon(color='cadetblue',icon = 'fa-industry', prefix='fa')).add_to(feature_group5)
        my_map.add_child(feature_group)
        my_map.add_child(feature_group2)
        my_map.add_child(feature_group3)
        my_map.add_child(feature_group4)
        my_map.add_child(feature_group5)

    With this code I get the map above but I need to make another layer control option for another summary.
    For ex. if I add another

    folium.LayerControl().add_to(my_map)

    to my code I get the following(2nd Image):

    But this layer control has the same options as the above summary.
    Is there a way in folium to create different layer controls with different data on the same map so that If I am selecting the first summary in the first layer control I get the data like in image1 but if I choose the below layer control the data is displayed according to that particular layer control.
    How do I link different data with different layer control to view them on the same map.
    Thank you

    Image 1

    map1.png

    Image 2

    Inkedmap_screenshot_LI.jpg

    Wilson Cheung
    @wcheung-code
    Hello Folium community, I am a new member recently using folium to build out a map visualization as a side project. I am wondering if there is any status update on this issue: python-visualization/folium#1007. I find myself needing this capability to visualize raster data on the world map with temporal settings. Is there an alternate solution relying on the currently supported capabilities that folium has? Thanks!
    marcusdambrosio
    @marcusdambrosio
    Hello, I am exploring the capabilities of folium and want to see if anyone knows about this:
    When making marker clusters in folium I want to prevent the map from creating subclusters (shown below) when zooming in.
    mmap_bad.PNG
    I want only the main cluster (shown below) to display until it is zoomed in far enough to display each individual marker. Is there a way to do this?
    mmap_good.PNG
    Here is a simplified example of the code I am using
    import pandas as pd
    import folium
    from folium.plugins import MarkerCluster
    import shapely.wkt
    
    data = pd.read_csv('crops.csv', index_col='UniqueID')
    field = data.iloc[50, :]
    pgon = shapely.wkt.loads(field['geometry'])
    coords = [[j,i] for i,j,k in list(pgon.exterior.coords)]
    mmap = folium.Map(location = coords[0], zoom_start = 20)
    folium.PolyLine(locations=coords,
                    line_opacity=0.5).add_to(mmap)
    MarkerCluster(coords).add_to(mmap)
    display(mmap)
    marcusdambrosio
    @marcusdambrosio
    Thank you in advance!
    Vedant S Goyal
    @vsgo222

    Hi community. I have question related to selecting a feature object after using a search. I want to highlight the searched feature, so that it is selected. Here is my code.
    '''
    from folium.plugins import Search
    search_link = Search(layer=pct_feature_group, geom_type="LineString", placeholders = "Search for Link ID",
    collapsed="True", search_label = 'id', search_zoom = 17, position='topleft',
    ).add_to(pct_m)

    ratio

    step_pct.add_to(pct_m)
    pct_m
    '''
    How should I insert the highlight_function?

    Jeremy Mathew
    @Jerry-Mah
    Hello
    MyasinE
    @MyasinE
    Hi , I am using "folium.Map(location, zoom_start=14)" in python script. I need web address followed by the library because I have a firewall and I want to give permission for this lib . For first step , I give an access permission for "www.openstreetmap.org" but I coulnd'nt see any map on the script.
    Chris Hoina
    @chrishoina
    Hi all. I'm working on a project for work to demo our APIs with folium. And I can't seem to find the answer anywhere. For markers, I know that I have to indicate the lat/long coordinates. But when I try to add a vega-lite chart (doing this with Altair), I can't seem to figure out how to inform the marker as to which chart goes in which popup. I have one API coming for lat/long and the name of the location. And I have another API coming in that provides the data to populate the chart. They do share a unique ID, but I'm not sure how to go about this. Has anybody on here faced a similar scenario? Thanks!
    João Martins | Spatial Data Scientist | MSc Env. Eng.
    @joaoambiente

    Hi everyone, Just wondering is there any way to plot markers on a specific date on a TimeSliderChoropleth map at all? Trying to plot a marker on a specific date and then removing it after that date has been passed on the slider. Any advice welcome!

    I've got this very same question, but can simplify it by asking one that might be simpler to answer:

    • How may I retrieve the date output from TimeSliderChoropleth (current date in the slider)?
    João Martins | Spatial Data Scientist | MSc Env. Eng.
    @joaoambiente
    Ray
    @rayrrr
    Hello all, I'm a folium fan, and trying to grok how the templates fit together with the Python code. When I look at a template like https://github.com/python-visualization/folium/blob/main/folium/templates/tiles/openstreetmap/tiles.txt I see what looks like the contents of a Python f-string with four variables: s, x, y, and z. Where in the Python code are these template f-strings invoked, so I can see how these variables are populated?
    1 reply