geost.base.Collection.spatial_join#

Collection.spatial_join(geometries: str | Path | GeoDataFrame, label_id: str | list[str], drop_label_if_exists: bool = True, include_in_header: bool = False, **kwargs) GeoDataFrame | None[source]#

Join information from another GeoDataFrame by a spatial relationship (e.g. overlap) between the geometries in the header table of the Collection with the geometries in the other GeoDataFrame.

Parameters:
  • geometries (str | Path | gpd.GeoDataFrame) – Geometries to join with the information from. Can be a GeoDataFrame or a file path to a geospatial file that can be read as a GeoDataFrame.

  • label_id (str | Iterable) – Column name(s) in the geometries GeoDataFrame to join the information from.

  • drop_label_if_exists (bool, optional) – If True, will drop the specified ‘label_id’ from the original GeoDataFrame if these already exist as a column or columns, before the spatial join. Otherwise, suffixes will automatically be added to the joined columns to avoid naming conflicts. The default is False.

  • **kwargs – Keyword arguments to be passed to the GeoPandas geopandas.GeoDataFrame.sjoin() function. See relevant documentation for more information. Note that the “how” parameter is not allowed when include_in_header is True (error is raised), as the spatial join will always be performed with “how=’left’” in that case.

Returns:

GeoDataFrame resulting from the spatial join if include_in_header is False. Otherwise, returns None and the result is included in the header of the Collection instance.

Return type:

gpd.GeoDataFrame | None