Skip to content

Commit

Permalink
Add RelateNG and RelateNGTest
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Jul 28, 2024
1 parent 5b8e267 commit 4f213c1
Show file tree
Hide file tree
Showing 19 changed files with 2,083 additions and 190 deletions.
7 changes: 0 additions & 7 deletions include/geos/geom/GeometryCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@ class GEOS_DLL GeometryCollection : public Geometry {
return &envelope;
}

/**
* \brief
* Recurse into collection and populate vector with just the
* simple non-collection components of the collection.
*/
void getAllGeometries(std::vector<const Geometry*>& geoms) const;

protected:

GeometryCollection(const GeometryCollection& gc);
Expand Down
92 changes: 92 additions & 0 deletions include/geos/geom/util/GeometryLister.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2011 Sandro Santilli <[email protected]>
* Copyright (C) 2001-2002 Vivid Solutions Inc.
* Copyright (C) 2006 Refractions Research 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.
*
**********************************************************************
*
* Last port: geom/util/GeometryExtracter.java r320 (JTS-1.12)
*
**********************************************************************/

#pragma once

#include <geos/export.h>
#include <geos/geom/GeometryFilter.h>
#include <geos/geom/GeometryCollection.h>
#include <vector>

namespace geos {
namespace geom { // geos.geom
namespace util { // geos.geom.util

/**
* Extracts all the components of a collection, or just echoes back a
* pointers to singletons.
*/
class GEOS_DLL GeometryLister {

public:

/**
* Extracts the components from a {@link Geometry}
* and adds them to the provided container.
*
* Useful for iterating over components of a collection.
*
* @param geom the geometry from which to extract
* @param lst the list to add the extracted elements to
*/
static void
list(const Geometry* geom, std::vector<const Geometry*>& lst)
{
if(geom->isCollection()) {
GeometryLister::Lister lister(lst);
geom->apply_ro(&lister);
}
else {
lst.push_back(geom);
}
}

private:

struct Lister : public GeometryFilter {

/**
* Constructs a filter with a list in which to store the elements found.
*
* @param comps the container to extract into (will push_back to it)
*/
Lister(std::vector<const Geometry*>& p_geoms) : geoms(p_geoms) {}

std::vector<const Geometry*>& geoms;

void
filter_ro(const Geometry* geom) override
{
if(!geom->isCollection()) {
geoms.push_back(geom);
}
}

// // Declare type as noncopyable
// Lister(const Lister& other);
// Lister& operator=(const Lister& rhs);
};
};


} // namespace geos.geom.util
} // namespace geos.geom
} // namespace geos

