GEOS  3.13.0dev
UniqueCoordinateArrayFilter.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 #pragma once
17 
18 #include <geos/export.h>
19 #include <cassert>
20 #include <set>
21 #include <vector>
22 
23 #include <geos/geom/CoordinateFilter.h>
24 #include <geos/geom/CoordinateSequence.h>
25 #include <geos/geom/Coordinate.h>
26 
27 #ifdef _MSC_VER
28 #pragma warning(push)
29 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
30 #endif
31 
32 namespace geos {
33 namespace util { // geos::util
34 
35 /*
36  * A CoordinateFilter that fills a vector of Coordinate const pointers.
37  * The set of coordinates contains no duplicate points.
38  *
39  * Last port: util/UniqueCoordinateArrayFilter.java rev. 1.17
40  */
41 class GEOS_DLL UniqueCoordinateArrayFilter : public geom::CoordinateInspector<UniqueCoordinateArrayFilter> {
42 public:
48  UniqueCoordinateArrayFilter(std::vector<const geom::Coordinate*>& target)
49  : pts(target)
50  , maxUnique(NO_COORD_INDEX)
51  {}
52 
53  UniqueCoordinateArrayFilter(std::vector<const geom::Coordinate*>& target, std::size_t p_maxUnique)
54  : pts(target)
55  , maxUnique(p_maxUnique)
56  {}
57 
64  ~UniqueCoordinateArrayFilter() override {}
65 
71  template<typename CoordType>
72  void filter(const CoordType* coord)
73  {
74  if(uniqPts.insert(coord).second) {
75  // TODO make `pts` a CoordinateSequence rather than coercing the type
76  pts.push_back(coord);
77  }
78  if(maxUnique != NO_COORD_INDEX && uniqPts.size() > maxUnique) {
79  done = true;
80  }
81  }
82 
83  void filter(const geom::CoordinateXY*) {
84  assert(0); // not supported
85  }
86 
87 
88  void filter(const geom::CoordinateXYM*) {
89  assert(0); // not supported
90  }
91 
92  bool isDone() const override {
93  return done;
94  }
95 
96 private:
97  std::vector<const geom::Coordinate*>& pts; // target set reference
98  std::set<const geom::CoordinateXY*, geom::CoordinateLessThan> uniqPts; // unique points set
99  std::size_t maxUnique; // stop visiting when we have this many unique coordinates
100  bool done = false;
101 
102  // Declare type as noncopyable
103  UniqueCoordinateArrayFilter(const UniqueCoordinateArrayFilter& other) = delete;
104  UniqueCoordinateArrayFilter& operator=(const UniqueCoordinateArrayFilter& rhs) = delete;
105 };
106 
107 
108 } // namespace geos::util
109 } // namespace geos
110 
111 #ifdef _MSC_VER
112 #pragma warning(pop)
113 #endif
114 
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25