Socket
Socket
Sign inDemoInstall

wkx

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

test/geojson.js

2

bower.json
{
"name": "wkx",
"version": "0.1.0",
"version": "0.2.0",
"description": "A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/cschwarz/wkx",

@@ -6,29 +6,36 @@ var fs = require('fs');

var testdata = JSON.parse(fs.readFileSync('./test/testdata.json', { encoding: 'utf8' }));
updateTestData('./test/testdata.json');
updateTestData('./test/testdataZ.json');
updateTestData('./test/testdataM.json');
updateTestData('./test/testdataZM.json');
var connectionString = 'postgres://postgres:postgres@localhost/postgres';
function updateTestData(file) {
var testdata = JSON.parse(fs.readFileSync(file, { encoding: 'utf8' }));
var client = new pg.Client(connectionString);
client.connect(function(err) {
async.forEachOf(testdata, function (value, key, callback) {
client.query('SELECT encode(ST_AsBinary(ST_GeomFromText($1)), \'hex\') wkb, ' +
'encode(ST_AsEWKB(ST_GeomFromText($1, 4326)), \'hex\') ewkb, ' +
'encode(ST_AsBinary(ST_GeomFromText($1), \'xdr\'), \'hex\') wkbxdr, ' +
'encode(ST_AsEWKB(ST_GeomFromText($1, 4326), \'xdr\'), \'hex\') ewkbxdr, ' +
'encode(ST_AsTWKB(ST_GeomFromText($1, 4326)), \'hex\') twkb, ' +
'ST_AsGeoJSON(ST_GeomFromText($1, 4326)) geojson', [value.wkt], function (err, result) {
var connectionString = 'postgres://postgres:postgres@localhost/postgres';
value.wkb = result.rows[0].wkb;
value.ewkb = result.rows[0].ewkb;
value.wkbXdr = result.rows[0].wkbxdr;
value.ewkbXdr = result.rows[0].ewkbxdr;
value.twkb = result.rows[0].twkb;
value.geoJSON = JSON.parse(result.rows[0].geojson);
var client = new pg.Client(connectionString);
client.connect(function(err) {
async.forEachOf(testdata, function (value, key, callback) {
client.query('SELECT encode(ST_AsBinary(ST_GeomFromText($1)), \'hex\') wkb, ' +
'encode(ST_AsEWKB(ST_GeomFromText($1, 4326)), \'hex\') ewkb, ' +
'encode(ST_AsBinary(ST_GeomFromText($1), \'xdr\'), \'hex\') wkbxdr, ' +
'encode(ST_AsEWKB(ST_GeomFromText($1, 4326), \'xdr\'), \'hex\') ewkbxdr, ' +
'encode(ST_AsTWKB(ST_GeomFromText($1, 4326)), \'hex\') twkb, ' +
'ST_AsGeoJSON(ST_GeomFromText($1, 4326)) geojson', [value.wkt], function (err, result) {
callback();
value.wkb = result.rows[0].wkb;
value.ewkb = result.rows[0].ewkb;
value.wkbXdr = result.rows[0].wkbxdr;
value.ewkbXdr = result.rows[0].ewkbxdr;
value.twkb = result.rows[0].twkb;
value.geoJSON = JSON.parse(result.rows[0].geojson);
callback();
});
}, function () {
client.end();
fs.writeFileSync(file, stringify(testdata));
});
}, function () {
client.end();
fs.writeFileSync('./test/testdata.json', stringify(testdata));
});
});
}

@@ -1,2 +0,2 @@

require=function t(e,r,n){function i(s,a){if(!r[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var h=r[s]={exports:{}};e[s][0].call(h.exports,function(t){var r=e[s][1][t];return i(r?r:t)},h,h.exports,t,e,r,n)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(t,e,r){(function(t){function r(t,e){this.buffer=t,this.position=0,this.isBigEndian=e||!1}function n(t,e,r){return function(){var n;return n=this.isBigEndian?e.call(this.buffer,this.position):t.call(this.buffer,this.position),this.position+=r,n}}e.exports=r,r.prototype.readUInt8=n(t.prototype.readUInt8,t.prototype.readUInt8,1),r.prototype.readUInt16=n(t.prototype.readUInt16LE,t.prototype.readUInt16BE,2),r.prototype.readUInt32=n(t.prototype.readUInt32LE,t.prototype.readUInt32BE,4),r.prototype.readInt8=n(t.prototype.readInt8,t.prototype.readInt8,1),r.prototype.readInt16=n(t.prototype.readInt16LE,t.prototype.readInt16BE,2),r.prototype.readInt32=n(t.prototype.readInt32LE,t.prototype.readInt32BE,4),r.prototype.readFloat=n(t.prototype.readFloatLE,t.prototype.readFloatBE,4),r.prototype.readDouble=n(t.prototype.readDoubleLE,t.prototype.readDoubleBE,8),r.prototype.readVarInt=function(){var t,e=0,r=0;do t=this.buffer[this.position+r],e+=(127&t)<<7*r,r++;while(t>=128);return this.position+=r,e}}).call(this,t("buffer").Buffer)},{buffer:"buffer"}],2:[function(t,e,r){(function(t){function r(e,r){this.buffer=new t(e),this.position=0,this.allowResize=r}function n(t,e){return function(r){this.ensureSize(e),t.call(this.buffer,r,this.position),this.position+=e}}e.exports=r,r.prototype.writeUInt8=n(t.prototype.writeUInt8,1),r.prototype.writeUInt16LE=n(t.prototype.writeUInt16LE,2),r.prototype.writeUInt16BE=n(t.prototype.writeUInt16BE,2),r.prototype.writeUInt32LE=n(t.prototype.writeUInt32LE,4),r.prototype.writeUInt32BE=n(t.prototype.writeUInt32BE,4),r.prototype.writeInt8=n(t.prototype.writeInt8,1),r.prototype.writeInt16LE=n(t.prototype.writeInt16LE,2),r.prototype.writeInt16BE=n(t.prototype.writeInt16BE,2),r.prototype.writeInt32LE=n(t.prototype.writeInt32LE,4),r.prototype.writeInt32BE=n(t.prototype.writeInt32BE,4),r.prototype.writeFloatLE=n(t.prototype.writeFloatLE,4),r.prototype.writeFloatBE=n(t.prototype.writeFloatBE,4),r.prototype.writeDoubleLE=n(t.prototype.writeDoubleLE,8),r.prototype.writeDoubleBE=n(t.prototype.writeDoubleBE,8),r.prototype.writeBuffer=function(t){this.ensureSize(t.length),t.copy(this.buffer,this.position,0,t.length),this.position+=t.length},r.prototype.writeVarInt=function(t){for(var e=1;0!==(4294967168&t);)this.writeUInt8(127&t|128),t>>>=7,e++;return this.writeUInt8(127&t),e},r.prototype.ensureSize=function(e){if(this.buffer.length<this.position+e){if(!this.allowResize)throw new RangeError("index out of range");var r=new t(this.position+e);this.buffer.copy(r,0,0,this.buffer.length),this.buffer=r}}}).call(this,t("buffer").Buffer)},{buffer:"buffer"}],3:[function(t,e,r){(function(r){function n(){this.srid=0}e.exports=n;var i=t("./types"),o=t("./point"),s=t("./linestring"),a=t("./polygon"),u=t("./multipoint"),p=t("./multilinestring"),h=t("./multipolygon"),f=t("./geometrycollection"),c=t("./binaryreader"),l=t("./binarywriter"),g=t("./wktparser"),y=t("./zigzag.js");n.parse=function(t){var e=typeof t;if("string"===e||t instanceof g)return n._parseWkt(t);if(r.isBuffer(t)||t instanceof c)return n._parseWkb(t);throw new Error("first argument must be a string or Buffer")},n._parseWkt=function(t){var e,r;e=t instanceof g?t:new g(t);var n=e.matchRegex([/^SRID=(\d+);/]);n&&(r=n[1]);var c=e.matchType(),l={srid:r||0};switch(c){case i.wkt.Point:return o._parseWkt(e,l);case i.wkt.LineString:return s._parseWkt(e,l);case i.wkt.Polygon:return a._parseWkt(e,l);case i.wkt.MultiPoint:return u._parseWkt(e,l);case i.wkt.MultiLineString:return p._parseWkt(e,l);case i.wkt.MultiPolygon:return h._parseWkt(e,l);case i.wkt.GeometryCollection:return f._parseWkt(e,l);default:throw new Error("GeometryType "+c+" not supported")}},n._parseWkb=function(t){var e,r,n,l,g;e=t instanceof c?t:new c(t),e.isBigEndian=!e.readInt8(),l=e.readUInt32(),g=255&l,r=536870912===(536870912&l),r&&(n=e.readUInt32());var y={srid:n||0};switch(g){case i.wkb.Point:return o._parseWkb(e,y);case i.wkb.LineString:return s._parseWkb(e,y);case i.wkb.Polygon:return a._parseWkb(e,y);case i.wkb.MultiPoint:return u._parseWkb(e,y);case i.wkb.MultiLineString:return p._parseWkb(e,y);case i.wkb.MultiPolygon:return h._parseWkb(e,y);case i.wkb.GeometryCollection:return f._parseWkb(e,y);default:throw new Error("GeometryType "+g+" not supported")}},n.parseTwkb=function(t){var e,r={};e=t instanceof c?t:new c(t);var n=e.readUInt8(),l=e.readUInt8(),g=15&n;if(r.precision=y.decode(n>>4),r.precisionFactor=Math.pow(10,r.precision),r.hasBoundingBox=l>>0&1,r.hasSizeAttribute=l>>1&1,r.hasIdList=l>>2&1,r.hasExtendedPrecision=l>>3&1,r.isEmpty=l>>4&1,r.hasExtendedPrecision){var w=e.readUInt8();r.hasZ=1&w,r.hasM=2&w}if(r.hasSizeAttribute&&e.readVarInt(),r.hasBoundingBox){var d=2;r.hasZ&&d++,r.hasM&&d++;for(var b=0;d>b;b++)e.readVarInt(),e.readVarInt()}switch(g){case i.wkb.Point:return o._parseTwkb(e,r);case i.wkb.LineString:return s._parseTwkb(e,r);case i.wkb.Polygon:return a._parseTwkb(e,r);case i.wkb.MultiPoint:return u._parseTwkb(e,r);case i.wkb.MultiLineString:return p._parseTwkb(e,r);case i.wkb.MultiPolygon:return h._parseTwkb(e,r);case i.wkb.GeometryCollection:return f._parseTwkb(e,r);default:throw new Error("GeometryType "+g+" not supported")}},n.parseGeoJSON=function(t){switch(t.type){case i.geoJSON.Point:return o._parseGeoJSON(t);case i.geoJSON.LineString:return s._parseGeoJSON(t);case i.geoJSON.Polygon:return a._parseGeoJSON(t);case i.geoJSON.MultiPoint:return u._parseGeoJSON(t);case i.geoJSON.MultiLineString:return p._parseGeoJSON(t);case i.geoJSON.MultiPolygon:return h._parseGeoJSON(t);case i.geoJSON.GeometryCollection:return f._parseGeoJSON(t);default:throw new Error("GeometryType "+t.type+" not supported")}},n.prototype.toEwkt=function(){return"SRID="+this.srid+";"+this.toWkt()},n.prototype.toEwkb=function(){var t=new l(this._getWkbSize()+4),e=this.toWkb();return t.writeInt8(1),t.writeUInt32LE(536870912|e.slice(1,5).readUInt32LE(0)),t.writeUInt32LE(this.srid),t.writeBuffer(e.slice(5)),t.buffer},n.prototype._writeTwkbHeader=function(t,e,r,n){var i=(y.encode(r)<<4)+e,o=n<<4;t.writeUInt8(i),t.writeUInt8(o)}}).call(this,t("buffer").Buffer)},{"./binaryreader":1,"./binarywriter":2,"./geometrycollection":4,"./linestring":5,"./multilinestring":6,"./multipoint":7,"./multipolygon":8,"./point":9,"./polygon":10,"./types":11,"./wktparser":12,"./zigzag.js":13,buffer:"buffer"}],4:[function(t,e,r){function n(t){s.call(this),this.geometries=t||[]}e.exports=n;{var i=t("util"),o=t("./types"),s=t("./geometry"),a=t("./binarywriter");t("./zigzag.js")}i.inherits(n,s),n._parseWkt=function(t,e){var r=new n;if(r.srid=e.srid,t.isMatch(["EMPTY"]))return r;t.expectGroupStart();do r.geometries.push(s.parse(t));while(t.isMatch([","]));return t.expectGroupEnd(),r},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid;for(var i=t.readUInt32(),o=0;i>o;o++)r.geometries.push(s.parse(t));return r},n._parseTwkb=function(t,e){var r=new n;if(e.isEmpty)return r;for(var i=t.readVarInt(),o=0;i>o;o++)r.geometries.push(s.parseTwkb(t));return r},n._parseGeoJSON=function(t){for(var e=new n,r=0;r<t.geometries.length;r++)e.geometries.push(s.parseGeoJSON(t.geometries[r]));return e},n.prototype.toWkt=function(){if(0===this.geometries.length)return o.wkt.GeometryCollection+" EMPTY";for(var t=o.wkt.GeometryCollection+"(",e=0;e<this.geometries.length;e++)t+=this.geometries[e].toWkt()+",";return t=t.slice(0,-1),t+=")"},n.prototype.toWkb=function(){var t=new a(this._getWkbSize());t.writeInt8(1),t.writeUInt32LE(o.wkb.GeometryCollection),t.writeUInt32LE(this.geometries.length);for(var e=0;e<this.geometries.length;e++)t.writeBuffer(this.geometries[e].toWkb());return t.buffer},n.prototype.toTwkb=function(){var t=new a(0,!0),e=5,r=(Math.pow(10,e),0===this.geometries.length);if(this._writeTwkbHeader(t,o.wkb.GeometryCollection,e,r),this.geometries.length>0){t.writeVarInt(this.geometries.length);for(var n=0;n<this.geometries.length;n++)t.writeBuffer(this.geometries[n].toTwkb())}return t.buffer},n.prototype._getWkbSize=function(){for(var t=9,e=0;e<this.geometries.length;e++)t+=this.geometries[e]._getWkbSize();return t},n.prototype.toGeoJSON=function(){for(var t={type:o.geoJSON.GeometryCollection,geometries:[]},e=0;e<this.geometries.length;e++)t.geometries.push(this.geometries[e].toGeoJSON());return t}},{"./binarywriter":2,"./geometry":3,"./types":11,"./zigzag.js":13,util:20}],5:[function(t,e,r){function n(t){o.call(this),this.points=t||[]}e.exports=n;var i=t("util"),o=t("./geometry"),s=t("./types"),a=t("./point"),u=t("./binarywriter"),p=t("./zigzag.js");i.inherits(n,o),n._parseWkt=function(t,e){var r=new n;return r.srid=e.srid,t.isMatch(["EMPTY"])?r:(t.expectGroupStart(),r.points.push.apply(r.points,t.matchCoordinates()),t.expectGroupEnd(),r)},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid;for(var i=t.readUInt32(),o=0;i>o;o++)r.points.push(new a(t.readDouble(),t.readDouble()));return r},n._parseTwkb=function(t,e){var r=new n;if(e.isEmpty)return r;for(var i=0,o=0,s=t.readVarInt(),u=0;s>u;u++)i+=p.decode(t.readVarInt())/e.precisionFactor,o+=p.decode(t.readVarInt())/e.precisionFactor,r.points.push(new a(i,o));return r},n._parseGeoJSON=function(t){for(var e=new n,r=0;r<t.coordinates.length;r++)e.points.push(new a(t.coordinates[r][0],t.coordinates[r][1]));return e},n.prototype.toWkt=function(){return 0===this.points.length?s.wkt.LineString+" EMPTY":s.wkt.LineString+this._toInnerWkt()},n.prototype._toInnerWkt=function(){for(var t="(",e=0;e<this.points.length;e++)t+=this.points[e].x+" "+this.points[e].y+",";return t=t.slice(0,-1),t+=")"},n.prototype.toWkb=function(){var t=new u(this._getWkbSize());t.writeInt8(1),t.writeUInt32LE(s.wkb.LineString),t.writeUInt32LE(this.points.length);for(var e=0;e<this.points.length;e++)t.writeDoubleLE(this.points[e].x),t.writeDoubleLE(this.points[e].y);return t.buffer},n.prototype.toTwkb=function(){var t=new u(0,!0),e=5,r=Math.pow(10,e),n=0===this.points.length;if(this._writeTwkbHeader(t,s.wkb.LineString,e,n),this.points.length>0){t.writeVarInt(this.points.length);for(var i=0,o=0,a=0;a<this.points.length;a++){var h=this.points[a].x*r,f=this.points[a].y*r;t.writeVarInt(p.encode(h-i)),t.writeVarInt(p.encode(f-o)),i=h,o=f}}return t.buffer},n.prototype._getWkbSize=function(){return 9+16*this.points.length},n.prototype.toGeoJSON=function(){for(var t={type:s.geoJSON.LineString,coordinates:[]},e=0;e<this.points.length;e++)t.coordinates.push([this.points[e].x,this.points[e].y]);return t}},{"./binarywriter":2,"./geometry":3,"./point":9,"./types":11,"./zigzag.js":13,util:20}],6:[function(t,e,r){function n(t){s.call(this),this.lineStrings=t||[]}e.exports=n;var i=t("util"),o=t("./types"),s=t("./geometry"),a=t("./point"),u=t("./linestring"),p=t("./binarywriter"),h=t("./zigzag.js");i.inherits(n,s),n._parseWkt=function(t,e){var r=new n;if(r.srid=e.srid,t.isMatch(["EMPTY"]))return r;t.expectGroupStart();do t.expectGroupStart(),r.lineStrings.push(new u(t.matchCoordinates())),t.expectGroupEnd();while(t.isMatch([","]));return t.expectGroupEnd(),r},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid;for(var i=t.readUInt32(),o=0;i>o;o++)r.lineStrings.push(s.parse(t));return r},n._parseTwkb=function(t,e){var r=new n;if(e.isEmpty)return r;for(var i=0,o=0,s=t.readVarInt(),p=0;s>p;p++){for(var f=new u,c=t.readVarInt(),l=0;c>l;l++)i+=h.decode(t.readVarInt())/e.precisionFactor,o+=h.decode(t.readVarInt())/e.precisionFactor,f.points.push(new a(i,o));r.lineStrings.push(f)}return r},n._parseGeoJSON=function(t){for(var e=new n,r=0;r<t.coordinates.length;r++)e.lineStrings.push(u._parseGeoJSON({coordinates:t.coordinates[r]}));return e},n.prototype.toWkt=function(){if(0===this.lineStrings.length)return o.wkt.MultiLineString+" EMPTY";for(var t=o.wkt.MultiLineString+"(",e=0;e<this.lineStrings.length;e++)t+=this.lineStrings[e]._toInnerWkt()+",";return t=t.slice(0,-1),t+=")"},n.prototype.toWkb=function(){var t=new p(this._getWkbSize());t.writeInt8(1),t.writeUInt32LE(o.wkb.MultiLineString),t.writeUInt32LE(this.lineStrings.length);for(var e=0;e<this.lineStrings.length;e++)t.writeBuffer(this.lineStrings[e].toWkb());return t.buffer},n.prototype.toTwkb=function(){var t=new p(0,!0),e=5,r=Math.pow(10,e),n=0===this.lineStrings.length;if(this._writeTwkbHeader(t,o.wkb.MultiLineString,e,n),this.lineStrings.length>0){t.writeVarInt(this.lineStrings.length);for(var i=0,s=0,a=0;a<this.lineStrings.length;a++){t.writeVarInt(this.lineStrings[a].points.length);for(var u=0;u<this.lineStrings[a].points.length;u++){var f=this.lineStrings[a].points[u].x*r,c=this.lineStrings[a].points[u].y*r;t.writeVarInt(h.encode(f-i)),t.writeVarInt(h.encode(c-s)),i=f,s=c}}}return t.buffer},n.prototype._getWkbSize=function(){for(var t=9,e=0;e<this.lineStrings.length;e++)t+=this.lineStrings[e]._getWkbSize();return t},n.prototype.toGeoJSON=function(){for(var t={type:o.geoJSON.MultiLineString,coordinates:[]},e=0;e<this.lineStrings.length;e++)t.coordinates.push(this.lineStrings[e].toGeoJSON().coordinates);return t}},{"./binarywriter":2,"./geometry":3,"./linestring":5,"./point":9,"./types":11,"./zigzag.js":13,util:20}],7:[function(t,e,r){function n(t){s.call(this),this.points=t||[]}e.exports=n;var i=t("util"),o=t("./types"),s=t("./geometry"),a=t("./point"),u=t("./binarywriter"),p=t("./zigzag");i.inherits(n,s),n._parseWkt=function(t,e){var r=new n;return r.srid=e.srid,t.isMatch(["EMPTY"])?r:(t.expectGroupStart(),r.points.push.apply(r.points,t.matchCoordinates()),t.expectGroupEnd(),r)},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid;for(var i=t.readUInt32(),o=0;i>o;o++)r.points.push(s.parse(t));return r},n._parseTwkb=function(t,e){var r=new n;if(e.isEmpty)return r;for(var i=t.readVarInt(),o=0,s=0,u=0;i>u;u++)o+=p.decode(t.readVarInt())/e.precisionFactor,s+=p.decode(t.readVarInt())/e.precisionFactor,r.points.push(new a(o,s));return r},n._parseGeoJSON=function(t){for(var e=new n,r=0;r<t.coordinates.length;r++)e.points.push(a._parseGeoJSON({coordinates:t.coordinates[r]}));return e},n.prototype.toWkt=function(){if(0===this.points.length)return o.wkt.MultiPoint+" EMPTY";for(var t=o.wkt.MultiPoint+"(",e=0;e<this.points.length;e++)t+=this.points[e].x+" "+this.points[e].y+",";return t=t.slice(0,-1),t+=")"},n.prototype.toWkb=function(){var t=new u(this._getWkbSize());t.writeInt8(1),t.writeUInt32LE(o.wkb.MultiPoint),t.writeUInt32LE(this.points.length);for(var e=0;e<this.points.length;e++)t.writeBuffer(this.points[e].toWkb());return t.buffer},n.prototype.toTwkb=function(){var t=new u(0,!0),e=5,r=Math.pow(10,e),n=0===this.points.length;if(this._writeTwkbHeader(t,o.wkb.MultiPoint,e,n),this.points.length>0){t.writeVarInt(this.points.length);for(var i=0,s=0,a=0;a<this.points.length;a++){var h=this.points[a].x*r,f=this.points[a].y*r;t.writeVarInt(p.encode(h-i)),t.writeVarInt(p.encode(f-s)),i=h,s=f}}return t.buffer},n.prototype._getWkbSize=function(){return 9+21*this.points.length},n.prototype.toGeoJSON=function(){for(var t={type:o.geoJSON.MultiPoint,coordinates:[]},e=0;e<this.points.length;e++)t.coordinates.push(this.points[e].toGeoJSON().coordinates);return t}},{"./binarywriter":2,"./geometry":3,"./point":9,"./types":11,"./zigzag":13,util:20}],8:[function(t,e,r){function n(t){s.call(this),this.polygons=t||[]}e.exports=n;var i=t("util"),o=t("./types"),s=t("./geometry"),a=t("./point"),u=t("./polygon"),p=t("./binarywriter"),h=t("./zigzag.js");i.inherits(n,s),n._parseWkt=function(t,e){var r=new n;if(r.srid=e.srid,t.isMatch(["EMPTY"]))return r;t.expectGroupStart();do{t.expectGroupStart();var i=new u;for(t.expectGroupStart(),i.exteriorRing.push.apply(i.exteriorRing,t.matchCoordinates()),t.expectGroupEnd();t.isMatch([","]);)t.expectGroupStart(),i.interiorRings.push(t.matchCoordinates()),t.expectGroupEnd();r.polygons.push(i),t.expectGroupEnd()}while(t.isMatch([","]));return t.expectGroupEnd(),r},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid;for(var i=t.readUInt32(),o=0;i>o;o++)r.polygons.push(s.parse(t));return r},n._parseTwkb=function(t,e){var r=new n;if(e.isEmpty)return r;for(var i=0,o=0,s=t.readVarInt(),p=0;s>p;p++){for(var f=new u,c=t.readVarInt(),l=t.readVarInt(),g=0;l>g;g++)i+=h.decode(t.readVarInt())/e.precisionFactor,o+=h.decode(t.readVarInt())/e.precisionFactor,f.exteriorRing.push(new a(i,o));for(g=1;c>g;g++){for(var y=[],w=t.readVarInt(),d=0;w>d;d++)i+=h.decode(t.readVarInt())/e.precisionFactor,o+=h.decode(t.readVarInt())/e.precisionFactor,y.push(new a(i,o));f.interiorRings.push(y)}r.polygons.push(f)}return r},n._parseGeoJSON=function(t){for(var e=new n,r=0;r<t.coordinates.length;r++)e.polygons.push(u._parseGeoJSON({coordinates:t.coordinates[r]}));return e},n.prototype.toWkt=function(){if(0===this.polygons.length)return o.wkt.MultiPolygon+" EMPTY";for(var t=o.wkt.MultiPolygon+"(",e=0;e<this.polygons.length;e++)t+=this.polygons[e]._toInnerWkt()+",";return t=t.slice(0,-1),t+=")"},n.prototype.toWkb=function(){var t=new p(this._getWkbSize());t.writeInt8(1),t.writeUInt32LE(o.wkb.MultiPolygon),t.writeUInt32LE(this.polygons.length);for(var e=0;e<this.polygons.length;e++)t.writeBuffer(this.polygons[e].toWkb());return t.buffer},n.prototype.toTwkb=function(){var t=new p(0,!0),e=5,r=Math.pow(10,e),n=0===this.polygons.length;if(this._writeTwkbHeader(t,o.wkb.MultiPolygon,e,n),this.polygons.length>0){t.writeVarInt(this.polygons.length);for(var i=0,s=0,a=0,u=0,f=0;f<this.polygons.length;f++){t.writeVarInt(1+this.polygons[f].interiorRings.length),t.writeVarInt(this.polygons[f].exteriorRing.length);for(var c=0;c<this.polygons[f].exteriorRing.length;c++)a=this.polygons[f].exteriorRing[c].x*r,u=this.polygons[f].exteriorRing[c].y*r,t.writeVarInt(h.encode(a-i)),t.writeVarInt(h.encode(u-s)),i=a,s=u;for(c=0;c<this.polygons[f].interiorRings.length;c++){t.writeVarInt(this.polygons[f].interiorRings[c].length);for(var l=0;l<this.polygons[f].interiorRings[c].length;l++)a=this.polygons[f].interiorRings[c][l].x*r,u=this.polygons[f].interiorRings[c][l].y*r,t.writeVarInt(h.encode(a-i)),t.writeVarInt(h.encode(u-s)),i=a,s=u}}}return t.buffer},n.prototype._getWkbSize=function(){for(var t=9,e=0;e<this.polygons.length;e++)t+=this.polygons[e]._getWkbSize();return t},n.prototype.toGeoJSON=function(){for(var t={type:o.geoJSON.MultiPolygon,coordinates:[]},e=0;e<this.polygons.length;e++)t.coordinates.push(this.polygons[e].toGeoJSON().coordinates);return t}},{"./binarywriter":2,"./geometry":3,"./point":9,"./polygon":10,"./types":11,"./zigzag.js":13,util:20}],9:[function(t,e,r){function n(t,e){o.call(this),this.x=t,this.y=e}e.exports=n;var i=t("util"),o=t("./geometry"),s=t("./types"),a=t("./binarywriter"),u=t("./zigzag.js");i.inherits(n,o),n._parseWkt=function(t,e){var r=new n;if(r.srid=e.srid,t.isMatch(["EMPTY"]))return r;t.expectGroupStart();var i=t.matchCoordinate();return r.x=i.x,r.y=i.y,t.expectGroupEnd(),r},n._parseWkb=function(t,e){var r=new n(t.readDouble(),t.readDouble());return r.srid=e.srid,r},n._parseTwkb=function(t,e){if(e.isEmpty)return new n;var r=u.decode(t.readVarInt())/e.precisionFactor,i=u.decode(t.readVarInt())/e.precisionFactor;return new n(r,i)},n._parseGeoJSON=function(t){return 0===t.coordinates.length?new n:new n(t.coordinates[0],t.coordinates[1])},n.prototype.toWkt=function(){return"undefined"==typeof this.x&&"undefined"==typeof this.y?s.wkt.Point+" EMPTY":s.wkt.Point+"("+this.x+" "+this.y+")"},n.prototype.toWkb=function(){var t=new a(this._getWkbSize());return t.writeInt8(1),"undefined"==typeof this.x&&"undefined"==typeof this.y?(t.writeUInt32LE(s.wkb.MultiPoint),t.writeUInt32LE(0)):(t.writeUInt32LE(s.wkb.Point),t.writeDoubleLE(this.x),t.writeDoubleLE(this.y)),t.buffer},n.prototype.toTwkb=function(){var t=new a(0,!0),e=5,r=Math.pow(10,e),n="undefined"==typeof this.x&&"undefined"==typeof this.y;return this._writeTwkbHeader(t,s.wkb.Point,e,n),n||(t.writeVarInt(u.encode(this.x*r)),t.writeVarInt(u.encode(this.y*r))),t.buffer},n.prototype._getWkbSize=function(){return"undefined"==typeof this.x&&"undefined"==typeof this.y?9:21},n.prototype.toGeoJSON=function(){var t={type:s.geoJSON.Point};return t.coordinates="undefined"==typeof this.x&&"undefined"==typeof this.y?[]:[this.x,this.y],t}},{"./binarywriter":2,"./geometry":3,"./types":11,"./zigzag.js":13,util:20}],10:[function(t,e,r){function n(t,e){o.call(this),this.exteriorRing=t||[],this.interiorRings=e||[]}e.exports=n;var i=t("util"),o=t("./geometry"),s=t("./types"),a=t("./point"),u=t("./binarywriter"),p=t("./zigzag");i.inherits(n,o),n._parseWkt=function(t,e){var r=new n;if(r.srid=e.srid,t.isMatch(["EMPTY"]))return r;for(t.expectGroupStart(),t.expectGroupStart(),r.exteriorRing.push.apply(r.exteriorRing,t.matchCoordinates()),t.expectGroupEnd();t.isMatch([","]);)t.expectGroupStart(),r.interiorRings.push(t.matchCoordinates()),t.expectGroupEnd();return t.expectGroupEnd(),r},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid;var i=t.readUInt32();if(i>0){for(var o=t.readUInt32(),s=0;o>s;s++)r.exteriorRing.push(new a(t.readDouble(),t.readDouble()));for(s=1;i>s;s++){for(var u=[],p=t.readUInt32(),h=0;p>h;h++)u.push(new a(t.readDouble(),t.readDouble()));r.interiorRings.push(u)}}return r},n._parseTwkb=function(t,e){var r=new n;if(e.isEmpty)return r;for(var i=0,o=0,s=t.readVarInt(),u=t.readVarInt(),h=0;u>h;h++)i+=p.decode(t.readVarInt())/e.precisionFactor,o+=p.decode(t.readVarInt())/e.precisionFactor,r.exteriorRing.push(new a(i,o));for(h=1;s>h;h++){for(var f=[],c=t.readVarInt(),l=0;c>l;l++)i+=p.decode(t.readVarInt())/e.precisionFactor,o+=p.decode(t.readVarInt())/e.precisionFactor,f.push(new a(i,o));r.interiorRings.push(f)}return r},n._parseGeoJSON=function(t){for(var e=new n,r=0;r<t.coordinates.length;r++){r>0&&e.interiorRings.push([]);for(var i=0;i<t.coordinates[r].length;i++)0===r?e.exteriorRing.push(new a(t.coordinates[r][i][0],t.coordinates[r][i][1])):e.interiorRings[r-1].push(new a(t.coordinates[r][i][0],t.coordinates[r][i][1]))}return e},n.prototype.toWkt=function(){return 0===this.exteriorRing.length?s.wkt.Polygon+" EMPTY":s.wkt.Polygon+this._toInnerWkt()},n.prototype._toInnerWkt=function(){for(var t="((",e=0;e<this.exteriorRing.length;e++)t+=this.exteriorRing[e].x+" "+this.exteriorRing[e].y+",";for(t=t.slice(0,-1),t+=")",e=0;e<this.interiorRings.length;e++){t+=",(";for(var r=0;r<this.interiorRings[e].length;r++)t+=this.interiorRings[e][r].x+" "+this.interiorRings[e][r].y+",";t=t.slice(0,-1),t+=")"}return t+=")"},n.prototype.toWkb=function(){var t=new u(this._getWkbSize());t.writeInt8(1),t.writeUInt32LE(s.wkb.Polygon),this.exteriorRing.length>0?(t.writeUInt32LE(1+this.interiorRings.length),t.writeUInt32LE(this.exteriorRing.length)):t.writeUInt32LE(0);for(var e=0;e<this.exteriorRing.length;e++)t.writeDoubleLE(this.exteriorRing[e].x),t.writeDoubleLE(this.exteriorRing[e].y);for(e=0;e<this.interiorRings.length;e++){t.writeUInt32LE(this.interiorRings[e].length);for(var r=0;r<this.interiorRings[e].length;r++)t.writeDoubleLE(this.interiorRings[e][r].x),t.writeDoubleLE(this.interiorRings[e][r].y)}return t.buffer},n.prototype.toTwkb=function(){var t=new u(0,!0),e=5,r=Math.pow(10,e),n=0===this.exteriorRing.length;if(this._writeTwkbHeader(t,s.wkb.Polygon,e,n),this.exteriorRing.length>0){t.writeVarInt(1+this.interiorRings.length),t.writeVarInt(this.exteriorRing.length);for(var i=0,o=0,a=0,h=0,f=0;f<this.exteriorRing.length;f++)a=this.exteriorRing[f].x*r,h=this.exteriorRing[f].y*r,t.writeVarInt(p.encode(a-i)),t.writeVarInt(p.encode(h-o)),i=a,o=h;for(f=0;f<this.interiorRings.length;f++){t.writeVarInt(this.interiorRings[f].length);for(var c=0;c<this.interiorRings[f].length;c++)a=this.interiorRings[f][c].x*r,h=this.interiorRings[f][c].y*r,t.writeVarInt(p.encode(a-i)),t.writeVarInt(p.encode(h-o)),i=a,o=h}}return t.buffer},n.prototype._getWkbSize=function(){var t=9;this.exteriorRing.length>0&&(t+=4+16*this.exteriorRing.length);for(var e=0;e<this.interiorRings.length;e++)t+=4+16*this.interiorRings[e].length;return t},n.prototype.toGeoJSON=function(){var t={type:s.geoJSON.Polygon,coordinates:[]};if(this.exteriorRing.length>0){for(var e=[],r=0;r<this.exteriorRing.length;r++)e.push([this.exteriorRing[r].x,this.exteriorRing[r].y]);t.coordinates.push(e)}for(var n=0;n<this.interiorRings.length;n++){for(var i=[],o=0;o<this.interiorRings[n].length;o++)i.push([this.interiorRings[n][o].x,this.interiorRings[n][o].y]);t.coordinates.push(i)}return t}},{"./binarywriter":2,"./geometry":3,"./point":9,"./types":11,"./zigzag":13,util:20}],11:[function(t,e,r){e.exports={wkt:{Point:"POINT",LineString:"LINESTRING",Polygon:"POLYGON",MultiPoint:"MULTIPOINT",MultiLineString:"MULTILINESTRING",MultiPolygon:"MULTIPOLYGON",GeometryCollection:"GEOMETRYCOLLECTION"},wkb:{Point:1,LineString:2,Polygon:3,MultiPoint:4,MultiLineString:5,MultiPolygon:6,GeometryCollection:7},geoJSON:{Point:"Point",LineString:"LineString",Polygon:"Polygon",MultiPoint:"MultiPoint",MultiLineString:"MultiLineString",MultiPolygon:"MultiPolygon",GeometryCollection:"GeometryCollection"}}},{}],12:[function(t,e,r){function n(t){this.value=t,this.position=0}e.exports=n;var i=t("./types"),o=t("./point");n.prototype.match=function(t){this.skipWhitespaces();for(var e=0;e<t.length;e++)if(0===this.value.substring(this.position).indexOf(t[e]))return this.position+=t[e].length,t[e];return null},n.prototype.matchRegex=function(t){this.skipWhitespaces();for(var e=0;e<t.length;e++){var r=this.value.substring(this.position).match(t[e]);if(r)return this.position+=r[0].length,r}return null},n.prototype.isMatch=function(t){this.skipWhitespaces();for(var e=0;e<t.length;e++)if(0===this.value.substring(this.position).indexOf(t[e]))return this.position+=t[e].length,!0;return!1},n.prototype.matchType=function(){var t=this.match([i.wkt.Point,i.wkt.LineString,i.wkt.Polygon,i.wkt.MultiPoint,i.wkt.MultiLineString,i.wkt.MultiPolygon,i.wkt.GeometryCollection]);if(!t)throw new Error("Expected geometry type");return t},n.prototype.expectGroupStart=function(){if(!this.isMatch(["("]))throw new Error("Expected group start")},n.prototype.expectGroupEnd=function(){if(!this.isMatch([")"]))throw new Error("Expected group end")},n.prototype.matchCoordinate=function(){var t=this.matchRegex([/^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)/]);if(!t)throw new Error("Expected coordinate pair");return new o(parseFloat(t[1]),parseFloat(t[2]))},n.prototype.matchCoordinates=function(){var t=[];do t.push(this.matchCoordinate());while(this.isMatch([","]));return t},n.prototype.skipWhitespaces=function(){for(;this.position<this.value.length&&" "===this.value[this.position];)this.position++}},{"./point":9,"./types":11}],13:[function(t,e,r){e.exports={encode:function(t){return t<<1^t>>31},decode:function(t){return t>>1^-(1&t)}}},{}],14:[function(t,e,r){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(t){"use strict";function e(t){var e=t.charCodeAt(0);return e===s||e===f?62:e===a||e===c?63:u>e?-1:u+10>e?e-u+26+26:h+26>e?e-h:p+26>e?e-p+26:void 0}function r(t){function r(t){p[f++]=t}var n,i,s,a,u,p;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var h=t.length;u="="===t.charAt(h-2)?2:"="===t.charAt(h-1)?1:0,p=new o(3*t.length/4-u),s=u>0?t.length-4:t.length;var f=0;for(n=0,i=0;s>n;n+=4,i+=3)a=e(t.charAt(n))<<18|e(t.charAt(n+1))<<12|e(t.charAt(n+2))<<6|e(t.charAt(n+3)),r((16711680&a)>>16),r((65280&a)>>8),r(255&a);return 2===u?(a=e(t.charAt(n))<<2|e(t.charAt(n+1))>>4,r(255&a)):1===u&&(a=e(t.charAt(n))<<10|e(t.charAt(n+1))<<4|e(t.charAt(n+2))>>2,r(a>>8&255),r(255&a)),p}function i(t){function e(t){return n.charAt(t)}function r(t){return e(t>>18&63)+e(t>>12&63)+e(t>>6&63)+e(63&t)}var i,o,s,a=t.length%3,u="";for(i=0,s=t.length-a;s>i;i+=3)o=(t[i]<<16)+(t[i+1]<<8)+t[i+2],u+=r(o);switch(a){case 1:o=t[t.length-1],u+=e(o>>2),u+=e(o<<4&63),u+="==";break;case 2:o=(t[t.length-2]<<8)+t[t.length-1],u+=e(o>>10),u+=e(o>>4&63),u+=e(o<<2&63),u+="="}return u}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="+".charCodeAt(0),a="/".charCodeAt(0),u="0".charCodeAt(0),p="a".charCodeAt(0),h="A".charCodeAt(0),f="-".charCodeAt(0),c="_".charCodeAt(0);t.toByteArray=r,t.fromByteArray=i}("undefined"==typeof r?this.base64js={}:r)},{}],15:[function(t,e,r){r.read=function(t,e,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,p=u>>1,h=-7,f=r?i-1:0,c=r?-1:1,l=t[e+f];for(f+=c,o=l&(1<<-h)-1,l>>=-h,h+=a;h>0;o=256*o+t[e+f],f+=c,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+t[e+f],f+=c,h-=8);if(0===o)o=1-p;else{if(o===u)return s?0/0:(l?-1:1)*(1/0);s+=Math.pow(2,n),o-=p}return(l?-1:1)*s*Math.pow(2,o-n)},r.write=function(t,e,r,n,i,o){var s,a,u,p=8*o-i-1,h=(1<<p)-1,f=h>>1,c=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=n?0:o-1,g=n?1:-1,y=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),e+=s+f>=1?c/u:c*Math.pow(2,1-f),e*u>=2&&(s++,u/=2),s+f>=h?(a=0,s=h):s+f>=1?(a=(e*u-1)*Math.pow(2,i),s+=f):(a=e*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;t[r+l]=255&a,l+=g,a/=256,i-=8);for(s=s<<i|a,p+=i;p>0;t[r+l]=255&s,l+=g,s/=256,p-=8);t[r+l-g]|=128*y}},{}],16:[function(t,e,r){var n=Array.isArray,i=Object.prototype.toString;e.exports=n||function(t){return!!t&&"[object Array]"==i.call(t)}},{}],17:[function(t,e,r){e.exports="function"==typeof Object.create?function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}},{}],18:[function(t,e,r){function n(){h=!1,a.length?p=a.concat(p):f=-1,p.length&&i()}function i(){if(!h){var t=setTimeout(n);h=!0;for(var e=p.length;e;){for(a=p,p=[];++f<e;)a[f].run();f=-1,e=p.length}a=null,h=!1,clearTimeout(t)}}function o(t,e){this.fun=t,this.array=e}function s(){}var a,u=e.exports={},p=[],h=!1,f=-1;u.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];p.push(new o(t,e)),1!==p.length||h||setTimeout(i,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},u.title="browser",u.browser=!0,u.env={},u.argv=[],u.version="",u.versions={},u.on=s,u.addListener=s,u.once=s,u.off=s,u.removeListener=s,u.removeAllListeners=s,u.emit=s,u.binding=function(t){throw new Error("process.binding is not supported")},u.cwd=function(){return"/"},u.chdir=function(t){throw new Error("process.chdir is not supported")},u.umask=function(){return 0}},{}],19:[function(t,e,r){e.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},{}],20:[function(t,e,r){(function(e,n){function i(t,e){var n={seen:[],stylize:s};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),y(e)?n.showHidden=e:e&&r._extend(n,e),I(n.showHidden)&&(n.showHidden=!1),I(n.depth)&&(n.depth=2),I(n.colors)&&(n.colors=!1),I(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=o),u(n,t,n.depth)}function o(t,e){var r=i.styles[e];return r?"["+i.colors[r][0]+"m"+t+"["+i.colors[r][1]+"m":t}function s(t,e){return t}function a(t){var e={};return t.forEach(function(t,r){e[t]=!0}),e}function u(t,e,n){if(t.customInspect&&e&&R(e.inspect)&&e.inspect!==r.inspect&&(!e.constructor||e.constructor.prototype!==e)){var i=e.inspect(n,t);return v(i)||(i=u(t,i,n)),i}var o=p(t,e);if(o)return o;var s=Object.keys(e),y=a(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(e)),x(e)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return h(e);if(0===s.length){if(R(e)){var w=e.name?": "+e.name:"";return t.stylize("[Function"+w+"]","special")}if(m(e))return t.stylize(RegExp.prototype.toString.call(e),"regexp");if(k(e))return t.stylize(Date.prototype.toString.call(e),"date");if(x(e))return h(e)}var d="",b=!1,E=["{","}"];if(g(e)&&(b=!0,
E=["[","]"]),R(e)){var I=e.name?": "+e.name:"";d=" [Function"+I+"]"}if(m(e)&&(d=" "+RegExp.prototype.toString.call(e)),k(e)&&(d=" "+Date.prototype.toUTCString.call(e)),x(e)&&(d=" "+h(e)),0===s.length&&(!b||0==e.length))return E[0]+d+E[1];if(0>n)return m(e)?t.stylize(RegExp.prototype.toString.call(e),"regexp"):t.stylize("[Object]","special");t.seen.push(e);var S;return S=b?f(t,e,n,y,s):s.map(function(r){return c(t,e,n,y,r,b)}),t.seen.pop(),l(S,d,E)}function p(t,e){if(I(e))return t.stylize("undefined","undefined");if(v(e)){var r="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(r,"string")}return b(e)?t.stylize(""+e,"number"):y(e)?t.stylize(""+e,"boolean"):w(e)?t.stylize("null","null"):void 0}function h(t){return"["+Error.prototype.toString.call(t)+"]"}function f(t,e,r,n,i){for(var o=[],s=0,a=e.length;a>s;++s)o.push(B(e,String(s))?c(t,e,r,n,String(s),!0):"");return i.forEach(function(i){i.match(/^\d+$/)||o.push(c(t,e,r,n,i,!0))}),o}function c(t,e,r,n,i,o){var s,a,p;if(p=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]},p.get?a=p.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):p.set&&(a=t.stylize("[Setter]","special")),B(n,i)||(s="["+i+"]"),a||(t.seen.indexOf(p.value)<0?(a=w(r)?u(t,p.value,null):u(t,p.value,r-1),a.indexOf("\n")>-1&&(a=o?a.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+a.split("\n").map(function(t){return" "+t}).join("\n"))):a=t.stylize("[Circular]","special")),I(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+a}function l(t,e,r){var n=0,i=t.reduce(function(t,e){return n++,e.indexOf("\n")>=0&&n++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?r[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+r[1]:r[0]+e+" "+t.join(", ")+" "+r[1]}function g(t){return Array.isArray(t)}function y(t){return"boolean"==typeof t}function w(t){return null===t}function d(t){return null==t}function b(t){return"number"==typeof t}function v(t){return"string"==typeof t}function E(t){return"symbol"==typeof t}function I(t){return void 0===t}function m(t){return S(t)&&"[object RegExp]"===L(t)}function S(t){return"object"==typeof t&&null!==t}function k(t){return S(t)&&"[object Date]"===L(t)}function x(t){return S(t)&&("[object Error]"===L(t)||t instanceof Error)}function R(t){return"function"==typeof t}function _(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||"undefined"==typeof t}function L(t){return Object.prototype.toString.call(t)}function U(t){return 10>t?"0"+t.toString(10):t.toString(10)}function P(){var t=new Date,e=[U(t.getHours()),U(t.getMinutes()),U(t.getSeconds())].join(":");return[t.getDate(),A[t.getMonth()],e].join(" ")}function B(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var M=/%[sdj%]/g;r.format=function(t){if(!v(t)){for(var e=[],r=0;r<arguments.length;r++)e.push(i(arguments[r]));return e.join(" ")}for(var r=1,n=arguments,o=n.length,s=String(t).replace(M,function(t){if("%%"===t)return"%";if(r>=o)return t;switch(t){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(e){return"[Circular]"}default:return t}}),a=n[r];o>r;a=n[++r])s+=w(a)||!S(a)?" "+a:" "+i(a);return s},r.deprecate=function(t,i){function o(){if(!s){if(e.throwDeprecation)throw new Error(i);e.traceDeprecation?console.trace(i):console.error(i),s=!0}return t.apply(this,arguments)}if(I(n.process))return function(){return r.deprecate(t,i).apply(this,arguments)};if(e.noDeprecation===!0)return t;var s=!1;return o};var T,O={};r.debuglog=function(t){if(I(T)&&(T=e.env.NODE_DEBUG||""),t=t.toUpperCase(),!O[t])if(new RegExp("\\b"+t+"\\b","i").test(T)){var n=e.pid;O[t]=function(){var e=r.format.apply(r,arguments);console.error("%s %d: %s",t,n,e)}}else O[t]=function(){};return O[t]},r.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=g,r.isBoolean=y,r.isNull=w,r.isNullOrUndefined=d,r.isNumber=b,r.isString=v,r.isSymbol=E,r.isUndefined=I,r.isRegExp=m,r.isObject=S,r.isDate=k,r.isError=x,r.isFunction=R,r.isPrimitive=_,r.isBuffer=t("./support/isBuffer");var A=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];r.log=function(){console.log("%s - %s",P(),r.format.apply(r,arguments))},r.inherits=t("inherits"),r._extend=function(t,e){if(!e||!S(e))return t;for(var r=Object.keys(e),n=r.length;n--;)t[r[n]]=e[r[n]];return t}}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":19,_process:18,inherits:17}],buffer:[function(t,e,r){function n(){return i.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function i(t){return this instanceof i?(this.length=0,this.parent=void 0,"number"==typeof t?o(this,t):"string"==typeof t?s(this,t,arguments.length>1?arguments[1]:"utf8"):a(this,t)):arguments.length>1?new i(t,arguments[1]):new i(t)}function o(t,e){if(t=l(t,0>e?0:0|g(e)),!i.TYPED_ARRAY_SUPPORT)for(var r=0;e>r;r++)t[r]=0;return t}function s(t,e,r){("string"!=typeof r||""===r)&&(r="utf8");var n=0|w(e,r);return t=l(t,n),t.write(e,r),t}function a(t,e){if(i.isBuffer(e))return u(t,e);if(q(e))return p(t,e);if(null==e)throw new TypeError("must start with number, buffer, array or string");return"undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer?h(t,e):e.length?f(t,e):c(t,e)}function u(t,e){var r=0|g(e.length);return t=l(t,r),e.copy(t,0,0,r),t}function p(t,e){var r=0|g(e.length);t=l(t,r);for(var n=0;r>n;n+=1)t[n]=255&e[n];return t}function h(t,e){var r=0|g(e.length);t=l(t,r);for(var n=0;r>n;n+=1)t[n]=255&e[n];return t}function f(t,e){var r=0|g(e.length);t=l(t,r);for(var n=0;r>n;n+=1)t[n]=255&e[n];return t}function c(t,e){var r,n=0;"Buffer"===e.type&&q(e.data)&&(r=e.data,n=0|g(r.length)),t=l(t,n);for(var i=0;n>i;i+=1)t[i]=255&r[i];return t}function l(t,e){i.TYPED_ARRAY_SUPPORT?t=i._augment(new Uint8Array(e)):(t.length=e,t._isBuffer=!0);var r=0!==e&&e<=i.poolSize>>>1;return r&&(t.parent=$),t}function g(t){if(t>=n())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n().toString(16)+" bytes");return 0|t}function y(t,e){if(!(this instanceof y))return new y(t,e);var r=new i(t,e);return delete r.parent,r}function w(t,e){"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"binary":case"raw":case"raws":return r;case"utf8":case"utf-8":return D(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Y(t).length;default:if(n)return D(t).length;e=(""+e).toLowerCase(),n=!0}}function d(t,e,r){var n=!1;if(e=0|e,r=void 0===r||r===1/0?this.length:0|r,t||(t="utf8"),0>e&&(e=0),r>this.length&&(r=this.length),e>=r)return"";for(;;)switch(t){case"hex":return L(this,e,r);case"utf8":case"utf-8":return x(this,e,r);case"ascii":return R(this,e,r);case"binary":return _(this,e,r);case"base64":return k(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function b(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var o=e.length;if(o%2!==0)throw new Error("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;n>s;s++){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))throw new Error("Invalid hex string");t[r+s]=a}return s}function v(t,e,r,n){return J(D(e,t.length-r),t,r,n)}function E(t,e,r,n){return J(C(e),t,r,n)}function I(t,e,r,n){return E(t,e,r,n)}function m(t,e,r,n){return J(Y(e),t,r,n)}function S(t,e,r,n){return J(V(e,t.length-r),t,r,n)}function k(t,e,r){return j.fromByteArray(0===e&&r===t.length?t:t.slice(e,r))}function x(t,e,r){var n="",i="";r=Math.min(t.length,r);for(var o=e;r>o;o++)t[o]<=127?(n+=F(i)+String.fromCharCode(t[o]),i=""):i+="%"+t[o].toString(16);return n+F(i)}function R(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;r>i;i++)n+=String.fromCharCode(127&t[i]);return n}function _(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;r>i;i++)n+=String.fromCharCode(t[i]);return n}function L(t,e,r){var n=t.length;(!e||0>e)&&(e=0),(!r||0>r||r>n)&&(r=n);for(var i="",o=e;r>o;o++)i+=N(t[o]);return i}function U(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function P(t,e,r){if(t%1!==0||0>t)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,o,s){if(!i.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");if(e>o||s>e)throw new RangeError("value is out of bounds");if(r+n>t.length)throw new RangeError("index out of range")}function M(t,e,r,n){0>e&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);o>i;i++)t[r+i]=(e&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function T(t,e,r,n){0>e&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);o>i;i++)t[r+i]=e>>>8*(n?i:3-i)&255}function O(t,e,r,n,i,o){if(e>i||o>e)throw new RangeError("value is out of bounds");if(r+n>t.length)throw new RangeError("index out of range");if(0>r)throw new RangeError("index out of range")}function A(t,e,r,n,i){return i||O(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),H.write(t,e,r,n,23,4),r+4}function G(t,e,r,n,i){return i||O(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),H.write(t,e,r,n,52,8),r+8}function z(t){if(t=W(t).replace(X,""),t.length<2)return"";for(;t.length%4!==0;)t+="=";return t}function W(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function N(t){return 16>t?"0"+t.toString(16):t.toString(16)}function D(t,e){e=e||1/0;for(var r,n=t.length,i=null,o=[],s=0;n>s;s++){if(r=t.charCodeAt(s),r>55295&&57344>r){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(56320>r){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=i-55296<<10|r-56320|65536,i=null}else i&&((e-=3)>-1&&o.push(239,191,189),i=null);if(128>r){if((e-=1)<0)break;o.push(r)}else if(2048>r){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(65536>r){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(2097152>r))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function C(t){for(var e=[],r=0;r<t.length;r++)e.push(255&t.charCodeAt(r));return e}function V(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);s++)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Y(t){return j.toByteArray(z(t))}function J(t,e,r,n){for(var i=0;n>i&&!(i+r>=e.length||i>=t.length);i++)e[i+r]=t[i];return i}function F(t){try{return decodeURIComponent(t)}catch(e){return String.fromCharCode(65533)}}var j=t("base64-js"),H=t("ieee754"),q=t("is-array");r.Buffer=i,r.SlowBuffer=y,r.INSPECT_MAX_BYTES=50,i.poolSize=8192;var $={};i.TYPED_ARRAY_SUPPORT=function(){try{var t=new ArrayBuffer(0),e=new Uint8Array(t);return e.foo=function(){return 42},42===e.foo()&&"function"==typeof e.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(r){return!1}}(),i.isBuffer=function(t){return!(null==t||!t._isBuffer)},i.compare=function(t,e){if(!i.isBuffer(t)||!i.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,o=0,s=Math.min(r,n);s>o&&t[o]===e[o];)++o;return o!==s&&(r=t[o],n=e[o]),n>r?-1:r>n?1:0},i.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},i.concat=function(t,e){if(!q(t))throw new TypeError("list argument must be an Array of Buffers.");if(0===t.length)return new i(0);if(1===t.length)return t[0];var r;if(void 0===e)for(e=0,r=0;r<t.length;r++)e+=t[r].length;var n=new i(e),o=0;for(r=0;r<t.length;r++){var s=t[r];s.copy(n,o),o+=s.length}return n},i.byteLength=w,i.prototype.length=void 0,i.prototype.parent=void 0,i.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?x(this,0,t):d.apply(this,arguments)},i.prototype.equals=function(t){if(!i.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:0===i.compare(this,t)},i.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),"<Buffer "+t+">"},i.prototype.compare=function(t){if(!i.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?0:i.compare(this,t)},i.prototype.indexOf=function(t,e){function r(t,e,r){for(var n=-1,i=0;r+i<t.length;i++)if(t[r+i]===e[-1===n?0:i-n]){if(-1===n&&(n=i),i-n+1===e.length)return r+n}else n=-1;return-1}if(e>2147483647?e=2147483647:-2147483648>e&&(e=-2147483648),e>>=0,0===this.length)return-1;if(e>=this.length)return-1;if(0>e&&(e=Math.max(this.length+e,0)),"string"==typeof t)return 0===t.length?-1:String.prototype.indexOf.call(this,t,e);if(i.isBuffer(t))return r(this,t,e);if("number"==typeof t)return i.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,t,e):r(this,[t],e);throw new TypeError("val must be string, number or Buffer")},i.prototype.get=function(t){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(t)},i.prototype.set=function(t,e){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(t,e)},i.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else if(isFinite(e))e=0|e,isFinite(r)?(r=0|r,void 0===n&&(n="utf8")):(n=r,r=void 0);else{var i=n;n=e,e=0|r,r=i}var o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(0>r||0>e)||e>this.length)throw new RangeError("attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return b(this,t,e,r);case"utf8":case"utf-8":return v(this,t,e,r);case"ascii":return E(this,t,e,r);case"binary":return I(this,t,e,r);case"base64":return m(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,t,e,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},i.prototype.slice=function(t,e){var r=this.length;t=~~t,e=void 0===e?r:~~e,0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),t>e&&(e=t);var n;if(i.TYPED_ARRAY_SUPPORT)n=i._augment(this.subarray(t,e));else{var o=e-t;n=new i(o,void 0);for(var s=0;o>s;s++)n[s]=this[s+t]}return n.length&&(n.parent=this.parent||this),n},i.prototype.readUIntLE=function(t,e,r){t=0|t,e=0|e,r||P(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n},i.prototype.readUIntBE=function(t,e,r){t=0|t,e=0|e,r||P(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},i.prototype.readUInt8=function(t,e){return e||P(t,1,this.length),this[t]},i.prototype.readUInt16LE=function(t,e){return e||P(t,2,this.length),this[t]|this[t+1]<<8},i.prototype.readUInt16BE=function(t,e){return e||P(t,2,this.length),this[t]<<8|this[t+1]},i.prototype.readUInt32LE=function(t,e){return e||P(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},i.prototype.readUInt32BE=function(t,e){return e||P(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},i.prototype.readIntLE=function(t,e,r){t=0|t,e=0|e,r||P(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},i.prototype.readIntBE=function(t,e,r){t=0|t,e=0|e,r||P(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},i.prototype.readInt8=function(t,e){return e||P(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},i.prototype.readInt16LE=function(t,e){e||P(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},i.prototype.readInt16BE=function(t,e){e||P(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},i.prototype.readInt32LE=function(t,e){return e||P(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},i.prototype.readInt32BE=function(t,e){return e||P(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},i.prototype.readFloatLE=function(t,e){return e||P(t,4,this.length),H.read(this,t,!0,23,4)},i.prototype.readFloatBE=function(t,e){return e||P(t,4,this.length),H.read(this,t,!1,23,4)},i.prototype.readDoubleLE=function(t,e){return e||P(t,8,this.length),H.read(this,t,!0,52,8)},i.prototype.readDoubleBE=function(t,e){return e||P(t,8,this.length),H.read(this,t,!1,52,8)},i.prototype.writeUIntLE=function(t,e,r,n){t=+t,e=0|e,r=0|r,n||B(this,t,e,r,Math.pow(2,8*r),0);var i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},i.prototype.writeUIntBE=function(t,e,r,n){t=+t,e=0|e,r=0|r,n||B(this,t,e,r,Math.pow(2,8*r),0);var i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},i.prototype.writeUInt8=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,1,255,0),i.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=t,e+1},i.prototype.writeUInt16LE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,2,65535,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t,this[e+1]=t>>>8):M(this,t,e,!0),e+2},i.prototype.writeUInt16BE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,2,65535,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=t):M(this,t,e,!1),e+2},i.prototype.writeUInt32LE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,4,4294967295,0),i.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t):T(this,t,e,!0),e+4},i.prototype.writeUInt32BE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,4,4294967295,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t):T(this,t,e,!1),e+4},i.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);B(this,t,e,r,i-1,-i)}var o=0,s=1,a=0>t?1:0;for(this[e]=255&t;++o<r&&(s*=256);)this[e+o]=(t/s>>0)-a&255;return e+r},i.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);B(this,t,e,r,i-1,-i)}var o=r-1,s=1,a=0>t?1:0;for(this[e+o]=255&t;--o>=0&&(s*=256);)this[e+o]=(t/s>>0)-a&255;return e+r},i.prototype.writeInt8=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,1,127,-128),i.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),0>t&&(t=255+t+1),this[e]=t,e+1},i.prototype.writeInt16LE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,2,32767,-32768),i.TYPED_ARRAY_SUPPORT?(this[e]=t,this[e+1]=t>>>8):M(this,t,e,!0),e+2},i.prototype.writeInt16BE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,2,32767,-32768),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=t):M(this,t,e,!1),e+2},i.prototype.writeInt32LE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,4,2147483647,-2147483648),i.TYPED_ARRAY_SUPPORT?(this[e]=t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):T(this,t,e,!0),e+4},i.prototype.writeInt32BE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,4,2147483647,-2147483648),0>t&&(t=4294967295+t+1),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t):T(this,t,e,!1),e+4},i.prototype.writeFloatLE=function(t,e,r){return A(this,t,e,!0,r)},i.prototype.writeFloatBE=function(t,e,r){return A(this,t,e,!1,r)},i.prototype.writeDoubleLE=function(t,e,r){return G(this,t,e,!0,r)},i.prototype.writeDoubleBE=function(t,e,r){return G(this,t,e,!1,r)},i.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&r>n&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(0>e)throw new RangeError("targetStart out of bounds");if(0>r||r>=this.length)throw new RangeError("sourceStart out of bounds");if(0>n)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var o=n-r;if(1e3>o||!i.TYPED_ARRAY_SUPPORT)for(var s=0;o>s;s++)t[s+e]=this[s+r];else t._set(this.subarray(r,r+o),e);return o},i.prototype.fill=function(t,e,r){if(t||(t=0),e||(e=0),r||(r=this.length),e>r)throw new RangeError("end < start");if(r!==e&&0!==this.length){if(0>e||e>=this.length)throw new RangeError("start out of bounds");if(0>r||r>this.length)throw new RangeError("end out of bounds");var n;if("number"==typeof t)for(n=e;r>n;n++)this[n]=t;else{var i=D(t.toString()),o=i.length;for(n=e;r>n;n++)this[n]=i[n%o]}return this}},i.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(i.TYPED_ARRAY_SUPPORT)return new i(this).buffer;for(var t=new Uint8Array(this.length),e=0,r=t.length;r>e;e+=1)t[e]=this[e];return t.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var Z=i.prototype;i._augment=function(t){return t.constructor=i,t._isBuffer=!0,t._set=t.set,t.get=Z.get,t.set=Z.set,t.write=Z.write,t.toString=Z.toString,t.toLocaleString=Z.toString,t.toJSON=Z.toJSON,t.equals=Z.equals,t.compare=Z.compare,t.indexOf=Z.indexOf,t.copy=Z.copy,t.slice=Z.slice,t.readUIntLE=Z.readUIntLE,t.readUIntBE=Z.readUIntBE,t.readUInt8=Z.readUInt8,t.readUInt16LE=Z.readUInt16LE,t.readUInt16BE=Z.readUInt16BE,t.readUInt32LE=Z.readUInt32LE,t.readUInt32BE=Z.readUInt32BE,t.readIntLE=Z.readIntLE,t.readIntBE=Z.readIntBE,t.readInt8=Z.readInt8,t.readInt16LE=Z.readInt16LE,t.readInt16BE=Z.readInt16BE,t.readInt32LE=Z.readInt32LE,t.readInt32BE=Z.readInt32BE,t.readFloatLE=Z.readFloatLE,t.readFloatBE=Z.readFloatBE,t.readDoubleLE=Z.readDoubleLE,t.readDoubleBE=Z.readDoubleBE,t.writeUInt8=Z.writeUInt8,t.writeUIntLE=Z.writeUIntLE,t.writeUIntBE=Z.writeUIntBE,t.writeUInt16LE=Z.writeUInt16LE,t.writeUInt16BE=Z.writeUInt16BE,t.writeUInt32LE=Z.writeUInt32LE,t.writeUInt32BE=Z.writeUInt32BE,t.writeIntLE=Z.writeIntLE,t.writeIntBE=Z.writeIntBE,t.writeInt8=Z.writeInt8,t.writeInt16LE=Z.writeInt16LE,t.writeInt16BE=Z.writeInt16BE,t.writeInt32LE=Z.writeInt32LE,t.writeInt32BE=Z.writeInt32BE,t.writeFloatLE=Z.writeFloatLE,t.writeFloatBE=Z.writeFloatBE,t.writeDoubleLE=Z.writeDoubleLE,t.writeDoubleBE=Z.writeDoubleBE,t.fill=Z.fill,t.inspect=Z.inspect,t.toArrayBuffer=Z.toArrayBuffer,t};var X=/[^+\/0-9A-z\-]/g},{"base64-js":14,ieee754:15,"is-array":16}],wkx:[function(t,e,r){r.Types=t("./types"),r.Geometry=t("./geometry"),r.Point=t("./point"),r.LineString=t("./linestring"),r.Polygon=t("./polygon"),r.MultiPoint=t("./multipoint"),r.MultiLineString=t("./multilinestring"),r.MultiPolygon=t("./multipolygon"),r.GeometryCollection=t("./geometrycollection")},{"./geometry":3,"./geometrycollection":4,"./linestring":5,"./multilinestring":6,"./multipoint":7,"./multipolygon":8,"./point":9,"./polygon":10,"./types":11}]},{},[]);
require=function t(e,r,n){function i(s,a){if(!r[s]){if(!e[s]){var h="function"==typeof require&&require;if(!a&&h)return h(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var p=r[s]={exports:{}};e[s][0].call(p.exports,function(t){var r=e[s][1][t];return i(r?r:t)},p,p.exports,t,e,r,n)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(t,e,r){(function(t){function r(t,e){this.buffer=t,this.position=0,this.isBigEndian=e||!1}function n(t,e,r){return function(){var n;return n=this.isBigEndian?e.call(this.buffer,this.position):t.call(this.buffer,this.position),this.position+=r,n}}e.exports=r,r.prototype.readUInt8=n(t.prototype.readUInt8,t.prototype.readUInt8,1),r.prototype.readUInt16=n(t.prototype.readUInt16LE,t.prototype.readUInt16BE,2),r.prototype.readUInt32=n(t.prototype.readUInt32LE,t.prototype.readUInt32BE,4),r.prototype.readInt8=n(t.prototype.readInt8,t.prototype.readInt8,1),r.prototype.readInt16=n(t.prototype.readInt16LE,t.prototype.readInt16BE,2),r.prototype.readInt32=n(t.prototype.readInt32LE,t.prototype.readInt32BE,4),r.prototype.readFloat=n(t.prototype.readFloatLE,t.prototype.readFloatBE,4),r.prototype.readDouble=n(t.prototype.readDoubleLE,t.prototype.readDoubleBE,8),r.prototype.readVarInt=function(){var t,e=0,r=0;do t=this.buffer[this.position+r],e+=(127&t)<<7*r,r++;while(t>=128);return this.position+=r,e}}).call(this,t("buffer").Buffer)},{buffer:"buffer"}],2:[function(t,e,r){(function(t){function r(e,r){this.buffer=new t(e),this.position=0,this.allowResize=r}function n(t,e){return function(r,n){this.ensureSize(e),t.call(this.buffer,r,this.position,n),this.position+=e}}e.exports=r,r.prototype.writeUInt8=n(t.prototype.writeUInt8,1),r.prototype.writeUInt16LE=n(t.prototype.writeUInt16LE,2),r.prototype.writeUInt16BE=n(t.prototype.writeUInt16BE,2),r.prototype.writeUInt32LE=n(t.prototype.writeUInt32LE,4),r.prototype.writeUInt32BE=n(t.prototype.writeUInt32BE,4),r.prototype.writeInt8=n(t.prototype.writeInt8,1),r.prototype.writeInt16LE=n(t.prototype.writeInt16LE,2),r.prototype.writeInt16BE=n(t.prototype.writeInt16BE,2),r.prototype.writeInt32LE=n(t.prototype.writeInt32LE,4),r.prototype.writeInt32BE=n(t.prototype.writeInt32BE,4),r.prototype.writeFloatLE=n(t.prototype.writeFloatLE,4),r.prototype.writeFloatBE=n(t.prototype.writeFloatBE,4),r.prototype.writeDoubleLE=n(t.prototype.writeDoubleLE,8),r.prototype.writeDoubleBE=n(t.prototype.writeDoubleBE,8),r.prototype.writeBuffer=function(t){this.ensureSize(t.length),t.copy(this.buffer,this.position,0,t.length),this.position+=t.length},r.prototype.writeVarInt=function(t){for(var e=1;0!==(4294967168&t);)this.writeUInt8(127&t|128),t>>>=7,e++;return this.writeUInt8(127&t),e},r.prototype.ensureSize=function(e){if(this.buffer.length<this.position+e){if(!this.allowResize)throw new RangeError("index out of range");var r=new t(this.position+e);this.buffer.copy(r,0,0,this.buffer.length),this.buffer=r}}}).call(this,t("buffer").Buffer)},{buffer:"buffer"}],3:[function(t,e,r){(function(r){function n(){this.srid=void 0,this.hasZ=!1,this.hasM=!1}e.exports=n;var i=t("./types"),o=t("./point"),s=t("./linestring"),a=t("./polygon"),h=t("./multipoint"),u=t("./multilinestring"),p=t("./multipolygon"),f=t("./geometrycollection"),c=t("./binaryreader"),l=t("./binarywriter"),g=t("./wktparser"),y=t("./zigzag.js");n.parse=function(t,e){var i=typeof t;if("string"===i||t instanceof g)return n._parseWkt(t);if(r.isBuffer(t)||t instanceof c)return n._parseWkb(t,e);throw new Error("first argument must be a string or Buffer")},n._parseWkt=function(t){var e,r;e=t instanceof g?t:new g(t);var n=e.matchRegex([/^SRID=(\d+);/]);n&&(r=n[1]);var c=e.matchType(),l=e.matchDimension(),y={srid:r,hasZ:l.hasZ,hasM:l.hasM};switch(c){case i.wkt.Point:return o._parseWkt(e,y);case i.wkt.LineString:return s._parseWkt(e,y);case i.wkt.Polygon:return a._parseWkt(e,y);case i.wkt.MultiPoint:return h._parseWkt(e,y);case i.wkt.MultiLineString:return u._parseWkt(e,y);case i.wkt.MultiPolygon:return p._parseWkt(e,y);case i.wkt.GeometryCollection:return f._parseWkt(e,y)}},n._parseWkb=function(t,e){var r,n,l,g={};switch(r=t instanceof c?t:new c(t),r.isBigEndian=!r.readInt8(),n=r.readUInt32(),g.hasSrid=536870912===(536870912&n),g.hasSrid&&(g.srid=r.readUInt32()),g.hasZ=!1,g.hasM=!1,g.hasSrid||e&&e.hasSrid?(2147483648&n&&(g.hasZ=!0),1073741824&n&&(g.hasM=!0),l=15&n):n>=1e3&&2e3>n?(g.hasZ=!0,l=n-1e3):n>=2e3&&3e3>n?(g.hasM=!0,l=n-2e3):n>=3e3&&4e3>n?(g.hasZ=!0,g.hasM=!0,l=n-3e3):l=n,l){case i.wkb.Point:return o._parseWkb(r,g);case i.wkb.LineString:return s._parseWkb(r,g);case i.wkb.Polygon:return a._parseWkb(r,g);case i.wkb.MultiPoint:return h._parseWkb(r,g);case i.wkb.MultiLineString:return u._parseWkb(r,g);case i.wkb.MultiPolygon:return p._parseWkb(r,g);case i.wkb.GeometryCollection:return f._parseWkb(r,g);default:throw new Error("GeometryType "+l+" not supported")}},n.parseTwkb=function(t){var e,r={};e=t instanceof c?t:new c(t);var n=e.readUInt8(),l=e.readUInt8(),g=15&n;if(r.precision=y.decode(n>>4),r.precisionFactor=Math.pow(10,r.precision),r.hasBoundingBox=l>>0&1,r.hasSizeAttribute=l>>1&1,r.hasIdList=l>>2&1,r.hasExtendedPrecision=l>>3&1,r.isEmpty=l>>4&1,r.hasExtendedPrecision){var d=e.readUInt8();r.hasZ=1===(1&d),r.hasM=2===(2&d),r.zPrecision=y.decode((28&d)>>2),r.zPrecisionFactor=Math.pow(10,r.zPrecision),r.mPrecision=y.decode((224&d)>>5),r.mPrecisionFactor=Math.pow(10,r.mPrecision)}else r.hasZ=!1,r.hasM=!1;if(r.hasSizeAttribute&&e.readVarInt(),r.hasBoundingBox){var w=2;r.hasZ&&w++,r.hasM&&w++;for(var b=0;w>b;b++)e.readVarInt(),e.readVarInt()}switch(g){case i.wkb.Point:return o._parseTwkb(e,r);case i.wkb.LineString:return s._parseTwkb(e,r);case i.wkb.Polygon:return a._parseTwkb(e,r);case i.wkb.MultiPoint:return h._parseTwkb(e,r);case i.wkb.MultiLineString:return u._parseTwkb(e,r);case i.wkb.MultiPolygon:return p._parseTwkb(e,r);case i.wkb.GeometryCollection:return f._parseTwkb(e,r);default:throw new Error("GeometryType "+g+" not supported")}},n.parseGeoJSON=function(t){var e;switch(t.type){case i.geoJSON.Point:e=o._parseGeoJSON(t);break;case i.geoJSON.LineString:e=s._parseGeoJSON(t);break;case i.geoJSON.Polygon:e=a._parseGeoJSON(t);break;case i.geoJSON.MultiPoint:e=h._parseGeoJSON(t);break;case i.geoJSON.MultiLineString:e=u._parseGeoJSON(t);break;case i.geoJSON.MultiPolygon:e=p._parseGeoJSON(t);break;case i.geoJSON.GeometryCollection:e=f._parseGeoJSON(t);break;default:throw new Error("GeometryType "+t.type+" not supported")}if(t.crs&&t.crs.type&&"name"===t.crs.type&&t.crs.properties&&t.crs.properties.name){var r=t.crs.properties.name;if(0===r.indexOf("EPSG:"))e.srid=parseInt(r.substring(5));else{if(0!==r.indexOf("urn:ogc:def:crs:EPSG::"))throw new Error("Unsupported crs: "+r);e.srid=parseInt(r.substring(22))}}return e},n.prototype.toEwkt=function(){return"SRID="+this.srid+";"+this.toWkt()},n.prototype.toEwkb=function(){var t=new l(this._getWkbSize()+4),e=this.toWkb();return t.writeInt8(1),t.writeUInt32LE(536870912|e.slice(1,5).readUInt32LE(0),!0),t.writeUInt32LE(this.srid),t.writeBuffer(e.slice(5)),t.buffer},n.prototype._getWktType=function(t,e){var r=t;return this.hasZ&&this.hasM?r+=" ZM ":this.hasZ?r+=" Z ":this.hasM&&(r+=" M "),!e||this.hasZ||this.hasM||(r+=" "),e&&(r+="EMPTY"),r},n.prototype._getWktCoordinate=function(t){var e=t.x+" "+t.y;return this.hasZ&&(e+=" "+t.z),this.hasM&&(e+=" "+t.m),e},n.prototype._writeWkbType=function(t,e,r){var n=0;"undefined"!=typeof this.srid||r&&"undefined"!=typeof r.srid?(this.hasZ&&(n|=2147483648),this.hasM&&(n|=1073741824)):this.hasZ&&this.hasM?n+=3e3:this.hasZ?n+=1e3:this.hasM&&(n+=2e3),t.writeUInt32LE(n+e,!0)},n.getTwkbPrecision=function(t,e,r){return{xy:t,z:e,m:r,xyFactor:Math.pow(10,t),zFactor:Math.pow(10,e),mFactor:Math.pow(10,r)}},n.prototype._writeTwkbHeader=function(t,e,r,n){var i=(y.encode(r.xy)<<4)+e,o=(this.hasZ||this.hasM)<<3;if(o+=n<<4,t.writeUInt8(i),t.writeUInt8(o),this.hasZ||this.hasM){var s=0;this.hasZ&&(s|=1),this.hasM&&(s|=2),t.writeUInt8(s)}},n.prototype.toGeoJSON=function(t){var e={};return this.srid&&t&&(t.shortCrs?e.crs={type:"name",properties:{name:"EPSG:"+this.srid}}:t.longCrs&&(e.crs={type:"name",properties:{name:"urn:ogc:def:crs:EPSG::"+this.srid}})),e}}).call(this,{isBuffer:t("../node_modules/browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js")})},{"../node_modules/browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":18,"./binaryreader":1,"./binarywriter":2,"./geometrycollection":4,"./linestring":5,"./multilinestring":6,"./multipoint":7,"./multipolygon":8,"./point":9,"./polygon":10,"./types":11,"./wktparser":12,"./zigzag.js":13}],4:[function(t,e,r){function n(t){s.call(this),this.geometries=t||[]}e.exports=n;var i=t("util"),o=t("./types"),s=t("./geometry"),a=t("./binarywriter");i.inherits(n,s),n.Z=function(t){var e=new n(t);return e.hasZ=!0,e},n.M=function(t){var e=new n(t);return e.hasM=!0,e},n.ZM=function(t){var e=new n(t);return e.hasZ=!0,e.hasM=!0,e},n._parseWkt=function(t,e){var r=new n;if(r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM,t.isMatch(["EMPTY"]))return r;t.expectGroupStart();do r.geometries.push(s.parse(t));while(t.isMatch([","]));return t.expectGroupEnd(),r},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM;for(var i=t.readUInt32(),o=0;i>o;o++)r.geometries.push(s.parse(t,e));return r},n._parseTwkb=function(t,e){var r=new n;if(r.hasZ=e.hasZ,r.hasM=e.hasM,e.isEmpty)return r;for(var i=t.readVarInt(),o=0;i>o;o++)r.geometries.push(s.parseTwkb(t));return r},n._parseGeoJSON=function(t){for(var e=new n,r=0;r<t.geometries.length;r++)e.geometries.push(s.parseGeoJSON(t.geometries[r]));return e.geometries.length>0&&(e.hasZ=e.geometries[0].hasZ),e},n.prototype.toWkt=function(){if(0===this.geometries.length)return this._getWktType(o.wkt.GeometryCollection,!0);for(var t=this._getWktType(o.wkt.GeometryCollection,!1)+"(",e=0;e<this.geometries.length;e++)t+=this.geometries[e].toWkt()+",";return t=t.slice(0,-1),t+=")"},n.prototype.toWkb=function(){var t=new a(this._getWkbSize());t.writeInt8(1),this._writeWkbType(t,o.wkb.GeometryCollection),t.writeUInt32LE(this.geometries.length);for(var e=0;e<this.geometries.length;e++)t.writeBuffer(this.geometries[e].toWkb({srid:this.srid}));return t.buffer},n.prototype.toTwkb=function(){var t=new a(0,!0),e=s.getTwkbPrecision(5,0,0),r=0===this.geometries.length;if(this._writeTwkbHeader(t,o.wkb.GeometryCollection,e,r),this.geometries.length>0){t.writeVarInt(this.geometries.length);for(var n=0;n<this.geometries.length;n++)t.writeBuffer(this.geometries[n].toTwkb())}return t.buffer},n.prototype._getWkbSize=function(){for(var t=9,e=0;e<this.geometries.length;e++)t+=this.geometries[e]._getWkbSize();return t},n.prototype.toGeoJSON=function(t){var e=s.prototype.toGeoJSON.call(this,t);e.type=o.geoJSON.GeometryCollection,e.geometries=[];for(var r=0;r<this.geometries.length;r++)e.geometries.push(this.geometries[r].toGeoJSON());return e}},{"./binarywriter":2,"./geometry":3,"./types":11,util:21}],5:[function(t,e,r){function n(t){o.call(this),this.points=t||[],this.points.length>0&&(this.hasZ=this.points[0].hasZ,this.hasM=this.points[0].hasM)}e.exports=n;var i=t("util"),o=t("./geometry"),s=t("./types"),a=t("./point"),h=t("./binarywriter");t("./zigzag.js");i.inherits(n,o),n.Z=function(t){var e=new n(t);return e.hasZ=!0,e},n.M=function(t){var e=new n(t);return e.hasM=!0,e},n.ZM=function(t){var e=new n(t);return e.hasZ=!0,e.hasM=!0,e},n._parseWkt=function(t,e){var r=new n;return r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM,t.isMatch(["EMPTY"])?r:(t.expectGroupStart(),r.points.push.apply(r.points,t.matchCoordinates(e)),t.expectGroupEnd(),r)},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM;for(var i=t.readUInt32(),o=0;i>o;o++)r.points.push(a._readWkbPoint(t,e));return r},n._parseTwkb=function(t,e){var r=new n;if(r.hasZ=e.hasZ,r.hasM=e.hasM,e.isEmpty)return r;for(var i=new a(0,0,e.hasZ?0:void 0,e.hasM?0:void 0),o=t.readVarInt(),s=0;o>s;s++)r.points.push(a._readTwkbPoint(t,e,i));return r},n._parseGeoJSON=function(t){var e=new n;t.coordinates.length>0&&(e.hasZ=t.coordinates[0].length>2);for(var r=0;r<t.coordinates.length;r++)e.points.push(a._readGeoJSONPoint(t.coordinates[r]));return e},n.prototype.toWkt=function(){return 0===this.points.length?this._getWktType(s.wkt.LineString,!0):this._getWktType(s.wkt.LineString,!1)+this._toInnerWkt()},n.prototype._toInnerWkt=function(){for(var t="(",e=0;e<this.points.length;e++)t+=this._getWktCoordinate(this.points[e])+",";return t=t.slice(0,-1),t+=")"},n.prototype.toWkb=function(t){var e=new h(this._getWkbSize());e.writeInt8(1),this._writeWkbType(e,s.wkb.LineString,t),e.writeUInt32LE(this.points.length);for(var r=0;r<this.points.length;r++)this.points[r]._writeWkbPoint(e);return e.buffer},n.prototype.toTwkb=function(){var t=new h(0,!0),e=o.getTwkbPrecision(5,0,0),r=0===this.points.length;if(this._writeTwkbHeader(t,s.wkb.LineString,e,r),this.points.length>0){t.writeVarInt(this.points.length);for(var n=new a(0,0,0,0),i=0;i<this.points.length;i++)this.points[i]._writeTwkbPoint(t,e,n)}return t.buffer},n.prototype._getWkbSize=function(){var t=16;return this.hasZ&&(t+=8),this.hasM&&(t+=8),9+this.points.length*t},n.prototype.toGeoJSON=function(t){var e=o.prototype.toGeoJSON.call(this,t);e.type=s.geoJSON.LineString,e.coordinates=[];for(var r=0;r<this.points.length;r++)this.hasZ?e.coordinates.push([this.points[r].x,this.points[r].y,this.points[r].z]):e.coordinates.push([this.points[r].x,this.points[r].y]);return e}},{"./binarywriter":2,"./geometry":3,"./point":9,"./types":11,"./zigzag.js":13,util:21}],6:[function(t,e,r){function n(t){s.call(this),this.lineStrings=t||[]}e.exports=n;var i=t("util"),o=t("./types"),s=t("./geometry"),a=t("./point"),h=t("./linestring"),u=t("./binarywriter");t("./zigzag.js");i.inherits(n,s),n.Z=function(t){var e=new n(t);return e.hasZ=!0,e},n.M=function(t){var e=new n(t);return e.hasM=!0,e},n.ZM=function(t){var e=new n(t);return e.hasZ=!0,e.hasM=!0,e},n._parseWkt=function(t,e){var r=new n;if(r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM,t.isMatch(["EMPTY"]))return r;t.expectGroupStart();do t.expectGroupStart(),r.lineStrings.push(new h(t.matchCoordinates(e))),t.expectGroupEnd();while(t.isMatch([","]));return t.expectGroupEnd(),r},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM;for(var i=t.readUInt32(),o=0;i>o;o++)r.lineStrings.push(s.parse(t,e));return r},n._parseTwkb=function(t,e){var r=new n;if(r.hasZ=e.hasZ,r.hasM=e.hasM,e.isEmpty)return r;for(var i=new a(0,0,e.hasZ?0:void 0,e.hasM?0:void 0),o=t.readVarInt(),s=0;o>s;s++){var u=new h;u.hasZ=e.hasZ,u.hasM=e.hasM;for(var p=t.readVarInt(),f=0;p>f;f++)u.points.push(a._readTwkbPoint(t,e,i));r.lineStrings.push(u)}return r},n._parseGeoJSON=function(t){var e=new n;t.coordinates.length>0&&t.coordinates[0].length>0&&(e.hasZ=t.coordinates[0][0].length>2);for(var r=0;r<t.coordinates.length;r++)e.lineStrings.push(h._parseGeoJSON({coordinates:t.coordinates[r]}));return e},n.prototype.toWkt=function(){if(0===this.lineStrings.length)return this._getWktType(o.wkt.MultiLineString,!0);for(var t=this._getWktType(o.wkt.MultiLineString,!1)+"(",e=0;e<this.lineStrings.length;e++)t+=this.lineStrings[e]._toInnerWkt()+",";return t=t.slice(0,-1),t+=")"},n.prototype.toWkb=function(){var t=new u(this._getWkbSize());t.writeInt8(1),this._writeWkbType(t,o.wkb.MultiLineString),t.writeUInt32LE(this.lineStrings.length);for(var e=0;e<this.lineStrings.length;e++)t.writeBuffer(this.lineStrings[e].toWkb({srid:this.srid}));return t.buffer},n.prototype.toTwkb=function(){var t=new u(0,!0),e=s.getTwkbPrecision(5,0,0),r=0===this.lineStrings.length;if(this._writeTwkbHeader(t,o.wkb.MultiLineString,e,r),this.lineStrings.length>0){t.writeVarInt(this.lineStrings.length);for(var n=new a(0,0,0,0),i=0;i<this.lineStrings.length;i++){t.writeVarInt(this.lineStrings[i].points.length);for(var h=0;h<this.lineStrings[i].points.length;h++)this.lineStrings[i].points[h]._writeTwkbPoint(t,e,n)}}return t.buffer},n.prototype._getWkbSize=function(){for(var t=9,e=0;e<this.lineStrings.length;e++)t+=this.lineStrings[e]._getWkbSize();return t},n.prototype.toGeoJSON=function(t){var e=s.prototype.toGeoJSON.call(this,t);e.type=o.geoJSON.MultiLineString,e.coordinates=[];for(var r=0;r<this.lineStrings.length;r++)e.coordinates.push(this.lineStrings[r].toGeoJSON().coordinates);return e}},{"./binarywriter":2,"./geometry":3,"./linestring":5,"./point":9,"./types":11,"./zigzag.js":13,util:21}],7:[function(t,e,r){function n(t){s.call(this),this.points=t||[]}e.exports=n;var i=t("util"),o=t("./types"),s=t("./geometry"),a=t("./point"),h=t("./binarywriter");t("./zigzag");i.inherits(n,s),n.Z=function(t){var e=new n(t);return e.hasZ=!0,e},n.M=function(t){var e=new n(t);return e.hasM=!0,e},n.ZM=function(t){var e=new n(t);return e.hasZ=!0,e.hasM=!0,e},n._parseWkt=function(t,e){var r=new n;return r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM,t.isMatch(["EMPTY"])?r:(t.expectGroupStart(),r.points.push.apply(r.points,t.matchCoordinates(e)),t.expectGroupEnd(),r)},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM;for(var i=t.readUInt32(),o=0;i>o;o++)r.points.push(s.parse(t,e));return r},n._parseTwkb=function(t,e){var r=new n;if(r.hasZ=e.hasZ,r.hasM=e.hasM,e.isEmpty)return r;for(var i=new a(0,0,e.hasZ?0:void 0,e.hasM?0:void 0),o=t.readVarInt(),s=0;o>s;s++)r.points.push(a._readTwkbPoint(t,e,i));return r},n._parseGeoJSON=function(t){var e=new n;t.coordinates.length>0&&(e.hasZ=t.coordinates[0].length>2);for(var r=0;r<t.coordinates.length;r++)e.points.push(a._parseGeoJSON({coordinates:t.coordinates[r]}));return e},n.prototype.toWkt=function(){if(0===this.points.length)return this._getWktType(o.wkt.MultiPoint,!0);for(var t=this._getWktType(o.wkt.MultiPoint,!1)+"(",e=0;e<this.points.length;e++)t+=this._getWktCoordinate(this.points[e])+",";return t=t.slice(0,-1),t+=")"},n.prototype.toWkb=function(){var t=new h(this._getWkbSize());t.writeInt8(1),this._writeWkbType(t,o.wkb.MultiPoint),t.writeUInt32LE(this.points.length);for(var e=0;e<this.points.length;e++)t.writeBuffer(this.points[e].toWkb({srid:this.srid}));return t.buffer},n.prototype.toTwkb=function(){var t=new h(0,!0),e=s.getTwkbPrecision(5,0,0),r=0===this.points.length;if(this._writeTwkbHeader(t,o.wkb.MultiPoint,e,r),this.points.length>0){t.writeVarInt(this.points.length);for(var n=new a(0,0,0,0),i=0;i<this.points.length;i++)this.points[i]._writeTwkbPoint(t,e,n)}return t.buffer},n.prototype._getWkbSize=function(){var t=16;return this.hasZ&&(t+=8),this.hasM&&(t+=8),t+=5,9+this.points.length*t},n.prototype.toGeoJSON=function(t){var e=s.prototype.toGeoJSON.call(this,t);e.type=o.geoJSON.MultiPoint,e.coordinates=[];for(var r=0;r<this.points.length;r++)e.coordinates.push(this.points[r].toGeoJSON().coordinates);return e}},{"./binarywriter":2,"./geometry":3,"./point":9,"./types":11,"./zigzag":13,util:21}],8:[function(t,e,r){function n(t){s.call(this),this.polygons=t||[]}e.exports=n;var i=t("util"),o=t("./types"),s=t("./geometry"),a=t("./point"),h=t("./polygon"),u=t("./binarywriter");t("./zigzag.js");i.inherits(n,s),n.Z=function(t){var e=new n(t);return e.hasZ=!0,e},n.M=function(t){var e=new n(t);return e.hasM=!0,e},n.ZM=function(t){var e=new n(t);return e.hasZ=!0,e.hasM=!0,e},n._parseWkt=function(t,e){var r=new n;if(r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM,t.isMatch(["EMPTY"]))return r;t.expectGroupStart();do{t.expectGroupStart();var i=[],o=[];for(t.expectGroupStart(),i.push.apply(i,t.matchCoordinates(e)),t.expectGroupEnd();t.isMatch([","]);)t.expectGroupStart(),o.push(t.matchCoordinates(e)),t.expectGroupEnd();r.polygons.push(new h(i,o)),t.expectGroupEnd()}while(t.isMatch([","]));return t.expectGroupEnd(),r},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM;for(var i=t.readUInt32(),o=0;i>o;o++)r.polygons.push(s.parse(t,e));return r},n._parseTwkb=function(t,e){var r=new n;if(r.hasZ=e.hasZ,r.hasM=e.hasM,e.isEmpty)return r;for(var i=new a(0,0,e.hasZ?0:void 0,e.hasM?0:void 0),o=t.readVarInt(),s=0;o>s;s++){var u=new h;u.hasZ=e.hasZ,u.hasM=e.hasM;for(var p=t.readVarInt(),f=t.readVarInt(),c=0;f>c;c++)u.exteriorRing.push(a._readTwkbPoint(t,e,i));for(c=1;p>c;c++){for(var l=[],g=t.readVarInt(),y=0;g>y;y++)l.push(a._readTwkbPoint(t,e,i));u.interiorRings.push(l)}r.polygons.push(u)}return r},n._parseGeoJSON=function(t){var e=new n;t.coordinates.length>0&&t.coordinates[0].length>0&&t.coordinates[0][0].length>0&&(e.hasZ=t.coordinates[0][0][0].length>2);for(var r=0;r<t.coordinates.length;r++)e.polygons.push(h._parseGeoJSON({coordinates:t.coordinates[r]}));return e},n.prototype.toWkt=function(){if(0===this.polygons.length)return this._getWktType(o.wkt.MultiPolygon,!0);for(var t=this._getWktType(o.wkt.MultiPolygon,!1)+"(",e=0;e<this.polygons.length;e++)t+=this.polygons[e]._toInnerWkt()+",";return t=t.slice(0,-1),t+=")"},n.prototype.toWkb=function(){var t=new u(this._getWkbSize());t.writeInt8(1),this._writeWkbType(t,o.wkb.MultiPolygon),t.writeUInt32LE(this.polygons.length);for(var e=0;e<this.polygons.length;e++)t.writeBuffer(this.polygons[e].toWkb({srid:this.srid}));return t.buffer},n.prototype.toTwkb=function(){var t=new u(0,!0),e=s.getTwkbPrecision(5,0,0),r=0===this.polygons.length;if(this._writeTwkbHeader(t,o.wkb.MultiPolygon,e,r),this.polygons.length>0){t.writeVarInt(this.polygons.length);for(var n=new a(0,0,0,0),i=0;i<this.polygons.length;i++){t.writeVarInt(1+this.polygons[i].interiorRings.length),t.writeVarInt(this.polygons[i].exteriorRing.length);for(var h=0;h<this.polygons[i].exteriorRing.length;h++)this.polygons[i].exteriorRing[h]._writeTwkbPoint(t,e,n);for(h=0;h<this.polygons[i].interiorRings.length;h++){t.writeVarInt(this.polygons[i].interiorRings[h].length);for(var p=0;p<this.polygons[i].interiorRings[h].length;p++)this.polygons[i].interiorRings[h][p]._writeTwkbPoint(t,e,n)}}}return t.buffer},n.prototype._getWkbSize=function(){for(var t=9,e=0;e<this.polygons.length;e++)t+=this.polygons[e]._getWkbSize();return t},n.prototype.toGeoJSON=function(t){var e=s.prototype.toGeoJSON.call(this,t);e.type=o.geoJSON.MultiPolygon,e.coordinates=[];for(var r=0;r<this.polygons.length;r++)e.coordinates.push(this.polygons[r].toGeoJSON().coordinates);return e}},{"./binarywriter":2,"./geometry":3,"./point":9,"./polygon":10,"./types":11,"./zigzag.js":13,util:21}],9:[function(t,e,r){function n(t,e,r,n){o.call(this),this.x=t,this.y=e,this.z=r,this.m=n,this.hasZ="undefined"!=typeof this.z,this.hasM="undefined"!=typeof this.m}e.exports=n;var i=t("util"),o=t("./geometry"),s=t("./types"),a=t("./binarywriter"),h=t("./zigzag.js");i.inherits(n,o),n.Z=function(t,e,r){var i=new n(t,e,r);return i.hasZ=!0,i},n.M=function(t,e,r){var i=new n(t,e,void 0,r);return i.hasM=!0,i},n.ZM=function(t,e,r,i){var o=new n(t,e,r,i);return o.hasZ=!0,o.hasM=!0,o},n._parseWkt=function(t,e){var r=new n;if(r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM,t.isMatch(["EMPTY"]))return r;t.expectGroupStart();var i=t.matchCoordinate(e);return r.x=i.x,r.y=i.y,r.z=i.z,r.m=i.m,t.expectGroupEnd(),r},n._parseWkb=function(t,e){var r=n._readWkbPoint(t,e);return r.srid=e.srid,r},n._readWkbPoint=function(t,e){return new n(t.readDouble(),t.readDouble(),e.hasZ?t.readDouble():void 0,e.hasM?t.readDouble():void 0)},n._parseTwkb=function(t,e){var r=new n;return r.hasZ=e.hasZ,r.hasM=e.hasM,e.isEmpty?r:(r.x=h.decode(t.readVarInt())/e.precisionFactor,r.y=h.decode(t.readVarInt())/e.precisionFactor,r.z=e.hasZ?h.decode(t.readVarInt())/e.zPrecisionFactor:void 0,r.m=e.hasM?h.decode(t.readVarInt())/e.mPrecisionFactor:void 0,r)},n._readTwkbPoint=function(t,e,r){return r.x+=h.decode(t.readVarInt())/e.precisionFactor,r.y+=h.decode(t.readVarInt())/e.precisionFactor,e.hasZ&&(r.z+=h.decode(t.readVarInt())/e.zPrecisionFactor),e.hasM&&(r.m+=h.decode(t.readVarInt())/e.mPrecisionFactor),new n(r.x,r.y,r.z,r.m)},n._parseGeoJSON=function(t){return n._readGeoJSONPoint(t.coordinates)},n._readGeoJSONPoint=function(t){return 0===t.length?new n:t.length>2?new n(t[0],t[1],t[2]):new n(t[0],t[1])},n.prototype.toWkt=function(){return"undefined"==typeof this.x&&"undefined"==typeof this.y&&"undefined"==typeof this.z&&"undefined"==typeof this.m?this._getWktType(s.wkt.Point,!0):this._getWktType(s.wkt.Point,!1)+"("+this._getWktCoordinate(this)+")"},n.prototype.toWkb=function(t){var e=new a(this._getWkbSize());return e.writeInt8(1),"undefined"==typeof this.x&&"undefined"==typeof this.y?(this._writeWkbType(e,s.wkb.MultiPoint,t),e.writeUInt32LE(0)):(this._writeWkbType(e,s.wkb.Point,t),this._writeWkbPoint(e)),e.buffer},n.prototype._writeWkbPoint=function(t){t.writeDoubleLE(this.x),t.writeDoubleLE(this.y),this.hasZ&&t.writeDoubleLE(this.z),this.hasM&&t.writeDoubleLE(this.m)},n.prototype.toTwkb=function(){var t=new a(0,!0),e=o.getTwkbPrecision(5,0,0),r="undefined"==typeof this.x&&"undefined"==typeof this.y;return this._writeTwkbHeader(t,s.wkb.Point,e,r),r||this._writeTwkbPoint(t,e,new n(0,0,0,0)),t.buffer},n.prototype._writeTwkbPoint=function(t,e,r){var n=this.x*e.xyFactor,i=this.y*e.xyFactor,o=this.z*e.zFactor,s=this.m*e.mFactor;t.writeVarInt(h.encode(n-r.x)),t.writeVarInt(h.encode(i-r.y)),this.hasZ&&t.writeVarInt(h.encode(o-r.z)),this.hasM&&t.writeVarInt(h.encode(s-r.m)),r.x=n,r.y=i,r.z=o,r.m=s},n.prototype._getWkbSize=function(){if("undefined"==typeof this.x&&"undefined"==typeof this.y)return 9;var t=21;return this.hasZ&&(t+=8),this.hasM&&(t+=8),t},n.prototype.toGeoJSON=function(t){var e=o.prototype.toGeoJSON.call(this,t);return e.type=s.geoJSON.Point,"undefined"==typeof this.x&&"undefined"==typeof this.y?e.coordinates=[]:"undefined"!=typeof this.z?e.coordinates=[this.x,this.y,this.z]:e.coordinates=[this.x,this.y],e}},{"./binarywriter":2,"./geometry":3,"./types":11,"./zigzag.js":13,util:21}],10:[function(t,e,r){function n(t,e){o.call(this),this.exteriorRing=t||[],this.interiorRings=e||[],this.exteriorRing.length>0&&(this.hasZ=this.exteriorRing[0].hasZ,this.hasM=this.exteriorRing[0].hasM)}e.exports=n;var i=t("util"),o=t("./geometry"),s=t("./types"),a=t("./point"),h=t("./binarywriter");t("./zigzag");i.inherits(n,o),n.Z=function(t,e){var r=new n(t,e);return r.hasZ=!0,r},n.M=function(t,e){var r=new n(t,e);return r.hasM=!0,r},n.ZM=function(t,e){var r=new n(t,e);return r.hasZ=!0,r.hasM=!0,r},n._parseWkt=function(t,e){var r=new n;if(r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM,t.isMatch(["EMPTY"]))return r;for(t.expectGroupStart(),t.expectGroupStart(),r.exteriorRing.push.apply(r.exteriorRing,t.matchCoordinates(e)),t.expectGroupEnd();t.isMatch([","]);)t.expectGroupStart(),r.interiorRings.push(t.matchCoordinates(e)),t.expectGroupEnd();return t.expectGroupEnd(),r},n._parseWkb=function(t,e){var r=new n;r.srid=e.srid,r.hasZ=e.hasZ,r.hasM=e.hasM;var i=t.readUInt32();if(i>0){for(var o=t.readUInt32(),s=0;o>s;s++)r.exteriorRing.push(a._readWkbPoint(t,e));for(s=1;i>s;s++){for(var h=[],u=t.readUInt32(),p=0;u>p;p++)h.push(a._readWkbPoint(t,e));r.interiorRings.push(h)}}return r},n._parseTwkb=function(t,e){var r=new n;if(r.hasZ=e.hasZ,r.hasM=e.hasM,e.isEmpty)return r;for(var i=new a(0,0,e.hasZ?0:void 0,e.hasM?0:void 0),o=t.readVarInt(),s=t.readVarInt(),h=0;s>h;h++)r.exteriorRing.push(a._readTwkbPoint(t,e,i));for(h=1;o>h;h++){for(var u=[],p=t.readVarInt(),f=0;p>f;f++)u.push(a._readTwkbPoint(t,e,i));r.interiorRings.push(u)}return r},n._parseGeoJSON=function(t){var e=new n;t.coordinates.length>0&&t.coordinates[0].length>0&&(e.hasZ=t.coordinates[0][0].length>2);for(var r=0;r<t.coordinates.length;r++){r>0&&e.interiorRings.push([]);for(var i=0;i<t.coordinates[r].length;i++)0===r?e.exteriorRing.push(a._readGeoJSONPoint(t.coordinates[r][i])):e.interiorRings[r-1].push(a._readGeoJSONPoint(t.coordinates[r][i]))}return e},n.prototype.toWkt=function(){return 0===this.exteriorRing.length?this._getWktType(s.wkt.Polygon,!0):this._getWktType(s.wkt.Polygon,!1)+this._toInnerWkt()},n.prototype._toInnerWkt=function(){for(var t="((",e=0;e<this.exteriorRing.length;e++)t+=this._getWktCoordinate(this.exteriorRing[e])+",";for(t=t.slice(0,-1),t+=")",e=0;e<this.interiorRings.length;e++){t+=",(";for(var r=0;r<this.interiorRings[e].length;r++)t+=this._getWktCoordinate(this.interiorRings[e][r])+",";t=t.slice(0,-1),t+=")"}return t+=")"},n.prototype.toWkb=function(t){var e=new h(this._getWkbSize());e.writeInt8(1),this._writeWkbType(e,s.wkb.Polygon,t),this.exteriorRing.length>0?(e.writeUInt32LE(1+this.interiorRings.length),e.writeUInt32LE(this.exteriorRing.length)):e.writeUInt32LE(0);for(var r=0;r<this.exteriorRing.length;r++)this.exteriorRing[r]._writeWkbPoint(e);for(r=0;r<this.interiorRings.length;r++){e.writeUInt32LE(this.interiorRings[r].length);for(var n=0;n<this.interiorRings[r].length;n++)this.interiorRings[r][n]._writeWkbPoint(e)}return e.buffer},n.prototype.toTwkb=function(){var t=new h(0,!0),e=o.getTwkbPrecision(5,0,0),r=0===this.exteriorRing.length;if(this._writeTwkbHeader(t,s.wkb.Polygon,e,r),this.exteriorRing.length>0){t.writeVarInt(1+this.interiorRings.length),t.writeVarInt(this.exteriorRing.length);for(var n=new a(0,0,0,0),i=0;i<this.exteriorRing.length;i++)this.exteriorRing[i]._writeTwkbPoint(t,e,n);for(i=0;i<this.interiorRings.length;i++){t.writeVarInt(this.interiorRings[i].length);for(var u=0;u<this.interiorRings[i].length;u++)this.interiorRings[i][u]._writeTwkbPoint(t,e,n)}}return t.buffer},n.prototype._getWkbSize=function(){var t=16;this.hasZ&&(t+=8),this.hasM&&(t+=8);var e=9;this.exteriorRing.length>0&&(e+=4+this.exteriorRing.length*t);for(var r=0;r<this.interiorRings.length;r++)e+=4+this.interiorRings[r].length*t;return e},n.prototype.toGeoJSON=function(t){var e=o.prototype.toGeoJSON.call(this,t);if(e.type=s.geoJSON.Polygon,e.coordinates=[],this.exteriorRing.length>0){for(var r=[],n=0;n<this.exteriorRing.length;n++)this.hasZ?r.push([this.exteriorRing[n].x,this.exteriorRing[n].y,this.exteriorRing[n].z]):r.push([this.exteriorRing[n].x,this.exteriorRing[n].y]);e.coordinates.push(r)}for(var i=0;i<this.interiorRings.length;i++){for(var a=[],h=0;h<this.interiorRings[i].length;h++)this.hasZ?a.push([this.interiorRings[i][h].x,this.interiorRings[i][h].y,this.interiorRings[i][h].z]):a.push([this.interiorRings[i][h].x,this.interiorRings[i][h].y]);e.coordinates.push(a)}return e}},{"./binarywriter":2,"./geometry":3,"./point":9,"./types":11,"./zigzag":13,util:21}],11:[function(t,e,r){e.exports={wkt:{Point:"POINT",LineString:"LINESTRING",Polygon:"POLYGON",MultiPoint:"MULTIPOINT",MultiLineString:"MULTILINESTRING",MultiPolygon:"MULTIPOLYGON",GeometryCollection:"GEOMETRYCOLLECTION"},wkb:{Point:1,LineString:2,Polygon:3,MultiPoint:4,MultiLineString:5,MultiPolygon:6,GeometryCollection:7},geoJSON:{Point:"Point",LineString:"LineString",Polygon:"Polygon",MultiPoint:"MultiPoint",MultiLineString:"MultiLineString",MultiPolygon:"MultiPolygon",GeometryCollection:"GeometryCollection"}}},{}],12:[function(t,e,r){function n(t){this.value=t,this.position=0}e.exports=n;var i=t("./types"),o=t("./point");n.prototype.match=function(t){this.skipWhitespaces();for(var e=0;e<t.length;e++)if(0===this.value.substring(this.position).indexOf(t[e]))return this.position+=t[e].length,t[e];return null},n.prototype.matchRegex=function(t){this.skipWhitespaces();for(var e=0;e<t.length;e++){var r=this.value.substring(this.position).match(t[e]);if(r)return this.position+=r[0].length,r}return null},n.prototype.isMatch=function(t){this.skipWhitespaces();for(var e=0;e<t.length;e++)if(0===this.value.substring(this.position).indexOf(t[e]))return this.position+=t[e].length,!0;return!1},n.prototype.matchType=function(){var t=this.match([i.wkt.Point,i.wkt.LineString,i.wkt.Polygon,i.wkt.MultiPoint,i.wkt.MultiLineString,i.wkt.MultiPolygon,i.wkt.GeometryCollection]);if(!t)throw new Error("Expected geometry type");return t},n.prototype.matchDimension=function(){var t=this.match(["ZM","Z","M"]);switch(t){case"ZM":return{hasZ:!0,hasM:!0};case"Z":return{hasZ:!0,hasM:!1};case"M":return{hasZ:!1,hasM:!0};default:return{hasZ:!1,hasM:!1}}},n.prototype.expectGroupStart=function(){if(!this.isMatch(["("]))throw new Error("Expected group start");
},n.prototype.expectGroupEnd=function(){if(!this.isMatch([")"]))throw new Error("Expected group end")},n.prototype.matchCoordinate=function(t){var e;if(e=t.hasZ&&t.hasM?this.matchRegex([/^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)/]):t.hasZ||t.hasM?this.matchRegex([/^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)/]):this.matchRegex([/^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)/]),!e)throw new Error("Expected coordinates");return t.hasZ&&t.hasM?new o(parseFloat(e[1]),parseFloat(e[2]),parseFloat(e[3]),parseFloat(e[4])):t.hasZ?new o(parseFloat(e[1]),parseFloat(e[2]),parseFloat(e[3])):t.hasM?new o(parseFloat(e[1]),parseFloat(e[2]),void 0,parseFloat(e[3])):new o(parseFloat(e[1]),parseFloat(e[2]))},n.prototype.matchCoordinates=function(t){var e=[];do{var r=this.isMatch(["("]);e.push(this.matchCoordinate(t)),r&&this.expectGroupEnd()}while(this.isMatch([","]));return e},n.prototype.skipWhitespaces=function(){for(;this.position<this.value.length&&" "===this.value[this.position];)this.position++}},{"./point":9,"./types":11}],13:[function(t,e,r){e.exports={encode:function(t){return t<<1^t>>31},decode:function(t){return t>>1^-(1&t)}}},{}],14:[function(t,e,r){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(t){"use strict";function e(t){var e=t.charCodeAt(0);return e===s||e===f?62:e===a||e===c?63:h>e?-1:h+10>e?e-h+26+26:p+26>e?e-p:u+26>e?e-u+26:void 0}function r(t){function r(t){u[f++]=t}var n,i,s,a,h,u;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var p=t.length;h="="===t.charAt(p-2)?2:"="===t.charAt(p-1)?1:0,u=new o(3*t.length/4-h),s=h>0?t.length-4:t.length;var f=0;for(n=0,i=0;s>n;n+=4,i+=3)a=e(t.charAt(n))<<18|e(t.charAt(n+1))<<12|e(t.charAt(n+2))<<6|e(t.charAt(n+3)),r((16711680&a)>>16),r((65280&a)>>8),r(255&a);return 2===h?(a=e(t.charAt(n))<<2|e(t.charAt(n+1))>>4,r(255&a)):1===h&&(a=e(t.charAt(n))<<10|e(t.charAt(n+1))<<4|e(t.charAt(n+2))>>2,r(a>>8&255),r(255&a)),u}function i(t){function e(t){return n.charAt(t)}function r(t){return e(t>>18&63)+e(t>>12&63)+e(t>>6&63)+e(63&t)}var i,o,s,a=t.length%3,h="";for(i=0,s=t.length-a;s>i;i+=3)o=(t[i]<<16)+(t[i+1]<<8)+t[i+2],h+=r(o);switch(a){case 1:o=t[t.length-1],h+=e(o>>2),h+=e(o<<4&63),h+="==";break;case 2:o=(t[t.length-2]<<8)+t[t.length-1],h+=e(o>>10),h+=e(o>>4&63),h+=e(o<<2&63),h+="="}return h}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="+".charCodeAt(0),a="/".charCodeAt(0),h="0".charCodeAt(0),u="a".charCodeAt(0),p="A".charCodeAt(0),f="-".charCodeAt(0),c="_".charCodeAt(0);t.toByteArray=r,t.fromByteArray=i}("undefined"==typeof r?this.base64js={}:r)},{}],15:[function(t,e,r){r.read=function(t,e,r,n,i){var o,s,a=8*i-n-1,h=(1<<a)-1,u=h>>1,p=-7,f=r?i-1:0,c=r?-1:1,l=t[e+f];for(f+=c,o=l&(1<<-p)-1,l>>=-p,p+=a;p>0;o=256*o+t[e+f],f+=c,p-=8);for(s=o&(1<<-p)-1,o>>=-p,p+=n;p>0;s=256*s+t[e+f],f+=c,p-=8);if(0===o)o=1-u;else{if(o===h)return s?NaN:(l?-1:1)*(1/0);s+=Math.pow(2,n),o-=u}return(l?-1:1)*s*Math.pow(2,o-n)},r.write=function(t,e,r,n,i,o){var s,a,h,u=8*o-i-1,p=(1<<u)-1,f=p>>1,c=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=n?0:o-1,g=n?1:-1,y=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=p):(s=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-s))<1&&(s--,h*=2),e+=s+f>=1?c/h:c*Math.pow(2,1-f),e*h>=2&&(s++,h/=2),s+f>=p?(a=0,s=p):s+f>=1?(a=(e*h-1)*Math.pow(2,i),s+=f):(a=e*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;t[r+l]=255&a,l+=g,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;t[r+l]=255&s,l+=g,s/=256,u-=8);t[r+l-g]|=128*y}},{}],16:[function(t,e,r){var n=Array.isArray,i=Object.prototype.toString;e.exports=n||function(t){return!!t&&"[object Array]"==i.call(t)}},{}],17:[function(t,e,r){"function"==typeof Object.create?e.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}},{}],18:[function(t,e,r){e.exports=function(t){return!(null==t||!(t._isBuffer||t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)))}},{}],19:[function(t,e,r){function n(){p=!1,a.length?u=a.concat(u):f=-1,u.length&&i()}function i(){if(!p){var t=setTimeout(n);p=!0;for(var e=u.length;e;){for(a=u,u=[];++f<e;)a&&a[f].run();f=-1,e=u.length}a=null,p=!1,clearTimeout(t)}}function o(t,e){this.fun=t,this.array=e}function s(){}var a,h=e.exports={},u=[],p=!1,f=-1;h.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];u.push(new o(t,e)),1!==u.length||p||setTimeout(i,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},h.title="browser",h.browser=!0,h.env={},h.argv=[],h.version="",h.versions={},h.on=s,h.addListener=s,h.once=s,h.off=s,h.removeListener=s,h.removeAllListeners=s,h.emit=s,h.binding=function(t){throw new Error("process.binding is not supported")},h.cwd=function(){return"/"},h.chdir=function(t){throw new Error("process.chdir is not supported")},h.umask=function(){return 0}},{}],20:[function(t,e,r){e.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},{}],21:[function(t,e,r){(function(e,n){function i(t,e){var n={seen:[],stylize:s};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),y(e)?n.showHidden=e:e&&r._extend(n,e),m(n.showHidden)&&(n.showHidden=!1),m(n.depth)&&(n.depth=2),m(n.colors)&&(n.colors=!1),m(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=o),h(n,t,n.depth)}function o(t,e){var r=i.styles[e];return r?"["+i.colors[r][0]+"m"+t+"["+i.colors[r][1]+"m":t}function s(t,e){return t}function a(t){var e={};return t.forEach(function(t,r){e[t]=!0}),e}function h(t,e,n){if(t.customInspect&&e&&S(e.inspect)&&e.inspect!==r.inspect&&(!e.constructor||e.constructor.prototype!==e)){var i=e.inspect(n,t);return v(i)||(i=h(t,i,n)),i}var o=u(t,e);if(o)return o;var s=Object.keys(e),y=a(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(e)),I(e)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return p(e);if(0===s.length){if(S(e)){var d=e.name?": "+e.name:"";return t.stylize("[Function"+d+"]","special")}if(k(e))return t.stylize(RegExp.prototype.toString.call(e),"regexp");if(M(e))return t.stylize(Date.prototype.toString.call(e),"date");if(I(e))return p(e)}var w="",b=!1,E=["{","}"];if(g(e)&&(b=!0,E=["[","]"]),S(e)){var m=e.name?": "+e.name:"";w=" [Function"+m+"]"}if(k(e)&&(w=" "+RegExp.prototype.toString.call(e)),M(e)&&(w=" "+Date.prototype.toUTCString.call(e)),I(e)&&(w=" "+p(e)),0===s.length&&(!b||0==e.length))return E[0]+w+E[1];if(0>n)return k(e)?t.stylize(RegExp.prototype.toString.call(e),"regexp"):t.stylize("[Object]","special");t.seen.push(e);var _;return _=b?f(t,e,n,y,s):s.map(function(r){return c(t,e,n,y,r,b)}),t.seen.pop(),l(_,w,E)}function u(t,e){if(m(e))return t.stylize("undefined","undefined");if(v(e)){var r="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(r,"string")}return b(e)?t.stylize(""+e,"number"):y(e)?t.stylize(""+e,"boolean"):d(e)?t.stylize("null","null"):void 0}function p(t){return"["+Error.prototype.toString.call(t)+"]"}function f(t,e,r,n,i){for(var o=[],s=0,a=e.length;a>s;++s)U(e,String(s))?o.push(c(t,e,r,n,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(c(t,e,r,n,i,!0))}),o}function c(t,e,r,n,i,o){var s,a,u;if(u=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]},u.get?a=u.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):u.set&&(a=t.stylize("[Setter]","special")),U(n,i)||(s="["+i+"]"),a||(t.seen.indexOf(u.value)<0?(a=d(r)?h(t,u.value,null):h(t,u.value,r-1),a.indexOf("\n")>-1&&(a=o?a.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+a.split("\n").map(function(t){return" "+t}).join("\n"))):a=t.stylize("[Circular]","special")),m(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+a}function l(t,e,r){var n=0,i=t.reduce(function(t,e){return n++,e.indexOf("\n")>=0&&n++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?r[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+r[1]:r[0]+e+" "+t.join(", ")+" "+r[1]}function g(t){return Array.isArray(t)}function y(t){return"boolean"==typeof t}function d(t){return null===t}function w(t){return null==t}function b(t){return"number"==typeof t}function v(t){return"string"==typeof t}function E(t){return"symbol"==typeof t}function m(t){return void 0===t}function k(t){return _(t)&&"[object RegExp]"===x(t)}function _(t){return"object"==typeof t&&null!==t}function M(t){return _(t)&&"[object Date]"===x(t)}function I(t){return _(t)&&("[object Error]"===x(t)||t instanceof Error)}function S(t){return"function"==typeof t}function P(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||"undefined"==typeof t}function x(t){return Object.prototype.toString.call(t)}function T(t){return 10>t?"0"+t.toString(10):t.toString(10)}function R(){var t=new Date,e=[T(t.getHours()),T(t.getMinutes()),T(t.getSeconds())].join(":");return[t.getDate(),O[t.getMonth()],e].join(" ")}function U(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var L=/%[sdj%]/g;r.format=function(t){if(!v(t)){for(var e=[],r=0;r<arguments.length;r++)e.push(i(arguments[r]));return e.join(" ")}for(var r=1,n=arguments,o=n.length,s=String(t).replace(L,function(t){if("%%"===t)return"%";if(r>=o)return t;switch(t){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(e){return"[Circular]"}default:return t}}),a=n[r];o>r;a=n[++r])s+=d(a)||!_(a)?" "+a:" "+i(a);return s},r.deprecate=function(t,i){function o(){if(!s){if(e.throwDeprecation)throw new Error(i);e.traceDeprecation?console.trace(i):console.error(i),s=!0}return t.apply(this,arguments)}if(m(n.process))return function(){return r.deprecate(t,i).apply(this,arguments)};if(e.noDeprecation===!0)return t;var s=!1;return o};var Z,B={};r.debuglog=function(t){if(m(Z)&&(Z=e.env.NODE_DEBUG||""),t=t.toUpperCase(),!B[t])if(new RegExp("\\b"+t+"\\b","i").test(Z)){var n=e.pid;B[t]=function(){var e=r.format.apply(r,arguments);console.error("%s %d: %s",t,n,e)}}else B[t]=function(){};return B[t]},r.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=g,r.isBoolean=y,r.isNull=d,r.isNullOrUndefined=w,r.isNumber=b,r.isString=v,r.isSymbol=E,r.isUndefined=m,r.isRegExp=k,r.isObject=_,r.isDate=M,r.isError=I,r.isFunction=S,r.isPrimitive=P,r.isBuffer=t("./support/isBuffer");var O=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];r.log=function(){console.log("%s - %s",R(),r.format.apply(r,arguments))},r.inherits=t("inherits"),r._extend=function(t,e){if(!e||!_(e))return t;for(var r=Object.keys(e),n=r.length;n--;)t[r[n]]=e[r[n]];return t}}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":20,_process:19,inherits:17}],buffer:[function(t,e,r){(function(e){function n(){function t(){}try{var e=new Uint8Array(1);return e.foo=function(){return 42},e.constructor=t,42===e.foo()&&e.constructor===t&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(r){return!1}}function i(){return o.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t){return this instanceof o?(this.length=0,this.parent=void 0,"number"==typeof t?s(this,t):"string"==typeof t?a(this,t,arguments.length>1?arguments[1]:"utf8"):h(this,t)):arguments.length>1?new o(t,arguments[1]):new o(t)}function s(t,e){if(t=y(t,0>e?0:0|d(e)),!o.TYPED_ARRAY_SUPPORT)for(var r=0;e>r;r++)t[r]=0;return t}function a(t,e,r){("string"!=typeof r||""===r)&&(r="utf8");var n=0|b(e,r);return t=y(t,n),t.write(e,r),t}function h(t,e){if(o.isBuffer(e))return u(t,e);if($(e))return p(t,e);if(null==e)throw new TypeError("must start with number, buffer, array or string");if("undefined"!=typeof ArrayBuffer){if(e.buffer instanceof ArrayBuffer)return f(t,e);if(e instanceof ArrayBuffer)return c(t,e)}return e.length?l(t,e):g(t,e)}function u(t,e){var r=0|d(e.length);return t=y(t,r),e.copy(t,0,0,r),t}function p(t,e){var r=0|d(e.length);t=y(t,r);for(var n=0;r>n;n+=1)t[n]=255&e[n];return t}function f(t,e){var r=0|d(e.length);t=y(t,r);for(var n=0;r>n;n+=1)t[n]=255&e[n];return t}function c(t,e){return o.TYPED_ARRAY_SUPPORT?(e.byteLength,t=o._augment(new Uint8Array(e))):t=f(t,new Uint8Array(e)),t}function l(t,e){var r=0|d(e.length);t=y(t,r);for(var n=0;r>n;n+=1)t[n]=255&e[n];return t}function g(t,e){var r,n=0;"Buffer"===e.type&&$(e.data)&&(r=e.data,n=0|d(r.length)),t=y(t,n);for(var i=0;n>i;i+=1)t[i]=255&r[i];return t}function y(t,e){o.TYPED_ARRAY_SUPPORT?(t=o._augment(new Uint8Array(e)),t.__proto__=o.prototype):(t.length=e,t._isBuffer=!0);var r=0!==e&&e<=o.poolSize>>>1;return r&&(t.parent=X),t}function d(t){if(t>=i())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i().toString(16)+" bytes");return 0|t}function w(t,e){if(!(this instanceof w))return new w(t,e);var r=new o(t,e);return delete r.parent,r}function b(t,e){"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"binary":case"raw":case"raws":return r;case"utf8":case"utf-8":return J(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return j(t).length;default:if(n)return J(t).length;e=(""+e).toLowerCase(),n=!0}}function v(t,e,r){var n=!1;if(e=0|e,r=void 0===r||r===1/0?this.length:0|r,t||(t="utf8"),0>e&&(e=0),r>this.length&&(r=this.length),e>=r)return"";for(;;)switch(t){case"hex":return U(this,e,r);case"utf8":case"utf-8":return P(this,e,r);case"ascii":return T(this,e,r);case"binary":return R(this,e,r);case"base64":return S(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return L(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function E(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var o=e.length;if(o%2!==0)throw new Error("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;n>s;s++){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))throw new Error("Invalid hex string");t[r+s]=a}return s}function m(t,e,r,n){return V(J(e,t.length-r),t,r,n)}function k(t,e,r,n){return V(Y(e),t,r,n)}function _(t,e,r,n){return k(t,e,r,n)}function M(t,e,r,n){return V(j(e),t,r,n)}function I(t,e,r,n){return V(F(e,t.length-r),t,r,n)}function S(t,e,r){return 0===e&&r===t.length?H.fromByteArray(t):H.fromByteArray(t.slice(e,r))}function P(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;r>i;){var o=t[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(r>=i+a){var h,u,p,f;switch(a){case 1:128>o&&(s=o);break;case 2:h=t[i+1],128===(192&h)&&(f=(31&o)<<6|63&h,f>127&&(s=f));break;case 3:h=t[i+1],u=t[i+2],128===(192&h)&&128===(192&u)&&(f=(15&o)<<12|(63&h)<<6|63&u,f>2047&&(55296>f||f>57343)&&(s=f));break;case 4:h=t[i+1],u=t[i+2],p=t[i+3],128===(192&h)&&128===(192&u)&&128===(192&p)&&(f=(15&o)<<18|(63&h)<<12|(63&u)<<6|63&p,f>65535&&1114112>f&&(s=f))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=a}return x(n)}function x(t){var e=t.length;if(K>=e)return String.fromCharCode.apply(String,t);for(var r="",n=0;e>n;)r+=String.fromCharCode.apply(String,t.slice(n,n+=K));return r}function T(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;r>i;i++)n+=String.fromCharCode(127&t[i]);return n}function R(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;r>i;i++)n+=String.fromCharCode(t[i]);return n}function U(t,e,r){var n=t.length;(!e||0>e)&&(e=0),(!r||0>r||r>n)&&(r=n);for(var i="",o=e;r>o;o++)i+=D(t[o]);return i}function L(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function Z(t,e,r){if(t%1!==0||0>t)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,i,s){if(!o.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");if(e>i||s>e)throw new RangeError("value is out of bounds");if(r+n>t.length)throw new RangeError("index out of range")}function O(t,e,r,n){0>e&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);o>i;i++)t[r+i]=(e&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function W(t,e,r,n){0>e&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);o>i;i++)t[r+i]=e>>>8*(n?i:3-i)&255}function A(t,e,r,n,i,o){if(e>i||o>e)throw new RangeError("value is out of bounds");if(r+n>t.length)throw new RangeError("index out of range");if(0>r)throw new RangeError("index out of range")}function z(t,e,r,n,i){return i||A(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),q.write(t,e,r,n,23,4),r+4}function G(t,e,r,n,i){return i||A(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),q.write(t,e,r,n,52,8),r+8}function N(t){if(t=C(t).replace(tt,""),t.length<2)return"";for(;t.length%4!==0;)t+="=";return t}function C(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function D(t){return 16>t?"0"+t.toString(16):t.toString(16)}function J(t,e){e=e||1/0;for(var r,n=t.length,i=null,o=[],s=0;n>s;s++){if(r=t.charCodeAt(s),r>55295&&57344>r){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(56320>r){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,128>r){if((e-=1)<0)break;o.push(r)}else if(2048>r){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(65536>r){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(1114112>r))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Y(t){for(var e=[],r=0;r<t.length;r++)e.push(255&t.charCodeAt(r));return e}function F(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);s++)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function j(t){return H.toByteArray(N(t))}function V(t,e,r,n){for(var i=0;n>i&&!(i+r>=e.length||i>=t.length);i++)e[i+r]=t[i];return i}var H=t("base64-js"),q=t("ieee754"),$=t("is-array");r.Buffer=o,r.SlowBuffer=w,r.INSPECT_MAX_BYTES=50,o.poolSize=8192;var X={};o.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:n(),o.TYPED_ARRAY_SUPPORT&&(o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array),o.isBuffer=function(t){return!(null==t||!t._isBuffer)},o.compare=function(t,e){if(!o.isBuffer(t)||!o.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,s=Math.min(r,n);s>i&&t[i]===e[i];)++i;return i!==s&&(r=t[i],n=e[i]),n>r?-1:r>n?1:0},o.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(t,e){if(!$(t))throw new TypeError("list argument must be an Array of Buffers.");if(0===t.length)return new o(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;r++)e+=t[r].length;var n=new o(e),i=0;for(r=0;r<t.length;r++){var s=t[r];s.copy(n,i),i+=s.length}return n},o.byteLength=b,o.prototype.length=void 0,o.prototype.parent=void 0,o.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?P(this,0,t):v.apply(this,arguments)},o.prototype.equals=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:0===o.compare(this,t)},o.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),"<Buffer "+t+">"},o.prototype.compare=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?0:o.compare(this,t)},o.prototype.indexOf=function(t,e){function r(t,e,r){for(var n=-1,i=0;r+i<t.length;i++)if(t[r+i]===e[-1===n?0:i-n]){if(-1===n&&(n=i),i-n+1===e.length)return r+n}else n=-1;return-1}if(e>2147483647?e=2147483647:-2147483648>e&&(e=-2147483648),e>>=0,0===this.length)return-1;if(e>=this.length)return-1;if(0>e&&(e=Math.max(this.length+e,0)),"string"==typeof t)return 0===t.length?-1:String.prototype.indexOf.call(this,t,e);if(o.isBuffer(t))return r(this,t,e);if("number"==typeof t)return o.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,t,e):r(this,[t],e);throw new TypeError("val must be string, number or Buffer")},o.prototype.get=function(t){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(t)},o.prototype.set=function(t,e){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(t,e)},o.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else if(isFinite(e))e=0|e,isFinite(r)?(r=0|r,void 0===n&&(n="utf8")):(n=r,r=void 0);else{var i=n;n=e,e=0|r,r=i}var o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(0>r||0>e)||e>this.length)throw new RangeError("attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return E(this,t,e,r);case"utf8":case"utf-8":return m(this,t,e,r);case"ascii":return k(this,t,e,r);case"binary":return _(this,t,e,r);case"base64":return M(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,t,e,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var K=4096;o.prototype.slice=function(t,e){var r=this.length;t=~~t,e=void 0===e?r:~~e,0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),t>e&&(e=t);var n;if(o.TYPED_ARRAY_SUPPORT)n=o._augment(this.subarray(t,e));else{var i=e-t;n=new o(i,void 0);for(var s=0;i>s;s++)n[s]=this[s+t]}return n.length&&(n.parent=this.parent||this),n},o.prototype.readUIntLE=function(t,e,r){t=0|t,e=0|e,r||Z(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n},o.prototype.readUIntBE=function(t,e,r){t=0|t,e=0|e,r||Z(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},o.prototype.readUInt8=function(t,e){return e||Z(t,1,this.length),this[t]},o.prototype.readUInt16LE=function(t,e){return e||Z(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUInt16BE=function(t,e){return e||Z(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUInt32LE=function(t,e){return e||Z(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},o.prototype.readUInt32BE=function(t,e){return e||Z(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readIntLE=function(t,e,r){t=0|t,e=0|e,r||Z(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},o.prototype.readIntBE=function(t,e,r){t=0|t,e=0|e,r||Z(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},o.prototype.readInt8=function(t,e){return e||Z(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},o.prototype.readInt16LE=function(t,e){e||Z(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(t,e){e||Z(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(t,e){return e||Z(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,e){return e||Z(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readFloatLE=function(t,e){return e||Z(t,4,this.length),q.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,e){return e||Z(t,4,this.length),q.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,e){return e||Z(t,8,this.length),q.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,e){return e||Z(t,8,this.length),q.read(this,t,!1,52,8)},o.prototype.writeUIntLE=function(t,e,r,n){t=+t,e=0|e,r=0|r,n||B(this,t,e,r,Math.pow(2,8*r),0);var i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},o.prototype.writeUIntBE=function(t,e,r,n){t=+t,e=0|e,r=0|r,n||B(this,t,e,r,Math.pow(2,8*r),0);var i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},o.prototype.writeUInt8=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,1,255,0),o.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},o.prototype.writeUInt16LE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):O(this,t,e,!0),e+2},o.prototype.writeUInt16BE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):O(this,t,e,!1),e+2},o.prototype.writeUInt32LE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):W(this,t,e,!0),e+4},o.prototype.writeUInt32BE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):W(this,t,e,!1),e+4},o.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);B(this,t,e,r,i-1,-i)}var o=0,s=1,a=0>t?1:0;for(this[e]=255&t;++o<r&&(s*=256);)this[e+o]=(t/s>>0)-a&255;return e+r},o.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);B(this,t,e,r,i-1,-i)}var o=r-1,s=1,a=0>t?1:0;for(this[e+o]=255&t;--o>=0&&(s*=256);)this[e+o]=(t/s>>0)-a&255;return e+r},o.prototype.writeInt8=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,1,127,-128),o.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),0>t&&(t=255+t+1),this[e]=255&t,e+1},o.prototype.writeInt16LE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):O(this,t,e,!0),e+2},o.prototype.writeInt16BE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):O(this,t,e,!1),e+2},o.prototype.writeInt32LE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):W(this,t,e,!0),e+4},o.prototype.writeInt32BE=function(t,e,r){return t=+t,e=0|e,r||B(this,t,e,4,2147483647,-2147483648),0>t&&(t=4294967295+t+1),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):W(this,t,e,!1),e+4},o.prototype.writeFloatLE=function(t,e,r){return z(this,t,e,!0,r)},o.prototype.writeFloatBE=function(t,e,r){return z(this,t,e,!1,r)},o.prototype.writeDoubleLE=function(t,e,r){return G(this,t,e,!0,r)},o.prototype.writeDoubleBE=function(t,e,r){return G(this,t,e,!1,r)},o.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&r>n&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(0>e)throw new RangeError("targetStart out of bounds");if(0>r||r>=this.length)throw new RangeError("sourceStart out of bounds");if(0>n)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i,s=n-r;if(this===t&&e>r&&n>e)for(i=s-1;i>=0;i--)t[i+e]=this[i+r];else if(1e3>s||!o.TYPED_ARRAY_SUPPORT)for(i=0;s>i;i++)t[i+e]=this[i+r];else t._set(this.subarray(r,r+s),e);return s},o.prototype.fill=function(t,e,r){if(t||(t=0),e||(e=0),r||(r=this.length),e>r)throw new RangeError("end < start");if(r!==e&&0!==this.length){if(0>e||e>=this.length)throw new RangeError("start out of bounds");if(0>r||r>this.length)throw new RangeError("end out of bounds");var n;if("number"==typeof t)for(n=e;r>n;n++)this[n]=t;else{var i=J(t.toString()),o=i.length;for(n=e;r>n;n++)this[n]=i[n%o]}return this}},o.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(o.TYPED_ARRAY_SUPPORT)return new o(this).buffer;for(var t=new Uint8Array(this.length),e=0,r=t.length;r>e;e+=1)t[e]=this[e];return t.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var Q=o.prototype;o._augment=function(t){return t.constructor=o,t._isBuffer=!0,t._set=t.set,t.get=Q.get,t.set=Q.set,t.write=Q.write,t.toString=Q.toString,t.toLocaleString=Q.toString,t.toJSON=Q.toJSON,t.equals=Q.equals,t.compare=Q.compare,t.indexOf=Q.indexOf,t.copy=Q.copy,t.slice=Q.slice,t.readUIntLE=Q.readUIntLE,t.readUIntBE=Q.readUIntBE,t.readUInt8=Q.readUInt8,t.readUInt16LE=Q.readUInt16LE,t.readUInt16BE=Q.readUInt16BE,t.readUInt32LE=Q.readUInt32LE,t.readUInt32BE=Q.readUInt32BE,t.readIntLE=Q.readIntLE,t.readIntBE=Q.readIntBE,t.readInt8=Q.readInt8,t.readInt16LE=Q.readInt16LE,t.readInt16BE=Q.readInt16BE,t.readInt32LE=Q.readInt32LE,t.readInt32BE=Q.readInt32BE,t.readFloatLE=Q.readFloatLE,t.readFloatBE=Q.readFloatBE,t.readDoubleLE=Q.readDoubleLE,t.readDoubleBE=Q.readDoubleBE,t.writeUInt8=Q.writeUInt8,t.writeUIntLE=Q.writeUIntLE,t.writeUIntBE=Q.writeUIntBE,t.writeUInt16LE=Q.writeUInt16LE,t.writeUInt16BE=Q.writeUInt16BE,t.writeUInt32LE=Q.writeUInt32LE,t.writeUInt32BE=Q.writeUInt32BE,t.writeIntLE=Q.writeIntLE,t.writeIntBE=Q.writeIntBE,t.writeInt8=Q.writeInt8,t.writeInt16LE=Q.writeInt16LE,t.writeInt16BE=Q.writeInt16BE,t.writeInt32LE=Q.writeInt32LE,t.writeInt32BE=Q.writeInt32BE,t.writeFloatLE=Q.writeFloatLE,t.writeFloatBE=Q.writeFloatBE,t.writeDoubleLE=Q.writeDoubleLE,t.writeDoubleBE=Q.writeDoubleBE,t.fill=Q.fill,t.inspect=Q.inspect,t.toArrayBuffer=Q.toArrayBuffer,t};var tt=/[^+\/0-9A-Za-z-_]/g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"base64-js":14,ieee754:15,"is-array":16}],wkx:[function(t,e,r){r.Types=t("./types"),r.Geometry=t("./geometry"),r.Point=t("./point"),r.LineString=t("./linestring"),r.Polygon=t("./polygon"),r.MultiPoint=t("./multipoint"),r.MultiLineString=t("./multilinestring"),r.MultiPolygon=t("./multipolygon"),r.GeometryCollection=t("./geometrycollection")},{"./geometry":3,"./geometrycollection":4,"./linestring":5,"./multilinestring":6,"./multipoint":7,"./multipolygon":8,"./point":9,"./polygon":10,"./types":11}]},{},["wkx"]);

