GEOS  3.13.0dev
GeometryDistanceClusterFinder.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 #ifndef GEOS_OPERATION_CLUSTER_GEOMETRYDISTANCECLUSTERFINDER
16 #define GEOS_OPERATION_CLUSTER_GEOMETRYDISTANCECLUSTERFINDER
17 
18 #include <geos/operation/cluster/AbstractClusterFinder.h>
19 #include <geos/geom/prep/PreparedGeometry.h>
20 #include <geos/geom/prep/PreparedGeometryFactory.h>
21 
22 namespace geos {
23 namespace operation {
24 namespace cluster {
25 
31 public:
32  explicit GeometryDistanceClusterFinder(double distance) : m_distance(distance) {}
33 
34 protected:
35  bool shouldJoin(const geom::Geometry* a, const geom::Geometry *b) override {
36  if (m_prep == nullptr || &(m_prep->getGeometry()) != a) {
38  }
39 
40  return m_prep->isWithinDistance(b, m_distance);
41  }
42 
43  const geom::Envelope& queryEnvelope(const geom::Geometry* a) override {
44  m_envelope = *a->getEnvelopeInternal();
45  m_envelope.expandBy(m_distance);
46  return m_envelope;
47  }
48 
49 private:
50  std::unique_ptr<geom::prep::PreparedGeometry> m_prep;
51  double m_distance;
52  geom::Envelope m_envelope;
53 };
54 
55 }
56 }
57 }
58 
59 #endif
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
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:186
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 ...
static std::unique_ptr< PreparedGeometry > prepare(const geom::Geometry *geom)
Definition: PreparedGeometryFactory.h:63
Definition: AbstractClusterFinder.h:47
Definition: GeometryDistanceClusterFinder.h:30
bool shouldJoin(const geom::Geometry *a, const geom::Geometry *b) override
Definition: GeometryDistanceClusterFinder.h:35
const geom::Envelope & queryEnvelope(const geom::Geometry *a) override
Definition: GeometryDistanceClusterFinder.h:43
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25