GEOS  3.13.0dev
CheckOrdinatesFilter.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/geom/Coordinate.h>
18 #include <geos/geom/CoordinateSequence.h>
19 #include <geos/geom/CoordinateSequenceFilter.h>
20 #include <geos/io/OrdinateSet.h>
21 
22 namespace geos {
23 namespace io {
24 
25 class CheckOrdinatesFilter : public geom::CoordinateSequenceFilter {
26 public:
27  CheckOrdinatesFilter(OrdinateSet checkOrdinateFlags) :
28  m_checkFlags(checkOrdinateFlags),
29  m_foundFlags(OrdinateSet::createXY())
30  {}
31 
32  void filter_ro(const geom::CoordinateSequence& seq, std::size_t i) override {
33  bool checkZ = m_checkFlags.hasZ() && !m_foundFlags.hasZ();
34  bool checkM = m_checkFlags.hasM() && !m_foundFlags.hasM();
35 
36  if (checkZ || checkM) {
37  seq.getAt(i, m_coord);
38 
39  if (checkZ && !std::isnan(m_coord.z)) {
40  m_foundFlags.setZ(true);
41  }
42 
43  if (checkM && !std::isnan(m_coord.m)) {
44  m_foundFlags.setM(true);
45  }
46  }
47  }
48 
49  bool isGeometryChanged() const override {
50  return false;
51  }
52 
53  bool isDone() const override {
54  return m_checkFlags == m_foundFlags;
55  }
56 
57  OrdinateSet getFoundOrdinates() const {
58  return m_foundFlags;
59  }
60 
61 private:
62  OrdinateSet m_checkFlags;
63  OrdinateSet m_foundFlags;
64  geom::CoordinateXYZM m_coord;
65 };
66 
67 }
68 }
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25