| 15 | namespace generative::noding { |
| 16 | |
| 17 | class SegmentStringExtractor : public geos::geom::GeometryComponentFilter |
| 18 | { |
| 19 | public: |
| 20 | SegmentStringExtractor(geos::noding::SegmentString::NonConstVect& to) : m_to(to) {} |
| 21 | SegmentStringExtractor(const SegmentStringExtractor&) = delete; |
| 22 | SegmentStringExtractor& operator=(const SegmentStringExtractor&) = delete; |
| 23 | |
| 24 | void filter_ro(const geos::geom::Geometry* geometry) override |
| 25 | { |
| 26 | switch (geometry->getGeometryTypeId()) |
| 27 | { |
| 28 | case geos::geom::GeometryTypeId::GEOS_POINT: |
| 29 | { |
| 30 | // HACK: This is gross and dirty, and has the potential to explode in future GEOS |
| 31 | // releases. Single-coordinate segment strings (which isn't _really_ a **segment** |
| 32 | // string at all) don't get noded. |
| 33 | // |
| 34 | // So bold facedly lie to the noder, by treating POINTs as a "segment" with two |
| 35 | // duplicate coordinates. |
| 36 | auto coords = geometry->getCoordinates(); |
| 37 | coords->add(coords->getAt(0), true); |
| 38 | geos::noding::SegmentString* segment_string = |
| 39 | new geos::noding::NodedSegmentString(coords.release(), false, false, nullptr); |
| 40 | m_to.push_back(segment_string); |
| 41 | break; |
| 42 | } |
| 43 | case geos::geom::GeometryTypeId::GEOS_LINESTRING: |
| 44 | case geos::geom::GeometryTypeId::GEOS_LINEARRING: |
| 45 | { |
| 46 | auto coords = geometry->getCoordinates(); |
| 47 | geos::noding::SegmentString* segment_string = |
| 48 | new geos::noding::NodedSegmentString(coords.release(), false, false, nullptr); |
| 49 | m_to.push_back(segment_string); |
| 50 | break; |
| 51 | } |
| 52 | // need to get the interior holes too |
| 53 | case geos::geom::GeometryTypeId::GEOS_POLYGON: |
| 54 | { |
| 55 | const auto* poly = dynamic_cast<const geos::geom::Polygon*>(geometry); |
| 56 | if (poly != nullptr) |
| 57 | { |
| 58 | const auto* exterior = poly->getExteriorRing(); |
| 59 | this->filter_ro(exterior); |
| 60 | |
| 61 | for (size_t i = 0; i < poly->getNumInteriorRing(); i++) |
| 62 | { |
| 63 | const auto* interior = poly->getInteriorRingN(i); |
| 64 | this->filter_ro(interior); |
| 65 | } |
| 66 | } |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | // Intentional fallthrough |
| 71 | case geos::geom::GeometryTypeId::GEOS_CIRCULARSTRING: |
| 72 | case geos::geom::GeometryTypeId::GEOS_COMPOUNDCURVE: |
| 73 | case geos::geom::GeometryTypeId::GEOS_MULTICURVE: |
| 74 | case geos::geom::GeometryTypeId::GEOS_MULTISURFACE: |
nothing calls this directly
no outgoing calls
no test coverage detected