Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization to prepared polygon intersection #690

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions include/geos/noding/SegmentStringUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#pragma once

#include <geos/noding/BasicSegmentString.h>
#include <geos/noding/NodedSegmentString.h>
#include <geos/geom/LineString.h>
#include <geos/geom/CoordinateSequence.h>
Expand Down Expand Up @@ -53,15 +54,9 @@ class SegmentStringUtil {
geom::LineString::ConstVect lines;
geom::util::LinearComponentExtracter::getLines(*g, lines);

for(std::size_t i = 0, n = lines.size(); i < n; i++) {
geom::LineString* line = (geom::LineString*)(lines[i]);

// we take ownership of the coordinates here
// TODO: check if this can be optimized by getting
// the internal CS.
auto pts = line->getCoordinates();

segStr.push_back(new NodedSegmentString(pts.release(), g));
for(const geom::LineString* line : lines) {
auto pts = line->getCoordinatesRO();
segStr.push_back(new BasicSegmentString(const_cast<geom::CoordinateSequence*>(pts), g));
}
}

Expand Down
21 changes: 8 additions & 13 deletions src/algorithm/locate/SimplePointInAreaLocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ namespace locate { // geos.algorithm
geom::Location
SimplePointInAreaLocator::locate(const Coordinate& p, const Geometry* geom)
{
if(geom->isEmpty()) {
return Location::EXTERIOR;
}

/*
* Do a fast check against the geometry envelope first
*/
if (! geom->getEnvelopeInternal()->intersects(p))
return Location::EXTERIOR;

return locateInGeometry(p, geom);
}

Expand All @@ -62,16 +52,21 @@ SimplePointInAreaLocator::isContained(const Coordinate& p, const Geometry* geom)
geom::Location
SimplePointInAreaLocator::locateInGeometry(const Coordinate& p, const Geometry* geom)
{
/*
* Do a fast check against the geometry envelope first
*/
if (! geom->getEnvelopeInternal()->intersects(p))
return Location::EXTERIOR;

if (geom->getDimension() < 2) {
return Location::EXTERIOR;
}

if (geom->getNumGeometries() == 1) {
auto poly = dynamic_cast<const Polygon*>(geom->getGeometryN(0));
if (poly) {
if (geom->getGeometryTypeId() == GEOS_POLYGON) {
auto poly = static_cast<const Polygon*>(geom);
return locatePointInPolygon(p, poly);
}
// Else it is a collection with a single element. Will be handled below.
}
for (std::size_t i = 0; i < geom->getNumGeometries(); i++) {
const Geometry* gi = geom->getGeometryN(i);
Expand Down