Skip to content

v0.2.54..v0.2.55 changeset HootLib.js

Garret Voltz edited this page Aug 14, 2020 · 1 revision
diff --git a/rules/lib/HootLib.js b/rules/lib/HootLib.js
index 8a979a4..02701d0 100644
--- a/rules/lib/HootLib.js
+++ b/rules/lib/HootLib.js
@@ -46,7 +46,7 @@ function getRelatedTags(relateToKvp, d) {
     var result = [];
     for (var k in d) {
         var kvp = k + '=' + d[k];
-        // TODO: This needs to be updated for features other than POI before its used outside of Poi.js.
+        // This would need to be updated for features other than POI before it could be used outside of Poi.js.
         if (kvp != "poi=yes" && kvp != "place=locality") {
             if (hoot.OsmSchema.score(relateToKvp, kvp) > 0) {
                 result.push(kvp);
@@ -78,7 +78,7 @@ function getTagsByCategory(category, d) {
     for (var k in d) {
         var kvp = k + '=' + d[k];
         // if it is not a generic type
-        // TODO: This needs to be updated for features other than POI before its used outside of Poi.js.
+        // This would need to be updated for features other than POI before it could be used outside of Poi.js.
         if (kvp != "poi=yes" && kvp != "place=locality") {
             if (hoot.OsmSchema.getCategories(kvp).indexOf(category) >= 0) {
                 result.push(kvp);
@@ -152,6 +152,21 @@ function getTagDistance(commonKvp, t1, t2) {
 }
 
 /**
+ * Determines if both features have a populated name
+ */
+function bothElementsHaveName(e1, e2)
+{
+  var name1 = String(e1.getTags().get("name")).trim();
+  var name2 = String(e2.getTags().get("name")).trim();
+  var bothHaveName = false;
+  if (name1 !== 'undefined' && name1 !== null && name1 !== '' && name2 !== 'undefined' && name2 !== null && name2 !== '')
+  {
+    bothHaveName = true;
+  }
+  return bothHaveName;
+}
+
+/**
  * Determines if an element is a member of relation that has a specified type
  */
 function isMemberOfRelationType(map, childElementId, relationType)
@@ -184,6 +199,15 @@ function explicitTypeMismatch(e1, e2, minTypeScore)
 }
 
 /**
+ * Returns the most specific type tag found as determined by the hoot schema. 
+   If the element has more than one specific type, only the first will be returned.
+ */
+function mostSpecificType(e)
+{
+  return hoot.OsmSchema.mostSpecificType(e);
+}
+
+/**
  * Scores the similarity between two feature types
  */
 function getTypeScore(e1, e2, ignoreGenericTypes)
@@ -321,6 +345,30 @@ function removeElement(map, e)
 }
 
 /**
+ * Merges two collection relations (e.g. route, admin boundary, etc.)
+ */
+function mergeCollectionRelations(map, elementId1, elementId2)
+{
+  return map.mergeCollectionRelations(elementId1, elementId2);
+}
+
+/**
+ * Recursively returns the total number of nodes contained with a relation
+ */
+function getNumRelationMemberNodes(map, relationId)
+{
+  return map.getNumRelationMemberNodes(relationId);
+}
+
+/**
+ * Determines if two relations have at least one connected way member
+ */
+function relationsHaveConnectedWayMembers(map, relationId1, relationId2)
+{
+  return map.relationsHaveConnectedWayMembers(relationId1, relationId2);
+}
+
+/**
  * Snaps the ways in the second input to the first input. The replaced array will
  * be updated appropriately to reflect the elements that were replaced.
  */
@@ -330,6 +378,22 @@ function snapWays(sublineMatcher, map, pairs, replaced, matchedBy)
 }
 
 /**
+ * Merges rivers together
+ */
+function snapRivers(sublineMatcher, map, pairs, replaced, matchedBy, sublineMatcher2)
+{
+  return new hoot.HighwaySnapMerger().apply(sublineMatcher, map, pairs, replaced, matchedBy, sublineMatcher2);
+}
+
+/**
+ * Determines if a river is considered "long" by River Conflation standards
+ */
+function isLongRiverPair(map, e1, e2)
+{
+  return hoot.OsmSchema.isLongRiverPair(map, e1, e2);
+}
+
+/**
  * Uses the SearchRadiusCalculator to automatically calculate a search radius based on tie points found
  * in the two input datasets.
  *
@@ -378,6 +442,11 @@ function isNonBuildingArea(map, e)
   return hoot.OsmSchema.isNonBuildingArea(map, e);
 }
 
+function isCollectionRelation(e)
+{
+  return hoot.OsmSchema.isCollectionRelation(e);
+}
+
 function isHighway(map, e)
 {
   return hoot.OsmSchema.isHighway(map, e);
@@ -462,3 +531,11 @@ function isPowerLine(e)
 {
   return hoot.OsmSchema.isPowerLine(e);
 }
+
+/*
+ * Returns the length of the feature in meters
+ */
+function getLength(map, e)
+{
+  return hoot.ElementConverter.calculateLength(map, e);
+}
Clone this wiki locally