geopandas.GeoDataFrame.from_features#

classmethod GeoDataFrame.from_features(features, crs=None, columns=None)[来源]#

备用构造函数用于从特征的可迭代对象或特征集合创建GeoDataFrame。

Parameters:
features
  • 可迭代的特征,每个元素必须是特征字典或实现 __geo_interface__。

  • 特征集合,其中“features”键包含一个可迭代的特征。

  • 持有实现了__geo_interface__的要素集合的对象。

crsstr or dict (optional)

要在结果框架上设置的坐标参考系统。

columnslist of column names, optional

可选地指定要包含在输出框架中的列名称。这不会覆盖输入的属性名称,但可以确保输出格式的一致性。

Returns:
GeoDataFrame

笔记

有关 __geo_interface__ 的更多信息,请参见 https://gist.github.com/sgillies/2217756

示例

>>> feature_coll = {
...     "type": "FeatureCollection",
...     "features": [
...         {
...             "id": "0",
...             "type": "Feature",
...             "properties": {"col1": "name1"},
...             "geometry": {"type": "Point", "coordinates": (1.0, 2.0)},
...             "bbox": (1.0, 2.0, 1.0, 2.0),
...         },
...         {
...             "id": "1",
...             "type": "Feature",
...             "properties": {"col1": "name2"},
...             "geometry": {"type": "Point", "coordinates": (2.0, 1.0)},
...             "bbox": (2.0, 1.0, 2.0, 1.0),
...         },
...     ],
...     "bbox": (1.0, 1.0, 2.0, 2.0),
... }
>>> df = geopandas.GeoDataFrame.from_features(feature_coll)
>>> df
      geometry   col1
0  POINT (1 2)  name1
1  POINT (2 1)  name2