geopandas.GeoDataFrame.to_geo_dict#
- GeoDataFrame.to_geo_dict(na='null', show_bbox=False, drop_id=False)[来源]#
返回GeoDataFrame的python特征集合表示,作为一个字典,包含基于
__geo_interface__GeoJSON-like规范的特征列表。- 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的索引保留为生成字典中的id属性。默认为False,但如果索引只是任意的行号,可能希望设置为True。
另请参阅
GeoDataFrame.to_json返回一个GeoDataFrame作为GeoJSON字符串
示例
>>> from shapely.geometry import Point >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]} >>> gdf = geopandas.GeoDataFrame(d) >>> gdf col1 geometry 0 name1 POINT (1 2) 1 name2 POINT (2 1)
>>> gdf.to_geo_dict() {'type': 'FeatureCollection', 'features': [{'id': '0', 'type': 'Feature', 'properties': {'col1': 'name1'}, 'geometry': {'type': 'Point', 'coordinates': (1.0, 2.0)}}, {'id': '1', 'type': 'Feature', 'properties': {'col1': 'name2'}, 'geometry': {'type': 'Point', 'coordinates': (2.0, 1.0)}}]}