import { Feature_default as Feature_default2, transformGeometryWithOptions } from "./chunk-56VFHHUN.js"; import "./chunk-W7BDJOQY.js"; import { GeometryCollection_default, LineString_default, MultiLineString_default, MultiPoint_default, MultiPolygon_default } from "./chunk-7JXPN73Q.js"; import { Feature_default } from "./chunk-E53S5GN6.js"; import "./chunk-JFXZSSOM.js"; import { Point_default, Polygon_default } from "./chunk-AZGMK675.js"; import "./chunk-X52LGBOS.js"; import "./chunk-QFCIXVZ3.js"; import "./chunk-A3RXLHYB.js"; import "./chunk-ZLPTRF2L.js"; import "./chunk-54BTDBAD.js"; import { abstract } from "./chunk-Q5ZULJHM.js"; import "./chunk-NGFXCWUF.js"; import "./chunk-K25ZO44T.js"; import "./chunk-SRXHWJOY.js"; import "./chunk-5RHQVMYD.js"; import "./chunk-DC5AMYBS.js"; // node_modules/ol/format/TextFeature.js var TextFeature = class extends Feature_default2 { constructor() { super(); } /** * @return {import("./Feature.js").Type} Format. * @override */ getType() { return "text"; } /** * Read the feature from the source. * * @param {Document|Element|Object|string} source Source. * @param {import("./Feature.js").ReadOptions} [options] Read options. * @return {import("../Feature.js").default} Feature. * @api * @override */ readFeature(source, options) { return this.readFeatureFromText( getText(source), this.adaptOptions(options) ); } /** * @abstract * @param {string} text Text. * @param {import("./Feature.js").ReadOptions} [options] Read options. * @protected * @return {import("../Feature.js").default} Feature. */ readFeatureFromText(text, options) { return abstract(); } /** * Read the features from the source. * * @param {Document|Element|Object|string} source Source. * @param {import("./Feature.js").ReadOptions} [options] Read options. * @return {Array} Features. * @api * @override */ readFeatures(source, options) { return this.readFeaturesFromText( getText(source), this.adaptOptions(options) ); } /** * @abstract * @param {string} text Text. * @param {import("./Feature.js").ReadOptions} [options] Read options. * @protected * @return {Array} Features. */ readFeaturesFromText(text, options) { return abstract(); } /** * Read the geometry from the source. * * @param {Document|Element|Object|string} source Source. * @param {import("./Feature.js").ReadOptions} [options] Read options. * @return {import("../geom/Geometry.js").default} Geometry. * @api * @override */ readGeometry(source, options) { return this.readGeometryFromText( getText(source), this.adaptOptions(options) ); } /** * @abstract * @param {string} text Text. * @param {import("./Feature.js").ReadOptions} [options] Read options. * @protected * @return {import("../geom/Geometry.js").default} Geometry. */ readGeometryFromText(text, options) { return abstract(); } /** * Read the projection from the source. * * @param {Document|Element|Object|string} source Source. * @return {import("../proj/Projection.js").default|undefined} Projection. * @api * @override */ readProjection(source) { return this.readProjectionFromText(getText(source)); } /** * @param {string} text Text. * @protected * @return {import("../proj/Projection.js").default|undefined} Projection. */ readProjectionFromText(text) { return this.dataProjection; } /** * Encode a feature as a string. * * @param {import("../Feature.js").default} feature Feature. * @param {import("./Feature.js").WriteOptions} [options] Write options. * @return {string} Encoded feature. * @api * @override */ writeFeature(feature, options) { return this.writeFeatureText(feature, this.adaptOptions(options)); } /** * @abstract * @param {import("../Feature.js").default} feature Features. * @param {import("./Feature.js").WriteOptions} [options] Write options. * @protected * @return {string} Text. */ writeFeatureText(feature, options) { return abstract(); } /** * Encode an array of features as string. * * @param {Array} features Features. * @param {import("./Feature.js").WriteOptions} [options] Write options. * @return {string} Encoded features. * @api * @override */ writeFeatures(features, options) { return this.writeFeaturesText(features, this.adaptOptions(options)); } /** * @abstract * @param {Array} features Features. * @param {import("./Feature.js").WriteOptions} [options] Write options. * @protected * @return {string} Text. */ writeFeaturesText(features, options) { return abstract(); } /** * Write a single geometry. * * @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("./Feature.js").WriteOptions} [options] Write options. * @return {string} Geometry. * @api * @override */ writeGeometry(geometry, options) { return this.writeGeometryText(geometry, this.adaptOptions(options)); } /** * @abstract * @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("./Feature.js").WriteOptions} [options] Write options. * @protected * @return {string} Text. */ writeGeometryText(geometry, options) { return abstract(); } }; function getText(source) { if (typeof source === "string") { return source; } return ""; } var TextFeature_default = TextFeature; // node_modules/ol/format/WKT.js var GeometryConstructor = { "POINT": Point_default, "LINESTRING": LineString_default, "POLYGON": Polygon_default, "MULTIPOINT": MultiPoint_default, "MULTILINESTRING": MultiLineString_default, "MULTIPOLYGON": MultiPolygon_default }; var EMPTY = "EMPTY"; var Z = "Z"; var M = "M"; var ZM = "ZM"; var TokenType = { START: 0, TEXT: 1, LEFT_PAREN: 2, RIGHT_PAREN: 3, NUMBER: 4, COMMA: 5, EOF: 6 }; var wktTypeLookup = { Point: "POINT", LineString: "LINESTRING", Polygon: "POLYGON", MultiPoint: "MULTIPOINT", MultiLineString: "MULTILINESTRING", MultiPolygon: "MULTIPOLYGON", GeometryCollection: "GEOMETRYCOLLECTION", Circle: "CIRCLE" }; var Lexer = class { /** * @param {string} wkt WKT string. */ constructor(wkt) { this.wkt = wkt; this.index_ = -1; } /** * @param {string} c Character. * @return {boolean} Whether the character is alphabetic. * @private */ isAlpha_(c) { return c >= "a" && c <= "z" || c >= "A" && c <= "Z"; } /** * @param {string} c Character. * @param {boolean} [decimal] Whether the string number * contains a dot, i.e. is a decimal number. * @return {boolean} Whether the character is numeric. * @private */ isNumeric_(c, decimal) { decimal = decimal !== void 0 ? decimal : false; return c >= "0" && c <= "9" || c == "." && !decimal; } /** * @param {string} c Character. * @return {boolean} Whether the character is whitespace. * @private */ isWhiteSpace_(c) { return c == " " || c == " " || c == "\r" || c == "\n"; } /** * @return {string} Next string character. * @private */ nextChar_() { return this.wkt.charAt(++this.index_); } /** * Fetch and return the next token. * @return {Token} Next string token. */ nextToken() { const c = this.nextChar_(); const position = this.index_; let value = c; let type; if (c == "(") { type = TokenType.LEFT_PAREN; } else if (c == ",") { type = TokenType.COMMA; } else if (c == ")") { type = TokenType.RIGHT_PAREN; } else if (this.isNumeric_(c) || c == "-") { type = TokenType.NUMBER; value = this.readNumber_(); } else if (this.isAlpha_(c)) { type = TokenType.TEXT; value = this.readText_(); } else if (this.isWhiteSpace_(c)) { return this.nextToken(); } else if (c === "") { type = TokenType.EOF; } else { throw new Error("Unexpected character: " + c); } return { position, value, type }; } /** * @return {number} Numeric token value. * @private */ readNumber_() { let c; const index = this.index_; let decimal = false; let scientificNotation = false; do { if (c == ".") { decimal = true; } else if (c == "e" || c == "E") { scientificNotation = true; } c = this.nextChar_(); } while (this.isNumeric_(c, decimal) || // if we haven't detected a scientific number before, 'e' or 'E' // hint that we should continue to read !scientificNotation && (c == "e" || c == "E") || // once we know that we have a scientific number, both '-' and '+' // are allowed scientificNotation && (c == "-" || c == "+")); return parseFloat(this.wkt.substring(index, this.index_--)); } /** * @return {string} String token value. * @private */ readText_() { let c; const index = this.index_; do { c = this.nextChar_(); } while (this.isAlpha_(c)); return this.wkt.substring(index, this.index_--).toUpperCase(); } }; var Parser = class { /** * @param {Lexer} lexer The lexer. */ constructor(lexer) { this.lexer_ = lexer; this.token_ = { position: 0, type: TokenType.START }; this.layout_ = "XY"; } /** * Fetch the next token form the lexer and replace the active token. * @private */ consume_() { this.token_ = this.lexer_.nextToken(); } /** * Tests if the given type matches the type of the current token. * @param {TokenType} type Token type. * @return {boolean} Whether the token matches the given type. */ isTokenType(type) { return this.token_.type == type; } /** * If the given type matches the current token, consume it. * @param {TokenType} type Token type. * @return {boolean} Whether the token matches the given type. */ match(type) { const isMatch = this.isTokenType(type); if (isMatch) { this.consume_(); } return isMatch; } /** * Try to parse the tokens provided by the lexer. * @return {import("../geom/Geometry.js").default} The geometry. */ parse() { this.consume_(); return this.parseGeometry_(); } /** * Try to parse the dimensional info. * @return {import("../geom/Geometry.js").GeometryLayout} The layout. * @private */ parseGeometryLayout_() { let layout = "XY"; const dimToken = this.token_; if (this.isTokenType(TokenType.TEXT)) { const dimInfo = dimToken.value; if (dimInfo === Z) { layout = "XYZ"; } else if (dimInfo === M) { layout = "XYM"; } else if (dimInfo === ZM) { layout = "XYZM"; } if (layout !== "XY") { this.consume_(); } } return layout; } /** * @return {Array} A collection of geometries. * @private */ parseGeometryCollectionText_() { if (this.match(TokenType.LEFT_PAREN)) { const geometries = []; do { geometries.push(this.parseGeometry_()); } while (this.match(TokenType.COMMA)); if (this.match(TokenType.RIGHT_PAREN)) { return geometries; } } throw new Error(this.formatErrorMessage_()); } /** * @return {Array} All values in a point. * @private */ parsePointText_() { if (this.match(TokenType.LEFT_PAREN)) { const coordinates = this.parsePoint_(); if (this.match(TokenType.RIGHT_PAREN)) { return coordinates; } } throw new Error(this.formatErrorMessage_()); } /** * @return {Array>} All points in a linestring. * @private */ parseLineStringText_() { if (this.match(TokenType.LEFT_PAREN)) { const coordinates = this.parsePointList_(); if (this.match(TokenType.RIGHT_PAREN)) { return coordinates; } } throw new Error(this.formatErrorMessage_()); } /** * @return {Array>>} All points in a polygon. * @private */ parsePolygonText_() { if (this.match(TokenType.LEFT_PAREN)) { const coordinates = this.parseLineStringTextList_(); if (this.match(TokenType.RIGHT_PAREN)) { return coordinates; } } throw new Error(this.formatErrorMessage_()); } /** * @return {Array>} All points in a multipoint. * @private */ parseMultiPointText_() { if (this.match(TokenType.LEFT_PAREN)) { let coordinates; if (this.token_.type == TokenType.LEFT_PAREN) { coordinates = this.parsePointTextList_(); } else { coordinates = this.parsePointList_(); } if (this.match(TokenType.RIGHT_PAREN)) { return coordinates; } } throw new Error(this.formatErrorMessage_()); } /** * @return {Array>>} All linestring points * in a multilinestring. * @private */ parseMultiLineStringText_() { if (this.match(TokenType.LEFT_PAREN)) { const coordinates = this.parseLineStringTextList_(); if (this.match(TokenType.RIGHT_PAREN)) { return coordinates; } } throw new Error(this.formatErrorMessage_()); } /** * @return {Array>>>} All polygon points in a multipolygon. * @private */ parseMultiPolygonText_() { if (this.match(TokenType.LEFT_PAREN)) { const coordinates = this.parsePolygonTextList_(); if (this.match(TokenType.RIGHT_PAREN)) { return coordinates; } } throw new Error(this.formatErrorMessage_()); } /** * @return {Array} A point. * @private */ parsePoint_() { const coordinates = []; const dimensions = this.layout_.length; for (let i = 0; i < dimensions; ++i) { const token = this.token_; if (this.match(TokenType.NUMBER)) { coordinates.push( /** @type {number} */ token.value ); } else { break; } } if (coordinates.length == dimensions) { return coordinates; } throw new Error(this.formatErrorMessage_()); } /** * @return {Array>} An array of points. * @private */ parsePointList_() { const coordinates = [this.parsePoint_()]; while (this.match(TokenType.COMMA)) { coordinates.push(this.parsePoint_()); } return coordinates; } /** * @return {Array>} An array of points. * @private */ parsePointTextList_() { const coordinates = [this.parsePointText_()]; while (this.match(TokenType.COMMA)) { coordinates.push(this.parsePointText_()); } return coordinates; } /** * @return {Array>>} An array of points. * @private */ parseLineStringTextList_() { const coordinates = [this.parseLineStringText_()]; while (this.match(TokenType.COMMA)) { coordinates.push(this.parseLineStringText_()); } return coordinates; } /** * @return {Array>>>} An array of points. * @private */ parsePolygonTextList_() { const coordinates = [this.parsePolygonText_()]; while (this.match(TokenType.COMMA)) { coordinates.push(this.parsePolygonText_()); } return coordinates; } /** * @return {boolean} Whether the token implies an empty geometry. * @private */ isEmptyGeometry_() { const isEmpty = this.isTokenType(TokenType.TEXT) && this.token_.value == EMPTY; if (isEmpty) { this.consume_(); } return isEmpty; } /** * Create an error message for an unexpected token error. * @return {string} Error message. * @private */ formatErrorMessage_() { return "Unexpected `" + this.token_.value + "` at position " + this.token_.position + " in `" + this.lexer_.wkt + "`"; } /** * @return {import("../geom/Geometry.js").default} The geometry. * @private */ parseGeometry_() { const token = this.token_; if (this.match(TokenType.TEXT)) { const geomType = ( /** @type {string} */ token.value ); this.layout_ = this.parseGeometryLayout_(); const isEmpty = this.isEmptyGeometry_(); if (geomType == "GEOMETRYCOLLECTION") { if (isEmpty) { return new GeometryCollection_default([]); } const geometries = this.parseGeometryCollectionText_(); return new GeometryCollection_default(geometries); } const ctor = GeometryConstructor[geomType]; if (!ctor) { throw new Error("Invalid geometry type: " + geomType); } let coordinates; if (isEmpty) { if (geomType == "POINT") { coordinates = [NaN, NaN]; } else { coordinates = []; } } else { switch (geomType) { case "POINT": { coordinates = this.parsePointText_(); break; } case "LINESTRING": { coordinates = this.parseLineStringText_(); break; } case "POLYGON": { coordinates = this.parsePolygonText_(); break; } case "MULTIPOINT": { coordinates = this.parseMultiPointText_(); break; } case "MULTILINESTRING": { coordinates = this.parseMultiLineStringText_(); break; } case "MULTIPOLYGON": { coordinates = this.parseMultiPolygonText_(); break; } default: break; } } return new ctor(coordinates, this.layout_); } throw new Error(this.formatErrorMessage_()); } }; var WKT = class extends TextFeature_default { /** * @param {Options} [options] Options. */ constructor(options) { super(); options = options ? options : {}; this.splitCollection_ = options.splitCollection !== void 0 ? options.splitCollection : false; } /** * Parse a WKT string. * @param {string} wkt WKT string. * @return {import("../geom/Geometry.js").default} * The geometry created. * @private */ parse_(wkt) { const lexer = new Lexer(wkt); const parser = new Parser(lexer); return parser.parse(); } /** * @protected * @param {string} text Text. * @param {import("./Feature.js").ReadOptions} [options] Read options. * @return {import("../Feature.js").default} Feature. * @override */ readFeatureFromText(text, options) { const geom = this.readGeometryFromText(text, options); const feature = new Feature_default(); feature.setGeometry(geom); return feature; } /** * @param {string} text Text. * @param {import("./Feature.js").ReadOptions} [options] Read options. * @protected * @return {Array} Features. * @override */ readFeaturesFromText(text, options) { let geometries = []; const geometry = this.readGeometryFromText(text, options); if (this.splitCollection_ && geometry.getType() == "GeometryCollection") { geometries = /** @type {GeometryCollection} */ geometry.getGeometriesArray(); } else { geometries = [geometry]; } const features = []; for (let i = 0, ii = geometries.length; i < ii; ++i) { const feature = new Feature_default(); feature.setGeometry(geometries[i]); features.push(feature); } return features; } /** * @param {string} text Text. * @param {import("./Feature.js").ReadOptions} [options] Read options. * @protected * @return {import("../geom/Geometry.js").default} Geometry. * @override */ readGeometryFromText(text, options) { const geometry = this.parse_(text); return transformGeometryWithOptions(geometry, false, options); } /** * @param {import("../Feature.js").default} feature Features. * @param {import("./Feature.js").WriteOptions} [options] Write options. * @protected * @return {string} Text. * @override */ writeFeatureText(feature, options) { const geometry = feature.getGeometry(); if (geometry) { return this.writeGeometryText(geometry, options); } return ""; } /** * @param {Array} features Features. * @param {import("./Feature.js").WriteOptions} [options] Write options. * @protected * @return {string} Text. * @override */ writeFeaturesText(features, options) { if (features.length == 1) { return this.writeFeatureText(features[0], options); } const geometries = []; for (let i = 0, ii = features.length; i < ii; ++i) { geometries.push(features[i].getGeometry()); } const collection = new GeometryCollection_default(geometries); return this.writeGeometryText(collection, options); } /** * @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("./Feature.js").WriteOptions} [options] Write options. * @protected * @return {string} Text. * @override */ writeGeometryText(geometry, options) { return encode(transformGeometryWithOptions(geometry, true, options)); } }; function encodePointGeometry(geom) { const coordinates = geom.getCoordinates(); if (coordinates.length === 0) { return ""; } return coordinates.join(" "); } function encodeMultiPointGeometry(geom) { const array = []; const components = geom.getPoints(); for (let i = 0, ii = components.length; i < ii; ++i) { array.push("(" + encodePointGeometry(components[i]) + ")"); } return array.join(","); } function encodeGeometryCollectionGeometry(geom) { const array = []; const geoms = geom.getGeometries(); for (let i = 0, ii = geoms.length; i < ii; ++i) { array.push(encode(geoms[i])); } return array.join(","); } function encodeLineStringGeometry(geom) { const coordinates = geom.getCoordinates(); const array = []; for (let i = 0, ii = coordinates.length; i < ii; ++i) { array.push(coordinates[i].join(" ")); } return array.join(","); } function encodeMultiLineStringGeometry(geom) { const array = []; const components = geom.getLineStrings(); for (let i = 0, ii = components.length; i < ii; ++i) { array.push("(" + encodeLineStringGeometry(components[i]) + ")"); } return array.join(","); } function encodePolygonGeometry(geom) { const array = []; const rings = geom.getLinearRings(); for (let i = 0, ii = rings.length; i < ii; ++i) { array.push("(" + encodeLineStringGeometry(rings[i]) + ")"); } return array.join(","); } function encodeMultiPolygonGeometry(geom) { const array = []; const components = geom.getPolygons(); for (let i = 0, ii = components.length; i < ii; ++i) { array.push("(" + encodePolygonGeometry(components[i]) + ")"); } return array.join(","); } function encodeGeometryLayout(geom) { const layout = geom.getLayout(); let dimInfo = ""; if (layout === "XYZ" || layout === "XYZM") { dimInfo += Z; } if (layout === "XYM" || layout === "XYZM") { dimInfo += M; } return dimInfo; } var GeometryEncoder = { "Point": encodePointGeometry, "LineString": encodeLineStringGeometry, "Polygon": encodePolygonGeometry, "MultiPoint": encodeMultiPointGeometry, "MultiLineString": encodeMultiLineStringGeometry, "MultiPolygon": encodeMultiPolygonGeometry, "GeometryCollection": encodeGeometryCollectionGeometry }; function encode(geom) { const type = geom.getType(); const geometryEncoder = GeometryEncoder[type]; const enc = geometryEncoder(geom); let wktType = wktTypeLookup[type]; if (typeof /** @type {?} */ geom.getFlatCoordinates === "function") { const dimInfo = encodeGeometryLayout( /** @type {import("../geom/SimpleGeometry.js").default} */ geom ); if (dimInfo.length > 0) { wktType += " " + dimInfo; } } if (enc.length === 0) { return wktType + " " + EMPTY; } return wktType + "(" + enc + ")"; } var WKT_default = WKT; export { WKT_default as default }; //# sourceMappingURL=ol_format_WKT.js.map