Decode Compressed ArcGIS Geometry (Onwani) (v8)

Revision 8 of this benchmark created by Travis Butcher on


Description

Test geometry decompression for Onwani Tools

Setup

var tests = ["+1m91+2s73e+19g2d+5-5+3k+39"]

Test runner

Ready to run.

Testing in
TestOps/sec
Original _fromCompressedGeometry
function _fromCompressedGeometry( /*String*/ str, /*SpatialReference*/ sr) {
  var xDiffPrev = 0,
    yDiffPrev = 0,
    points = [],
    x, y,
    strings = str.replace(/(\+)|(\-)/g, ' $&').split(" "),
    j, jl = strings.length,
    coefficient = parseInt(strings[1], 32);

  for (j = 2; j < jl; j += 2) {
    //j is for x.
    // x = (parseInt(strings[j], 32) + xDiffPrev);
    // xDiffPrev = x;
    xDiffPrev = (x = (parseInt(strings[j], 32) + xDiffPrev));

    //j+1 is for y
    // y = (parseInt(strings[j+1], 32) + yDiffPrev);
    // yDiffPrev = y;
    yDiffPrev = (y = (parseInt(strings[j + 1], 32) + yDiffPrev));

    points.push([x / coefficient, y / coefficient]);
  }
  return points;
}

for (var i = 0; i < tests.length; i++) {
  _fromCompressedGeometry(tests[i]);
}
ready
New _fromCompressedGeometry
function _fromCompressedGeometry( /*String*/ str, /*SpatialReference*/ sr) {
  var xDiffPrev = 0,
    yDiffPrev = 0,
    points = [],
    x, y,
    strings,
    coefficient;

  // Split the string into an array on the + and - characters
  strings = str.match(/((\+|\-)[^\+\-]+)/g);

  // The first value is the coefficient in base 32
  coefficient = parseInt(strings[0], 32);

  for (var j = 1; j < strings.length; j += 2) {
    // j is the offset for the x value
    // Convert the value from base 32 and add the previous x value
    x = (parseInt(strings[j], 32) + xDiffPrev);
    xDiffPrev = x;

    // j+1 is the offset for the y value
    // Convert the value from base 32 and add the previous y value
    y = (parseInt(strings[j + 1], 32) + yDiffPrev);
    yDiffPrev = y;

    points.push([x / coefficient, y / coefficient]);
  }

  return points;
}


for (var i = 0; i < tests.length; i++) {
  _fromCompressedGeometry(tests[i]);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 8: published by Travis Butcher on