索引和选择数据#

GeoPandas 继承了标准 pandas 的数据索引/选择方法。这包括基于标签的索引 loc 和基于整数位置的索引 iloc,它们适用于 GeoSeriesGeoDataFrame 对象。有关索引/选择的更多信息,请参见 pandas 文档。

除了标准的 pandas 方法,GeoPandas 还提供基于坐标的索引功能,使用 cx 索引器,该索引器使用一个边界框进行切片。与边界框相交的 GeoSeriesGeoDataFrame 中的几何体将被返回。

使用 geoda.chile_labor 数据集,您可以使用此功能快速选择智利的部分区域,其边界延伸至-50度纬度以南。您可以先检查原始的 GeoDataFrame。

In [1]: import geodatasets

In [2]: chile = geopandas.read_file(geodatasets.get_path('geoda.chile_labor'))

In [3]: chile.plot(figsize=(8, 8));
../../_images/chile.png

然后只选择该国的南部。

In [4]: southern_chile = chile.cx[:, :-50]

In [5]: southern_chile.plot(figsize=(8, 8));
../../_images/chile_southern.png