coordinate_clustering#


class CoordinateEuclideanClusterer(clusterer: EuclideanClusterer)[source]#

Bases: EuclideanClusterer, GeoDataFrameWrapper

Wrapper around a clustering model. This class adds additional, geospatial-specific features to the provided clusterer

Parameters:

clusterer – an instance of ClusteringModel

class Cluster(coordinates: ndarray, identifier: Union[str, int])[source]#

Bases: Cluster, GeoDataFrameWrapper, LoadSaveInterface

Wrapper around a coordinates array

Parameters:
  • coordinates

  • identifier

to_geodf(crs='epsg:3857')[source]#

Export the cluster as a GeoDataFrame of length 1 with the cluster as an instance of MultiPoint and the identifier as index.

Parameters:

crs – projection. By default pseudo-mercator

Returns:

GeoDataFrame

as_multipoint()[source]#
Returns:

The cluster’s coordinates as a MultiPoint object

classmethod load(path)[source]#

Instantiate from a geopandas readable file containing a single row with an identifier and an instance of MultiPoint

Parameters:

path

Returns:

instance of CoordinateCluster

save(path, crs='EPSG:3857')[source]#

Saves the cluster’s coordinates as shapefile

Parameters:
  • crs

  • path

Returns:

fit(coordinates: Union[ndarray, shapely.geometry.MultiPoint, geopandas.GeoDataFrame, Cluster])[source]#

Fitting to coordinates from a numpy array, a MultiPoint object or a GeoDataFrame with one Point per row

Parameters:

coordinates

Returns:

to_geodf(condition: Callable[[Cluster], bool] = None, crs='epsg:3857', include_noise=False) geopandas.GeoDataFrame[source]#

GeoDataFrame containing all clusters found by the model. It is a concatenation of GeoDataFrames of individual clusters

Parameters:
  • condition – if provided, only clusters fulfilling the condition will be included

  • crs – projection. By default pseudo-mercator

  • include_noise

Returns:

GeoDataFrame with all clusters indexed by their identifier

plot(include_noise=False, condition=None, **kwargs)[source]#

Plots the resulting clusters with random coloring

Parameters:
  • include_noise – Whether to include the noise cluster

  • condition – If provided, only clusters fulfilling this condition will be included

  • kwargs – passed to GeoDataFrame.plot

Returns:

get_cluster(cluster_id: int) Cluster[source]#
noise_cluster() Cluster[source]#
clusters(condition: Optional[Callable[[Cluster], bool]] = None) Iterable[Cluster][source]#
Parameters:

condition – if provided, only clusters fulfilling the condition will be included

Returns:

generator of clusters

class SkLearnCoordinateClustering(clusterer: SkLearnClustererProtocol, noise_label=- 1, min_cluster_size: Optional[int] = None, max_cluster_size: Optional[int] = None)[source]#

Bases: CoordinateEuclideanClusterer

Wrapper around a sklearn clusterer. This class adds additional features like relabelling and convenient methods for handling geospatial data

Parameters:
  • clusterer – a clusterer object compatible the sklearn API

  • noise_label – label that is associated with the noise cluster or None

  • min_cluster_size – if not None, clusters below this size will be labeled as noise

  • max_cluster_size – if not None, clusters above this size will be labeled as noise