Skip to content

Commit 32fe187

Browse files
committed
also fold box polygons
1 parent 75e700e commit 32fe187

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

src/spatialjoin/Sweeper.cpp

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -214,39 +214,32 @@ I32Box Sweeper::add(const I32Polygon& poly, const std::string& gidR,
214214
cur.subid = subid;
215215
cur.gid = gid;
216216

217-
if (false && poly.getInners().size() == 0 && subid == 0 &&
217+
if (poly.getInners().size() == 0 && subid == 0 && gid.size() < 8 &&
218218
(!_cfg.useBoxIds || boxIds.front().first == 1) &&
219219
area(rawBox) == areaSize) {
220-
std::stringstream str;
221-
_simpleAreaCache.writeTo({poly.getOuter(), gid}, str);
222-
cur.raw = str.str();
223-
224-
size_t estimatedSize =
225-
poly.getOuter().size() * sizeof(util::geo::XSortedTuple<int32_t>);
226-
227220
cur.boxvalIn = {0, // placeholder, will be overwritten later on
228221
box.getLowerLeft().getY(),
229222
box.getUpperRight().getY(),
230223
box.getLowerLeft().getX(),
231224
false,
232-
BOX_POLYGON,
225+
FOLDED_BOX_POLYGON,
233226
areaSize,
234-
{},
227+
box.getUpperRight(),
235228
box45,
236229
side,
237-
estimatedSize > GEOM_LARGENESS_THRESHOLD};
230+
false};
238231
cur.boxvalOut = {0, // placeholder, will be overwritten later on
239232
box.getLowerLeft().getY(),
240233
box.getUpperRight().getY(),
241234
box.getUpperRight().getX(),
242235
true,
243-
BOX_POLYGON,
236+
FOLDED_BOX_POLYGON,
244237
areaSize,
245-
{},
238+
box.getLowerLeft(),
246239
box45,
247240
side,
248-
estimatedSize > GEOM_LARGENESS_THRESHOLD};
249-
batch.boxAreas.emplace_back(cur);
241+
false};
242+
batch.foldedBoxAreas.emplace_back(cur);
250243
} else if (poly.getInners().size() == 0 && poly.getOuter().size() < 10 &&
251244
subid == 0 && (!_cfg.useBoxIds || boxIds.front().first == 1)) {
252245
std::stringstream str;
@@ -604,6 +597,14 @@ void Sweeper::addBatch(WriteBatch& cands) {
604597
}
605598
}
606599

