Skip to content
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
87 changes: 47 additions & 40 deletions src/spatialjoin/Sweeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ I32Box Sweeper::add(const I32Polygon& poly, const std::string& gidR,
if (_cfg.de9imFilter.maxInteriorDim() < 2) return {};
if (side && _cfg.de9imFilter.maxRightInteriorDim() < 2) return {};
if (side && _cfg.de9imFilter.minRightBoundaryDim() > 1) return {};
if (_numSides > 1 && !side &&
_cfg.de9imFilter.maxLeftInteriorDim() < 2)
if (_numSides > 1 && !side && _cfg.de9imFilter.maxLeftInteriorDim() < 2)
return {};
if (_numSides > 1 && !side &&
_cfg.de9imFilter.minLeftBoundaryDim() > 1)
if (_numSides > 1 && !side && _cfg.de9imFilter.minLeftBoundaryDim() > 1)
return {};
}

Expand Down Expand Up @@ -329,9 +327,7 @@ I32Box Sweeper::add(const I32Polygon& poly, const std::string& gidR,
auto rightPoint = spoly.getOuter().rawRing().back().p;

std::stringstream str;
_areaCache.writeTo(
{std::move(spoly), gid, subid, boxIds, obb}, str);
;
_areaCache.writeTo({std::move(spoly), gid, subid, boxIds, obb}, str);

size_t estimatedSize = spoly.getOuter().rawRing().size() *
sizeof(util::geo::XSortedTuple<int32_t>);
Expand Down Expand Up @@ -398,14 +394,11 @@ I32Box Sweeper::add(const I32Line& line, const std::string& gidR, size_t subid,
if (side && _cfg.de9imFilter.minRightInteriorDim() > 1) return {};
if (side && _cfg.de9imFilter.minRightBoundaryDim() > 0) return {};
if (side && _cfg.de9imFilter.maxRightInteriorDim() < 1) return {};
if (_numSides > 1 && !side &&
_cfg.de9imFilter.minLeftInteriorDim() > 1)
if (_numSides > 1 && !side && _cfg.de9imFilter.minLeftInteriorDim() > 1)
return {};
if (_numSides > 1 && !side &&
_cfg.de9imFilter.maxLeftInteriorDim() < 1)
if (_numSides > 1 && !side && _cfg.de9imFilter.maxLeftInteriorDim() < 1)
return {};
if (_numSides > 1 && !side &&
_cfg.de9imFilter.minLeftBoundaryDim() > 0)
if (_numSides > 1 && !side && _cfg.de9imFilter.minLeftBoundaryDim() > 0)
return {};
}
if (_cfg.de9imFilter.maxExteriorDim() < 2) return {};
Expand Down Expand Up @@ -564,14 +557,11 @@ I32Box Sweeper::add(const I32Point& point, const std::string& gidR,
if (side && _cfg.de9imFilter.minRightInteriorDim() > 0) return {};
if (side && _cfg.de9imFilter.maxRightInteriorDim() < 0) return {};
if (side && _cfg.de9imFilter.minRightBoundaryDim() >= 0) return {};
if (_numSides > 1 && !side &&
_cfg.de9imFilter.minLeftInteriorDim() > 0)
if (_numSides > 1 && !side && _cfg.de9imFilter.minLeftInteriorDim() > 0)
return {};
if (_numSides > 1 && !side &&
_cfg.de9imFilter.maxLeftInteriorDim() < 0)
if (_numSides > 1 && !side && _cfg.de9imFilter.maxLeftInteriorDim() < 0)
return {};
if (_numSides > 1 && !side &&
_cfg.de9imFilter.minLeftBoundaryDim() >= 0)
if (_numSides > 1 && !side && _cfg.de9imFilter.minLeftBoundaryDim() >= 0)
return {};
}

Expand Down Expand Up @@ -1247,8 +1237,10 @@ void Sweeper::duplicatesToReferences() {
const size_t RBUF_SIZE = 100000;
unsigned char* buf = new unsigned char[sizeof(BoxVal) * RBUF_SIZE];

std::unordered_set<size_t> deleted;
std::unordered_set<size_t> referenced;
std::unordered_set<size_t> deletedLines;
std::unordered_set<size_t> referencedLines;
std::unordered_set<size_t> deletedPolys;
std::unordered_set<size_t> referencedPolys;

log("Removing duplicates...");

Expand Down Expand Up @@ -1288,13 +1280,25 @@ void Sweeper::duplicatesToReferences() {
jj++;

if (cur->out) {
if ((cur->type == POLYGON || cur->type == LINE) &&
deleted.erase(cur->id)) {
// erase it if present, to avoid unnecessary memory consumption
cur->type = DELETED;
updated = true;

if (cur->type == POLYGON) {
if (deletedPolys.erase(cur->id)) {
// erase it if present, to avoid unnecessary memory consumption
cur->type = DELETED;
updated = true;
}
referencedPolys.erase(cur->id);
}
referenced.erase(cur->id);

if (cur->type == LINE) {
if (deletedLines.erase(cur->id)) {
// erase it if present, to avoid unnecessary memory consumption
cur->type = DELETED;
updated = true;
}
referencedLines.erase(cur->id);
}

continue;
}

Expand All @@ -1315,8 +1319,8 @@ void Sweeper::duplicatesToReferences() {
existing->second.second ? -1 : 0);

if (a->geom == b->geom) {
deleted.insert(cur->id);
if (referenced.insert(existing->second.first).second) {
deletedPolys.insert(cur->id);
if (referencedPolys.insert(existing->second.first).second) {
// for the first element referencing this, modify this
// event to the self check of the referenced geom
cur->type = SELF_CHECK_AREA;
Expand Down Expand Up @@ -1344,8 +1348,8 @@ void Sweeper::duplicatesToReferences() {
existing->second.second ? -1 : 0);

if (a->geom == b->geom) {
deleted.insert(cur->id);
if (referenced.insert(existing->second.first).second) {
deletedLines.insert(cur->id);
if (referencedLines.insert(existing->second.first).second) {
// for the first element referencing this, modify this
// event to the self check of the referenced geom
cur->type = SELF_CHECK_LINE;
Expand Down Expand Up @@ -1750,7 +1754,7 @@ util::geo::DE9IMatrix Sweeper::DE9IMCheck(const Line* a, const Line* b,
// cheap equivalence check
if (a->geom == b->geom) {
// equivalent!
return util::geo::M10FF0FFF2;
return util::geo::M1FFF0FFF2;
}

if (_cfg.useBoxIds) {
Expand Down Expand Up @@ -2005,11 +2009,14 @@ void Sweeper::writeDE9IM(size_t t, const std::string& a, size_t aSub,
}
}

if (referersA != _refs.end()) {
const auto& subs = referersA->second.find(aSub);
if (subs != referersA->second.end()) {
for (const auto& idA : subs->second) {
writeDE9IM(t, idA.first, idA.second, b, bSub, de9im);
// no need to check exactly the same direction again
if (a != b || aSub != bSub) {
if (referersA != _refs.end()) {
const auto& subs = referersA->second.find(aSub);
if (subs != referersA->second.end()) {
for (const auto& idA : subs->second) {
writeDE9IM(t, idA.first, idA.second, b, bSub, de9im);
}
}
}
}
Expand Down Expand Up @@ -2107,7 +2114,7 @@ void Sweeper::selfCheck(const std::string& a, size_t subId, GeomType type,
size_t t) {
if (_cfg.computeDE9IM) {
if (type == SELF_CHECK_LINE)
writeDE9IM(t, a, subId, a, subId, util::geo::M10FF0FFF2);
writeDE9IM(t, a, subId, a, subId, util::geo::M1FFF0FFF2);
else if (type == SELF_CHECK_AREA)
writeDE9IM(t, a, subId, a, subId, util::geo::M2FFF1FFF2);
else if (type == SELF_CHECK_POINT)
Expand Down Expand Up @@ -4308,7 +4315,7 @@ size_t Sweeper::foldString(const std::string& s) {
ret |= (s.size() << 56);

return ret;
};
}

// _____________________________________________________________________________
std::string Sweeper::unfoldString(size_t folded) {
Expand All @@ -4323,4 +4330,4 @@ std::string Sweeper::unfoldString(size_t folded) {
}

return ret;
};
}
44 changes: 44 additions & 0 deletions src/spatialjoin/tests/TestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,31 @@ int main(int, char**) {
TEST(res.find("$Umkirch\tFF2F11212\tfreiburg1$") != std::string::npos);
TEST(res.find("$freiburg1\t212FF1FF2\tAltstadt$") != std::string::npos);
}
{
RunStats stats;
auto res = fullRun(TEST_DATASET_DIR "/issue-23", cfg, &stats);
TEST(stats.numReferences, ==, 2);

size_t a = res.find("$lsa\t1FFF0FFF2\tlsb$");
TEST(a != std::string::npos);
// no second time!
TEST(res.find("$lsa\t1FFF0FFF2\tlsb$", a+1) == std::string::npos);

size_t b = res.find("$lsb\t1FFF0FFF2\tlsa$");
TEST(b != std::string::npos);
// no second time!
TEST(res.find("$lsb\t1FFF0FFF2\tlsa$", b+1) == std::string::npos);

size_t c = res.find("$polya\t2FFF1FFF2\tpolyb$");
TEST(c != std::string::npos);
// no second time!
TEST(res.find("$polya\t2FFF1FFF2\tpolyb$", c+1) == std::string::npos);

size_t d = res.find("$polyb\t2FFF1FFF2\tpolya$");
TEST(d != std::string::npos);
// no second time!
TEST(res.find("$polyb\t2FFF1FFF2\tpolya$", d+1) == std::string::npos);
}
{
RunStats stats;
auto res = fullRun(TEST_DATASET_DIR "/references", cfg, &stats);
Expand Down Expand Up @@ -1136,5 +1161,24 @@ int main(int, char**) {
std::regex pattern4("\\$way\\t.*\\tpoint\\$");
TEST(!std::regex_search(res, pattern4));
}

cfg.withinDist = 1000000;
{
RunStats stats;
auto res = fullRun(TEST_DATASET_DIR "/util-issue-13", cfg, &stats);

std::regex pattern1("\\$germany\\t426521\\.\\d*\\tlondon\\$");
TEST(std::regex_search(res, pattern1));
std::regex pattern2("\\$london\\t426521\\.\\d*\\tgermany\\$");
TEST(std::regex_search(res, pattern2));
std::regex pattern3("\\$germany\\t314975\\.\\d*\\teiffel\\$");
TEST(std::regex_search(res, pattern3));
std::regex pattern4("\\$eiffel\\t314975\\.\\d*\\tgermany\\$");
TEST(std::regex_search(res, pattern4));
std::regex pattern5("\\$eiffel\\t340875\\.\\d*\\tlondon\\$");
TEST(std::regex_search(res, pattern5));
std::regex pattern6("\\$london\\t340875\\.\\d*\\teiffel\\$");
TEST(std::regex_search(res, pattern6));
}
}
}
Loading
Loading