在python中过滤geojson

2024-05-18 13:57:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这样的代码,它可以在地图上创建多边形

import geopandas as gpd import folium

gdf = gpd.read_file('NSW_fire_history_polygons.geojson').iloc[0:15000]

fmap= folium.Map(location=[-33.2532 , 149.9211], tiles='https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', zoom_start=6, attr = 'my attirbution', control_scale=True)

folium.GeoJson( gdf[['FireName','Label','Type', "AreaHa", "Year",'geometry']].to_json(), name='NSW_fires', show=True,
highlight_function=lambda x: {'weight':3, 'color':'red', 'fillOpacity':1},
tooltip=folium.features.GeoJsonTooltip( fields=['FireName','Label','Type',"AreaHa","Year"], aliases=['FireName:','Label:','Type:',"Hactares burned","Year"],
),
).add_to(fmap)

display(fmap)

数据设置如下:

{ "type": "FeatureCollection", "name": "NSW_fire_history_polygons", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, "features": [ { "type": "Feature", "properties": { "FID": 1, "FireName": " ", "FireNo": " ", "Label": "1968-69 Prescribed Burn", "StartDate": "1968/10/01 00:00:00+00", "EndDate": "1970/01/01 00:00:00+00", "AreaHa": 2.18476976, "PerimeterM": 1548.9606657500001, "Verdate": "26/03/2020", "Type": "Prescribed Burn", "Season": "1968-69", "ID": 0, "Year": 1968, "Year_Con": "1968/01/01 00:00:00+00", "Shape__Area": 21868.7578125, "Shape__Length": 1549.7039558799499 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 153.141431389746998, -30.177301150106899 ], [ 153.141436000570991, -30.177252368181101 ], [ 153.141393760314003, -30.176988785882699 ], [ 153.141350831175998, -30.176656371273499 ], [ 153.141353529142009, -30.1762662579604 ], [ 153.14139520102799, -30.175812758630801 ], [ 153.141497133786004...

我正在尝试过滤它,以便在地图上绘制特定年份的值。即2000年

对于编码来说,我所看到的很多东西都使用javascript,但我想用python来实现


Tags: nameimporttype地图yearlabelfirensw
1条回答
网友
1楼 · 发布于 2024-05-18 13:57:20

一种解决方案是将与该年份不对应的多边形保持透明,例如:

highlight_function=lambda x: {'opacity':1 if x['properties']['Year']=2000 else 0,'weight':3, 'color':'red', 'fillOpacity':1},

相关问题 更多 >

    热门问题