Feature #647

make polygon data accessible to JavaScript (was: Specify Percentage of Overlapped Polygon)

Added by Chris Stefanich over 5 years ago. Updated over 5 years ago.

Status:ResolvedStart date:11/09/2011
Priority:NormalDue date:12/01/2011
Assignee:Kyle Monico% Done:

100%

Category:Internal Code Refactoring
Target version:1.0
Complexity: OIC Priority:
Required by:Grand Rapids, Michigan

Description

We need to be able to specify the percentage of the polygon that is overlapped to determine whether or not to include it in the overlapped keys. For example: if someone is drawing a custom polygon or circle and just a tiny corner (less than the specified percentage) is overlapped, we would like to be able to not include that polygon in the set.

History

#1 Updated by Andy Dufilie over 5 years ago

If we provide a way to get the polygon coordinates for each record, you can do the calculation in JavaScript. Is that acceptable?

#2 Updated by Andy Dufilie over 5 years ago

  • Status changed from Open to Awaiting Feedback

#3 Updated by Andy Dufilie over 5 years ago

  • Target version set to 1.0

#4 Updated by Chris Stefanich over 5 years ago

Yes, that sounds good.

#5 Updated by Andy Dufilie over 5 years ago

  • Subject changed from Specify Percentage of Overlapped Polygon to make polygon data accessible to JavaScript (was: Specify Percentage of Overlapped Polygon)
  • Category set to Internal Code Refactoring
  • Assignee set to Kyle Monico

#6 Updated by Andy Dufilie over 5 years ago

  • Status changed from Awaiting Feedback to Open

#7 Updated by Kyle Monico over 5 years ago

  • Status changed from Open to Resolved
  • % Done changed from 0 to 100

This should be in the nightly build tonight.

var keys = weave.evaluateExpression(['MapTool'], 'getOverlappingQKeys("penTool")', null);
var geoms = [];
for (var i = 0; i < keys.length; ++i)
{
    var key = keys[i];
    var geom = weave.evaluateExpression(['MapTool', 'children', 'visualization', 'layers', 'plot', 'plotter', 'internalObject', 'geometryColumn'], 'ColumnUtils.getGeometry(this, qkey)', {qkey : key}, ['weave.utils::ColumnUtils']);
    geoms.push(geom);
}

function odump(object, depth, max){
  depth = depth || 0;
  max = max || 2;

  if (depth > max)
    return false;

  var indent = "";
  for (var i = 0; i < depth; i++)
    indent += "  ";

  var output = "";  
  for (var key in object){
    output += "\n" + indent + key + ": ";
    switch (typeof object[key]){
      case "object": output += odump(object[key], depth + 1, max); break;
      case "function": output += "function"; break;
      default: output += object[key]; break;        
    }
  }
  return output;
}

console.log(odump(geoms, 0, 4));

The odump function comes here http://refactormycode.com/codes/226-recursively-dump-an-object

The example code first gets the overlapping keys, then for each key it gets the geometries. ColumnUtils.getGeometry needs a reference to the geometry column, which is passed as the "this" pointer using the object path.

The value returned from 'getGeometry' is an array of arrays of arrays of points.
Internally in Weave, it's an array of GeneralizedGeometry objects, where each GeneralizedGeometry is essentially an array of trees used for querying by importance.

Each of those values returned were put in geoms. Thus, geoms is an array of arrays of arrays of arrays of points. If you checked geoms0[0][0][0], you would see an object with x and y properties. The length property of those objects is just the magnitude of the point--it has no meaning to the comprising geometries.

Let me know if you have any questions.

#8 Updated by Chris Stefanich over 5 years ago

I see the function is returning arrays of points that represent the overlapped polygons. What are the "depth" and "max" values? Is this assigning importance to the polygons based on overlapped area or is this just returning the coordinates to create the polygons that are overlapped?

#9 Updated by Kyle Monico over 5 years ago

The "depth" and "max" values are used for that recursive odump function. That function prints out the tree structure of the object returned from Weave. Max is the maximum depth in the tree, 4 (which is as far as you need to go in this example because geoms is an array of the objects returned from Weave). Depth is the current depth used to figure out when to exit.

The points are the points of the geometries that overlapped with the layer.

Suppose you have a world shp file and your polygon overlapped with Canada and the US. You would have those two keys and loop over them. The weave.evaluateExpression call to ColumnUtils.getGeometry (where you passed in the key for Canada) would return an object which is an Array of Array of Points. Let's call this object "geom".

Geom is a geometry. A geometry is an array of parts. A part is an array of points. Thus, geom is an array of arrays of points. For the US, each island is a part, and there are multiple parts.

Geom is an appropriate representation for the entire geometry corresponding to that key. You can then perform your own overlap/intersection tests to satisfy the % criterion.

geom[i] // corresponds to a single part/island of the geom
geom[i][j] // corresponds to a single point inside the part/island geom[i]

Let me know if you have any questions.

Also available in: Atom PDF