GEOS  3.9.0
Geometry.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2009 2011 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2005 2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions 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/Geometry.java rev. 1.112
18  *
19  **********************************************************************/
20 
21 #ifndef GEOS_GEOM_GEOMETRY_H
22 #define GEOS_GEOM_GEOMETRY_H
23 
24 #ifndef USE_UNSTABLE_GEOS_CPP_API
25 #ifndef _MSC_VER
26 # warning "The GEOS C++ API is unstable, please use the C API instead"
27 # warning "HINT: #include geos_c.h"
28 #else
29 #pragma message("The GEOS C++ API is unstable, please use the C API instead")
30 #pragma message("HINT: #include geos_c.h")
31 #endif
32 #endif
33 
34 #include <geos/export.h>
35 #include <geos/inline.h>
36 #include <geos/geom/Envelope.h>
37 #include <geos/geom/Dimension.h> // for Dimension::DimensionType
38 #include <geos/geom/GeometryComponentFilter.h> // for inheritance
39 #include <geos/geom/IntersectionMatrix.h>
40 
41 #include <algorithm>
42 #include <string>
43 #include <iostream>
44 #include <vector>
45 #include <memory>
46 
47 #ifdef _MSC_VER
48 #pragma warning(push)
49 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
50 #pragma warning(disable: 4355) // warning C4355: 'this' : used in base member initializer list
51 #endif
52 
53 // Forward declarations
54 namespace geos {
55 namespace geom {
56 class Coordinate;
57 class CoordinateFilter;
58 class CoordinateSequence;
59 class CoordinateSequenceFilter;
60 class GeometryComponentFilter;
61 class GeometryFactory;
62 class GeometryFilter;
63 class PrecisionModel;
64 class Point;
65 }
66 namespace io { // geos.io
67 class Unload;
68 } // namespace geos.io
69 }
70 
71 namespace geos {
72 namespace geom { // geos::geom
73 
92 };
93 
94 enum GeometrySortIndex {
95  SORTINDEX_POINT = 0,
96  SORTINDEX_MULTIPOINT = 1,
97  SORTINDEX_LINESTRING = 2,
98  SORTINDEX_LINEARRING = 3,
99  SORTINDEX_MULTILINESTRING = 4,
100  SORTINDEX_POLYGON = 5,
101  SORTINDEX_MULTIPOLYGON = 6,
102  SORTINDEX_GEOMETRYCOLLECTION = 7
103 };
104 
188 class GEOS_DLL Geometry {
189 
190 public:
191 
192  friend class GeometryFactory;
193 
195  using ConstVect = std::vector<const Geometry*>;
196 
198  using NonConstVect = std::vector<Geometry*>;
199 
201  using Ptr = std::unique_ptr<Geometry> ;
202 
204  virtual std::unique_ptr<Geometry> clone() const = 0;
205 
207  virtual ~Geometry();
208 
209 
217  const GeometryFactory*
218  getFactory() const
219  {
220  return _factory;
221  }
222 
236  void
237  setUserData(void* newUserData)
238  {
239  _userData = newUserData;
240  }
241 
248  void*
249  getUserData() const
250  {
251  return _userData;
252  }
253 
264  virtual int
265  getSRID() const
266  {
267  return SRID;
268  }
269 
273  virtual void
274  setSRID(int newSRID)
275  {
276  SRID = newSRID;
277  }
278 
284 
286  virtual const Coordinate* getCoordinate() const = 0; //Abstract
287 
293  virtual std::unique_ptr<CoordinateSequence> getCoordinates() const = 0; //Abstract
294 
296  virtual std::size_t getNumPoints() const = 0; //Abstract
297 
299  virtual bool isSimple() const;
300 
302  virtual std::string getGeometryType() const = 0; //Abstract
303 
305  virtual GeometryTypeId getGeometryTypeId() const = 0; //Abstract
306 
309  virtual std::size_t
311  {
312  return 1;
313  }
314 
317  virtual const Geometry*
318  getGeometryN(std::size_t /*n*/) const
319  {
320  return this;
321  }
322 
332  virtual bool isValid() const;
333 
335  virtual bool isEmpty() const = 0; //Abstract
336 
338  virtual bool
339  isRectangle() const
340  {
341  return false;
342  }
343 
345  virtual Dimension::DimensionType getDimension() const = 0; //Abstract
346 
349  return d == getDimension();
350  }
351 
352  bool isPuntal() const {
353  return isDimensionStrict(Dimension::P);
354  }
355 
356  bool isLineal()