【问题标题】:Create a GeoDataFrame from a GeoJSON object从 GeoJSON 对象创建 GeoDataFrame
【发布时间】:2016-10-10 06:12:42
【问题描述】:

我有一个多边形特征集合,我必须先将它写入一个临时文件,然后使用geopandas.GeoDataFrame.from_file(tmp_json_file) 加载它,有什么方法可以不写入临时文件并从GeoJSON 对象?

【问题讨论】:

    标签: python gis geojson geopandas


    【解决方案1】:

    您可以为此使用GeoDataFrame.from_features() 函数。一个小例子(假设你有一个geojson FeatureCollection):

    In [1]: from geojson import Feature, Point, FeatureCollection
    
    In [2]: my_feature = Feature(geometry=Point((1.6432, -19.123)), properties={"country": "Spain"})
    
    In [3]: my_other_feature = Feature(geometry=Point((-80.234, -22.532)), properties={'country': 'Brazil'})
    
    In [4]: collection = FeatureCollection([my_feature, my_other_feature])
    
    In [6]: import geopandas
    
    In [7]: geopandas.GeoDataFrame.from_features(collection['features'])
    Out[7]:
      country                 geometry
    0   Spain   POINT (1.6432 -19.123)
    1  Brazil  POINT (-80.234 -22.532)
    

    【讨论】:

    • 它对简单的多边形很有效,但我还有另一个由PolygonsMultiPolygons 组成的FeatureColletion,我不知道如何处理它的几何形状
    • “如何处理它的几何形状”是什么意思?是否无法创建 geopandas GeoDataFrame? (因为它们可以包含具有不同几何类型的几何列,所以这应该不是问题)
    • 你能单独提出一个问题吗? (因为它是另外一回事,关于如何创建一个 FeatureCollection)
    猜你喜欢
    • 2014-07-10
    • 1970-01-01
    • 2021-10-18
    • 2021-12-01
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    相关资源
    最近更新 更多