The `geostyler-sld-parser` package provides an implementation of a GeoStyler style parser for Styled Layer Descriptor (SLD) XML. It facilitates the conversion between the GeoStyler's internal, technology-agnostic style object model and OGC SLD XML documents. The current stable version is 8.4.2, with releases occurring frequently, often on a monthly or bi-monthly basis, indicating active development and maintenance. Its key differentiator is its role within the broader GeoStyler ecosystem, enabling seamless interoperability and transformation of styling information across various geospatial platforms and formats, using a unified API. This parser handles both reading SLD XML into a GeoStyler style object and writing a GeoStyler style object out to SLD XML, including complex features like filters, symbolizers, and vendor options.
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
The library primarily uses ES Module syntax. Direct CommonJS `require` for the default export will lead to issues. For Node.js, ensure your environment supports ESM or use dynamic `import()`.
import SLDParser from 'geostyler-sld-parser';
The `Style` type definition, fundamental for interacting with GeoStyler parsers, comes from the `geostyler-style` package, not `geostyler-sld-parser` directly.
import { Style } from 'geostyler-style';
While the default export `SLDParser` is common, `SldStyleParser` can also be imported as a named export. Both refer to the same class.
import { SldStyleParser } from 'geostyler-sld-parser';
This quickstart demonstrates how to instantiate the SLDParser, convert a GeoStyler style object into an SLD XML string using `writeStyle`, and parse an existing SLD XML string back into a GeoStyler style object using `readStyle`.
import SLDParser from 'geostyler-sld-parser';
import { Style } from 'geostyler-style';
const pointSimplePoint = {
name: 'My Style',
rules: [
{
name: 'My Rule',
symbolizers: [
{
kind: 'Mark',
wellKnownName: 'circle',
color: '#FF0000',
radius: 6
}
]
}
]
};
const parser = new SLDParser();
console.log('--- Writing Style ---');
parser
.writeStyle(pointSimplePoint)
.then(({output: sld}) => {
console.log('Generated SLD:');
console.log(sld);
})
.catch(error => console.error('Error writing style:', error));
// Read style from string
let sldString = '<?xml version="1.0" encoding="UTF-8"?><sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0"> <sld:NamedLayer> <sld:Name>Default Styler</sld:Name> <sld:UserStyle> <sld:Name>Default Styler</sld:Name> <sld:Title>Gravel_Program_2016</sld:Title> <sld:FeatureTypeStyle> <sld:Name>name</sld:Name> <sld:Rule> <sld:MinScaleDenominator>1.0</sld:MinScaleDenominator> <sld:MaxScaleDenominator>1.0E7</sld:MaxScaleDenominator> <sld:LineSymbolizer> <sld:Stroke> <sld:CssParameter name="stroke">#8000FF</sld:CssParameter> <sld:CssParameter name="stroke-width">3.000</sld:CssParameter> </sld:Stroke> </sld:LineSymbolizer> </sld:Rule> </sld:FeatureTypeStyle> </sld:UserStyle> </sld:NamedLayer> </sld:StyledLayerDescriptor>';
console.log('\n--- Reading Style ---');
parser
.readStyle(sldString)
.then(({output: sldObject}) => {
console.log('Parsed GeoStyler Style Object:');
console.log(JSON.stringify(sldObject, null, 2));
})
.catch(error => console.error('Error reading style:', error));
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.