GEOS  3.9.0dev
GeometryExtracter.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2001-2002 Vivid Solutions Inc.
8  * Copyright (C) 2006 Refractions Research Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: geom/util/GeometryExtracter.java r320 (JTS-1.12)
18  *
19  **********************************************************************/
20 
21 #ifndef GEOS_GEOM_UTIL_GEOMETRYEXTRACTER_H
22 #define GEOS_GEOM_UTIL_GEOMETRYEXTRACTER_H
23 
24 #include <geos/export.h>
25 #include <geos/geom/GeometryFilter.h>
26 #include <geos/geom/GeometryCollection.h>
27 #include <vector>
28 
29 namespace geos {
30 namespace geom { // geos.geom
31 namespace util { // geos.geom.util
32 
36 class GEOS_DLL GeometryExtracter {
37 
38 public:
39 
47  template <class ComponentType, class TargetContainer>
48  static void
49  extract(const Geometry& geom, TargetContainer& lst)
50  {
51  if(const ComponentType* p_c = dynamic_cast<const ComponentType*>(&geom)) {
52  lst.push_back(p_c);
53  }
54  else if(const GeometryCollection* p_c1 =
55  dynamic_cast<const GeometryCollection*>(&geom)) {
56  GeometryExtracter::Extracter<ComponentType, TargetContainer> extracter(lst);
57  p_c1->apply_ro(&extracter);
58  }
59  }
60 
61 private:
62 
63  template <class ComponentType, class TargetContainer>
64  struct Extracter: public GeometryFilter {
65 
71  Extracter(TargetContainer& comps) : comps_(comps) {}
72 
73  TargetContainer& comps_;
74 
75  void
76  filter_ro(const Geometry* geom) override
77  {
78  if(const ComponentType* c = dynamic_cast<const ComponentType*>(geom)) {
79  comps_.push_back(c);
80  }
81  }
82 
83  // Declare type as noncopyable
84  Extracter(const Extracter& other);
85  Extracter& operator=(const Extracter& rhs);
86  };
87 
88  // Declare type as noncopyable
89  GeometryExtracter(const GeometryExtracter& other) = delete;
90  GeometryExtracter& operator=(const GeometryExtracter& rhs) = delete;
91 };
92 
93 } // namespace geos.geom.util
94 } // namespace geos.geom
95 } // namespace geos
96 
97 #endif
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:47
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:55
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
Definition: GeometryExtracter.h:36
static void extract(const Geometry &geom, TargetContainer &lst)
Definition: GeometryExtracter.h:49