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

Use GEOS threadsafe functions (_r), add call to GEOSWKTReader_destroy_r #187

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
14 changes: 8 additions & 6 deletions src/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,8 @@ bool Surface::validate_projected_ring(Polygon &pgn, std::string id)

bool Surface::validate_polygon(std::vector<Polygon> &lsRings, std::string polygonid)
{
initGEOS(NULL, NULL);
// Use the _r geos functions to make it thread-safe
auto geos_ctx = GEOS_init_r();
//-- check the orientation of the rings: oring != irings
//-- we don't care about CCW or CW at this point, just opposite is important
//-- GEOS doesn't do its job, so we have to do it here. Shame on you GEOS.
Expand Down Expand Up @@ -785,10 +786,10 @@ bool Surface::validate_polygon(std::vector<Polygon> &lsRings, std::string polygo
}
wkt << ")";
GEOSWKTReader* r;
r = GEOSWKTReader_create();
r = GEOSWKTReader_create_r(geos_ctx);
GEOSGeometry* mygeom;
mygeom = GEOSWKTReader_read(r, wkt.str().c_str());
string reason = (string)GEOSisValidReason(mygeom);
mygeom = GEOSWKTReader_read_r(geos_ctx, r, wkt.str().c_str());
string reason = (string)GEOSisValidReason_r(geos_ctx, mygeom);
if (reason.find("Valid Geometry") == string::npos)
{
isvalid = false;
Expand All @@ -805,8 +806,9 @@ bool Surface::validate_polygon(std::vector<Polygon> &lsRings, std::string polygo
else
this->add_error(999, polygonid, reason.c_str());
}
GEOSGeom_destroy( mygeom );
finishGEOS();
GEOSWKTReader_destroy_r(geos_ctx, r);
GEOSGeom_destroy_r(geos_ctx, mygeom );
GEOS_finish_r(geos_ctx);
return isvalid;
}

Expand Down
Loading