geopandas.GeoDataFrame.iterfeatures#
- GeoDataFrame.iterfeatures(na='null', show_bbox=False, drop_id=False)#
返回一个迭代器,该迭代器生成符合 __geo_interface__
- 参数
- na字符串,可选
选项为{‘Null’,‘Drop’,‘Keep’},默认为‘Null’。指示如何输出GeoDataFrame中缺少的(NAN)值
NULL:将缺少的条目输出为JSON NULL
删除:从要素中删除该属性。这将分别应用于每个要素,因此要素可能具有不同的属性
Keep:将缺少的条目输出为NaN
- show_bbox布尔值,可选
在Geojson中包含BBox(边界)。默认为FALSE。
- drop_id布尔默认为: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.00000 2.00000) 1 name2 POINT (2.00000 1.00000)
>>> feature = next(gdf.iterfeatures()) >>> feature {'id': '0', 'type': 'Feature', 'properties': {'col1': 'name1'}, 'geometry': {'type': 'Point', 'coordinates': (1.0, 2.0)}}