将 geopandas.geodataframe 转换为 geojson

Convert geopandas.geodataframe to geojson

我正在尝试以 geojson 格式保存 geopandas.geodataframe。但我有一个错误,我不知道它来自哪里以及如何解决它。这是代码和错误:

在此先感谢您的帮助。

  batiments = ox.geometries_from_place(saint_denis, tags={'building':['office', 
  'university', 'stadium', 
                                                      'civic']})
  routes = ox.geometries_from_place(saint_denis, tags={'highway':['primary', 
 'secondary']})
  #export to geojson 
  batiments.to_file('dataframe.geojson', driver='GeoJSON')

而不是.to_file() 您可以创建一个新的 geojson 文件并在其中填充 .to_json() 对象,它是 (str) 格式的 json 字典。

with open('dataframe.geojson' , 'w') as file:
    file.write(batiments.to_json())