python-visualization / python-visualization/folium

Features not displayed with style_function

オープン
#1,782 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
7.4k
フォーク
2.3k
平均マージ
17時間 22分
マージ済み PR(30日)
11

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、添付された demo.json データを使い、style_function の有無それぞれで issue の GeoJSON 再現を Jupyter Notebook で実行します。Folium GeoJson のスタイリングパスを追跡し、LineString フィーチャが要求された色、線幅、不透明度、dashArray でレンダリングされた時点で完了を確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
jupyter-notebook, python
領域
data-visualization
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。