well-known-parser
Version:
A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer
3 lines (2 loc) • 1.9 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./well-known-parser6.cjs"),d=require("./well-known-parser4.cjs"),g=require("./well-known-parser16.cjs");function f(o,n){const r=new h.Polygon;if(r.srid=n.srid,r.hasZ=n.hasZ??!1,r.hasM=n.hasM??!1,o.isMatch(["EMPTY"]))return r;o.expectGroupStart(),o.expectGroupStart();const e=o.matchCoordinates(n);for(const i of e)r.exteriorRing.push(i);for(o.expectGroupEnd();o.isMatch([","]);){o.expectGroupStart();const i=o.matchCoordinates(n),s=[];for(const t of i)s.push(t);r.interiorRings.push(s),o.expectGroupEnd()}return o.expectGroupEnd(),r}function l(o,n){const r=new h.Polygon;r.srid=n.srid,r.hasZ=n.hasZ??!1,r.hasM=n.hasM??!1;const e=o.readUInt32(),i={...n,srid:void 0};if(e>0){const s=o.readUInt32();for(let t=0;t<s;t++)r.exteriorRing.push(g.parsePointWkb(o,i));for(let t=1;t<e;t++){const c=[],p=o.readUInt32();for(let a=0;a<p;a++)c.push(g.parsePointWkb(o,i));r.interiorRings.push(c)}}return r}function P(o,n){const r=new h.Polygon;if(r.hasZ=n.hasZ??!1,r.hasM=n.hasM??!1,n.isEmpty)return r;const e=new d.Point(0,0,n.hasZ?0:void 0,n.hasM?0:void 0),i=o.readVarInt(),s=o.readVarInt();for(let t=0;t<s;t++)r.exteriorRing.push(g.parseRelativePointTwkb(o,n,e));for(let t=1;t<i;t++){const c=[],p=o.readVarInt();for(let a=0;a<p;a++)c.push(g.parseRelativePointTwkb(o,n,e));r.interiorRings.push(c)}return r}function y(o){const n=new h.Polygon;o.coordinates.length>0&&o.coordinates[0].length>0&&(n.hasZ=o.coordinates[0][0].length>2);for(let r=0;r<o.coordinates.length;r++){r>0&&n.interiorRings.push([]);for(let e=0;e<o.coordinates[r].length;e++){const i=g.parsePointGeoJSON(o.coordinates[r][e]);r===0?n.exteriorRing.push(i):n.interiorRings[r-1].push(i)}}return n}exports.parsePolygonGeoJSON=y;exports.parsePolygonTwkb=P;exports.parsePolygonWkb=l;exports.parsePolygonWkt=f;
//# sourceMappingURL=well-known-parser18.cjs.map