55 return OGRRingAdapter::borrowed(
geomPtr->getExteriorRing());
65 return std::ranges::views::iota(0,
geomPtr->getNumInteriorRings())
66 | std::ranges::views::transform([
this](
int i){
67 return OGRRingAdapter::borrowed(
geomPtr->getInteriorRing(i));
79 auto deleter =
geomPtr.get_deleter();
96 return OGRRingAdapter::fromCanonicalRing(*
exteriorRing());
104 std::vector<OGRRingAdapter> holes;
105 holes.reserve(
static_cast<size_t>(
geomPtr->getNumInteriorRings()));
106 for(
int i = 0; i <
geomPtr->getNumInteriorRings(); ++i){
107 holes.emplace_back(OGRRingAdapter::fromCanonicalHole(*
geomPtr->getInteriorRing(i)));
113 return geomPtr->getNumInteriorRings() == 0;
121 std::vector<Ring<double>> holes;
122 holes.reserve(
static_cast<size_t>(
geomPtr->getNumInteriorRings()));
123 for(
const auto & hole :
getHoles()){
124 holes.push_back(hole.toNative());
137 auto boundary = borrowedBoundary();
138 auto accumulatedArea = boundary.area();
139 for(
const auto & hole : borrowedHoles()){
140 accumulatedArea -= hole.area();
142 auto accumulatedCentroid = boundary.centroid() * (boundary.area() / accumulatedArea);
143 for(
const auto & hole : borrowedHoles()){
144 accumulatedCentroid = accumulatedCentroid + hole.centroid() * (-hole.area() / accumulatedArea);
146 return accumulatedCentroid;
150 return std::ranges::any_of(borrowedHoles(), [&point](
const auto & hole){
return hole.contains(point);});
154 auto otherBoundary = other.getBoundary();
155 return std::ranges::any_of(borrowedHoles(), [&otherBoundary](
const auto & hole){
return hole.contains(otherBoundary);});
159 if(borrowedBoundary().
intersects(linearFeature))
161 return std::ranges::any_of(borrowedHoles(), [&linearFeature](
const auto & hole){
return hole.intersects(linearFeature);});
165 std::unordered_set<Vec2DReal> intersectionSet;
166 for(
const auto & point : borrowedBoundary().
intersections(linearFeature)){
167 intersectionSet.insert(point);
169 for(
const auto & hole : borrowedHoles()){
170 for(
const auto & point : hole.intersections(linearFeature)){
171 intersectionSet.insert(point);
174 return intersectionSet;
178 if(not this->
aaBB().overlap(other.aaBB()))
182 auto otherBoundary = other.getBoundary();
183 if(borrowedBoundary().
crosses(otherBoundary))
185 return std::ranges::any_of(borrowedHoles(), [&otherBoundary](
const auto & hole){
return hole.crosses(otherBoundary);});
189 if(not this->
aaBB().overlap(other.aaBB()))
193 auto otherBoundary = other.getBoundary();
194 if(borrowedBoundary().
touches(otherBoundary))
196 return std::ranges::any_of(borrowedHoles(), [&otherBoundary](
const auto & hole){
198 return hole.contains(otherBoundary) && std::ranges::any_of(otherBoundary.getPoints(),[&hole](
const auto & p){
199 return hole.isOnBoundary(p);
212 if(this->
aaBB().overlap(other.aaBB())){
218 auto otherBoundary = other.getBoundary();
219 for(
const auto & hole : borrowedHoles()){
220 if(hole.contains(otherBoundary)){
224 return borrowedBoundary().
distance(otherBoundary);
238static_assert(IPolygon<OGRPolygonAdapter>);
239static_assert(Shape<OGRPolygonAdapter>);
OGRUniquePtr< OGRPolygon > geomPtr
Definition OGRAdapterBase.hpp:85
Adapter for an OGRGeometry of statically unknown type, as handed out by a data source.
Definition OGRGeometryAdapter.hpp:83
IMultiPolygon implementation backed by an OGRMultiPolygon.
Definition OGRMultiPolygonAdapter.hpp:19
IPolygon implementation backed by an OGRPolygon.
Definition OGRPolygonAdapter.hpp:22
bool isSimple() const
Definition OGRPolygonAdapter.hpp:112
OGRRingAdapter getBoundary() const
Definition OGRPolygonAdapter.hpp:95
OGRPolygonAdapter(IPolygon auto const &polygon)
Definition OGRPolygonAdapter.hpp:90
Vec2DReal centroid() const
Area weighted centroid of the polygon, obtained by decomposition into its rings.
Definition OGRPolygonAdapter.hpp:136
bool contains(const IPoint auto &point) const
Definition OGRPolygonalAdapter.hpp:178
double distance(const IPolygon auto &other) const
Distance between the two polygons.
Definition OGRPolygonAdapter.hpp:209
OGRPolygonAdapter(OGRUniquePtr< OGRPolygon > &&polygonPtr)
Definition OGRPolygonAdapter.hpp:88
static constexpr GeometryType type
Definition OGRPolygonAdapter.hpp:86
Polygon< double > toNative() const
Copy the polygon out into a fishnet Polygon, which precomputes its segments.
Definition OGRPolygonAdapter.hpp:120
double numeric_type
Definition OGRPolygonAdapter.hpp:85
bool crosses(const IPolygon auto &other) const
Definition OGRPolygonAdapter.hpp:177
double distance(const OGRPolygonAdapter &other) const
Distance between two OGR backed polygons.
Definition OGRPolygonAdapter.hpp:234
bool intersects(const LinearGeometry auto &linearFeature) const
Definition OGRPolygonAdapter.hpp:158
bool containsInHole(const IPolygon auto &other) const
Definition OGRPolygonAdapter.hpp:153
std::unordered_set< Vec2DReal > intersections(const LinearGeometry auto &linearFeature) const
Definition OGRPolygonAdapter.hpp:164
bool touches(const IPolygon auto &other) const
Definition OGRPolygonAdapter.hpp:188
bool containsInHole(const IPoint auto &point) const
Definition OGRPolygonAdapter.hpp:149
std::vector< OGRRingAdapter > getHoles() const
Definition OGRPolygonAdapter.hpp:103
Common base of the OGR backed adapters which enclose an area.
Definition OGRPolygonalAdapter.hpp:24
const OGRLinearRing * exteriorRing() const noexcept
Definition OGRPolygonalAdapter.hpp:116
bool contains(const IPoint auto &point) const
Definition OGRPolygonalAdapter.hpp:178
static OGRUniquePtr< OGRPolygon > toOGRPolygon(const IRing auto &ring)
Copy an arbitrary IRing into an OGRPolygon, ready to be used with GEOS.
Definition OGRPolygonalAdapter.hpp:44
Rectangle< double > aaBB() const
Definition OGRPolygonalAdapter.hpp:151
IRing implementation backed by an OGRPolygon holding nothing but an exterior ring.
Definition OGRRingAdapter.hpp:30
double distance(const IRing auto &other) const
Definition OGRRingAdapter.hpp:232
std::unordered_set< Vec2DReal > intersections(const LinearGeometry auto &linearFeature) const
Definition OGRRingAdapter.hpp:205
Polygon implementation A Polygon consist of a boundary (IRing) and zero or more holes (IRing)
Definition Polygon.hpp:14
Implementation of a two-dimensional vector.
Definition Vec2D.hpp:16
Interface for a point.
Definition IPoint.hpp:92
Interface for a polygon A polygon is a two-dimensional shape defined by a boundary and zero or more h...
Definition IPolygon.hpp:98
Definition IGeometry.hpp:13
Definition CollectionConcepts.hpp:27
Definition BoundingBoxWrapper.hpp:5
std::unique_ptr< T, __impl::OGRGeometryDeleter > OGRUniquePtr
Definition OGRAdapterBase.hpp:48
GeometryType
Definition GeometryBase.hpp:6
static fishnet::math::DEFAULT_FLOATING_POINT shapeDistance(Shape auto const &lhs, Shape auto const &rhs, util::BiFunction< Vec2DReal, Vec2DReal, fishnet::math::DEFAULT_FLOATING_POINT > auto const &distanceFunction) noexcept
Compute the distance between two shapes, with custom distance function.
Definition PolygonDistance.hpp:465
Tag for a polygon which is known to be in canonical form already.
Definition OGRPolygonalAdapter.hpp:125