GEOS  3.12.0
Point.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) 2005 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/Point.java r320 (JTS-1.12)
18  *
19  **********************************************************************/
20 
21 #pragma once
22 
23 #include <geos/export.h>
24 #include <geos/geom/Geometry.h> // for inheritance
25 #include <geos/geom/CoordinateSequence.h> // for proper use of unique_ptr<>
26 #include <geos/geom/Envelope.h> // for proper use of unique_ptr<>
27 #include <geos/geom/Dimension.h> // for Dimension::DimensionType
28 
29 #include <string>
30 #include <vector>
31 #include <memory> // for unique_ptr
32 
33 #ifdef _MSC_VER
34 #pragma warning(push)
35 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36 #endif
37 
38 // Forward declarations
39 namespace geos {
40 namespace geom { // geos::geom
41 class Coordinate;
42 class CoordinateFilter;
43 class CoordinateSequenceFilter;
44 class GeometryComponentFilter;
45 class GeometryFilter;
46 }
47 }
48 
49 namespace geos {
50 namespace geom { // geos::geom
51 
61 class GEOS_DLL Point : public Geometry {
62 
63 public:
64 
65  friend class GeometryFactory;
66 
68  typedef std::vector<const Point*> ConstVect;
69 
70  ~Point() override = default;
71 
78  std::unique_ptr<Point> clone() const
79  {
80  return std::unique_ptr<Point>(cloneImpl());
81  }
82 
83  std::unique_ptr<CoordinateSequence> getCoordinates(void) const override;
84 
85  const CoordinateSequence* getCoordinatesRO() const;
86 
87  std::size_t getNumPoints() const override;
88  bool isEmpty() const override;
89  bool isSimple() const override;
90 
92  Dimension::DimensionType getDimension() const override;
93 
95  uint8_t getCoordinateDimension() const override;
96 
97  bool hasM() const override;
98 
99  bool hasZ() const override;
100 
102  int getBoundaryDimension() const override;
103 
112  std::unique_ptr<Geometry> getBoundary() const override;
113 
114  void setXY(double x, double y) {
115  if (isEmpty()) {
116  coordinates.add(x, y);
117  } else {
118  CoordinateXY& prev = coordinates.front<CoordinateXY>();
119  prev.x = x;
120  prev.y = y;
121  }
122  geometryChangedAction();
123  }
124 
125  const CoordinateXY* getCoordinate() const override {
126  return isEmpty() ? nullptr : &coordinates.getAt<CoordinateXY>(0);
127  }
128 
129  double getX() const;
130  double getY() const;
131  double getZ() const;
132  double getM() const;
133 
134  std::string getGeometryType() const override;
135  GeometryTypeId getGeometryTypeId() const override;
136  void apply_ro(CoordinateFilter* filter) const override;
137  void apply_rw(const CoordinateFilter* filter) override;
138  void apply_ro(GeometryFilter* filter) const override;
139  void apply_rw(GeometryFilter* filter) override;
140  void apply_rw(GeometryComponentFilter* filter) override;
141  void apply_ro(GeometryComponentFilter* filter) const override;
142  void apply_rw(CoordinateSequenceFilter& filter) override;
143  void apply_ro(CoordinateSequenceFilter& filter) const override;
144 
145  bool equalsExact(const Geometry* other, double tolerance = 0) const override;
146 
147  bool equalsIdentical(const Geometry* other) const override;
148 
149  void
150  normalize(void) override
151  {
152  // a Point is always in normalized form
153  }
154 
155  std::unique_ptr<Point> reverse() const
156  {
157  return std::unique_ptr<Point>(reverseImpl());
158  }
159 
160  const Envelope* getEnvelopeInternal() const override {
161  return &envelope;
162  }
163 
164 protected:
165 
178  Point(CoordinateSequence&& newCoords, const GeometryFactory* newFactory);
179 
180  Point(const Coordinate& c, const GeometryFactory* newFactory);
181 
182  Point(const CoordinateXY& c, const GeometryFactory* newFactory);
183 
184  Point(const CoordinateXYM& c, const GeometryFactory* newFactory);
185 
186  Point(const CoordinateXYZM& c, const GeometryFactory* newFactory);
187 
188  Point(const Point& p);
189 
190  Point* cloneImpl() const override { return new Point(*this); }
191 
192  Point* reverseImpl() const override { return new Point(*this); }
193 
194  Envelope computeEnvelopeInternal() const;
195 
196  int compareToSameClass(const Geometry* p) const override;
197 
198  int
199  getSortIndex() const override
200  {
201  return SORTINDEX_POINT;
202  };
203 
204  void geometryChangedAction() override {
205  envelope = computeEnvelopeInternal();
206  }
207 
208 private:
209 
210  CoordinateSequence coordinates;
211  Envelope envelope;
212 };
213 
214 } // namespace geos::geom
215 } // namespace geos
216 
217 
218 #ifdef _MSC_VER
219 #pragma warning(pop)
220 #endif
221 
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:45
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Point * reverseImpl() const override
Make a geometry with coordinates in reverse order.
Definition: Point.h:192
std::unique_ptr< Point > clone() const
Definition: Point.h:78
std::vector< const Point * > ConstVect
A vector of const Point pointers.
Definition: Point.h:68
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:216
const CoordinateXY * getCoordinate() const override
Returns a vertex of this Geometry, or NULL if this is the empty geometry.
Definition: Point.h:125
Interface for classes which provide operations that can be applied to the coordinates in a Coordinate...
Definition: CoordinateSequenceFilter.h:55
GeometryTypeId
Geometry types.
Definition: Geometry.h:73
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition: CoordinateFilter.h:43
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:65
const Envelope * getEnvelopeInternal() const override
Returns the minimum and maximum x and y values in this Geometry, or a null Envelope if this Geometry ...
Definition: Point.h:160
void normalize(void) override
Definition: Point.h:150
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25
Point * cloneImpl() const override
Make a deep-copy of this Geometry.
Definition: Point.h:190
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:56
Definition: Point.h:61
DimensionType
Definition: Dimension.h:29
Definition: GeometryComponentFilter.h:41
void geometryChangedAction() override
Notifies this Geometry that its Coordinates have been changed by an external party.
Definition: Point.h:204