4 changes: 2 additions & 2 deletions include/geos/operation/relateng/EdgeSegmentIntersector.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class GEOS_DLL EdgeSegmentIntersector : public SegmentIntersector {

public:

EdgeSegmentIntersector(TopologyComputer& p_topoBuilder)
: topoComputer(p_topoBuilder)
EdgeSegmentIntersector(TopologyComputer& p_topoComputer)
: topoComputer(p_topoComputer)
{};

void processIntersections(
Expand Down
8 changes: 4 additions & 4 deletions include/geos/operation/relateng/EdgeSetIntersector.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ class GEOS_DLL EdgeSetIntersector {

// Methods

void addToIndex(std::unique_ptr<RelateSegmentString>& segStr);
void addToIndex(const SegmentString* segStr);

void addEdges(std::vector<std::unique_ptr<RelateSegmentString>>& segStrings);
void addEdges(std::vector<const SegmentString*>& segStrings);


public:

EdgeSetIntersector(
std::vector<std::unique_ptr<RelateSegmentString>>& edgesA,
std::vector<std::unique_ptr<RelateSegmentString>>& edgesB,
std::vector<const SegmentString*>& edgesA,
std::vector<const SegmentString*>& edgesB,
const Envelope* env)
: envelope(env)
, idCounter(0)
Expand Down
6 changes: 3 additions & 3 deletions include/geos/operation/relateng/IntersectionMatrixPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ class GEOS_DLL IntersectionMatrixPattern {
* A DE-9IM pattern to detect whether two polygonal geometries are adjacent along
* an edge, but do not overlap.
*/
static constexpr std::string ADJACENT = "F***1****";
static constexpr const char* ADJACENT = "F***1****";

/**
* A DE-9IM pattern to detect a geometry which properly contains another
* geometry (i.e. which lies entirely in the interior of the first geometry).
*/
static constexpr std::string CONTAINS_PROPERLY = "T**FF*FF*";
static constexpr const char* CONTAINS_PROPERLY = "T**FF*FF*";

/**
* A DE-9IM pattern to detect if two geometries intersect in their interiors.
* This can be used to determine if a polygonal coverage contains any overlaps
* (although not whether they are correctly noded).
*/
static constexpr std::string INTERIOR_INTERSECTS = "T********";
static constexpr const char* INTERIOR_INTERSECTS = "T********";


};
Expand Down
4 changes: 2 additions & 2 deletions include/geos/operation/relateng/NodeSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <vector>
#include <memory>
// #include <geos/operation/relateng/NodeSection.h>
#include <geos/operation/relateng/NodeSection.h>
#include <geos/export.h>


Expand All @@ -26,7 +26,7 @@ namespace geos {
namespace operation {
namespace relateng {
class RelateNode;
class NodeSection;
// class NodeSection;
}
}
namespace geom {
Expand Down
40 changes: 29 additions & 11 deletions include/geos/operation/relateng/RelateGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <geos/geom/Dimension.h>
#include <geos/geom/Location.h>
#include <geos/operation/relateng/RelatePointLocator.h>
#include <geos/operation/relateng/RelateSegmentString.h>
#include <geos/export.h>


#include <string>
#include <sstream>

Expand All @@ -38,15 +38,14 @@ namespace geom {
class MultiPolygon;
class Point;
}
namespace operation {
namespace relateng {
class RelateSegmentString;
}
namespace noding {
class SegmentString;
}
}


using geos::algorithm::BoundaryNodeRule;
using geos::noding::SegmentString;
using namespace geos::geom;


Expand Down Expand Up @@ -76,6 +75,12 @@ class GEOS_DLL RelateGeometry {
bool hasLines = false;
bool hasAreas = false;

/*
* Memory contexts for lower level allocations
*/
std::vector<std::unique_ptr<const RelateSegmentString>> segStringStore;
std::vector<std::unique_ptr<CoordinateSequence>> csStore;


// Methods

Expand All @@ -99,17 +104,22 @@ class GEOS_DLL RelateGeometry {
void extractSegmentStringsFromAtomic(bool isA,
const Geometry* geom, const MultiPolygon* parentPolygonal,
const Envelope* env,
std::vector<std::unique_ptr<RelateSegmentString>>& segStrings);
std::vector<const SegmentString*>& segStrings);

void extractRingToSegmentString(bool isA,
const LinearRing* ring, int ringId, const Envelope* env,
const Geometry* parentPoly,
std::vector<std::unique_ptr<RelateSegmentString>>& segStrings);
std::vector<const SegmentString*>& segStrings);

void extractSegmentStrings(bool isA,
const Envelope* env, const Geometry* geom,
std::vector<std::unique_ptr<RelateSegmentString>>& segStrings);
std::vector<const SegmentString*>& segStrings);

const CoordinateSequence* orientAndRemoveRepeated(
const CoordinateSequence* cs, bool orientCW);

const CoordinateSequence* removeRepeated(
const CoordinateSequence* cs);

public:

Expand Down Expand Up @@ -191,20 +201,28 @@ class GEOS_DLL RelateGeometry {
std::vector<const Point*> getEffectivePoints();

/**
* Extract RelateSegmentStrings from the geometry which
* Extract RSegmentStrings from the geometry which
* intersect a given envelope.
* If the envelope is null all edges are extracted.
* @param geomA
*
* @param env the envelope to extract around (may be null)
* @return a list of RelateSegmentStrings
* @return a list of SegmentStrings
*/
std::vector<std::unique_ptr<RelateSegmentString>> extractSegmentStrings(bool isA, const Envelope* env);
std::vector<const SegmentString*> extractSegmentStrings(bool isA, const Envelope* env);

std::string toString() const;

friend std::ostream& operator<<(std::ostream& os, const RelateGeometry& rg);

/**
* Disable copy construction and assignment. Needed to make this
* class compile under MSVC. (See https://stackoverflow.com/q/29565299)
* Classes with members that are vector<> of unique_ptr<> need this.
*/
RelateGeometry(const RelateGeometry&) = delete;
RelateGeometry& operator=(const RelateGeometry&) = delete;

};

} // namespace geos.operation.relateng
Expand Down
Loading

0 comments on commit 4f213c1

Please sign in to comment.