python-visualization / python-visualization/folium

Features not displayed with style_function

Offen
#1,782 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
7.4k
Forks
2.3k
Ø Merge
17 Std. 22 Min.
Gemergte PRs (30 T.)
11

Beschreibung

Describe the bug
When loading a set of GeoJSON LineString features, they are not displayed on the Folium map in my Jupyter Notebook (GColab, as well) when using style_function. If style_function=style_functions is removed from the following code, the features are displayed correctly, even though without styling.

To Reproduce

import folium
import json

# Load the GeoJSON file
with open('demo.json') as f:
    data = json.load(f)

# Create a Folium map centered on a location of your choice
m = folium.Map(location=[37.982759260869564, 23.901986296376812], zoom_start=18)

# Define a style function that changes the color of LineString features
def style_functions(feature):
    color = 'red'  # Change the color to your desired color or use a custom logic
    return {
        'color': 'blue',
        'weight': 3,
        'opacity': 0.7,
        'dashArray': [5, 10]
    }

# Add the GeoJSON data to the map with the style function applied
folium.GeoJson(data, style_function=style_functions).add_to(m)

# Display the map
m

Demo GeoJSON has been attached. Please remove the .txt extension for it to load.
demo.json.txt

Expected behavior

style_function should not hide the features, but display them with the styling specified.

Environment (please complete the following information):

  • Browser [e.g. firefox]
  • Jupyter Lab & Google Colab
  • Python 3.10.12
  • folium 0.14.0
  • branca 0.6.0

Additional context
In a similar test, PointString features were correctly displayed, with or without the style_function argument.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die GeoJSON-Reproduktion des Issues im Jupyter Notebook mit und ohne style_function unter Verwendung der angehängten demo.json-Daten auszuführen. Verfolge den Folium GeoJson-Stylingpfad und überprüfe den Abschluss, wenn LineString-Features mit der angeforderten Farbe, Linienstärke, Opazität und dashArray gerendert werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
jupyter-notebook, python
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.