-
Notifications
You must be signed in to change notification settings - Fork 74
v0.2.49..v0.2.50 changeset PoiPolygonMatchVisitor.cpp
Garret Voltz edited this page Nov 6, 2019
·
1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/visitors/poi-polygon/PoiPolygonMatchVisitor.cpp b/hoot-core/src/main/cpp/hoot/core/visitors/poi-polygon/PoiPolygonMatchVisitor.cpp
index 05c7c93..8a89fdd 100644
--- a/hoot-core/src/main/cpp/hoot/core/visitors/poi-polygon/PoiPolygonMatchVisitor.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/visitors/poi-polygon/PoiPolygonMatchVisitor.cpp
@@ -48,7 +48,7 @@ namespace hoot
{
PoiPolygonMatchVisitor::PoiPolygonMatchVisitor(const ConstOsmMapPtr& map,
- std::vector<const Match*>& result,
+ std::vector<ConstMatchPtr>& result,
ElementCriterionPtr filter) :
_map(map),
_result(result),
@@ -57,9 +57,10 @@ _filter(filter)
}
PoiPolygonMatchVisitor::PoiPolygonMatchVisitor(const ConstOsmMapPtr& map,
- std::vector<const Match*>& result,
+ std::vector<ConstMatchPtr>& result,
ConstMatchThresholdPtr threshold,
std::shared_ptr<PoiPolygonRfClassifier> rf,
+ PoiPolygonCachePtr infoCache,
ElementCriterionPtr filter) :
_map(map),
_result(result),
@@ -70,13 +71,16 @@ _threshold(threshold),
_rf(rf),
_numElementsVisited(0),
_numMatchCandidatesVisited(0),
-_filter(filter)
+_filter(filter),
+_infoCache(infoCache)
{
ConfigOptions opts = ConfigOptions();
_enableAdvancedMatching = opts.getPoiPolygonEnableAdvancedMatching();
_enableReviewReduction = opts.getPoiPolygonEnableReviewReduction();
_reviewDistanceThreshold = opts.getPoiPolygonReviewDistanceThreshold();
_taskStatusUpdateInterval = opts.getTaskStatusUpdateInterval();
+
+ LOG_VART(_infoCache.get());
}
PoiPolygonMatchVisitor::~PoiPolygonMatchVisitor()
@@ -85,39 +89,39 @@ PoiPolygonMatchVisitor::~PoiPolygonMatchVisitor()
void PoiPolygonMatchVisitor::_checkForMatch(const std::shared_ptr<const Element>& e)
{
+ LOG_TRACE("Checking for match with POI: " << e->getElementId());
+
std::shared_ptr<geos::geom::Envelope> env(e->getEnvelope(_map));
env->expandBy(_getSearchRadius(e));
// find other nearby candidates
- std::set<ElementId> neighbors = IndexElementsVisitor::findNeighbors(*env,
- _getPolyIndex(),
- _polyIndexToEid,
- _getMap());
- ElementId from(e->getElementType(), e->getId());
+ LOG_TRACE("Searching for polys neighboring the POI...");
+ const std::set<ElementId> neighbors =
+ IndexElementsVisitor::findNeighbors(*env, _getPolyIndex(), _polyIndexToEid, _getMap());
+ LOG_TRACE("Attempting to match poly neighbors with POI...");
+ const ElementId poiId(e->getElementType(), e->getId());
_elementsEvaluated++;
int neighborCount = 0;
-
for (std::set<ElementId>::const_iterator it = neighbors.begin(); it != neighbors.end(); ++it)
{
- if (from != *it)
+ const ElementId polyId = *it;
+ if (poiId != polyId)
{
- const std::shared_ptr<const Element>& n = _map->getElement(*it);
-
- if (n->isUnknown() && _polyCrit.isSatisfied(n))
+ const std::shared_ptr<const Element>& poly = _map->getElement(polyId);
+ if (poly->isUnknown() && _polyCrit.isSatisfied(poly))
{
// score each candidate and push it on the result vector
- PoiPolygonMatch* m =
- new PoiPolygonMatch(_map, _threshold, _rf, _surroundingPolyIds, _surroundingPoiIds);
+ LOG_TRACE(
+ "Calculating match between: " << poiId << " and " << poly->getElementId() << "...");
+ std::shared_ptr<PoiPolygonMatch> m(
+ new PoiPolygonMatch(
+ _map, _threshold, _rf, _infoCache, _surroundingPolyIds, _surroundingPoiIds));
m->setConfiguration(conf());
- m->calculateMatch(from, *it);
+ m->calculateMatch(poiId, polyId);
// if we're confident this is a miss
- if (m->getType() == MatchType::Miss)
- {
- delete m;
- }
- else
+ if (m->getType() != MatchType::Miss)
{
_result.push_back(m);
neighborCount++;
@@ -132,26 +136,25 @@ void PoiPolygonMatchVisitor::_checkForMatch(const std::shared_ptr<const Element>
void PoiPolygonMatchVisitor::_collectSurroundingPolyIds(const std::shared_ptr<const Element>& e)
{
+ LOG_TRACE("Collecting surrounding poly IDs...");
+
_surroundingPolyIds.clear();
std::shared_ptr<geos::geom::Envelope> env(e->getEnvelope(_map));
env->expandBy(_getSearchRadius(e));
// find other nearby candidates
- std::set<ElementId> neighbors = IndexElementsVisitor::findNeighbors(*env,
- _getPolyIndex(),
- _polyIndexToEid,
- _getMap());
- ElementId from(e->getElementType(), e->getId());
+ LOG_TRACE("Searching for neighbors...");
+ const std::set<ElementId> neighbors =
+ IndexElementsVisitor::findNeighbors(*env, _getPolyIndex(), _polyIndexToEid, _getMap());
+ LOG_TRACE("Processing neighbors...");
+ ElementId from(e->getElementType(), e->getId());
for (std::set<ElementId>::const_iterator it = neighbors.begin(); it != neighbors.end(); ++it)
{
if (from != *it)
{
const std::shared_ptr<const Element>& n = _map->getElement(*it);
-
- // TODO: Aren't we already filtering by poly when we create the index? Check this. Also,
- // maybe could make the unknown part of the criteria to being with.
- if (n->isUnknown() && _polyCrit.isSatisfied(n))
+ if (n->isUnknown())
{
_surroundingPolyIds.insert(*it);
}
@@ -161,26 +164,25 @@ void PoiPolygonMatchVisitor::_collectSurroundingPolyIds(const std::shared_ptr<co
void PoiPolygonMatchVisitor::_collectSurroundingPoiIds(const std::shared_ptr<const Element>& e)
{
+ LOG_TRACE("Collecting surrounding POI IDs...");
+
_surroundingPoiIds.clear();
std::shared_ptr<geos::geom::Envelope> env(e->getEnvelope(_map));
env->expandBy(_getSearchRadius(e));
// find other nearby candidates
- std::set<ElementId> neighbors = IndexElementsVisitor::findNeighbors(*env,
- _getPoiIndex(),
- _poiIndexToEid,
- _getMap());
- ElementId from(e->getElementType(), e->getId());
+ LOG_TRACE("Searching for neighbors...");
+ const std::set<ElementId> neighbors =
+ IndexElementsVisitor::findNeighbors(*env, _getPoiIndex(), _poiIndexToEid, _getMap());
+ LOG_TRACE("Processing neighbors...");
+ ElementId from(e->getElementType(), e->getId());
for (std::set<ElementId>::const_iterator it = neighbors.begin(); it != neighbors.end(); ++it)
{
if (from != *it)
{
const std::shared_ptr<const Element>& n = _map->getElement(*it);
-
- // TODO: Aren't we already filtering by poi when we create the index? Check this. Also,
- // maybe could make the unknown part of the criteria to begin with.
- if (n->isUnknown() && _poiCrit.isSatisfied(n))
+ if (n->isUnknown())
{
_surroundingPoiIds.insert(*it);
}
@@ -197,15 +199,18 @@ Meters PoiPolygonMatchVisitor::_getSearchRadius(const std::shared_ptr<const Elem
void PoiPolygonMatchVisitor::visit(const ConstElementPtr& e)
{
+ // See if the element is a POI as defined by poi/poly conflation.
if (isMatchCandidate(e))
{
- // Technically, the density based matches depends on this data too, but since that code has
- // been disabled, this check is good enough.
+ // If we are doing advanced matching or review reduction, let's collect all polys that surround
+ // the POI and also all POIs that surround it.
if (_enableAdvancedMatching || _enableReviewReduction)
{
_collectSurroundingPolyIds(e);
_collectSurroundingPoiIds(e);
}
+ // Now, let's try to match all polys in the search radius with this POI (both as defined by
+ // poi/poly conflation).
_checkForMatch(e);
_numMatchCandidatesVisited++;
@@ -219,6 +224,8 @@ void PoiPolygonMatchVisitor::visit(const ConstElementPtr& e)
}
_numElementsVisited++;
+ // poi/poly matching can be a little slow at times compared to the others, so keep the log update
+ // interval a little lower.
if (_numElementsVisited % (_taskStatusUpdateInterval * 10) == 0)
{
PROGRESS_INFO(
@@ -234,10 +241,10 @@ bool PoiPolygonMatchVisitor::isMatchCandidate(ConstElementPtr element)
return false;
}
- //simpler logic to just examine each POI and check for surrounding polys, rather than check both
- //POIs and their surrounding polys and polys and their surrounding POIs; note that this is
- //different than PoiPolygonMatchCreator::isMatchCandidate, which is looking at both to appease
- //the stats
+ // Itssimpler logic to just examine each POI and check for surrounding polys, rather than check
+ // both POIs and their surrounding polys and polys and their surrounding POIs; note that this is
+ // different than PoiPolygonMatchCreator::isMatchCandidate, which is looking at both to appease
+ // the stats.
return element->isUnknown() && PoiPolygonPoiCriterion().isSatisfied(element);
}