Skip to content

Commit

Permalink
experimentally use the covers functionality of util, existing contain…
Browse files Browse the repository at this point in the history
…s() and intersects() should not be affected by these changes
  • Loading branch information
patrickbr committed Apr 12, 2024
1 parent ad73b20 commit 28fdec0
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 67 deletions.
8 changes: 4 additions & 4 deletions src/spatialjoin/BoxIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ inline BoxIdList getBoxIds(const util::geo::I32XSortedLine& line,

const util::geo::I32XSortedPolygon boxPoly{util::geo::I32Polygon(box)};

if (util::geo::intersectsContains(line, envelope, boxPoly, box).first) {
if (std::get<0>(util::geo::intersectsContainsCovered(line, envelope, boxPoly, box))) {
int32_t newId = y * NUM_GRID_CELLS + x + 1;
if (!boxIds.empty() && boxIds.back().second < 254 &&
boxIds.back().first + boxIds.back().second == newId - 1) {
Expand Down Expand Up @@ -107,10 +107,10 @@ inline void getBoxIds(

const util::geo::I32XSortedPolygon boxPoly{util::geo::I32Polygon(box)};

auto check = util::geo::intersectsContains(
auto check = util::geo::intersectsContainsCovered(
boxPoly, box, util::geo::area(box), poly, envelope, area);

if (check.second) {
if (std::get<1>(check)) {
// we can insert all at once
for (int32_t ly = y; ly < y + localYHeight; ly++) {
int a = 1;
Expand All @@ -122,7 +122,7 @@ inline void getBoxIds(
a++;
}
}
} else if (check.first) {
} else if (std::get<0>(check)) {
// compute cutout if requested
// osm2rdf::geometry::Area intersection;
// if (cutouts) {
Expand Down
72 changes: 42 additions & 30 deletions src/spatialjoin/SpatialJoinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,37 @@ static const char* AUTHORS = "Patrick Brosi <[email protected]>";
// _____________________________________________________________________________
void printHelp(int argc, char** argv) {
UNUSED(argc);
std::cout << "\n"
<< "(C) 2023-" << YEAR << " " << COPY << "\n"
<< "Authors: " << AUTHORS << "\n\n"
<< "Usage: " << argv[0] << " [--help] [-h] <input>\n\n"
<< "Allowed options:\n\n"
<< std::setfill(' ') << std::left << "General:\n"
<< std::setw(41) << " -h [ --help ]"
<< "show this help message\n"
<< std::setw(41) << " -o [ --output ] (default: '')"
<< "output file, empty (default) prints to stdout\n"
<< std::setw(41) << " -c [ --cache ] (default: '.')"
<< "cache directory for intermediate files\n"
<< std::setw(41) << " -C"
<< "don't parse input, re-use intermediate cache files\n"
<< std::setw(41) << " --prefix (default: '')"
<< "prefix added at the beginning of every relation\n"
<< std::setw(41) << " --intersects (default: ' intersects ')"
<< "separator between intersecting geometry IDs\n"
<< std::setw(41) << " --contains (default: ' contains ')"
<< "separator between containing geometry IDs\n"
<< std::setw(41) << " --suffix (default: '\\n')"
<< "suffix added at the beginning of every relation\n\n"
<< std::setfill(' ') << std::left << "Geometric computation:\n"
<< std::setw(41) << " --no-box-ids"
<< "disable box id criteria for contains/intersect computation\n"
<< std::setw(41) << " --no-surface-area"
<< "disable surface area criteria for polygon contains\n"
<< std::endl;
std::cout
<< "\n"
<< "(C) 2023-" << YEAR << " " << COPY << "\n"
<< "Authors: " << AUTHORS << "\n\n"
<< "Usage: " << argv[0] << " [--help] [-h] <input>\n\n"
<< "Allowed options:\n\n"
<< std::setfill(' ') << std::left << "General:\n"
<< std::setw(41) << " -h [ --help ]"
<< "show this help message\n"
<< std::setw(41) << " -o [ --output ] (default: '')"
<< "output file, empty (default) prints to stdout\n"
<< std::setw(41) << " -c [ --cache ] (default: '.')"
<< "cache directory for intermediate files\n"
<< std::setw(41) << " -C"
<< "don't parse input, re-use intermediate cache files\n"
<< std::setw(41) << " --prefix (default: '')"
<< "prefix added at the beginning of every relation\n"
<< std::setw(41) << " --intersects (default: ' intersects ')"
<< "separator between intersecting geometry IDs\n"
<< std::setw(41) << " --contains (default: ' contains ')"
<< "separator between containing geometry IDs\n"
<< std::setw(41) << " --covers (default: ' covers ')"
<< "separator between covering geometry IDs\n"
<< std::setw(41) << " --suffix (default: '\\n')"
<< "suffix added at the beginning of every relation\n\n"
<< std::setfill(' ') << std::left << "Geometric computation:\n"
<< std::setw(41) << " --no-box-ids"
<< "disable box id criteria for contains/covers/intersect computation\n"
<< std::setw(41) << " --no-surface-area"
<< "disable surface area criteria for polygon contains/covers\n"
<< std::endl;
}

// _____________________________________________________________________________
Expand Down Expand Up @@ -215,6 +218,7 @@ int main(int argc, char** argv) {
std::string cache = ".";
std::string contains = " contains ";
std::string intersects = " intersects ";
std::string covers = " covers ";
std::string suffix = "\n";

bool useBoxIds = true;
Expand Down Expand Up @@ -249,6 +253,9 @@ int main(int argc, char** argv) {
if (cur == "--cache" || cur == "-c") {
state = 6;
}
if (cur == "--covers") {
state = 7;
}
if (cur == "--no-box-ids") {
useBoxIds = false;
}
Expand Down Expand Up @@ -280,6 +287,10 @@ int main(int argc, char** argv) {
cache = cur;
state = 0;
break;
case 7:
covers = cur;
state = 0;
break;
}
}

Expand All @@ -291,8 +302,9 @@ int main(int argc, char** argv) {

size_t NUM_THREADS = std::thread::hardware_concurrency();

Sweeper sweeper({NUM_THREADS, prefix, intersects, contains, suffix, useBoxIds, useArea}, useCache,
cache, output);
Sweeper sweeper({NUM_THREADS, prefix, intersects, contains, covers, suffix,
useBoxIds, useArea},
useCache, cache, output);

size_t gid = 0;

Expand Down
Loading

0 comments on commit 28fdec0

Please sign in to comment.