geopandas.GeoDataFrame.to_json#

GeoDataFrame.to_json(na='null', show_bbox=False, drop_id=False, **kwargs)#

对象的GeoJSON表示形式 GeoDataFrame 作为一根弦。

参数
na{‘Null’,‘Drop’,‘Keep’},默认为‘Null’

指示如何输出GeoDataFrame中缺少的(NAN)值。请参见下面的内容。

show_bbox布尔值,可选,默认值:FALSE

在Geojson中包含BBox(边界)

drop_id布尔默认为:FALSE

是否将GeoDataFrame的索引保留为生成的GeoJSON中的id属性。默认值为False,但如果索引只是任意行号,则可能需要True。

参见

GeoDataFrame.to_file

将GeoDataFrame写入文件

注意事项

剩下的 科瓦格人 被传递给json.umps()。

GeoDataFrame中缺少的(NAN)值可表示如下:

  • null :将缺少的条目输出为JSON NULL。

  • drop :从要素中删除特性。这将分别应用于每个要素,因此要素可能具有不同的属性。

  • keep :将缺少的条目输出为NaN。

示例

>>> 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)
>>> gdf.to_json()
'{"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]}}]}'

或者,您可以将GeoJSON写入文件:

>>> gdf.to_file(path, driver="GeoJSON")