geostyler-sld-parser
Version:
GeoStyler Style Parser implementation for SLD
576 lines (575 loc) • 23.6 kB
TypeScript
import { Channel, ChannelSelection, ColorMap, ColorMapType, ComparisonFilter, ContrastEnhancement, Expression, FillSymbolizer, Filter, FunctionCall, IconSymbolizer, LineSymbolizer, MarkSymbolizer, PointSymbolizer, RasterSymbolizer, ReadStyleResult, Rule, ScaleDenominator, Style, StyleParser, Symbolizer, TextSymbolizer, UnsupportedProperties, WriteStyleResult, DistanceUnit, BasePointSymbolizer, BaseSymbolizer } from 'geostyler-style';
import { X2jOptions, XMLBuilder, XmlBuilderOptions, XMLParser } from 'fast-xml-parser';
import { Base64ImageObject } from './Util/SldUtil';
declare const SLD_VERSIONS: readonly ["1.0.0", "1.1.0"];
export type SldVersion = (typeof SLD_VERSIONS)[number];
/** GeoServer allows VendorOptions and mix some SLD versions */
export declare const sldEnvGeoServer = "GeoServer";
declare const SLD_ENVIRONMENTS: readonly ["GeoServer"];
/** Environment Configuration for the SLD parser/writer. */
export type SldEnvironment = (typeof SLD_ENVIRONMENTS)[number];
export type ParserOptions = Omit<X2jOptions, 'ignoreDeclaration' | 'removeNSPrefix' | 'ignoreAttributes' | 'preserveOrder' | 'trimValues'>;
export type BuilderOptions = Omit<XmlBuilderOptions, 'cdataPropName' | 'ignoreAttributes' | 'suppressEmptyNode' | 'preserveOrder'>;
export type ConstructorParams = {
numericFilterFields?: string[];
boolFilterFields?: string[];
sldVersion?: SldVersion;
sldEnvironment?: SldEnvironment;
symbolizerUnits?: string;
parserOptions?: ParserOptions;
builderOptions?: XmlBuilderOptions;
translations?: SldStyleParserTranslations;
locale?: string;
};
declare const COMPARISON_MAP: {
PropertyIsEqualTo: string;
PropertyIsNotEqualTo: string;
PropertyIsLike: string;
PropertyIsLessThan: string;
PropertyIsLessThanOrEqualTo: string;
PropertyIsGreaterThan: string;
PropertyIsGreaterThanOrEqualTo: string;
PropertyIsNull: string;
PropertyIsBetween: string;
};
type ComparisonType = keyof typeof COMPARISON_MAP;
export declare const ARITHMETIC_OPERATORS: readonly ["add", "sub", "mul", "div"];
export type ArithmeticType = typeof ARITHMETIC_OPERATORS[number];
export type SldStyleParserTranslationKeys = {
marksymbolizerParseFailedUnknownWellknownName?: (params: {
wellKnownName: string;
}) => string;
noFilterDetected?: string;
symbolizerKindParseFailed?: (params: {
sldSymbolizerName: string;
}) => string;
colorMapEntriesParseFailedColorUndefined?: string;
contrastEnhancParseFailedHistoAndNormalizeMutuallyExclusive?: string;
channelSelectionParseFailedRGBAndGrayscaleMutuallyExclusive?: string;
channelSelectionParseFailedRGBChannelsUndefined?: string;
};
export type SldStyleParserTranslations = Record<string, SldStyleParserTranslationKeys>;
export declare const defaultTranslations: SldStyleParserTranslations;
/**
* This parser can be used with the GeoStyler.
* It implements the geostyler-style StyleParser interface.
*
* @class SldStyleParser
* @implements StyleParser
*/
export declare class SldStyleParser implements StyleParser<string> {
/**
* The name of the SLD Style Parser.
*/
static title: string;
title: string;
unsupportedProperties: UnsupportedProperties;
translations: SldStyleParserTranslations;
locale: string;
constructor(opts?: ConstructorParams);
translate(key: keyof SldStyleParserTranslationKeys, params?: any): string;
private _parser;
get parser(): XMLParser;
set parser(parser: XMLParser);
private _builder;
get builder(): XMLBuilder;
set builder(builder: XMLBuilder);
/**
* Array of field / property names in a filter, which are casted to numerics
* while parsing a SLD.
*/
private _numericFilterFields;
/**
* Getter for _numericFilterFields
* @return The numericFilterFields
*/
get numericFilterFields(): string[];
/**
* Setter for _numericFilterFields
* @param numericFilterFields The numericFilterFields to set
*/
set numericFilterFields(numericFilterFields: string[]);
/**
* Array of field / property names in a filter, which are casted to boolean
* while parsing a SLD.
*/
private _boolFilterFields;
/**
* Getter for _boolFilterFields
* @return The boolFilterFields
*/
get boolFilterFields(): string[];
/**
* Setter for _boolFilterFields
* @param boolFilterFields The boolFilterFields to set
*/
set boolFilterFields(boolFilterFields: string[]);
/**
* String indicating the SLD version to use. 1.1.0 will make use of
* Symbology Encoding.
*/
private _sldVersion;
/**
* Getter for _sldVersion
* @return
*/
get sldVersion(): SldVersion;
/**
* Setter for _sldVersion
* @param sldVersion The _sldVersion value to set
*/
set sldVersion(sldVersion: SldVersion);
/**
* Indicate the sld environment to parse the SLD or write the SLD.
* This allows or restrict some SLD tags.
* @private
*/
private _sldEnvironment;
/**
* Getter for _sldEnvironment
* @return SldEnvironment or null.
*/
get sldEnvironment(): SldEnvironment | null;
/**
* Setter for _sldEnvironment
* @param a SldEnvironment or null.
*/
set sldEnvironment(env: SldEnvironment | null);
/**
* Check if the given SldEnvironment match the current environment.
* @param env the SldEnvironment to check.
* @private
*/
private isSldEnv;
/**
* String indicating the SLD version used in reading mode
*/
private _readingSldVersion;
/**
* Getter for _readingSldVersion
* @return
*/
get readingSldVersion(): SldVersion;
/**
* Setter for _readingSldVersion
* @param sldVersion The _readingSldVersion value to set
*/
set readingSldVersion(sldVersion: SldVersion);
/**
* Used to add a `uom` attribute to the symbolizer tag. Can be one of
* `metre`, `foot` or `pixel`. Defaults to pixel.
*/
private _symbolizerUnits;
/**
* Getter for _symbolizerUnits
* @return {string}
*/
get symbolizerUnits(): string;
/**
* Setter for _symbolizerUnits
* @param {string} symbolizerUnits The _symbolizerUnits value to set
*/
set symbolizerUnits(symbolizerUnits: string);
/**
* The readStyle implementation of the geostyler-style StyleParser interface.
* It reads a SLD as a string and returns a Promise.
* The Promise itself resolves with an object containing the geostyler-style.
*
* @param sldString A SLD as a string.
* @return The Promise resolving with an object containing the geostyler-style.
*/
readStyle(sldString: string): Promise<ReadStyleResult>;
/**
* Get the geostyler-style from a SLD Object (created with fast-xml-parser).
*
* @param sldObject The SLD object representation (created with fast-xml-parser)
* @return The geostyler-style
*/
sldObjectToGeoStylerStyle(sldObject: any): Style;
/**
* Get the geostyler-style rules from a SLD Object (created with fast-xml-parser).
*
* @param sldObject The SLD object representation (created with fast-xml-parser)
* @return The geostyler-style rules
*/
getRulesFromSldObject(sldObject: any): Rule[];
/**
* Get the name for the Style from the SLD Object. Returns the Title of the UserStyle
* if defined or the Name of the NamedLayer if defined or an empty string.
*
* @param sldObject The SLD object representation (created with fast-xml-parser)
* @return The name to be used for the GeoStyler Style Style
*/
getStyleNameFromSldObject(sldObject: any): string;
/**
* Get the geostyler-style Filter from a SLD Rule.
*
* Currently only supports one Filter per Rule.
*
* @param sldRule The SLD Rule
* @return The geostyler-style Filter
*/
getFilterFromRule(sldRule: any[]): Filter | undefined;
/**
* Get the geostyler-style ScaleDenominator from a SLD Rule.
*
* @param sldRule The SLD Rule
* @return The geostyler-style ScaleDenominator
*/
getScaleDenominatorFromRule(sldRule: any[]): ScaleDenominator | undefined;
/**
* Get the geostyler-style Symbolizers from a SLD Rule.
*
* @param sldRule The SLD Rule
* @return The geostyler-style Symbolizer array
*/
getSymbolizersFromRule(sldRule: any[]): Symbolizer[];
/**
* Creates a geostyler-style Filter from a given operator name and the js
* SLD object representation (created with fast-xml-parser) of the SLD Filter.
*
* @param sldOperatorName The Name of the SLD Filter Operator
* @param sldFilter The SLD Filter
* @return The geostyler-style Filter
*/
getFilterFromOperatorAndComparison(sldOperatorName: ComparisonType | 'Function', sldFilter: any): Filter;
getFilterFromComparisonOperator(sldOperatorName: ComparisonType | 'Function', sldFilter: any): Filter;
/**
* Creates a FunctionCall from arithmetic operators in SLD filters.
* Handles nested arithmetic operations recursively.
*/
getFilterArgsFromArithmeticOperators(arithmeticOperatorName: ArithmeticType, arithmeticOperator: any): FunctionCall<number>;
/**
* Processes a single operand in an arithmetic operation.
* If the operand is itself an arithmetic operator, processes it recursively.
*/
private processArithmeticOperand;
getFilterArgsFromPropertyName(child: any, children?: any, index?: number): FunctionCall<unknown>;
/**
* Get offset from Displacement.
* In SLD positive y values mean a displacement to the top.
* In geostyler-style positive y values mean a displacement to the bottom.
* Thus the y value is inverted.
*
* @param displacement The SLD Displacement object as written by fast-xml-parser
* @returns The offset as tuple or undefined if displacement is undefined
*/
getOffsetFromDisplacement(displacement: any): BasePointSymbolizer['offset'] | undefined;
/**
* Get the geostyler-style PointSymbolizer from a SLD Symbolizer.
*
* The opacity of the Symbolizer is taken from the <Graphic>.
*
* @param sldSymbolizer The SLD Symbolizer
* @return The geostyler-style PointSymbolizer
*/
getPointSymbolizerFromSldSymbolizer(sldSymbolizer: any, distanceUnit?: DistanceUnit | undefined): PointSymbolizer;
/**
* Get the geostyler-style LineSymbolizer from a SLD Symbolizer.
*
* Currently only the CssParameters are available.
*
* @param sldSymbolizer The SLD Symbolizer
* @return The geostyler-style LineSymbolizer
*/
getLineSymbolizerFromSldSymbolizer(sldSymbolizer: any): LineSymbolizer;
/**
* Get the geostyler-style TextSymbolizer from a SLD Symbolizer.
*
* @param sldSymbolizer The SLD Symbolizer
* @return The geostyler-style TextSymbolizer
*/
getTextSymbolizerFromSldSymbolizer(sldSymbolizer: any): TextSymbolizer;
/**
* Create a template string from a TextSymbolizer Label element.
* The ordering of the elemments inside the Label element is preserved.
*
* Examples:
* <Label>
* <Literal>foo</Literal>
* <PropertyName>bar</PropertyName>
* </Label>
* --> "foo{{bar}}"
*
* <Label>
* <PropertyName>bar</PropertyName>
* <Literal>foo</Literal>
* </Label>
* --> "{{bar}}foo"
*
* <Label>
* <PropertyName>bar</PropertyName>
* <Literal>foo</Literal>
* <PropertyName>john</PropertyName>
* </Label>
* --> "{{bar}}foo{{john}}"
*
* <Label>
* <PropertyName>bar</PropertyName>
* <PropertyName>john</PropertyName>
* <Literal>foo</Literal>
* </Label>
* --> "{{bar}}{{john}}foo"
*
* <Label>
* <PropertyName>bar</PropertyName>
* <PropertyName>john</PropertyName>
* <Literal>foo</Literal>
* <PropertyName>doe</PropertyName>
* </Label>
* --> "{{bar}}{{john}}foo{{doe}}"
*
* @param sldLabel
*/
getTextSymbolizerLabelFromSldSymbolizer: (sldLabel: any) => string | Expression<string>;
/**
* Get the geostyler-style FillSymbolizer from a SLD Symbolizer.
*
* PolygonSymbolizer Stroke is just partially supported.
*
* @param sldSymbolizer The SLD Symbolizer
* @return The geostyler-style FillSymbolizer
*/
getFillSymbolizerFromSldSymbolizer(sldSymbolizer: any): FillSymbolizer;
/**
* Get the geostyler-style RasterSymbolizer from a SLD Symbolizer.
*
* @param sldSymbolizer The SLD Symbolizer
*/
getRasterSymbolizerFromSldSymbolizer(sldSymbolizer: any): RasterSymbolizer;
/**
* Get the geostyler-style MarkSymbolizer from a SLD Symbolizer
*
* @param sldSymbolizer The SLD Symbolizer
* @return The geostyler-style MarkSymbolizer
*/
getMarkSymbolizerFromSldSymbolizer(sldSymbolizer: any): MarkSymbolizer;
/**
* Get the geostyler-style IconSymbolizer from a SLD Symbolizer
*
* @param sldSymbolizer The SLD Symbolizer
* @return The geostyler-style IconSymbolizer
*/
getIconSymbolizerFromSldSymbolizer(sldSymbolizer: any, forcedDistanceUnit?: DistanceUnit | undefined): IconSymbolizer;
/**
* Add a "Geometry" function or text from a Sld Symbolizer Geometry nested value.
*/
addGeometrySymbolizerFromSld(symbolizer: BaseSymbolizer, sldSymbolizer: any): void;
/**
* Get the geostyler-style ColorMap from a SLD ColorMap.
*
* @param sldColorMap The SLD ColorMap
*/
getColorMapFromSldColorMap(sldColorMap: any, type?: ColorMapType, extended?: string): ColorMap;
/**
* Get the geostyler-style ContrastEnhancement from a SLD ContrastEnhancement.
*
* @param sldContrastEnhancement The SLD ContrastEnhancement
*/
getContrastEnhancementFromSldContrastEnhancement(sldContrastEnhancement: any): ContrastEnhancement;
/**
* Get the geostyler-style Channel from a SLD Channel.
*
* @param sldChannel The SLD Channel
*/
getChannelFromSldChannel(sldChannel: any): Channel;
/**
* Get the geostyler-style ChannelSelection from a SLD ChannelSelection.
*
* @param sldChannelSelection The SLD ChannelSelection
*/
getChannelSelectionFromSldChannelSelection(sldChannelSelection: any): ChannelSelection;
/**
* The writeStyle implementation of the geostyler-style StyleParser interface.
* It reads a geostyler-style and returns a Promise.
* The Promise itself resolves with a SLD string.
*
* @param geoStylerStyle A geostyler-style.
* @return The Promise resolving with the SLD as a string.
*/
writeStyle(geoStylerStyle: Style): Promise<WriteStyleResult<string>>;
/**
* Get the correct tagName in dependency to the configured sldVersion.
*
* @param tagName
* @returns The tagName as used by the configured sldVersion
*/
getTagName(tagName: string): string;
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style
*
* @param geoStylerStyle A geostyler-style.
* @return The object representation of a SLD Style (readable with fast-xml-parser)
*/
geoStylerStyleToSldObject(geoStylerStyle: Style): any;
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style Rule.
*
* @param rules An array of geostyler-style Rules.
* @return The object representation of a SLD Rule (readable with fast-xml-parser)
*/
getSldRulesFromRules(rules: Rule[]): any[];
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style ComparisonFilter.
*
* @param comparisonFilter A geostyler-style ComparisonFilter.
* @return The object representation of a SLD Filter Expression with a
* comparison operator (readable with fast-xml-parser)
*/
getSldComparisonFilterFromComparisonFilter(comparisonFilter: ComparisonFilter): any[];
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style Filter.
*
* @param filter A geostyler-style Filter.
* @return The object representation of a SLD Filter Expression (readable with fast-xml-parser)
*/
getSldFilterFromFilter(filter: Filter): any[];
/**
* Checks on presence of the pseudo-property 'uom' inserted by function 'addUomEntry', removes it and inserts
* an uom-attribute. Do it only for SLD 1.1.0, ignore it otherwise.
*/
moveUomEntryToAttributes(sldSymbolizer: any, sldSymbolizerProperties: any[]): void;
/**
* Checks Distance-Unit used by given symbolizer and inserts a pseudo-property 'uom' if required, because
* we only have a property-array returned by the getSldXXXSymbolizerFromXXXSymbolizer-functions.
* Later, we will move to an attribute within function 'moveUomEntryToAttributes'
*/
addUomEntry(sldSymbolizerProperties: any[], unit: DistanceUnit | undefined): void;
/**
* Checks for an 'uom'-attribute and returns the distance-unit to be used for interpreting the
* units of the symbolizer.
*/
getDistanceUnit(sldSymbolizer: any): DistanceUnit | undefined;
/**
* Get the SLD Object (readable with fast-xml-parser) from geostyler-style Symbolizers.
*
* @param symbolizers A geostyler-style Symbolizer array.
* @return The object representation of a SLD Symbolizer (readable with fast-xml-parser)
*/
getSldSymbolizersFromSymbolizers(symbolizers: Symbolizer[]): any;
/**
* Get the SLD Displacement Object (readable with fast-xml-parser) from a geostyler-style offset.
* In SLD positive y values mean a displacement to the top.
* In geostyler-style positive y values mean a displacement to the bottom.
* Thus the y value is inverted.
*
* @param offset A geostyler-style offset as a tuple of two numbers or two functions.
* @returns The object representation of a SLD Displacement (readable with fast-xml-parser)
*/
getDisplacementFromOffset(offset: [Expression<number>, Expression<number>]): any;
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style MarkSymbolizer.
*
* @param markSymbolizer A geostyler-style MarkSymbolizer.
* @return The object representation of a SLD PointSymbolizer with a Mark
*/
getSldPointSymbolizerFromMarkSymbolizer(markSymbolizer: MarkSymbolizer): any;
/**
* Push a new GeoServerVendorOption in the given array if such options are allowed.
*/
pushGeoServerVendorOption(elementArray: any[], name: string, text: string): void;
/**
* @returns <VendorOption name="name">text</VendorOption>
*/
createGeoServerVendorOption(name: string, text: string): {
[x: string]: {
'#text': string;
}[] | {
'@_name': string;
};
':@': {
'@_name': string;
};
};
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style IconSymbolizer.
*
* @param iconSymbolizer A geostyler-style IconSymbolizer.
* @return The object representation of a SLD PointSymbolizer with
* an "ExternalGraphic" (readable with fast-xml-parser)
*/
getSldPointSymbolizerFromIconSymbolizer(iconSymbolizer: IconSymbolizer): any;
/**
* From a Base64ImageObject, create a SLD ExternalGraphic.
* @return a base64 InlineContent in an ExternalGraphic (readable with fast-xml-parser).
*/
getSldExternalResourceInlineContent(image: Base64ImageObject): any;
/**
* From a URL, create a SLD ExternalGraphic.
* @return an OnlineResource in an ExternalGraphic (readable with fast-xml-parser).
*/
getSldExternalResourceOnlineResource(image: string): any;
/**
* Translates an anchor-setting into SLD-anchor-numbers
*/
getSldAnchorPointFromAnchor(anchor: TextSymbolizer['anchor'], dimension: 'x' | 'y'): number;
/**
* Translates a SLD-anchor-number into a geostyler anchor-setting
*/
getAnchorFromSldAnchorPoint(anchorX: any, anchorY: any): TextSymbolizer['anchor'] | undefined;
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style TextSymbolizer.
*
* @param textSymbolizer A geostyler-style TextSymbolizer.
* @return The object representation of a SLD TextSymbolizer (readable with fast-xml-parser)
*/
getSldTextSymbolizerFromTextSymbolizer(textSymbolizer: TextSymbolizer): any;
/**
* Get the Label from a TextSymbolizer
*
* @param template The Expression<string> representing the label
*/
getSldLabelFromTextSymbolizer: (template: Expression<string>) => any;
/**
* Recursively converts a GeoStylerFunction (including nested) to SLD function structure.
*/
private geoStylerFunctionToSldFunctionRecursive;
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style LineSymbolizer.
*
* @param lineSymbolizer A geostyler-style LineSymbolizer.
* @return The object representation of a SLD LineSymbolizer (readable with fast-xml-parser)
*/
getSldLineSymbolizerFromLineSymbolizer(lineSymbolizer: LineSymbolizer): any[];
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style FillSymbolizer.
*
* @param fillSymbolizer A geostyler-style FillSymbolizer.
* @return The object representation of a SLD PolygonSymbolizer (readable with fast-xml-parser)
*/
getSldPolygonSymbolizerFromFillSymbolizer(fillSymbolizer: FillSymbolizer): any;
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style RasterSymbolizer.
*
* @param rasterSymbolizer A geostyler-style RasterSymbolizer.
* @return The object representation of a SLD RasterSymbolizer (readable with fast-xml-parser)
*/
getSldRasterSymbolizerFromRasterSymbolizer(rasterSymbolizer: RasterSymbolizer): any;
/**
* Add a sld "Geometry" function or text into a Sld Symbolizer.
*/
addSldGeometrySymbolizer(sldSymbolizerProperties: any[], symbolizer: BaseSymbolizer): void;
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style ColorMap.
*
* @param colorMap A geostyler-style ColorMap.
* @return The object representation of a SLD ColorMap (readable with fast-xml-parser)
*/
getSldColorMapFromColorMap(colorMap: ColorMap): any;
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style ChannelSelection.
*
* @param channelSelection A geostyler-style ChannelSelection.
* @return The object representation of a SLD ChannelSelection (readable with fast-xml-parser)
*/
getSldChannelSelectionFromChannelSelection(channelSelection: ChannelSelection): any;
/**
* Get the SLD Object (readable with fast-xml-parser) from a geostyler-style ContrastEnhancement.
*
* @param contrastEnhancement A geostyler-style ContrastEnhancement.
* @return The object representation of a SLD ContrastEnhancement (readable with fast-xml-parser)
*/
getSldContrastEnhancementFromContrastEnhancement(contrastEnhancement: ContrastEnhancement): any;
checkForUnsupportedProperties(geoStylerStyle: Style): UnsupportedProperties | undefined;
}
export default SldStyleParser;