@@ -10,6 +10,6 @@ module.exports = BinaryWriter;

function _write(write, size) {
return function (value) {
return function (value, noAssert) {
this.ensureSize(size);
write.call(this.buffer, value, this.position);
write.call(this.buffer, value, this.position, noAssert);
this.position += size;

@@ -16,0 +16,0 @@ };

@@ -17,6 +17,8 @@ module.exports = Geometry;

function Geometry() {
this.srid = 0;
this.srid = undefined;
this.hasZ = false;
this.hasM = false;
}
Geometry.parse = function (value) {
Geometry.parse = function (value, options) {
var valueType = typeof value;

@@ -27,3 +29,3 @@

else if (Buffer.isBuffer(value) || value instanceof BinaryReader)
return Geometry._parseWkb(value);
return Geometry._parseWkb(value, options);
else

@@ -47,5 +49,8 @@ throw new Error('first argument must be a string or Buffer');

var geometryType = wktParser.matchType();
var dimension = wktParser.matchDimension();
var options = {
srid: srid || 0
srid: srid,
hasZ: dimension.hasZ,
hasM: dimension.hasM
};

@@ -68,8 +73,6 @@

return GeometryCollection._parseWkt(wktParser, options);
default:
throw new Error('GeometryType ' + geometryType + ' not supported');
}
};
Geometry._parseWkb = function (value) {
Geometry._parseWkb = function (value, parentOptions) {
var binaryReader,

@@ -79,3 +82,4 @@ hasSrid,

wkbType,
geometryType;
geometryType,
options = {};

@@ -90,13 +94,38 @@ if (value instanceof BinaryReader)

wkbType = binaryReader.readUInt32();
geometryType = wkbType & 0xFF;
hasSrid = (wkbType & 0x20000000) === 0x20000000;
options.hasSrid = (wkbType & 0x20000000) === 0x20000000;
if (hasSrid)
srid = binaryReader.readUInt32();
if (options.hasSrid)
options.srid = binaryReader.readUInt32();
var options = {
srid: srid || 0
};
options.hasZ = false;
options.hasM = false;
if (!options.hasSrid && (!parentOptions || !parentOptions.hasSrid)) {
if (wkbType >= 1000 && wkbType < 2000) {
options.hasZ = true;
geometryType = wkbType - 1000;
}
else if (wkbType >= 2000 && wkbType < 3000) {
options.hasM = true;
geometryType = wkbType - 2000;
}
else if (wkbType >= 3000 && wkbType < 4000) {
options.hasZ = true;
options.hasM = true;
geometryType = wkbType - 3000;
}
else {
geometryType = wkbType;
}
}
else {
if (wkbType & 0x80000000)
options.hasZ = true;
if (wkbType & 0x40000000)
options.hasM = true;
geometryType = wkbType & 0xF;
}
switch (geometryType) {

@@ -146,5 +175,16 @@ case Types.wkb.Point:

var extendedPrecision = binaryReader.readUInt8();
options.hasZ = (extendedPrecision & 0x01);
options.hasM = (extendedPrecision & 0x02);
options.hasZ = (extendedPrecision & 0x01) === 0x01;
options.hasM = (extendedPrecision & 0x02) === 0x02;
options.zPrecision = ZigZag.decode((extendedPrecision & 0x1C) >> 2);
options.zPrecisionFactor = Math.pow(10, options.zPrecision);
options.mPrecision = ZigZag.decode((extendedPrecision & 0xE0) >> 5);
options.mPrecisionFactor = Math.pow(10, options.mPrecision);
}
else {
options.hasZ = false;
options.hasM = false;
}
if (options.hasSizeAttribute)

@@ -187,20 +227,35 @@ binaryReader.readVarInt();

Geometry.parseGeoJSON = function (value) {
var geometry;
switch (value.type) {
case Types.geoJSON.Point:
return Point._parseGeoJSON(value);
geometry = Point._parseGeoJSON(value); break;
case Types.geoJSON.LineString:
return LineString._parseGeoJSON(value);
geometry = LineString._parseGeoJSON(value); break;
case Types.geoJSON.Polygon:
return Polygon._parseGeoJSON(value);
geometry = Polygon._parseGeoJSON(value); break;
case Types.geoJSON.MultiPoint:
return MultiPoint._parseGeoJSON(value);
geometry = MultiPoint._parseGeoJSON(value); break;
case Types.geoJSON.MultiLineString:
return MultiLineString._parseGeoJSON(value);
geometry = MultiLineString._parseGeoJSON(value); break;
case Types.geoJSON.MultiPolygon:
return MultiPolygon._parseGeoJSON(value);
geometry = MultiPolygon._parseGeoJSON(value); break;
case Types.geoJSON.GeometryCollection:
return GeometryCollection._parseGeoJSON(value);
geometry = GeometryCollection._parseGeoJSON(value); break;
default:
throw new Error('GeometryType ' + value.type + ' not supported');
}
if (value.crs && value.crs.type && value.crs.type === 'name' && value.crs.properties && value.crs.properties.name) {
var crs = value.crs.properties.name;
if (crs.indexOf('EPSG:') === 0)
geometry.srid = parseInt(crs.substring(5));
else if (crs.indexOf('urn:ogc:def:crs:EPSG::') === 0)
geometry.srid = parseInt(crs.substring(22));
else
throw new Error('Unsupported crs: ' + crs);
}
return geometry;
};

@@ -217,3 +272,3 @@

ewkb.writeInt8(1);
ewkb.writeUInt32LE(wkb.slice(1, 5).readUInt32LE(0) | 0x20000000);
ewkb.writeUInt32LE(wkb.slice(1, 5).readUInt32LE(0) | 0x20000000, true);
ewkb.writeUInt32LE(this.srid);

@@ -226,8 +281,108 @@

Geometry.prototype._getWktType = function (wktType, isEmpty) {
var wkt = wktType;
if (this.hasZ && this.hasM)
wkt += ' ZM ';
else if (this.hasZ)
wkt += ' Z ';
else if (this.hasM)
wkt += ' M ';
if (isEmpty && !this.hasZ && !this.hasM)
wkt += ' ';
if (isEmpty)
wkt += 'EMPTY';
return wkt;
};
Geometry.prototype._getWktCoordinate = function (point) {
var coordinates = point.x + ' ' + point.y;
if (this.hasZ)
coordinates += ' ' + point.z;
if (this.hasM)
coordinates += ' ' + point.m;
return coordinates;
};
Geometry.prototype._writeWkbType = function (wkb, geometryType, parentOptions) {
var dimensionType = 0;
if (typeof this.srid === 'undefined' && (!parentOptions || typeof parentOptions.srid === 'undefined')) {
if (this.hasZ && this.hasM)
dimensionType += 3000;
else if(this.hasZ)
dimensionType += 1000;
else if(this.hasM)
dimensionType += 2000;
}
else {
if (this.hasZ)
dimensionType |= 0x80000000;
if (this.hasM)
dimensionType |= 0x40000000;
}
wkb.writeUInt32LE(dimensionType + geometryType, true);
};
Geometry.getTwkbPrecision = function (xyPrecision, zPrecision, mPrecision) {
return {
xy: xyPrecision,
z: zPrecision,
m: mPrecision,
xyFactor: Math.pow(10, xyPrecision),
zFactor: Math.pow(10, zPrecision),
mFactor: Math.pow(10, mPrecision)
};
};
Geometry.prototype._writeTwkbHeader = function (twkb, geometryType, precision, isEmpty) {
var type = (ZigZag.encode(precision) << 4) + geometryType;
var metadataHeader = isEmpty << 4;
var type = (ZigZag.encode(precision.xy) << 4) + geometryType;
var metadataHeader = (this.hasZ || this.hasM) << 3;
metadataHeader += isEmpty << 4;
twkb.writeUInt8(type);
twkb.writeUInt8(metadataHeader);
if (this.hasZ || this.hasM) {
var extendedPrecision = 0;
if (this.hasZ)
extendedPrecision |= 0x1;
if (this.hasM)
extendedPrecision |= 0x2;
twkb.writeUInt8(extendedPrecision);
}
};
Geometry.prototype.toGeoJSON = function (options) {
var geoJSON = {};
if (this.srid) {
if (options) {
if (options.shortCrs) {
geoJSON.crs = {
type: 'name',
properties: {
name: 'EPSG:' + this.srid
}
};
}
else if (options.longCrs) {
geoJSON.crs = {
type: 'name',
properties: {
name: 'urn:ogc:def:crs:EPSG::' + this.srid
}
};
}
}
}
return geoJSON;
};

@@ -8,3 +8,2 @@ module.exports = GeometryCollection;

var BinaryWriter = require('./binarywriter');
var ZigZag = require('./zigzag.js');

@@ -19,5 +18,26 @@ function GeometryCollection(geometries) {

GeometryCollection.Z = function (geometries) {
var geometryCollection = new GeometryCollection(geometries);
geometryCollection.hasZ = true;
return geometryCollection;
};
GeometryCollection.M = function (geometries) {
var geometryCollection = new GeometryCollection(geometries);
geometryCollection.hasM = true;
return geometryCollection;
};
GeometryCollection.ZM = function (geometries) {
var geometryCollection = new GeometryCollection(geometries);
geometryCollection.hasZ = true;
geometryCollection.hasM = true;
return geometryCollection;
};
GeometryCollection._parseWkt = function (value, options) {
var geometryCollection = new GeometryCollection();
geometryCollection.srid = options.srid;
geometryCollection.hasZ = options.hasZ;
geometryCollection.hasM = options.hasM;

@@ -41,2 +61,4 @@ if (value.isMatch(['EMPTY']))

geometryCollection.srid = options.srid;
geometryCollection.hasZ = options.hasZ;
geometryCollection.hasM = options.hasM;

@@ -46,3 +68,3 @@ var geometryCount = value.readUInt32();

for (var i = 0; i < geometryCount; i++)
geometryCollection.geometries.push(Geometry.parse(value));
geometryCollection.geometries.push(Geometry.parse(value, options));

@@ -54,2 +76,4 @@ return geometryCollection;

var geometryCollection = new GeometryCollection();
geometryCollection.hasZ = options.hasZ;
geometryCollection.hasM = options.hasM;

@@ -73,2 +97,5 @@ if (options.isEmpty)

if (geometryCollection.geometries.length > 0)
geometryCollection.hasZ = geometryCollection.geometries[0].hasZ;
return geometryCollection;

@@ -79,5 +106,5 @@ };

if (this.geometries.length === 0)
return Types.wkt.GeometryCollection + ' EMPTY';
return this._getWktType(Types.wkt.GeometryCollection, true);
var wkt = Types.wkt.GeometryCollection + '(';
var wkt = this._getWktType(Types.wkt.GeometryCollection, false) + '(';

@@ -98,7 +125,7 @@ for (var i = 0; i < this.geometries.length; i++)

wkb.writeUInt32LE(Types.wkb.GeometryCollection);
this._writeWkbType(wkb, Types.wkb.GeometryCollection);
wkb.writeUInt32LE(this.geometries.length);
for (var i = 0; i < this.geometries.length; i++)
wkb.writeBuffer(this.geometries[i].toWkb());
wkb.writeBuffer(this.geometries[i].toWkb({ srid: this.srid }));

@@ -111,4 +138,3 @@ return wkb.buffer;

var precision = 5;
var precisionFactor = Math.pow(10, precision);
var precision = Geometry.getTwkbPrecision(5, 0, 0);
var isEmpty = this.geometries.length === 0;

@@ -137,7 +163,6 @@

GeometryCollection.prototype.toGeoJSON = function () {
var geoJSON = {
type: Types.geoJSON.GeometryCollection,
geometries: []
};
GeometryCollection.prototype.toGeoJSON = function (options) {
var geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
geoJSON.type = Types.geoJSON.GeometryCollection;
geoJSON.geometries = [];

@@ -144,0 +169,0 @@ for (var i = 0; i < this.geometries.length; i++)

@@ -15,2 +15,7 @@ module.exports = LineString;

this.points = points || [];
if (this.points.length > 0) {
this.hasZ = this.points[0].hasZ;
this.hasM = this.points[0].hasM;
}
}

@@ -20,5 +25,26 @@

LineString.Z = function (points) {
var lineString = new LineString(points);
lineString.hasZ = true;
return lineString;
};
LineString.M = function (points) {
var lineString = new LineString(points);
lineString.hasM = true;
return lineString;
};
LineString.ZM = function (points) {
var lineString = new LineString(points);
lineString.hasZ = true;
lineString.hasM = true;
return lineString;
};
LineString._parseWkt = function (value, options) {
var lineString = new LineString();
lineString.srid = options.srid;
lineString.hasZ = options.hasZ;
lineString.hasM = options.hasM;

@@ -29,3 +55,3 @@ if (value.isMatch(['EMPTY']))

value.expectGroupStart();
lineString.points.push.apply(lineString.points, value.matchCoordinates());
lineString.points.push.apply(lineString.points, value.matchCoordinates(options));
value.expectGroupEnd();

@@ -39,2 +65,4 @@

lineString.srid = options.srid;
lineString.hasZ = options.hasZ;
lineString.hasM = options.hasM;

@@ -44,3 +72,3 @@ var pointCount = value.readUInt32();

for (var i = 0; i < pointCount; i++)
lineString.points.push(new Point(value.readDouble(), value.readDouble()));
lineString.points.push(Point._readWkbPoint(value, options));

@@ -52,2 +80,4 @@ return lineString;

var lineString = new LineString();
lineString.hasZ = options.hasZ;
lineString.hasM = options.hasM;

@@ -57,13 +87,8 @@ if (options.isEmpty)

var x = 0;
var y = 0;
var previousPoint = new Point(0, 0, options.hasZ ? 0 : undefined, options.hasM ? 0 : undefined);
var pointCount = value.readVarInt();
for (var i = 0; i < pointCount; i++) {
x += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
y += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
for (var i = 0; i < pointCount; i++)
lineString.points.push(Point._readTwkbPoint(value, options, previousPoint));
lineString.points.push(new Point(x, y));
}
return lineString;

@@ -75,4 +100,7 @@ };

if (value.coordinates.length > 0)
lineString.hasZ = value.coordinates[0].length > 2;
for (var i = 0; i < value.coordinates.length; i++)
lineString.points.push(new Point(value.coordinates[i][0], value.coordinates[i][1]));
lineString.points.push(Point._readGeoJSONPoint(value.coordinates[i]));

@@ -84,5 +112,5 @@ return lineString;

if (this.points.length === 0)
return Types.wkt.LineString + ' EMPTY';
return this._getWktType(Types.wkt.LineString, true);
return Types.wkt.LineString + this._toInnerWkt();
return this._getWktType(Types.wkt.LineString, false) + this._toInnerWkt();
};

@@ -94,3 +122,3 @@

for (var i = 0; i < this.points.length; i++)
innerWkt += this.points[i].x + ' ' + this.points[i].y + ',';
innerWkt += this._getWktCoordinate(this.points[i]) + ',';

@@ -103,3 +131,3 @@ innerWkt = innerWkt.slice(0, -1);

LineString.prototype.toWkb = function () {
LineString.prototype.toWkb = function (parentOptions) {
var wkb = new BinaryWriter(this._getWkbSize());

@@ -109,9 +137,7 @@

wkb.writeUInt32LE(Types.wkb.LineString);
this._writeWkbType(wkb, Types.wkb.LineString, parentOptions);
wkb.writeUInt32LE(this.points.length);
for (var i = 0; i < this.points.length; i++) {
wkb.writeDoubleLE(this.points[i].x);
wkb.writeDoubleLE(this.points[i].y);
}
for (var i = 0; i < this.points.length; i++)
this.points[i]._writeWkbPoint(wkb);

@@ -124,4 +150,3 @@ return wkb.buffer;

var precision = 5;
var precisionFactor = Math.pow(10, precision);
var precision = Geometry.getTwkbPrecision(5, 0, 0);
var isEmpty = this.points.length === 0;

@@ -134,14 +159,5 @@

var lastX = 0;
var lastY = 0;
for (var i = 0; i < this.points.length; i++) {
var x = this.points[i].x * precisionFactor;
var y = this.points[i].y * precisionFactor;
twkb.writeVarInt(ZigZag.encode(x - lastX));
twkb.writeVarInt(ZigZag.encode(y - lastY));
lastX = x;
lastY = y;
}
var previousPoint = new Point(0, 0, 0, 0);
for (var i = 0; i < this.points.length; i++)
this.points[i]._writeTwkbPoint(twkb, precision, previousPoint);
}

@@ -153,15 +169,25 @@

LineString.prototype._getWkbSize = function () {
return 1 + 4 + 4 + (this.points.length * 16);
var coordinateSize = 16;
if (this.hasZ)
coordinateSize += 8;
if (this.hasM)
coordinateSize += 8;
return 1 + 4 + 4 + (this.points.length * coordinateSize);
};
LineString.prototype.toGeoJSON = function () {
var geoJSON = {
type: Types.geoJSON.LineString,
coordinates: []
};
LineString.prototype.toGeoJSON = function (options) {
var geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
geoJSON.type = Types.geoJSON.LineString;
geoJSON.coordinates = [];
for (var i = 0; i < this.points.length; i++)
geoJSON.coordinates.push([this.points[i].x, this.points[i].y]);
for (var i = 0; i < this.points.length; i++) {
if (this.hasZ)
geoJSON.coordinates.push([this.points[i].x, this.points[i].y, this.points[i].z]);
else
geoJSON.coordinates.push([this.points[i].x, this.points[i].y]);
}
return geoJSON;
};

@@ -20,5 +20,26 @@ module.exports = MultiLineString;

MultiLineString.Z = function (lineStrings) {
var multiLineString = new MultiLineString(lineStrings);
multiLineString.hasZ = true;
return multiLineString;
};
MultiLineString.M = function (lineStrings) {
var multiLineString = new MultiLineString(lineStrings);
multiLineString.hasM = true;
return multiLineString;
};
MultiLineString.ZM = function (lineStrings) {
var multiLineString = new MultiLineString(lineStrings);
multiLineString.hasZ = true;
multiLineString.hasM = true;
return multiLineString;
};
MultiLineString._parseWkt = function (value, options) {
var multiLineString = new MultiLineString();
multiLineString.srid = options.srid;
multiLineString.hasZ = options.hasZ;
multiLineString.hasM = options.hasM;

@@ -32,3 +53,3 @@ if (value.isMatch(['EMPTY']))

value.expectGroupStart();
multiLineString.lineStrings.push(new LineString(value.matchCoordinates()));
multiLineString.lineStrings.push(new LineString(value.matchCoordinates(options)));
value.expectGroupEnd();

@@ -45,7 +66,9 @@ } while (value.isMatch([',']));

multiLineString.srid = options.srid;
multiLineString.hasZ = options.hasZ;
multiLineString.hasM = options.hasM;
var pointCount = value.readUInt32();
var lineStringCount = value.readUInt32();
for (var i = 0; i < pointCount; i++)
multiLineString.lineStrings.push(Geometry.parse(value));
for (var i = 0; i < lineStringCount; i++)
multiLineString.lineStrings.push(Geometry.parse(value, options));

@@ -57,2 +80,4 @@ return multiLineString;

var multiLineString = new MultiLineString();
multiLineString.hasZ = options.hasZ;
multiLineString.hasM = options.hasM;

@@ -62,4 +87,3 @@ if (options.isEmpty)

var x = 0;
var y = 0;
var previousPoint = new Point(0, 0, options.hasZ ? 0 : undefined, options.hasM ? 0 : undefined);
var lineStringCount = value.readVarInt();

@@ -69,11 +93,10 @@

var lineString = new LineString();
lineString.hasZ = options.hasZ;
lineString.hasM = options.hasM;
var pointCount = value.readVarInt();
for (var j = 0; j < pointCount; j++) {
x += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
y += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
for (var j = 0; j < pointCount; j++)
lineString.points.push(Point._readTwkbPoint(value, options, previousPoint));
lineString.points.push(new Point(x, y));
}
multiLineString.lineStrings.push(lineString);

@@ -88,2 +111,5 @@ }

if (value.coordinates.length > 0 && value.coordinates[0].length > 0)
multiLineString.hasZ = value.coordinates[0][0].length > 2;
for (var i = 0; i < value.coordinates.length; i++)

@@ -97,5 +123,5 @@ multiLineString.lineStrings.push(LineString._parseGeoJSON({ coordinates: value.coordinates[i] }));

if (this.lineStrings.length === 0)
return Types.wkt.MultiLineString + ' EMPTY';
return this._getWktType(Types.wkt.MultiLineString, true);
var wkt = Types.wkt.MultiLineString + '(';
var wkt = this._getWktType(Types.wkt.MultiLineString, false) + '(';

@@ -116,7 +142,7 @@ for (var i = 0; i < this.lineStrings.length; i++)

wkb.writeUInt32LE(Types.wkb.MultiLineString);
this._writeWkbType(wkb, Types.wkb.MultiLineString);
wkb.writeUInt32LE(this.lineStrings.length);
for (var i = 0; i < this.lineStrings.length; i++)
wkb.writeBuffer(this.lineStrings[i].toWkb());
wkb.writeBuffer(this.lineStrings[i].toWkb({ srid: this.srid }));

@@ -129,4 +155,3 @@ return wkb.buffer;

var precision = 5;
var precisionFactor = Math.pow(10, precision);
var precision = Geometry.getTwkbPrecision(5, 0, 0);
var isEmpty = this.lineStrings.length === 0;

@@ -139,17 +164,8 @@

var lastX = 0;
var lastY = 0;
var previousPoint = new Point(0, 0, 0, 0);
for (var i = 0; i < this.lineStrings.length; i++) {
twkb.writeVarInt(this.lineStrings[i].points.length);
for (var j = 0; j < this.lineStrings[i].points.length; j++) {
var x = this.lineStrings[i].points[j].x * precisionFactor;
var y = this.lineStrings[i].points[j].y * precisionFactor;
twkb.writeVarInt(ZigZag.encode(x - lastX));
twkb.writeVarInt(ZigZag.encode(y - lastY));
lastX = x;
lastY = y;
}
for (var j = 0; j < this.lineStrings[i].points.length; j++)
this.lineStrings[i].points[j]._writeTwkbPoint(twkb, precision, previousPoint);
}

@@ -170,7 +186,6 @@ }

MultiLineString.prototype.toGeoJSON = function () {
var geoJSON = {
type: Types.geoJSON.MultiLineString,
coordinates: []
};
MultiLineString.prototype.toGeoJSON = function (options) {
var geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
geoJSON.type = Types.geoJSON.MultiLineString;
geoJSON.coordinates = [];

@@ -177,0 +192,0 @@ for (var i = 0; i < this.lineStrings.length; i++)

@@ -19,5 +19,26 @@ module.exports = MultiPoint;

MultiPoint.Z = function (points) {
var multiPoint = new MultiPoint(points);
multiPoint.hasZ = true;
return multiPoint;
};
MultiPoint.M = function (points) {
var multiPoint = new MultiPoint(points);
multiPoint.hasM = true;
return multiPoint;
};
MultiPoint.ZM = function (points) {
var multiPoint = new MultiPoint(points);
multiPoint.hasZ = true;
multiPoint.hasM = true;
return multiPoint;
};
MultiPoint._parseWkt = function (value, options) {
var multiPoint = new MultiPoint();
multiPoint.srid = options.srid;
multiPoint.hasZ = options.hasZ;
multiPoint.hasM = options.hasM;

@@ -28,3 +49,3 @@ if (value.isMatch(['EMPTY']))

value.expectGroupStart();
multiPoint.points.push.apply(multiPoint.points, value.matchCoordinates());
multiPoint.points.push.apply(multiPoint.points, value.matchCoordinates(options));
value.expectGroupEnd();

@@ -38,2 +59,4 @@

multiPoint.srid = options.srid;
multiPoint.hasZ = options.hasZ;
multiPoint.hasM = options.hasM;

@@ -43,3 +66,3 @@ var pointCount = value.readUInt32();

for (var i = 0; i < pointCount; i++)
multiPoint.points.push(Geometry.parse(value));
multiPoint.points.push(Geometry.parse(value, options));

@@ -51,2 +74,4 @@ return multiPoint;

var multiPoint = new MultiPoint();
multiPoint.hasZ = options.hasZ;
multiPoint.hasM = options.hasM;

@@ -56,14 +81,8 @@ if (options.isEmpty)

var previousPoint = new Point(0, 0, options.hasZ ? 0 : undefined, options.hasM ? 0 : undefined);
var pointCount = value.readVarInt();
var x = 0;
var y = 0;
for (var i = 0; i < pointCount; i++)
multiPoint.points.push(Point._readTwkbPoint(value, options, previousPoint));
for (var i = 0; i < pointCount; i++) {
x += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
y += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
multiPoint.points.push(new Point(x, y));
}
return multiPoint;

@@ -75,2 +94,5 @@ };

if (value.coordinates.length > 0)
multiPoint.hasZ = value.coordinates[0].length > 2;
for (var i = 0; i < value.coordinates.length; i++)

@@ -84,8 +106,8 @@ multiPoint.points.push(Point._parseGeoJSON({ coordinates: value.coordinates[i] }));

if (this.points.length === 0)
return Types.wkt.MultiPoint + ' EMPTY';
return this._getWktType(Types.wkt.MultiPoint, true);
var wkt = Types.wkt.MultiPoint + '(';
var wkt = this._getWktType(Types.wkt.MultiPoint, false) + '(';
for (var i = 0; i < this.points.length; i++)
wkt += this.points[i].x + ' ' + this.points[i].y + ',';
wkt += this._getWktCoordinate(this.points[i]) + ',';

@@ -103,7 +125,7 @@ wkt = wkt.slice(0, -1);

wkb.writeUInt32LE(Types.wkb.MultiPoint);
this._writeWkbType(wkb, Types.wkb.MultiPoint);
wkb.writeUInt32LE(this.points.length);
for (var i = 0; i < this.points.length; i++)
wkb.writeBuffer(this.points[i].toWkb());
wkb.writeBuffer(this.points[i].toWkb({ srid: this.srid }));

@@ -116,4 +138,3 @@ return wkb.buffer;

var precision = 5;
var precisionFactor = Math.pow(10, precision);
var precision = Geometry.getTwkbPrecision(5, 0, 0);
var isEmpty = this.points.length === 0;

@@ -126,14 +147,5 @@

var lastX = 0;
var lastY = 0;
for (var i = 0; i < this.points.length; i++) {
var x = this.points[i].x * precisionFactor;
var y = this.points[i].y * precisionFactor;
twkb.writeVarInt(ZigZag.encode(x - lastX));
twkb.writeVarInt(ZigZag.encode(y - lastY));
lastX = x;
lastY = y;
}
var previousPoint = new Point(0, 0, 0, 0);
for (var i = 0; i < this.points.length; i++)
this.points[i]._writeTwkbPoint(twkb, precision, previousPoint);
}

@@ -145,10 +157,18 @@

MultiPoint.prototype._getWkbSize = function () {
return 1 + 4 + 4 + (this.points.length * 21);
var coordinateSize = 16;
if (this.hasZ)
coordinateSize += 8;
if (this.hasM)
coordinateSize += 8;
coordinateSize += 5;
return 1 + 4 + 4 + (this.points.length * coordinateSize);
};
MultiPoint.prototype.toGeoJSON = function () {
var geoJSON = {
type: Types.geoJSON.MultiPoint,
coordinates: []
};
MultiPoint.prototype.toGeoJSON = function (options) {
var geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
geoJSON.type = Types.geoJSON.MultiPoint;
geoJSON.coordinates = [];

@@ -155,0 +175,0 @@ for (var i = 0; i < this.points.length; i++)

@@ -20,5 +20,26 @@ module.exports = MultiPolygon;

MultiPolygon.Z = function (polygons) {
var multiPolygon = new MultiPolygon(polygons);
multiPolygon.hasZ = true;
return multiPolygon;
};
MultiPolygon.M = function (polygons) {
var multiPolygon = new MultiPolygon(polygons);
multiPolygon.hasM = true;
return multiPolygon;
};
MultiPolygon.ZM = function (polygons) {
var multiPolygon = new MultiPolygon(polygons);
multiPolygon.hasZ = true;
multiPolygon.hasM = true;
return multiPolygon;
};
MultiPolygon._parseWkt = function (value, options) {
var multiPolygon = new MultiPolygon();
multiPolygon.srid = options.srid;
multiPolygon.hasZ = options.hasZ;
multiPolygon.hasM = options.hasM;

@@ -33,6 +54,7 @@ if (value.isMatch(['EMPTY']))

var polygon = new Polygon();
var exteriorRing = [];
var interiorRings = [];
value.expectGroupStart();
polygon.exteriorRing.push.apply(polygon.exteriorRing, value.matchCoordinates());
exteriorRing.push.apply(exteriorRing, value.matchCoordinates(options));
value.expectGroupEnd();

@@ -42,7 +64,7 @@

value.expectGroupStart();
polygon.interiorRings.push(value.matchCoordinates());
interiorRings.push(value.matchCoordinates(options));
value.expectGroupEnd();
}
multiPolygon.polygons.push(polygon);
multiPolygon.polygons.push(new Polygon(exteriorRing, interiorRings));

@@ -61,2 +83,4 @@ value.expectGroupEnd();

multiPolygon.srid = options.srid;
multiPolygon.hasZ = options.hasZ;
multiPolygon.hasM = options.hasM;

@@ -66,3 +90,3 @@ var polygonCount = value.readUInt32();

for (var i = 0; i < polygonCount; i++)
multiPolygon.polygons.push(Geometry.parse(value));
multiPolygon.polygons.push(Geometry.parse(value, options));

@@ -74,2 +98,4 @@ return multiPolygon;

var multiPolygon = new MultiPolygon();
multiPolygon.hasZ = options.hasZ;
multiPolygon.hasM = options.hasM;

@@ -79,4 +105,3 @@ if (options.isEmpty)

var x = 0;
var y = 0;
var previousPoint = new Point(0, 0, options.hasZ ? 0 : undefined, options.hasM ? 0 : undefined);
var polygonCount = value.readVarInt();

@@ -86,12 +111,11 @@

var polygon = new Polygon();
polygon.hasZ = options.hasZ;
polygon.hasM = options.hasM;
var ringCount = value.readVarInt();
var exteriorRingCount = value.readVarInt();
for (var j = 0; j < exteriorRingCount; j++) {
x += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
y += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
for (var j = 0; j < exteriorRingCount; j++)
polygon.exteriorRing.push(Point._readTwkbPoint(value, options, previousPoint));
polygon.exteriorRing.push(new Point(x, y));
}
for (j = 1; j < ringCount; j++) {

@@ -102,9 +126,5 @@ var interiorRing = [];

for (var k = 0; k < interiorRingCount; k++) {
x += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
y += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
for (var k = 0; k < interiorRingCount; k++)
interiorRing.push(Point._readTwkbPoint(value, options, previousPoint));
interiorRing.push(new Point(x, y));
}
polygon.interiorRings.push(interiorRing);

@@ -122,2 +142,5 @@ }

if (value.coordinates.length > 0 && value.coordinates[0].length > 0 && value.coordinates[0][0].length > 0)
multiPolygon.hasZ = value.coordinates[0][0][0].length > 2;
for (var i = 0; i < value.coordinates.length; i++)

@@ -131,5 +154,5 @@ multiPolygon.polygons.push(Polygon._parseGeoJSON({ coordinates: value.coordinates[i] }));

if (this.polygons.length === 0)
return Types.wkt.MultiPolygon + ' EMPTY';
return this._getWktType(Types.wkt.MultiPolygon, true);
var wkt = Types.wkt.MultiPolygon + '(';
var wkt = this._getWktType(Types.wkt.MultiPolygon, false) + '(';

@@ -150,7 +173,7 @@ for (var i = 0; i < this.polygons.length; i++)

wkb.writeUInt32LE(Types.wkb.MultiPolygon);
this._writeWkbType(wkb, Types.wkb.MultiPolygon);
wkb.writeUInt32LE(this.polygons.length);
for (var i = 0; i < this.polygons.length; i++)
wkb.writeBuffer(this.polygons[i].toWkb());
wkb.writeBuffer(this.polygons[i].toWkb({ srid: this.srid }));

@@ -163,4 +186,3 @@ return wkb.buffer;

var precision = 5;
var precisionFactor = Math.pow(10, precision);
var precision = Geometry.getTwkbPrecision(5, 0, 0);
var isEmpty = this.polygons.length === 0;

@@ -173,7 +195,3 @@

var lastX = 0;
var lastY = 0;
var x = 0;
var y = 0;
var previousPoint = new Point(0, 0, 0, 0);
for (var i = 0; i < this.polygons.length; i++) {

@@ -184,26 +202,10 @@ twkb.writeVarInt(1 + this.polygons[i].interiorRings.length);

for (var j = 0; j < this.polygons[i].exteriorRing.length; j++) {
x = this.polygons[i].exteriorRing[j].x * precisionFactor;
y = this.polygons[i].exteriorRing[j].y * precisionFactor;
for (var j = 0; j < this.polygons[i].exteriorRing.length; j++)
this.polygons[i].exteriorRing[j]._writeTwkbPoint(twkb, precision, previousPoint);
twkb.writeVarInt(ZigZag.encode(x - lastX));
twkb.writeVarInt(ZigZag.encode(y - lastY));
lastX = x;
lastY = y;
}
for (j = 0; j < this.polygons[i].interiorRings.length; j++) {
twkb.writeVarInt(this.polygons[i].interiorRings[j].length);
for (var k = 0; k < this.polygons[i].interiorRings[j].length; k++) {
x = this.polygons[i].interiorRings[j][k].x * precisionFactor;
y = this.polygons[i].interiorRings[j][k].y * precisionFactor;
twkb.writeVarInt(ZigZag.encode(x - lastX));
twkb.writeVarInt(ZigZag.encode(y - lastY));
lastX = x;
lastY = y;
}
for (var k = 0; k < this.polygons[i].interiorRings[j].length; k++)
this.polygons[i].interiorRings[j][k]._writeTwkbPoint(twkb, precision, previousPoint);
}

@@ -225,7 +227,6 @@ }

MultiPolygon.prototype.toGeoJSON = function () {
var geoJSON = {
type: Types.geoJSON.MultiPolygon,
coordinates: []
};
MultiPolygon.prototype.toGeoJSON = function (options) {
var geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
geoJSON.type = Types.geoJSON.MultiPolygon;
geoJSON.coordinates = [];

@@ -232,0 +233,0 @@ for (var i = 0; i < this.polygons.length; i++)

@@ -10,3 +10,3 @@ module.exports = Point;

function Point(x, y) {
function Point(x, y, z, m) {
Geometry.call(this);

@@ -16,2 +16,7 @@

this.y = y;
this.z = z;
this.m = m;
this.hasZ = typeof this.z !== 'undefined';
this.hasM = typeof this.m !== 'undefined';
}

@@ -21,5 +26,26 @@

Point.Z = function (x, y, z) {
var point = new Point(x, y, z);
point.hasZ = true;
return point;
};
Point.M = function (x, y, m) {
var point = new Point(x, y, undefined, m);
point.hasM = true;
return point;
};
Point.ZM = function (x, y, z, m) {
var point = new Point(x, y, z, m);
point.hasZ = true;
point.hasM = true;
return point;
};
Point._parseWkt = function (value, options) {
var point = new Point();
point.srid = options.srid;
point.hasZ = options.hasZ;
point.hasM = options.hasM;

@@ -31,6 +57,8 @@ if (value.isMatch(['EMPTY']))

var coordinate = value.matchCoordinate();
var coordinate = value.matchCoordinate(options);
point.x = coordinate.x;
point.y = coordinate.y;
point.z = coordinate.z;
point.m = coordinate.m;

@@ -43,3 +71,3 @@ value.expectGroupEnd();

Point._parseWkb = function (value, options) {
var point = new Point(value.readDouble(), value.readDouble());
var point = Point._readWkbPoint(value, options);
point.srid = options.srid;

@@ -49,27 +77,59 @@ return point;

Point._readWkbPoint = function (value, options) {
return new Point(value.readDouble(), value.readDouble(),
options.hasZ ? value.readDouble() : undefined,
options.hasM ? value.readDouble() : undefined);
};
Point._parseTwkb = function (value, options) {
var point = new Point();
point.hasZ = options.hasZ;
point.hasM = options.hasM;
if (options.isEmpty)
return new Point();
return point;
var x = ZigZag.decode(value.readVarInt()) / options.precisionFactor;
var y = ZigZag.decode(value.readVarInt()) / options.precisionFactor;
point.x = ZigZag.decode(value.readVarInt()) / options.precisionFactor;
point.y = ZigZag.decode(value.readVarInt()) / options.precisionFactor;
point.z = options.hasZ ? ZigZag.decode(value.readVarInt()) / options.zPrecisionFactor : undefined;
point.m = options.hasM ? ZigZag.decode(value.readVarInt()) / options.mPrecisionFactor : undefined;
return new Point(x, y);
return point;
};
Point._readTwkbPoint = function (value, options, previousPoint) {
previousPoint.x += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
previousPoint.y += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
if (options.hasZ)
previousPoint.z += ZigZag.decode(value.readVarInt()) / options.zPrecisionFactor;
if (options.hasM)
previousPoint.m += ZigZag.decode(value.readVarInt()) / options.mPrecisionFactor;
return new Point(previousPoint.x, previousPoint.y, previousPoint.z, previousPoint.m);
};
Point._parseGeoJSON = function (value) {
if (value.coordinates.length === 0)
return Point._readGeoJSONPoint(value.coordinates);
};
Point._readGeoJSONPoint = function (coordinates) {
if (coordinates.length === 0)
return new Point();
return new Point(value.coordinates[0], value.coordinates[1]);
if (coordinates.length > 2)
return new Point(coordinates[0], coordinates[1], coordinates[2]);
return new Point(coordinates[0], coordinates[1]);
};
Point.prototype.toWkt = function () {
if (typeof this.x === 'undefined' && typeof this.y === 'undefined')
return Types.wkt.Point + ' EMPTY';
if (typeof this.x === 'undefined' && typeof this.y === 'undefined' &&
typeof this.z === 'undefined' && typeof this.m === 'undefined')
return this._getWktType(Types.wkt.Point, true);
return Types.wkt.Point + '(' + this.x + ' ' + this.y + ')';
return this._getWktType(Types.wkt.Point, false) + '(' + this._getWktCoordinate(this) + ')';
};
Point.prototype.toWkb = function () {
Point.prototype.toWkb = function (parentOptions) {
var wkb = new BinaryWriter(this._getWkbSize());

@@ -80,9 +140,8 @@

if (typeof this.x === 'undefined' && typeof this.y === 'undefined') {
wkb.writeUInt32LE(Types.wkb.MultiPoint);
this._writeWkbType(wkb, Types.wkb.MultiPoint, parentOptions);
wkb.writeUInt32LE(0);
}
else {
wkb.writeUInt32LE(Types.wkb.Point);
wkb.writeDoubleLE(this.x);
wkb.writeDoubleLE(this.y);
this._writeWkbType(wkb, Types.wkb.Point, parentOptions);
this._writeWkbPoint(wkb);
}

@@ -93,7 +152,16 @@

Point.prototype._writeWkbPoint = function (wkb) {
wkb.writeDoubleLE(this.x);
wkb.writeDoubleLE(this.y);
if (this.hasZ)
wkb.writeDoubleLE(this.z);
if (this.hasM)
wkb.writeDoubleLE(this.m);
};
Point.prototype.toTwkb = function () {
var twkb = new BinaryWriter(0, true);
var precision = 5;
var precisionFactor = Math.pow(10, precision);
var precision = Geometry.getTwkbPrecision(5, 0, 0);
var isEmpty = typeof this.x === 'undefined' && typeof this.y === 'undefined';

@@ -103,6 +171,4 @@

if (!isEmpty) {
twkb.writeVarInt(ZigZag.encode(this.x * precisionFactor));
twkb.writeVarInt(ZigZag.encode(this.y * precisionFactor));
}
if (!isEmpty)
this._writeTwkbPoint(twkb, precision, new Point(0, 0, 0, 0));

@@ -112,2 +178,21 @@ return twkb.buffer;

Point.prototype._writeTwkbPoint = function (twkb, precision, previousPoint) {
var x = this.x * precision.xyFactor;
var y = this.y * precision.xyFactor;
var z = this.z * precision.zFactor;
var m = this.m * precision.mFactor;
twkb.writeVarInt(ZigZag.encode(x - previousPoint.x));
twkb.writeVarInt(ZigZag.encode(y - previousPoint.y));
if (this.hasZ)
twkb.writeVarInt(ZigZag.encode(z - previousPoint.z));
if (this.hasM)
twkb.writeVarInt(ZigZag.encode(m - previousPoint.m));
previousPoint.x = x;
previousPoint.y = y;
previousPoint.z = z;
previousPoint.m = m;
};
Point.prototype._getWkbSize = function () {

@@ -117,12 +202,20 @@ if (typeof this.x === 'undefined' && typeof this.y === 'undefined')

return 1 + 4 + 8 + 8;
var size = 1 + 4 + 8 + 8;
if (this.hasZ)
size += 8;
if (this.hasM)
size += 8;
return size;
};
Point.prototype.toGeoJSON = function () {
var geoJSON = {
type: Types.geoJSON.Point
};
Point.prototype.toGeoJSON = function (options) {
var geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
geoJSON.type = Types.geoJSON.Point;
if (typeof this.x === 'undefined' && typeof this.y === 'undefined')
geoJSON.coordinates = [];
else if (typeof this.z !== 'undefined')
geoJSON.coordinates = [this.x, this.y, this.z];
else

@@ -129,0 +222,0 @@ geoJSON.coordinates = [this.x, this.y];

@@ -16,2 +16,7 @@ module.exports = Polygon;

this.interiorRings = interiorRings || [];
if (this.exteriorRing.length > 0) {
this.hasZ = this.exteriorRing[0].hasZ;
this.hasM = this.exteriorRing[0].hasM;
}
}

@@ -21,5 +26,26 @@

Polygon.Z = function (exteriorRing, interiorRings) {
var polygon = new Polygon(exteriorRing, interiorRings);
polygon.hasZ = true;
return polygon;
};
Polygon.M = function (exteriorRing, interiorRings) {
var polygon = new Polygon(exteriorRing, interiorRings);
polygon.hasM = true;
return polygon;
};
Polygon.ZM = function (exteriorRing, interiorRings) {
var polygon = new Polygon(exteriorRing, interiorRings);
polygon.hasZ = true;
polygon.hasM = true;
return polygon;
};
Polygon._parseWkt = function (value, options) {
var polygon = new Polygon();
polygon.srid = options.srid;
polygon.hasZ = options.hasZ;
polygon.hasM = options.hasM;

@@ -32,3 +58,3 @@ if (value.isMatch(['EMPTY']))

value.expectGroupStart();
polygon.exteriorRing.push.apply(polygon.exteriorRing, value.matchCoordinates());
polygon.exteriorRing.push.apply(polygon.exteriorRing, value.matchCoordinates(options));
value.expectGroupEnd();

@@ -38,3 +64,3 @@

value.expectGroupStart();
polygon.interiorRings.push(value.matchCoordinates());
polygon.interiorRings.push(value.matchCoordinates(options));
value.expectGroupEnd();

@@ -51,2 +77,4 @@ }

polygon.srid = options.srid;
polygon.hasZ = options.hasZ;
polygon.hasM = options.hasM;

@@ -59,3 +87,3 @@ var ringCount = value.readUInt32();

for (var i = 0; i < exteriorRingCount; i++)
polygon.exteriorRing.push(new Point(value.readDouble(), value.readDouble()));
polygon.exteriorRing.push(Point._readWkbPoint(value, options));

@@ -68,3 +96,3 @@ for (i = 1; i < ringCount; i++) {

for (var j = 0; j < interiorRingCount; j++)
interiorRing.push(new Point(value.readDouble(), value.readDouble()));
interiorRing.push(Point._readWkbPoint(value, options));

@@ -80,2 +108,4 @@ polygon.interiorRings.push(interiorRing);

var polygon = new Polygon();
polygon.hasZ = options.hasZ;
polygon.hasM = options.hasM;

@@ -85,14 +115,9 @@ if (options.isEmpty)

var x = 0;
var y = 0;
var previousPoint = new Point(0, 0, options.hasZ ? 0 : undefined, options.hasM ? 0 : undefined);
var ringCount = value.readVarInt();
var exteriorRingCount = value.readVarInt();
for (var i = 0; i < exteriorRingCount; i++) {
x += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
y += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
for (var i = 0; i < exteriorRingCount; i++)
polygon.exteriorRing.push(Point._readTwkbPoint(value, options, previousPoint));
polygon.exteriorRing.push(new Point(x, y));
}
for (i = 1; i < ringCount; i++) {

@@ -103,9 +128,5 @@ var interiorRing = [];

for (var j = 0; j < interiorRingCount; j++) {
x += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
y += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
for (var j = 0; j < interiorRingCount; j++)
interiorRing.push(Point._readTwkbPoint(value, options, previousPoint));
interiorRing.push(new Point(x, y));
}
polygon.interiorRings.push(interiorRing);

@@ -120,2 +141,5 @@ }

if (value.coordinates.length > 0 && value.coordinates[0].length > 0)
polygon.hasZ = value.coordinates[0][0].length > 2;
for (var i = 0; i < value.coordinates.length; i++) {

@@ -127,5 +151,5 @@ if (i > 0)

if (i === 0)
polygon.exteriorRing.push(new Point(value.coordinates[i][j][0], value.coordinates[i][j][1]));
polygon.exteriorRing.push(Point._readGeoJSONPoint(value.coordinates[i][j]));
else
polygon.interiorRings[i - 1].push(new Point(value.coordinates[i][j][0], value.coordinates[i][j][1]));
polygon.interiorRings[i - 1].push(Point._readGeoJSONPoint(value.coordinates[i][j]));
}

@@ -139,5 +163,5 @@ }

if (this.exteriorRing.length === 0)
return Types.wkt.Polygon + ' EMPTY';
return this._getWktType(Types.wkt.Polygon, true);
return Types.wkt.Polygon + this._toInnerWkt();
return this._getWktType(Types.wkt.Polygon, false) + this._toInnerWkt();
};

@@ -149,3 +173,3 @@

for (var i = 0; i < this.exteriorRing.length; i++)
innerWkt += this.exteriorRing[i].x + ' ' + this.exteriorRing[i].y + ',';
innerWkt += this._getWktCoordinate(this.exteriorRing[i]) + ',';

@@ -159,3 +183,3 @@ innerWkt = innerWkt.slice(0, -1);

for (var j = 0; j < this.interiorRings[i].length; j++) {
innerWkt += this.interiorRings[i][j].x + ' ' + this.interiorRings[i][j].y + ',';
innerWkt += this._getWktCoordinate(this.interiorRings[i][j]) + ',';
}

@@ -172,3 +196,3 @@

Polygon.prototype.toWkb = function () {
Polygon.prototype.toWkb = function (parentOptions) {
var wkb = new BinaryWriter(this._getWkbSize());

@@ -178,3 +202,3 @@

wkb.writeUInt32LE(Types.wkb.Polygon);
this._writeWkbType(wkb, Types.wkb.Polygon, parentOptions);

@@ -189,6 +213,4 @@ if (this.exteriorRing.length > 0) {

for (var i = 0; i < this.exteriorRing.length; i++) {
wkb.writeDoubleLE(this.exteriorRing[i].x);
wkb.writeDoubleLE(this.exteriorRing[i].y);
}
for (var i = 0; i < this.exteriorRing.length; i++)
this.exteriorRing[i]._writeWkbPoint(wkb);

@@ -198,6 +220,4 @@ for (i = 0; i < this.interiorRings.length; i++) {

for (var j = 0; j < this.interiorRings[i].length; j++) {
wkb.writeDoubleLE(this.interiorRings[i][j].x);
wkb.writeDoubleLE(this.interiorRings[i][j].y);
}
for (var j = 0; j < this.interiorRings[i].length; j++)
this.interiorRings[i][j]._writeWkbPoint(wkb);
}

@@ -211,4 +231,3 @@

var precision = 5;
var precisionFactor = Math.pow(10, precision);
var precision = Geometry.getTwkbPrecision(5, 0, 0);
var isEmpty = this.exteriorRing.length === 0;

@@ -223,31 +242,11 @@

var lastX = 0;
var lastY = 0;
var x = 0;
var y = 0;
var previousPoint = new Point(0, 0, 0, 0);
for (var i = 0; i < this.exteriorRing.length; i++)
this.exteriorRing[i]._writeTwkbPoint(twkb, precision, previousPoint);
for (var i = 0; i < this.exteriorRing.length; i++) {
x = this.exteriorRing[i].x * precisionFactor;
y = this.exteriorRing[i].y * precisionFactor;
twkb.writeVarInt(ZigZag.encode(x - lastX));
twkb.writeVarInt(ZigZag.encode(y - lastY));
lastX = x;
lastY = y;
}
for (i = 0; i < this.interiorRings.length; i++) {
twkb.writeVarInt(this.interiorRings[i].length);
for (var j = 0; j < this.interiorRings[i].length; j++) {
x = this.interiorRings[i][j].x * precisionFactor;
y = this.interiorRings[i][j].y * precisionFactor;
twkb.writeVarInt(ZigZag.encode(x - lastX));
twkb.writeVarInt(ZigZag.encode(y - lastY));
lastX = x;
lastY = y;
}
for (var j = 0; j < this.interiorRings[i].length; j++)
this.interiorRings[i][j]._writeTwkbPoint(twkb, precision, previousPoint);
}

@@ -260,9 +259,16 @@ }

Polygon.prototype._getWkbSize = function () {
var coordinateSize = 16;
if (this.hasZ)
coordinateSize += 8;
if (this.hasM)
coordinateSize += 8;
var size = 1 + 4 + 4;
if (this.exteriorRing.length > 0)
size += 4 + (this.exteriorRing.length * 16);
size += 4 + (this.exteriorRing.length * coordinateSize);
for (var i = 0; i < this.interiorRings.length; i++)
size += 4 + (this.interiorRings[i].length * 16);
size += 4 + (this.interiorRings[i].length * coordinateSize);

@@ -272,7 +278,6 @@ return size;

Polygon.prototype.toGeoJSON = function () {
var geoJSON = {
type: Types.geoJSON.Polygon,
coordinates: []
};
Polygon.prototype.toGeoJSON = function (options) {
var geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
geoJSON.type = Types.geoJSON.Polygon;
geoJSON.coordinates = [];

@@ -282,4 +287,8 @@ if (this.exteriorRing.length > 0) {

for (var i = 0; i < this.exteriorRing.length; i++)
exteriorRing.push([this.exteriorRing[i].x, this.exteriorRing[i].y]);
for (var i = 0; i < this.exteriorRing.length; i++) {
if (this.hasZ)
exteriorRing.push([this.exteriorRing[i].x, this.exteriorRing[i].y, this.exteriorRing[i].z]);
else
exteriorRing.push([this.exteriorRing[i].x, this.exteriorRing[i].y]);
}

@@ -292,4 +301,8 @@ geoJSON.coordinates.push(exteriorRing);

for (var k = 0; k < this.interiorRings[j].length; k++)
interiorRing.push([this.interiorRings[j][k].x, this.interiorRings[j][k].y]);
for (var k = 0; k < this.interiorRings[j].length; k++) {
if (this.hasZ)
interiorRing.push([this.interiorRings[j][k].x, this.interiorRings[j][k].y, this.interiorRings[j][k].z]);
else
interiorRing.push([this.interiorRings[j][k].x, this.interiorRings[j][k].y]);
}

@@ -296,0 +309,0 @@ geoJSON.coordinates.push(interiorRing);

@@ -62,2 +62,13 @@ module.exports = WktParser;

WktParser.prototype.matchDimension = function () {
var dimension = this.match(['ZM', 'Z', 'M']);
switch (dimension) {
case 'ZM': return { hasZ: true, hasM: true };
case 'Z': return { hasZ: true, hasM: false };
case 'M': return { hasZ: false, hasM: true };
default: return { hasZ: false, hasM: false };
}
};
WktParser.prototype.expectGroupStart = function () {

@@ -73,16 +84,35 @@ if (!this.isMatch(['(']))

WktParser.prototype.matchCoordinate = function () {
var match = this.matchRegex([/^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)/]);
WktParser.prototype.matchCoordinate = function (options) {
var match;
if (options.hasZ && options.hasM)
match = this.matchRegex([/^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)/]);
else if (options.hasZ || options.hasM)
match = this.matchRegex([/^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)/]);
else
match = this.matchRegex([/^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)/]);
if (!match)
throw new Error('Expected coordinate pair');
throw new Error('Expected coordinates');
return new Point(parseFloat(match[1]), parseFloat(match[2]));
if (options.hasZ && options.hasM)
return new Point(parseFloat(match[1]), parseFloat(match[2]), parseFloat(match[3]), parseFloat(match[4]));
else if (options.hasZ)
return new Point(parseFloat(match[1]), parseFloat(match[2]), parseFloat(match[3]));
else if (options.hasM)
return new Point(parseFloat(match[1]), parseFloat(match[2]), undefined, parseFloat(match[3]));
else
return new Point(parseFloat(match[1]), parseFloat(match[2]));
};
WktParser.prototype.matchCoordinates = function () {
WktParser.prototype.matchCoordinates = function (options) {
var coordinates = [];
do {
coordinates.push(this.matchCoordinate());
var startsWithBracket = this.isMatch(['(']);
coordinates.push(this.matchCoordinate(options));
if (startsWithBracket)
this.expectGroupEnd();
} while (this.isMatch([',']));

@@ -89,0 +119,0 @@

{
"name": "wkx",
"version": "0.1.0",
"version": "0.2.0",
"description": "A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer",

@@ -8,3 +8,3 @@ "main": "lib/wkx.js",

"test": "jshint . && mocha",
"build": "gulp",
"build": "browserify -r buffer -r ./lib/wkx.js:wkx ./lib/wkx.js > ./dist/wkx.js && uglifyjs -c -m -- ./dist/wkx.js > ./dist/wkx.min.js",
"coveralls": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"

@@ -15,15 +15,11 @@ },

"devDependencies": {
"async": "^1.3.0",
"browserify": "^10.2.4",
"coveralls": "^2.11.2",
"gulp": "^3.9.0",
"gulp-pathmap": "^0.1.0",
"gulp-uglify": "^1.2.0",
"gulp-util": "^3.0.6",
"istanbul": "^0.3.17",
"jshint": "^2.8.0",
"async": "^1.5.0",
"browserify": "^12.0.1",
"coveralls": "^2.11.4",
"istanbul": "^0.4.1",
"jshint": "^2.9.1-rc1",
"json-stringify-pretty-compact": "^1.0.1",
"mocha": "^2.2.5",
"pg": "^4.4.0",
"vinyl": "^0.5.0"
"mocha": "^2.3.4",
"pg": "^4.4.3",
"uglify-js": "^2.6.1"
},

@@ -30,0 +26,0 @@ "repository": {

@@ -34,2 +34,8 @@ wkx [![Build Status](https://travis-ci.org/cschwarz/wkx.svg?branch=master)](https://travis-ci.org/cschwarz/wkx) [![Coverage Status](https://coveralls.io/repos/cschwarz/wkx/badge.svg?branch=master)](https://coveralls.io/r/cschwarz/wkx?branch=master)

//Parsing a node Buffer containing a TWKB object
var geometry = wkx.Geometry.parseTwkb(twkbBuffer);
//Parsing a GeoJSON object
var geometry = wkx.Geometry.parseGeoJSON({ type: 'Point', coordinates: [1, 2] });
//Serializing a Point geometry to WKT

@@ -46,2 +52,8 @@ var wktString = new wkx.Point(1, 2).toWkt();

var ewkbBuffer = new wkx.Point(1, 2).toEwkb();
//Serializing a Point geometry to TWKB
var twkbBuffer = new wkx.Point(1, 2).toTwkb();
//Serializing a Point geometry to GeoJSON
var geoJSONObject = new wkx.Point(1, 2).toGeoJSON();
```

@@ -58,7 +70,2 @@

You may also use [RawGit][] as a CDN, so you don't need to copy `wkx` into your project:
```html
<script src="https://cdn.rawgit.com/cschwarz/wkx/v0.1.0/dist/wkx.js"></script>
```
If you use [browserify][] for your project, you can simply `npm install wkx --save`, and just require `wkx` as usual in

@@ -75,3 +82,3 @@ your code.

document.getElementById('output').innerText = JSON.stringify(geometry, null, ' ');
console.log(geometry.toGeoJSON());
```

@@ -81,18 +88,10 @@

```javascript
var Buffer = require('buffer');
var Buffer = require('buffer').Buffer;
var wkx = require('wkx');
var geometry = wkx.Geometry.parse(new Buffer([1,1,0,0,0,0,0,0,0,0,0,240,63,0,0,0,0,0,0,0,64]));
var wkbBuffer = new Buffer('0101000000000000000000f03f0000000000000040', 'hex');
var geometry = wkx.Geometry.parse(wkbBuffer);
document.getElementById('output').innerText = JSON.stringify(geometry, null, ' ');
console.log(geometry.toGeoJSON());
```
(`buffer` is also made available by browserify, so it will also work the same way regardless of your choice above)
[RawGit]: http://rawgit.com/
[browserify]: http://browserify.org/
Todo
----
- Add support for parsing and serializing 3D/4D geometries (Z, M and ZM)

@@ -0,0 +0,0 @@ {

@@ -0,1 +1,2 @@

var Geometry = require('../lib/geometry');
var Point = require('../lib/point');

@@ -6,2 +7,24 @@

describe('wkx', function () {
describe('parseTwkb', function () {
it('includes size', function () {
assert.deepEqual(Geometry.parseTwkb(
new Buffer('0102020204', 'hex')),
new Point(1, 2));
});
it('includes bounding box', function () {
assert.deepEqual(Geometry.parseTwkb(
new Buffer('0101020004000204', 'hex')),
new Point(1, 2));
});
it('includes extended precision', function () {
assert.deepEqual(Geometry.parseTwkb(
new Buffer('01080302040608', 'hex')),
new Point(1, 2, 3, 4));
});
it('includes extended precision and bounding box', function () {
assert.deepEqual(Geometry.parseTwkb(
new Buffer('010903020004000600080002040608', 'hex')),
new Point(1, 2, 3, 4));
});
});
describe('toTwkb', function () {

@@ -8,0 +31,0 @@ it('Point small', function () {

@@ -12,3 +12,8 @@ /* jshint evil: true */

var testData = require('./testdata.json');
var tests = {
'2D': require('./testdata.json'),
'Z': require('./testdataZ.json'),
'M': require('./testdataM.json'),
'ZM': require('./testdataZM.json')
};

@@ -23,3 +28,5 @@ var assert = require('assert');

var geometry = data.wkbGeometry ? data.wkbGeometry : data.geometry;
assert.deepEqual(Geometry.parse(new Buffer(data.wkb, 'hex')), eval(geometry));
geometry = eval(geometry);
geometry.srid = undefined;
assert.deepEqual(Geometry.parse(new Buffer(data.wkb, 'hex')), geometry);
}

@@ -29,9 +36,11 @@

var geometry = data.wkbGeometry ? data.wkbGeometry : data.geometry;
assert.deepEqual(Geometry.parse(new Buffer(data.wkbXdr, 'hex')), eval(geometry));
geometry = eval(geometry);
geometry.srid = undefined;
assert.deepEqual(Geometry.parse(new Buffer(data.wkbXdr, 'hex')), geometry);
}
function assertParseEwkt(data) {
data.geometry = eval(data.geometry);
data.geometry.srid = 4326;
assert.deepEqual(Geometry.parse('SRID=4326;' + data.wkt), data.geometry);
var geometry = eval(data.geometry);
geometry.srid = 4326;
assert.deepEqual(Geometry.parse('SRID=4326;' + data.wkt), geometry);
}

@@ -55,3 +64,3 @@

var geometry = eval(data.geometry);
geometry.srid = 0;
geometry.srid = undefined;
assert.deepEqual(Geometry.parseTwkb(new Buffer(data.twkb, 'hex')), geometry);

@@ -61,4 +70,5 @@ }

function assertParseGeoJSON(data) {
var geometry = eval(data.geometry);
geometry.srid = 0;
var geometry = data.geoJSONGeometry ? data.geoJSONGeometry : data.geometry;
geometry = eval(geometry);
geometry.srid = undefined;
assert.deepEqual(Geometry.parseGeoJSON(data.geoJSON), geometry);

@@ -76,11 +86,11 @@ }

function assertToEwkt(data) {
data.geometry = eval(data.geometry);
data.geometry.srid = 4326;
assert.equal(data.geometry.toEwkt(), 'SRID=4326;' + data.wkt);
var geometry = eval(data.geometry);
geometry.srid = 4326;
assert.equal(geometry.toEwkt(), 'SRID=4326;' + data.wkt);
}
function assertToEwkb(data) {
data.geometry = eval(data.geometry);
data.geometry.srid = 4326;
assert.equal(data.geometry.toEwkb().toString('hex'), data.ewkb);
var geometry = eval(data.geometry);
geometry.srid = 4326;
assert.equal(geometry.toEwkb().toString('hex'), data.ewkb);
}

@@ -93,3 +103,3 @@

function assertToGeoJSON(data) {
assert.deepEqual(data.geometry.toGeoJSON(), data.geoJSON);
assert.deepEqual(eval(data.geometry).toGeoJSON(), data.geoJSON);
}

@@ -112,2 +122,11 @@

assert.deepEqual(Geometry.parse('POINT(1.2 -3.4)'), new Point(1.2, -3.4));
assert.deepEqual(Geometry.parse('MULTIPOINT(1 2,3 4)'),
new MultiPoint([new Point(1, 2), new Point(3, 4)]));
assert.deepEqual(Geometry.parse('MULTIPOINT(1 2, 3 4)'),
new MultiPoint([new Point(1, 2), new Point(3, 4)]));
assert.deepEqual(Geometry.parse('MULTIPOINT((1 2),(3 4))'),
new MultiPoint([new Point(1, 2), new Point(3, 4)]));
assert.deepEqual(Geometry.parse('MULTIPOINT((1 2), (3 4))'),
new MultiPoint([new Point(1, 2), new Point(3, 4)]));
});

@@ -119,3 +138,3 @@ it('parse() - invalid input', function () {

assert.throws(function () { Geometry.parse('POINT(1 2'); }, /Expected group end/);
assert.throws(function () { Geometry.parse('POINT(1)'); }, /Expected coordinate pair/);
assert.throws(function () { Geometry.parse('POINT(1)'); }, /Expected coordinates/);
assert.throws(function () { Geometry.parse('TEST'); }, /Expected geometry type/);

@@ -132,12 +151,5 @@ assert.throws(function () {

});
it('parseTwkb() - bounding box, size, extended precision', function () {
assert.deepEqual(Geometry.parseTwkb(new Buffer('a1030ec09a0c0080b51800c09a0c80b518', 'hex')),
new Point(1, 2));
assert.deepEqual(Geometry.parseTwkb(
new Buffer('a10bb71cc09a0c0080b51800c0cf240080ea3000c09a0c80b518c0cf2480ea30', 'hex')),
new Point(1, 2));
});
});
function createTest (testKey) {
function createTest (testKey, testData) {
describe(testKey, function () {

@@ -189,5 +201,13 @@ it ('parse(wkt)', function () {

for (var testKey in testData) {
createTest(testKey);
function createTests (testKey, testData) {
describe(testKey, function () {
for (var testDataKey in testData) {
createTest(testDataKey, testData);
}
});
}
for (var testKey in tests) {
createTests(testKey, tests[testKey]);
}
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc