Registry / serialization / geostyler-sld-parser

geostyler-sld-parser

JSON →
library8.4.2jsnpmunverified

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.

npm install geostyler-sld-parser
INSTALL
IMPORT
SIG · GEOSTYLER-SLD-PARS
G
geostyler-sld-parser
serializationjavascriptv8.4.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SLDParser
import SLDParser from 'geostyler-sld-parser';
const SLDParser = require('geostyler-sld-parser');
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()`.
Style
import { Style } from 'geostyler-style';
import { Style } 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.
SldStyleParser
import { SldStyleParser } from 'geostyler-sld-parser';
While the default export `SLDParser` is common, `SldStyleParser` can also be imported as a named export. Both refer to the same class.

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));
Debug
Known issues
breakingThe package requires Node.js version 20.6.0 or higher. Older Node.js versions will likely encounter compatibility issues or fail to run.
fix
Upgrade your Node.js environment to version 20.6.0 or newer. Use `nvm install 20 && nvm use 20` or similar version management tools.
affects: <8.x.x
gotchaWhen using `geostyler-sld-parser` in a CommonJS environment (e.g., older Node.js scripts), direct `require('geostyler-sld-parser')` will typically return an object containing the `default` export. Access the parser using `.default` (e.g., `new (require('geostyler-sld-parser')).default()`).
fix
For ES Modules, use `import SLDParser from 'geostyler-sld-parser';`. For CommonJS, use `const SLDParser = require('geostyler-sld-parser').default;` or dynamic imports `import('geostyler-sld-parser').then(mod => new mod.default())`.
affects: >=1.0.0
breakingVersion 8.0.1 explicitly fixed a build issue by enforcing `geostyler-style` version 10.2. This suggests that earlier versions of `geostyler-sld-parser` (specifically around 8.0.0) might have had compatibility problems with `geostyler-style` versions prior to 10.2.
fix
Ensure your project's `geostyler-style` dependency is at least version 10.2 when using `geostyler-sld-parser` v8.0.0 or later to avoid potential build or runtime issues.
affects: 8.0.0
gotchaSLD styling has many nuances, and not all SLD capabilities (especially complex vendor-specific extensions or very old SLD versions) might be fully supported by the parser. Review the generated or parsed style for accuracy if encountering unexpected results.
fix
Consult the GeoStyler and SLD specifications. Report specific parsing or writing discrepancies as issues on the `geostyler-sld-parser` GitHub repository with example SLD and desired GeoStyler style.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: SLDParser is not a constructor
Attempting to `new` a default export from a CommonJS `require()` call without accessing the `.default` property, or using an incompatible Node.js version.
fix
For CommonJS, use `const SLDParser = require('geostyler-sld-parser').default;`. For ESM, ensure `import SLDParser from 'geostyler-sld-parser';` and that your Node.js environment is configured for ESM or is version 20.6.0+.
Error: Cannot find module 'geostyler-style'
The `geostyler-style` peer dependency is missing or an incompatible version is installed.
fix
Install `geostyler-style` explicitly: `npm install geostyler-style` or `yarn add geostyler-style`. Verify that the installed version meets the `geostyler-sld-parser`'s compatibility requirements (e.g., `>=10.2.0`).
XML parsing error: 'Unclosed tag' or 'Invalid character'
The input SLD string is malformed XML, contains invalid characters, or is not a valid SLD document.
fix
Validate the SLD XML string before passing it to `readStyle()`. Ensure it's well-formed, correctly encoded (UTF-8 recommended), and adheres to the SLD specification. Use an XML validator tool.
Upgrade
Version history
8.4.2latest on npm
Audit
Dependencies
geostyler-stylerequiredCore dependency providing the abstract style object model that this parser converts to and from.
Agent activity
6 hits · last 30 days
node
6
Resources