簡體   English   中英

使用 geopandas 探索 geojson LineString

[英]Using geopandas to explore a geojson LineString

我有以下 python 代碼:

import geopandas

data = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "GeometryCollection",
                "geometries": [
                    {
                        "type": "LineString",
                        "coordinates": [
                            [-118, 32], [-119, 33], [-120, 34], [-121, 35], [-122, 36], [-123, 37], [-124, 38]
                        ]
                    }
                ]
            },
            "properties": {
                "provider": "MyProvider"
            }
        }
    ]
}

gdf = geopandas.GeoDataFrame.from_features(data)
gdf.explore()

當我運行它時,它會生成警告:

UserWarning:GeoJsonTooltip 未配置為呈現 GeoJson GeometryCollection 幾何圖形。 請考慮重新設計這些功能:[{'provider': 'MyProvider'}] 到 MultiPolygon 以獲得完整功能。

並且 map 上的圖塊不會加載,盡管由 geojson 數據定義的行確實顯示了。

探索結果

如果我只使用 gdf.plot(),我會得到預期的圖像:

繪圖結果

但是,我想要 using.explore() 提供的交互式 map 磁貼。

警告到底是什么意思? 我的數據需要如何更改才能起作用?

背景/基地 map 問題應該通過明確分配一個 CRS 給你的 Geodataframe 來解決(我假設它是 EPSG:4326):

gdf = geopandas.GeoDataFrame.from_features(data)  
gdf = gdf.set_crs(4326)
gdf.explore()

或者,正如您在評論中所寫,在創建地理數據框時設置 crs。

gdf = geopandas.GeoDataFrame.from_features(data, crs=4326)

關於警告,我看起來像 function 的工具提示正確,需要不同的幾何類型(請參閱此處了解問題的討論 - 似乎是“類型”的問題:“GeometryCollection”)。

例如,對於以下 geojson 定義,標簽可以完美地工作:

data = {
    "type": "FeatureCollection",
    "features": [{
            "type": "Feature",
            "geometry": 
                    {
                        "type": "LineString",
                        "coordinates": [
                            [-118, 32], [-119, 33], [-120, 34], [-121, 35], [-122, 36], [-123, 37], [-124, 38]
                        ]
                    },
            "properties": {
                "provider": "MyProvider"
            }
        }]
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM