Skip to content

v0.2.52..v0.2.53 changeset Building.js.off

Garret Voltz edited this page Feb 12, 2020 · 1 revision
diff --git a/rules/archive/Building.js.off b/rules/archive/Building.js.off
new file mode 100644
index 0000000..b7a145b
--- /dev/null
+++ b/rules/archive/Building.js.off
@@ -0,0 +1,125 @@
+/**
+ * This script was created to demonstrate the feasibility of using generic conflation to conflate building polygons and is no longer supported.
+ * The Unifying Algorithm should be used for all building conflation.
+ * 
+ * Note that there never were any tag checks, so it was conflating types of features present other than buildings as well.
+ */
+
+var MATCH_OVERLAP_THRESHOLD = 0.75;
+var MISS_OVERLAP_THRESHOLD = 0.15;
+
+exports.candidateDistanceSigma = 1.0; // 1.0 * (CE95 + Worst CE95);
+exports.description = "Matches buildings";
+exports.matchThreshold = parseFloat(hoot.get("building.match.threshold"));
+exports.missThreshold = parseFloat(hoot.get("building.miss.threshold"));
+exports.reviewThreshold = parseFloat(hoot.get("building.review.threshold"));
+exports.experimental = false;
+exports.baseFeatureType = "Building";
+exports.writeMatchedBy = hoot.get("writer.include.matched.by.tag");
+exports.geometryType = "polygon";
+
+/**
+ * Returns true if e is a candidate for a match. Implementing this method is
+ * optional, but may dramatically increase speed if you can cull some features
+ * early on. E.g. no need to check nodes for a polygon to polygon match.
+ *
+ * exports.matchCandidateCriterion takes precedence over this function and must
+ * be commented out before using it.
+ */
+exports.isMatchCandidate = function(map, e)
+{
+  return isBuilding(e);
+};
+
+/**
+ * If this function returns true then all overlapping matches will be treated
+ * as a group. For now that means if two matches overlap then the whole group
+ * will be marked as needing review.
+ *
+ * If this function returns false the conflation routines will attempt to 
+ * pick the best subset of matches that do not conflict.
+ */
+exports.isWholeGroup = function()
+{
+  return true;
+};
+
+/**
+ * Returns the match score for the three class relationships.
+ * - match
+ * - miss
+ * - review
+ *
+ * The scores should always sum to one. If they don't you will be taunted 
+ * mercilessly and we'll normalize it anyway. :P
+ */
+exports.matchScore = function(map, e1, e2)
+{
+  var result;
+  if (isBuilding(e1) == false || isBuilding(e2) == false ||
+      e1.getStatusString() == e2.getStatusString())
+  {
+    result = { match: 0.0, miss: 1.0, review: 0.0 };
+  }
+  else
+  {
+    hoot.trace("e1: " + e1.getId() + ", " + e1.getTags().get("name"));
+    if (e1.getTags().get("note"))
+    {
+      hoot.trace("e1 note: " + e1.getTags().get("note"));
+    }
+    hoot.trace("e2: " + e2.getId() + ", " + e2.getTags().get("name"));
+    if (e2.getTags().get("note"))
+    {
+      hoot.trace("e2 note: " + e2.getTags().get("note"));
+    }
+
+    // These rules were derived by using training data in Weka with the
+    // REPTree model w/ maxDepth set to 3. 
+    var overlap = new hoot.SmallerOverlapExtractor().extract(map, e1, e2);
+    hoot.trace("overlap: " + overlap);
+    if (overlap < 0.20)
+    {
+      result = { match: 0.0, miss: 1.0, review: 0.0 };
+    }
+    else 
+    {
+      if (overlap < 0.45)
+      {
+        var hist = new hoot.AngleHistogramExtractor().extract(map, e1, e2);
+        hoot.trace("hist: " + hist);
+        if (hist < 0.58)
+        {
+          result = { match: 0.0, miss: 0.0, review: 1.0 };
+        }
+        else
+        {
+          result = { match: 1.0, miss: 0.0, review: 0.0 };
+        }
+      }
+      else
+      {
+        result = { match: 1.0, miss: 0.0, review: 0.0 };
+      }
+    }
+  }
+
+  hoot.trace("result: " + result);
+  return result;
+};
+
+exports.mergePair = function(map, e1, e2)
+{
+  // replace instances of e2 with e1 and merge tags
+  mergeElements(map, e1, e2);
+
+  e1.setStatusString("conflated");
+  if (exports.writeMatchedBy == "true")
+  {
+    // Technically, we should get this key from MetadataTags, but that's not integrated with hoot yet.
+    e1.setTag("hoot:matchedBy", exports.baseFeatureType);
+  }
+
+  return e1;
+};
+
Clone this wiki locally