GEOS  3.14.0dev
DBSCANClusterFinder.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2020-2021 Daniel Baston
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************/
14 
15 #pragma once
16 
17 #include <geos/operation/cluster/AbstractClusterFinder.h>
18 #include <geos/geom/Geometry.h>
19 #include <stdexcept>
20 
21 namespace geos {
22 namespace operation {
23 namespace cluster {
24 
28 class GEOS_DLL DBSCANClusterFinder : public AbstractClusterFinder {
29 public:
30  DBSCANClusterFinder(double eps, size_t minPoints) : m_eps(eps), m_minPoints(minPoints) {}
31 
32 protected:
33 
34  const geom::Envelope& queryEnvelope(const geom::Geometry* a) override {
35  m_envelope = *a->getEnvelopeInternal();
36  m_envelope.expandBy(m_eps);
37  return m_envelope;
38  }
39 
40  Clusters process(const std::vector<const geom::Geometry*> & components,
41  index::strtree::TemplateSTRtree<std::size_t> & index,
42  UnionFind & uf) override;
43 
44  bool shouldJoin(const geom::Geometry*, const geom::Geometry*) override {
45  throw std::runtime_error("Never get here.");
46  }
47 
48 private:
49  double m_eps;
50  size_t m_minPoints;
51  geom::Envelope m_envelope;
52 };
53 
54 }
55 }
56 }
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
void expandBy(double deltaX, double deltaY)
Expands this envelope by a given distance in all directions. Both positive and negative distances are...
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:197
virtual const Envelope * getEnvelopeInternal() const =0
Returns the minimum and maximum x and y values in this Geometry, or a null Envelope if this Geometry ...
Definition: AbstractClusterFinder.h:45
Definition: DBSCANClusterFinder.h:28
bool shouldJoin(const geom::Geometry *, const geom::Geometry *) override
Definition: DBSCANClusterFinder.h:44
Clusters process(const std::vector< const geom::Geometry * > &components, index::strtree::TemplateSTRtree< std::size_t > &index, UnionFind &uf) override
const geom::Envelope & queryEnvelope(const geom::Geometry *a) override
Definition: DBSCANClusterFinder.h:34
Definition: UnionFind.h:32
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25