geopandas.GeoDataFrame.iterfeatures#
- GeoDataFrame.iterfeatures(na='null', show_bbox=False, drop_id=False)[来源]#
返回一个迭代器,生成符合 __geo_interface__ 的要素字典
- Parameters:
- nastr, optional
选项为 {‘null’, ‘drop’, ‘keep’},默认值为 ‘null’。 指示如何在 GeoDataFrame 中输出缺失 (NaN) 值
null:将缺失的条目输出为 JSON null
drop: 从特征中移除属性。这适用于每个特征,因此特征可以具有不同的属性
保留:将缺失的条目输出为 NaN
- show_bboxbool, optional
在geojson中包含bbox(边界)。默认为False。
- drop_idbool, default: False
是否将GeoDataFrame的索引保留为生成的GeoJSON中的id属性。默认为False,但如果索引只是任意的行号,可以考虑设为True。
示例
>>> from shapely.geometry import Point >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]} >>> gdf = geopandas.GeoDataFrame(d, crs="EPSG:4326") >>> gdf col1 geometry 0 name1 POINT (1 2) 1 name2 POINT (2 1)
>>> feature = next(gdf.iterfeatures()) >>> feature {'id': '0', 'type': 'Feature', 'properties': {'col1': 'name1'}, 'geometry': {'type': 'Point', 'coordinates': (1.0, 2.0)}}