600+
{
601+
for (auto& cand : cands.foldedBoxAreas) {
602+
if (cand.boxvalIn.side) _numSides = 2;
603+
cand.boxvalIn.id = foldString(cand.gid);
604+
cand.boxvalOut.id = cand.boxvalIn.id;
605+
}
606+
}
607+
607608
{
608609
std::unique_lock<std::mutex> lock(_simpleAreaGeomCacheWriteMtx);
609610
for (auto& cand : cands.simpleAreas) {
@@ -690,6 +691,12 @@ void Sweeper::addBatch(WriteBatch& cands) {
690691
if (_curSweepId / 2 % 1000000 == 0)
691692
log("@ " + std::to_string(_curSweepId / 2));
692693
}
694+
for (const auto& cand : cands.foldedBoxAreas) {
695+
diskAdd(cand.boxvalIn);
696+
diskAdd(cand.boxvalOut);
697+
if (_curSweepId / 2 % 1000000 == 0)
698+
log("@ " + std::to_string(_curSweepId / 2));
699+
}
693700
for (const auto& cand : cands.simpleLines) {
694701
diskAdd(cand.boxvalIn);
695702
diskAdd(cand.boxvalOut);
@@ -2224,18 +2231,12 @@ void Sweeper::selfCheck(const JobVal cur, size_t t) {
22242231
writeIntersect(t, a->id, a->id);
22252232
writeEquals(t, a->id, 0, a->id, 0);
22262233
writeCovers(t, a->id, a->id, 0);
2227-
} else if (cur.type == POLYGON) {
2228-
auto a = _areaCache.get(cur.id, cur.large ? -1 : t);
2234+
} else if (isArea(cur.type)) {
2235+
auto a = getArea(cur, cur.large ? -1 : t);
22292236

22302237
writeIntersect(t, a->id, a->id);
22312238
writeEquals(t, a->id, a->subId, a->id, a->subId);
22322239
writeCovers(t, a->id, a->id, a->subId);
2233-
} else if (cur.type == SIMPLE_POLYGON) {
2234-
auto a = _simpleAreaCache.get(cur.id, cur.large ? -1 : t);
2235-
2236-
writeIntersect(t, a->id, a->id);
2237-
writeEquals(t, a->id, 0, a->id, 0);
2238-
writeCovers(t, a->id, a->id, 0);
22392240
}
22402241
}
22412242

@@ -2780,8 +2781,7 @@ void Sweeper::doCheck(const JobVal cur, const JobVal sv, size_t t) {
27802781
auto a = getSimpleLine(cur, cur.large ? -1 : t);
27812782
_stats[t].timeGeoCacheRetrievalSimpleLine += TOOK(ts);
27822783

2783-
if (a->id == b->id)
2784-
return; // no self-checks in multigeometries
2784+
if (a->id == b->id) return; // no self-checks in multigeometries
27852785

27862786
_stats[t].areaCmps++;
27872787
_stats[t].areaSizeSum += b->area;
@@ -2834,8 +2834,7 @@ void Sweeper::doCheck(const JobVal cur, const JobVal sv, size_t t) {
28342834
auto b = _lineCache.get(sv.id, sv.large ? -1 : t);
28352835
_stats[t].timeGeoCacheRetrievalLine += TOOK(ts);
28362836

2837-
if (a->id == b->id)
2838-
return; // no self-checks in multigeometries
2837+
if (a->id == b->id) return; // no self-checks in multigeometries
28392838

28402839
_stats[t].areaCmps++;
28412840
_stats[t].areaSizeSum += a->area;
@@ -4018,6 +4017,13 @@ std::shared_ptr<sj::Area> Sweeper::getArea(const JobVal& sv, size_t t) const {
40184017
if (sv.type == SIMPLE_POLYGON) {
40194018
auto p = _simpleAreaCache.get(sv.id, sv.large ? -1 : t);
40204019
asp = std::make_shared<sj::Area>(sj::Area(areaFromSimpleArea(p.get())));
4020+
} else if (sv.type == FOLDED_BOX_POLYGON) {
4021+
SimpleArea sa;
4022+
sa.id = unfoldString(sv.id);
4023+
sa.geom = util::geo::Polygon<int32_t>(
4024+
getBoundingBox(util::geo::Line<int32_t>{sv.point, sv.point2}))
4025+
.getOuter();
4026+
asp = std::make_shared<sj::Area>(sj::Area(areaFromSimpleArea(&sa)));
40214027
} else {
40224028
asp = _areaCache.get(sv.id, sv.large ? -1 : t);
40234029
}

src/spatialjoin/Sweeper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum GeomType : uint8_t {
4040
FOLDED_POINT = 5,
4141
// currently not used
4242
FOLDED_SIMPLE_LINE = 6,
43-
BOX_POLYGON = 7,
43+
FOLDED_BOX_POLYGON = 7,
4444
};
4545

4646
struct BoxVal {
@@ -72,7 +72,7 @@ struct WriteBatch {
7272
std::vector<WriteCand> foldedSimpleLines;
7373
std::vector<WriteCand> lines;
7474
std::vector<WriteCand> simpleAreas;
75-
std::vector<WriteCand> boxAreas;
75+
std::vector<WriteCand> foldedBoxAreas;
7676
std::vector<WriteCand> areas;
7777
std::vector<WriteCand> refs;
7878

@@ -562,7 +562,7 @@ class Sweeper {
562562
static bool isPoint(GeomType gt) { return gt == POINT || gt == FOLDED_POINT; }
563563

564564
static bool isArea(GeomType gt) {
565-
return gt == POLYGON || gt == SIMPLE_POLYGON || gt == BOX_POLYGON;
565+
return gt == POLYGON || gt == SIMPLE_POLYGON || gt == FOLDED_BOX_POLYGON;
566566
}
567567

568568
std::shared_ptr<sj::Area> getArea(const JobVal& j, size_t) const;

0 commit comments

Comments
 (0)