Skip to content

v0.2.47..v0.2.48 changeset ElementMergerJs.cpp

Garret Voltz edited this page Sep 27, 2019 · 1 revision
diff --git a/hoot-js/src/main/cpp/hoot/js/conflate/merging/ElementMergerJs.cpp b/hoot-js/src/main/cpp/hoot/js/conflate/merging/ElementMergerJs.cpp
index 225c7b9..ca7931c 100644
--- a/hoot-js/src/main/cpp/hoot/js/conflate/merging/ElementMergerJs.cpp
+++ b/hoot-js/src/main/cpp/hoot/js/conflate/merging/ElementMergerJs.cpp
@@ -90,7 +90,6 @@ void ElementMergerJs::mergeElements(const FunctionCallbackInfo<Value>& args)
   try
   {
     HandleScope scope(current);
-    //Context::Scope context_scope(current->GetCallingContext());
     if (args.Length() != 1)
     {
       args.GetReturnValue().Set(
@@ -108,9 +107,9 @@ void ElementMergerJs::mergeElements(const FunctionCallbackInfo<Value>& args)
     Handle<Object> returnMap = OsmMapJs::create(map);
     args.GetReturnValue().Set(returnMap);
   }
-  //This error handling has been proven to not work in that it never seems to return the
-  //error message to the nodejs calling service....making debugging a nightmare...or I'm just
-  //doing something wrong here.  Either way, need to fix this. - #2231
+  // This error handling has been proven to not work as it never returns the error message to the
+  // nodejs calling service....makes debugging very difficult. Need to fix: #2231. As a workaround,
+  // use scripts/core/MergeElements.js to see log output duriing merging.
   catch (const HootException& e)
   {
     LOG_ERROR(e.getWhat());
@@ -144,17 +143,18 @@ void ElementMergerJs::_mergeElements(OsmMapPtr map, Isolate* current)
 {  
   const MergeType mergeType = _determineMergeType(map);
   LOG_VART(_mergeTypeToString(mergeType));
+
   ElementId mergeTargetId;
-  //merge target id won't be passed in for poi/poly, as the poi/poly merging picks the target
-  //element itself
+  // merge target id won't be passed in for poi/poly, as the poi/poly merging picks the target
+  // element itself
   if (mergeType != MergeType::PoiToPolygon)
   {
     mergeTargetId = _getMergeTargetFeatureId(map);
     LOG_VART(mergeTargetId);
   }
 
-  //We're using a mix of generic conflation scripts and custom built classes to merge features
-  //here, depending on the feature type.
+  // We're using a mix of generic conflation scripts and custom built classes to merge features
+  // here, depending on the feature type.
   bool scriptMerge = false;
   switch (mergeType)
   {
@@ -163,7 +163,9 @@ void ElementMergerJs::_mergeElements(OsmMapPtr map, Isolate* current)
       break;
 
     case MergeType::PoiToPolygon:
-      mergeTargetId = PoiPolygonMerger::mergePoiAndPolygon(map);
+      // POI/Poly always merges into the polygon and there's only one of them, so we let the
+      // routine determine the merge target ID.
+      mergeTargetId = PoiPolygonMerger::mergeOnePoiAndOnePolygon(map);
       break;
 
     case MergeType::PoiToPoi:
@@ -181,8 +183,8 @@ void ElementMergerJs::_mergeElements(OsmMapPtr map, Isolate* current)
   }
   LOG_VART(scriptMerge);
 
-  //By convention, we're setting the status of any element that gets merged with something to
-  //conflated, even if its yet to be reviewed against something else.
+  // By convention, we're setting the status of any element that gets merged with something to
+  // conflated, even if its yet to be reviewed against something else.
   ElementPtr mergedElement = map->getElement(mergeTargetId);
   assert(mergedElement);
   mergedElement->setStatus(Status(Status::Conflated));
@@ -217,9 +219,10 @@ ElementId ElementMergerJs::_getMergeTargetFeatureId(ConstOsmMapPtr map)
 
 ElementMergerJs::MergeType ElementMergerJs::_determineMergeType(ConstOsmMapPtr map)
 {
-  //Making sure maps don't come in mixed, so callers don't have the expectation that they can merge
-  //multiple feature types within the same map.  Any features in the map with types other than what
-  //we know how to merge will just pass through.
+  // Making sure maps don't come in mixed, so callers don't have the expectation that they can merge
+  // multiple feature types within the same map.  After the initial feature requirements are
+  // satisified, any other features in the map with types other than what we know how to merge
+  // should just pass through.
 
   MergeType mergeType;
 
@@ -236,19 +239,17 @@ ElementMergerJs::MergeType ElementMergerJs::_determineMergeType(ConstOsmMapPtr m
   {
     mergeType = MergeType::PoiToPolygon;
   }
-  else if (OsmUtils::contains<PoiCriterion>(map, 2) &&
-           !containsPolys && !containsAreas &&
+  else if (OsmUtils::contains<PoiCriterion>(map, 2) && !containsPolys && !containsAreas &&
            !containsBuildings)
   {
     mergeType = MergeType::PoiToPoi;
   }
-  else if (OsmUtils::contains<BuildingCriterion>(map, 2) &&
-           !containsAreas && !containsPois)
+  else if (OsmUtils::contains<BuildingCriterion>(map, 2) && !containsAreas && !containsPois)
   {
     mergeType = MergeType::BuildingToBuilding;
   }
-  else if (OsmUtils::contains<NonBuildingAreaCriterion>(map, 2) &&
-           !containsBuildings && !containsPois)
+  else if (OsmUtils::contains<NonBuildingAreaCriterion>(map, 2) && !containsBuildings &&
+           !containsPois)
   {
     mergeType = MergeType::AreaToArea;
   }
Clone this wiki locally