Skip to content

Commit

Permalink
use new covers, implement point/point and point/line comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbr committed Apr 16, 2024
1 parent 28fdec0 commit 0af1ac8
Show file tree
Hide file tree
Showing 9 changed files with 464 additions and 83 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ find_package(BZip2 REQUIRED)
# export compile commands to tools like clang
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Compiler-specific C++11 activation.
# Compiler-specific C++14 activation.
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
Expand Down
7 changes: 4 additions & 3 deletions src/spatialjoin/BoxIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ inline BoxIdList getBoxIds(const util::geo::I32XSortedLine& line,

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

if (std::get<0>(util::geo::intersectsContainsCovered(line, envelope, boxPoly, box))) {
if (std::get<0>(util::geo::intersectsContainsCovers(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,7 +108,7 @@ inline void getBoxIds(

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

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

if (std::get<1>(check)) {
Expand Down Expand Up @@ -219,7 +220,7 @@ inline BoxIdList packBoxIds(const BoxIdList& ids) {

// ____________________________________________________________________________
inline std::pair<int32_t, int32_t> boxIdIsect(const BoxIdList& idsA,
const BoxIdList& idsB) {
const BoxIdList& idsB) {
size_t fullContained = 0;
size_t partContained = 0;

Expand Down
7 changes: 7 additions & 0 deletions src/spatialjoin/GeometryCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ sj::Line sj::GeometryCache<sj::Line>::getFromDisk(size_t off,
// sub id
_geomsFReads[tid].read(reinterpret_cast<char*>(&ret.subId), sizeof(uint16_t));

// length
_geomsFReads[tid].read(reinterpret_cast<char*>(&ret.length), sizeof(double));

// boxIds
uint32_t numBoxIds;
_geomsFReads[tid].read(reinterpret_cast<char*>(&numBoxIds), sizeof(uint32_t));
Expand Down Expand Up @@ -270,6 +273,10 @@ size_t sj::GeometryCache<sj::Line>::add(const sj::Line& val) {
_geomsF.write(reinterpret_cast<const char*>(&val.subId), sizeof(uint16_t));
_geomsOffset += sizeof(uint16_t);

// length
_geomsF.write(reinterpret_cast<const char*>(&val.length), sizeof(double));
_geomsOffset += sizeof(double);

// boxIds
uint32_t size = val.boxIds.size();
_geomsF.write(reinterpret_cast<const char*>(&size), sizeof(uint32_t));
Expand Down
3 changes: 3 additions & 0 deletions src/spatialjoin/GeometryCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ struct Line {
// sub id (for multilines)
uint16_t subId;

// length
double length;

// box ids
std::vector<sj::boxids::BoxId> boxIds;

Expand Down
10 changes: 6 additions & 4 deletions src/spatialjoin/SpatialJoinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using sj::Sweeper;
using util::geo::DLine;
using util::geo::DPoint;
using util::geo::I32Line;
using util::geo::I32MultiLine;
using util::geo::I32MultiPolygon;
using util::geo::I32Point;
using util::geo::I32Polygon;
Expand Down Expand Up @@ -132,15 +133,16 @@ void parse(const char* c, size_t size, std::string& dangling, size_t* gid,
}
} else if ((p = dangling.rfind("MULTILINESTRING(", start)) !=
std::string::npos) {
I32MultiLine ml;
p += 16;
size_t i = 0;
while ((p = dangling.find("(", p + 1)) != std::string::npos) {
while ((p = dangling.find("(", p)) != std::string::npos) {
const auto& line = parseLineString(dangling, p + 1);
if (line.size() != 0) {
// TODO, i is the line number
ml.push_back(line);
}
i++;
p += 1;
}
idx.add(ml, id);
} else if ((p = dangling.rfind("POLYGON(", start)) != std::string::npos) {
p += 7;
size_t i = 0;
Expand Down
33 changes: 27 additions & 6 deletions src/spatialjoin/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,52 @@ namespace sj {
struct Stats {
uint64_t timeGeoCacheRetrievalArea = 0;
uint64_t timeGeoCacheRetrievalLine = 0;
uint64_t timeGeoCacheRetrievalPoint = 0;

uint64_t timeWrite = 0;

uint64_t timeBoxIdIsectAreaArea = 0;
uint64_t timeBoxIdIsectAreaLine = 0;
uint64_t timeBoxIdIsectAreaPoint = 0;
uint64_t timeBoxIdIsectLineLine = 0;
uint64_t timeBoxIdIsectLinePoint = 0;

uint64_t timeFullGeoCheckAreaArea = 0;
uint64_t timeFullGeoCheckAreaLine = 0;
uint64_t timeFullGeoCheckAreaPoint = 0;
uint64_t timeFullGeoCheckLineLine = 0;
uint64_t timeFullGeoCheckLinePoint = 0;

size_t fullGeoChecksAreaArea = 0;
size_t fullGeoChecksAreaLine = 0;
size_t fullGeoChecksAreaPoint = 0;
size_t fullGeoChecksLineLine = 0;
size_t fullGeoChecksLinePoint = 0;

std::string toString();
};

inline std::string Stats::toString() {
double sum =
double(timeGeoCacheRetrievalArea + timeGeoCacheRetrievalLine + timeWrite +
double(timeGeoCacheRetrievalArea + timeGeoCacheRetrievalLine + timeGeoCacheRetrievalPoint + timeWrite +
timeBoxIdIsectAreaArea + timeBoxIdIsectAreaLine +
timeBoxIdIsectAreaPoint + timeBoxIdIsectLineLine +
timeBoxIdIsectAreaPoint + timeBoxIdIsectLineLine +timeBoxIdIsectLinePoint +
timeFullGeoCheckAreaArea + timeFullGeoCheckAreaLine +
timeFullGeoCheckAreaPoint + timeFullGeoCheckLineLine) /
timeFullGeoCheckAreaPoint + timeFullGeoCheckLineLine + timeFullGeoCheckLinePoint) /
1000000000.0;

std::stringstream ss;

double t = double(timeGeoCacheRetrievalArea) / 1000000000.0;
ss << "time for geo cache retrievel of AREAS: " << t << " s ("
ss << "time for geo cache retrieval of AREAS: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeGeoCacheRetrievalLine) / 1000000000.0;
ss << "time for geo cache retrievel of LINES: " << t << " s ("
ss << "time for geo cache retrieval of LINES: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeGeoCacheRetrievalPoint) / 1000000000.0;
ss << "time for geo cache retrieval of POINTS: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeBoxIdIsectAreaArea) / 1000000000.0;
Expand All @@ -64,6 +72,10 @@ inline std::string Stats::toString() {
ss << "time for box ID intersections LINE/LINE: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeBoxIdIsectLinePoint) / 1000000000.0;
ss << "time for box ID intersections LINE/POINT: " << t << " s ("
<< ((t / sum) * 100.0) << "%)\n";

t = double(timeFullGeoCheckAreaArea) / 1000000000.0;
ss << "time for " << fullGeoChecksAreaArea
<< " full geom checks AREA/AREA: " << t << " s (" << ((t / sum) * 100.0)
Expand All @@ -84,6 +96,11 @@ inline std::string Stats::toString() {
<< " full geom checks LINE/LINE: " << t << " s (" << ((t / sum) * 100.0)
<< "%)\n";

t = double(timeFullGeoCheckLinePoint) / 1000000000.0;
ss << "time for " << fullGeoChecksLinePoint
<< " full geom checks LINE/Point: " << t << " s (" << ((t / sum) * 100.0)
<< "%)\n";

t = double(timeWrite) / 1000000000.0;
ss << "time for output writing: " << t << " s (" << ((t / sum) * 100.0)
<< "%)\n";
Expand All @@ -95,19 +112,23 @@ inline std::string Stats::toString() {
inline Stats operator+(const Stats& a, const Stats& b) {
return Stats{a.timeGeoCacheRetrievalArea + b.timeGeoCacheRetrievalArea,
a.timeGeoCacheRetrievalLine + b.timeGeoCacheRetrievalLine,
a.timeGeoCacheRetrievalPoint + b.timeGeoCacheRetrievalPoint,
a.timeWrite + b.timeWrite,
a.timeBoxIdIsectAreaArea + b.timeBoxIdIsectAreaArea,
a.timeBoxIdIsectAreaLine + b.timeBoxIdIsectAreaLine,
a.timeBoxIdIsectAreaPoint + b.timeBoxIdIsectAreaPoint,
a.timeBoxIdIsectLineLine + b.timeBoxIdIsectLineLine,
a.timeBoxIdIsectLinePoint + b.timeBoxIdIsectLinePoint,
a.timeFullGeoCheckAreaArea + b.timeFullGeoCheckAreaArea,
a.timeFullGeoCheckAreaLine + b.timeFullGeoCheckAreaLine,
a.timeFullGeoCheckAreaPoint + b.timeFullGeoCheckAreaPoint,
a.timeFullGeoCheckLineLine + b.timeFullGeoCheckLineLine,
a.timeFullGeoCheckLinePoint + b.timeFullGeoCheckLinePoint,
a.fullGeoChecksAreaArea + b.fullGeoChecksAreaArea,
a.fullGeoChecksAreaLine + b.fullGeoChecksAreaLine,
a.fullGeoChecksAreaPoint + b.fullGeoChecksAreaPoint,
a.fullGeoChecksLineLine + b.fullGeoChecksLineLine};
a.fullGeoChecksLineLine + b.fullGeoChecksLineLine,
a.fullGeoChecksLinePoint + b.fullGeoChecksLinePoint};
}

inline void operator+=(Stats& a, const Stats& b) { a = a + b; }
Expand Down
Loading

0 comments on commit 0af1ac8

Please sign in to comment.