GEOS 3.14.0dev
DisjointOperation.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2022 ISciences LLC
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/export.h>
18#include <geos/operation/cluster/AbstractClusterFinder.h>
19#include <geos/operation/cluster/GeometryFlattener.h>
20#include <geos/geom/Geometry.h>
21#include <geos/geom/GeometryFactory.h>
22
23namespace geos {
24namespace operation {
25namespace cluster {
26
27class GEOS_DLL DisjointOperation {
28public:
29 DisjointOperation(AbstractClusterFinder& finder) : m_finder(finder), m_split_inputs(false) {}
30
34 void setSplitInputs(bool b) {
35 m_split_inputs = b;
36 }
37
47 template<typename Function>
48 std::unique_ptr<geom::Geometry> processDisjointSubsets(const geom::Geometry& g, Function&& f) {
49 if (g.getNumGeometries() == 1) {
50 return f(g);
51 }
52
53 auto flattened = m_split_inputs ? operation::cluster::GeometryFlattener::flatten(g.clone()) : g.clone();
54 auto clustered = m_finder.clusterToVector(std::move(flattened));
55
56 for (auto& subset : clustered) {
57 subset = f(*subset);
58 }
59
60 auto coll = g.getFactory()->createGeometryCollection(std::move(clustered));
61
62 return operation::cluster::GeometryFlattener::flatten(std::move(coll));
63 }
64
65private:
66 AbstractClusterFinder& m_finder;
67 bool m_split_inputs;
68};
69
70
71}
72}
73}
Basic namespace for all GEOS functionalities.
Definition geos.h:39