SurfaceImpl.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2024 ISciences, LLC
* Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
* Copyright (C) 2005 2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
#pragma once
#include <geos/geom/CoordinateSequenceFilter.h>
#include <geos/geom/Curve.h>
#include <geos/geom/GeometryComponentFilter.h>
#include <geos/geom/GeometryFilter.h>
#include <geos/geom/LinearRing.h>
#include <geos/geom/Surface.h>
#include <geos/util/IllegalArgumentException.h>
namespace geos {
namespace geom {
template<typename RingType>
class SurfaceImpl : public Surface {
protected:
SurfaceImpl(const SurfaceImpl& p)
:
Surface(p),
shell(static_cast<RingType*>(p.shell->clone().release())),
holes(p.holes.size())
{
for (std::size_t i = 0; i < holes.size(); ++i) {
holes[i].reset(static_cast<RingType*>(p.holes[i]->clone().release()));
}
}
SurfaceImpl(std::unique_ptr<RingType>&& newShell,
const GeometryFactory& newFactory) :
Surface(&newFactory),
shell(std::move(newShell))
{
if (shell == nullptr) {
shell.reset(static_cast<RingType*>(createEmptyRing(newFactory).release()));
}
}
SurfaceImpl(std::unique_ptr<RingType>&& newShell,
std::vector<std::unique_ptr<RingType>>&& newHoles,
const GeometryFactory& newFactory) :
Surface(&newFactory),
shell(std::move(newShell)),
holes(std::move(newHoles))
{
if (shell == nullptr) {
shell.reset(static_cast<RingType*>(createEmptyRing(newFactory).release()));
}
if(shell->isEmpty() && hasNonEmptyElements(&holes)) {
throw geos::util::IllegalArgumentException("shell is empty but holes are not");
}
if (hasNullElements(&holes)) {
throw geos::util::IllegalArgumentException("holes must not contain null elements");
}
}
public:
const RingType*
getExteriorRing() const override
{
return shell.get();
}
RingType*
getExteriorRing() override
{
return shell.get();
}
const RingType*
getInteriorRingN(std::size_t n) const override
{
return holes[n].get();
}
RingType*
getInteriorRingN(std::size_t n) override
{
return holes[n].get();
}
size_t getNumInteriorRing() const override
{
return holes.size();
}
std::unique_ptr<RingType>
releaseExteriorRing()
{
return std::move(shell);
}
std::vector<std::unique_ptr<RingType>> releaseInteriorRings()
{
return std::move(holes);
}
protected:
std::unique_ptr<RingType> shell;
std::vector<std::unique_ptr<RingType>> holes;
};
}
}
geos::geom::Geometry::hasNullElements
static bool hasNullElements(const CoordinateSequence *list)
Returns true if the CoordinateSequence contains any null elements.
geos::geom::Geometry::hasNonEmptyElements
static bool hasNonEmptyElements(const std::vector< T > *geometries)
Returns true if the array contains any non-empty Geometrys.
Definition Geometry.h:902
geos::geom::Geometry::clone
std::unique_ptr< Geometry > clone() const
Make a deep-copy of this Geometry.
Definition Geometry.h:212
geos::geom::Surface
Definition Surface.h:27
geos::geom::Surface::getNumInteriorRing
virtual size_t getNumInteriorRing() const =0
Returns number of interior rings (holes).
geos::geom::Surface::getExteriorRing
virtual const Curve * getExteriorRing() const =0
Returns the exterior ring (shell).
geos::geom
Definition Angle.h:26
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38