GEOS  3.4.2
PolygonExtracter.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2001-2002 Vivid Solutions Inc.
7  * Copyright (C) 2006 Refractions Research Inc.
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the GNU Lesser General Public Licence as published
11  * by the Free Software Foundation.
12  * See the COPYING file for more information.
13  *
14  **********************************************************************/
15 
16 #ifndef GEOS_GEOM_UTIL_POLYGONEXTRACTER_H
17 #define GEOS_GEOM_UTIL_POLYGONEXTRACTER_H
18 
19 #include <geos/export.h>
20 #include <geos/geom/GeometryFilter.h>
21 #include <geos/geom/Polygon.h>
22 #include <geos/platform.h>
23 #include <vector>
24 
25 namespace geos {
26 namespace geom { // geos.geom
27 namespace util { // geos.geom.util
28 
32 class GEOS_DLL PolygonExtracter: public GeometryFilter {
33 
34 public:
35 
43  static void getPolygons(const Geometry &geom, std::vector<const Polygon*>& ret)
44  {
45  PolygonExtracter pe(ret);
46  geom.apply_ro(&pe);
47  }
48 
53  PolygonExtracter(std::vector<const Polygon*>& newComps)
54  :
55  comps(newComps)
56  {}
57 
58  void filter_rw(Geometry *geom) {
59  if ( const Polygon *p=dynamic_cast<const Polygon *>(geom) )
60  {
61  comps.push_back(p);
62  }
63  }
64 
65  void filter_ro(const Geometry *geom)
66  {
67  if ( const Polygon *p=dynamic_cast<const Polygon *>(geom) )
68  {
69  comps.push_back(p);
70  }
71  }
72 
73 private:
74 
76  std::vector<const Polygon*>& comps;
77 
78  // Declare type as noncopyable
79  PolygonExtracter(const PolygonExtracter& other);
80  PolygonExtracter& operator=(const PolygonExtracter& rhs);
81 };
82 
83 } // namespace geos.geom.util
84 } // namespace geos.geom
85 } // namespace geos
86 
87 #endif
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:48
Definition: PolygonExtracter.h:32
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:167
Represents a linear polygon, which may include holes.
Definition: Polygon.h:66
PolygonExtracter(std::vector< const Polygon * > &newComps)
Definition: PolygonExtracter.h:53
static void getPolygons(const Geometry &geom, std::vector< const Polygon * > &ret)
Definition: PolygonExtracter.h:43