/src/geos/include/geos/operation/cluster/EnvelopeDistanceClusterFinder.h
Line | Count | Source (jump to first uncovered line) |
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/Envelope.h> |
19 | | |
20 | | namespace geos { |
21 | | namespace operation { |
22 | | namespace cluster { |
23 | | |
24 | | /** EnvelopeDistanceClusterFinder clusters geometries by the distance between their envelopes. |
25 | | * Any two geometries whose envelopes are within the specified distance will be included in the same cluster. |
26 | | */ |
27 | | class GEOS_DLL EnvelopeDistanceClusterFinder : public AbstractClusterFinder { |
28 | | public: |
29 | 0 | explicit EnvelopeDistanceClusterFinder(double d) : m_distance(d), m_distance_squared(d*d) {} |
30 | | |
31 | | protected: |
32 | 0 | const geom::Envelope& queryEnvelope(const geom::Geometry* a) override { |
33 | 0 | m_envelope = *a->getEnvelopeInternal(); |
34 | 0 | m_envelope.expandBy(m_distance); |
35 | 0 | return m_envelope; |
36 | 0 | } |
37 | | |
38 | 0 | bool shouldJoin(const geom::Geometry* a, const geom::Geometry *b) override { |
39 | 0 | return a->getEnvelopeInternal()->distanceSquared(*b->getEnvelopeInternal()) <= m_distance_squared; |
40 | 0 | } |
41 | | |
42 | | private: |
43 | | geom::Envelope m_envelope; |
44 | | double m_distance; |
45 | | double m_distance_squared; |
46 | | }; |
47 | | |
48 | | } |
49 | | } |
50 | | } |