File Geometry.h
File List > src > Geometry.h
Go to the documentation of this file
// Copyright (c) 2012-2013, IGN France.
// Copyright (c) 2012-2022, Oslandia.
// SPDX-License-Identifier: LGPL-2.0-or-later
#ifndef _SFCGAL_GEOMETRY_H_
#define _SFCGAL_GEOMETRY_H_
#include "SFCGAL/config.h"
#include <boost/endian/conversion.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>
#include <sstream>
#include <string>
#include <boost/assert.hpp>
namespace CGAL {
class Object;
}
namespace SFCGAL {
class Geometry;
class Point;
class LineString;
class Polygon;
class GeometryCollection;
class MultiPoint;
class MultiLineString;
class MultiPolygon;
class Triangle;
class TriangulatedSurface;
class PolyhedralSurface;
// not SFA, appears in GML/CityGML
class Solid;
// not SFA, appears in GML/CityGML
class MultiSolid;
class Envelope;
class GeometryVisitor;
class ConstGeometryVisitor;
} // namespace SFCGAL
namespace SFCGAL {
const uint32_t wkbSRID = 0x20000000;
const uint32_t wkbM = 0x40000000;
const uint32_t wkbZ = 0x80000000;
enum GeometryType {
// TYPE_GEOMETRY = 0, //abstract
TYPE_POINT = 1,
TYPE_LINESTRING = 2,
TYPE_POLYGON = 3,
TYPE_MULTIPOINT = 4,
TYPE_MULTILINESTRING = 5,
TYPE_MULTIPOLYGON = 6,
TYPE_GEOMETRYCOLLECTION = 7,
// TYPE_CIRCULARSTRING = 8, // not yet supported
// TYPE_COMPOUNDCURVE = 9, // not yet supported
// TYPE_CURVEPOLYGON = 10, // not yet supported
// TYPE_MULTICURVE = 11, //abstract
// TYPE_MULTISURFACE = 12, //abstract
// TYPE_CURVE = 13, //abstract
// TYPE_SURFACE = 14, //abstract
TYPE_POLYHEDRALSURFACE = 15,
TYPE_TRIANGULATEDSURFACE = 16,
TYPE_TRIANGLE = 17,
//-- not official codes
TYPE_SOLID = 101,
TYPE_MULTISOLID = 102
};
typedef enum {
COORDINATE_XY = 0,
COORDINATE_XYZ = 1000,
COORDINATE_XYM = 2000,
COORDINATE_XYZM = 3000
} CoordinateType;
class SFCGAL_API Geometry {
public:
Geometry();
Geometry(const Geometry &) = default;
Geometry &
operator=(const Geometry &other) = default;
virtual ~Geometry() = default;
virtual Geometry *
clone() const = 0;
virtual std::string
geometryType() const = 0;
virtual GeometryType
geometryTypeId() const = 0;
virtual int
dimension() const = 0;
virtual int
coordinateDimension() const = 0;
virtual bool
isEmpty() const = 0;
virtual bool
is3D() const = 0;
virtual bool
isMeasured() const = 0;
// virtual bool isSimple() const = 0 ;
void
forceValidityFlag(bool validity);
bool
hasValidityFlag() const;
std::string
asText(const int &numDecimals = -1) const;
std::string
asWkb(boost::endian::order wkbOrder = boost::endian::order::native,
bool asHex = false) const;
// std::unique_ptr< Geometry > envelope() const = 0 ;
Envelope
envelope() const;
virtual std::unique_ptr<Geometry>
boundary() const;
double
distance(const Geometry &other) const;
double
distance3D(const Geometry &other) const;
//-- helpers
void
round(const long &scale = 1);
auto
almostEqual(const Geometry &, const double tolerance) const -> bool;
virtual size_t
numGeometries() const;
virtual const Geometry &
geometryN(size_t const &n) const;
virtual Geometry &
geometryN(size_t const &n);
template <typename Derived>
inline bool
is() const
{
return dynamic_cast<Derived const *>(this) != NULL;
}
template <typename Derived>
inline const Derived &
as() const
{
BOOST_ASSERT(is<Derived>());
return *static_cast<Derived const *>(this);
}
template <typename Derived>
inline Derived &
as()
{
BOOST_ASSERT(is<Derived>());
return *static_cast<Derived *>(this);
}
virtual void
accept(GeometryVisitor &visitor) = 0;
virtual void
accept(ConstGeometryVisitor &visitor) const = 0;
template <class Archive>
void
serialize(Archive & /*ar*/, const unsigned int /*version*/)
{
}
protected:
bool validityFlag_;
};
SFCGAL_API bool
operator==(const Geometry &, const Geometry &);
} // namespace SFCGAL
#endif