Last active
January 4, 2016 18:38
-
-
Save ca0v/6a09c2fe6dfdfc0f5192 to your computer and use it in GitHub Desktop.
Port of C# code published by ESRI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************* | |
* see http://resources.esri.com/help/9.3/arcgisengine/ArcObjects/esrinetworkanalyst/INACompactStreetDirection_CompressedGeometry.htm | |
*************************************************/ | |
class DecompressGeometry { | |
public ExtractPointsFromCompressedGeometry(compresedGeometry: string) | |
{ | |
// initialize result storage | |
let result = <Array<{x: number; y: number;}>>[], | |
nIndex = {ref: 0}, | |
dMultBy = this.ExtractInt(compresedGeometry, nIndex), | |
nLastDiffX = 0, | |
nLastDiffY = 0, | |
nLength = compresedGeometry.length; | |
while (nIndex.ref != nLength) | |
{ | |
// extract number | |
let nDiffX = this.ExtractInt(compresedGeometry, nIndex); | |
let nDiffY = this.ExtractInt(compresedGeometry, nIndex); | |
// decompress | |
let nX = nDiffX + nLastDiffX; | |
let nY = nDiffY + nLastDiffY; | |
let dX = nX / dMultBy; | |
let dY = nY / dMultBy; | |
// add result item | |
let point = {x : dX, y: dY}; | |
result.push(point); | |
// prepare for next calculation | |
nLastDiffX = nX; | |
nLastDiffY = nY; | |
} | |
// return result | |
return result; | |
} | |
// Read one integer from compressed geometry string by using passed position | |
// Returns extracted integer, and re-writes nStartPos for the next integer | |
private ExtractInt(src: string, nStartPos: {ref: number}) | |
{ | |
let bStop = false, | |
result = "", | |
nCurrentPos = nStartPos.ref; | |
while (!bStop) | |
{ | |
let cCurrent = src[nCurrentPos]; | |
if (cCurrent == '+' || cCurrent == '-') | |
{ | |
if (nCurrentPos != nStartPos.ref) | |
{ | |
bStop = true; | |
continue; | |
} | |
} | |
result += cCurrent; | |
nCurrentPos++; | |
if (nCurrentPos == src.length) // check overflow | |
bStop = true; | |
} | |
let nResult = Number.MIN_VALUE; | |
if (result.length != 0) | |
{ | |
nResult = parseInt(result, 32); | |
nStartPos.ref = nCurrentPos; | |
} | |
return nResult; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage Example: