Registry / data / geostyler-qgis-parser

geostyler-qgis-parser

JSON →
library4.1.0jsnpmunverified

The `geostyler-qgis-parser` package provides a GeoStyler Style Parser implementation specifically for QGIS (QML) styles. It enables the conversion of QGIS native styling information into the GeoStyler internal style format and vice-versa, facilitating interoperability between QGIS and other mapping libraries or services supported by GeoStyler. The current stable version is 4.1.0, released in November 2025. The project demonstrates an active release cadence with several patch and minor updates throughout 2025, indicating ongoing development and maintenance. Key differentiators include its tight integration with the GeoStyler ecosystem and its ability to handle specific QGIS style properties like `fontweight`, `fontItalic`, and `PointPat` support, as noted in recent updates. This parser is crucial for applications that need to manage or display geospatial data styled originally in QGIS.

npm install geostyler-qgis-parser
INSTALL
IMPORT
SIG · GEOSTYLER-QGIS-PAR
G
geostyler-qgis-parser
datajavascriptv4.1.0
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.

QGISStyleParser
import { QGISStyleParser } from 'geostyler-qgis-parser';
const QGISStyleParser = require('geostyler-qgis-parser');
The package switched to ESM (ECMAScript Modules) only since v3.0.0. CommonJS `require` statements are no longer supported.
Style
import type { Style } from 'geostyler-style';
Importing GeoStyler's `Style` type for type safety when working with the parsed or generated style objects.
QgsStyle
import type { QgsStyle } from 'geostyler-qgis-parser/dist/types/qgs-classes';
For advanced use cases or introspection, you might need internal types representing the raw QGIS style structure, though direct manipulation is generally not recommended for users. The exact path may vary slightly with minor versions.

Demonstrates how to instantiate the `QGISStyleParser`, read a QML string into a GeoStyler Style object, modify the style, and then write the GeoStyler Style back to a QML string.

import { QGISStyleParser } from 'geostyler-qgis-parser'; import type { Style } from 'geostyler-style'; // A minimal QML string representing a simple red fill style const qmlString = `<?xml version="1.0" encoding="UTF-8"?>\n<qgis version="3.28.0-Firenze" stylebehaviorenabled="true" addtagsenabled="false" autotranslated="false">\n <renderer-v2 type="singleSymbol" symbollevels="0" enableorderby="0" forcemapped="no" inforcemap="no" legendtype="default">\n <symbols>\n <symbol name="0" type="fill" clip_to_extent="1" force_rhr="0" alpha="1">\n <layer class="SimpleFill" enabled="1" pass="0" locked="0">\n <prop k="color" v="255,0,0,255"/>\n <prop k="style" v="solid"/>\n </layer>\n </symbol>\n </symbols>\n <rotation/>\n <sizescale/>\n </renderer-v2>\n</qgis>`; const parser = new QGISStyleParser(); async function convertStyle() { try { // Parse QML to GeoStyler Style const { output: geoStylerStyle, errors: readErrors } = await parser.readStyle(qmlString); if (readErrors.length > 0) { console.warn('Errors during QML parsing:', readErrors); } console.log('Parsed GeoStyler Style:', JSON.stringify(geoStylerStyle, null, 2)); // Example: Modify the style (e.g., change fill color to blue) if (geoStylerStyle && geoStylerStyle.rules && geoStylerStyle.rules.length > 0) { const rule = geoStylerStyle.rules[0]; if (rule.symbolizers && rule.symbolizers.length > 0 && rule.symbolizers[0].kind === 'Fill') { rule.symbolizers[0].color = '#0000FF'; // Change to blue } } // Write the modified GeoStyler Style back to QML const { output: newQmlString, errors: writeErrors } = await parser.writeStyle(geoStylerStyle as Style); if (writeErrors.length > 0) { console.warn('Errors during QML writing:', writeErrors); } console.log('Converted QML String (blue fill):', newQmlString); } catch (error) { console.error('An error occurred during style conversion:', error); } } convertStyle();
Debug
Known issues
breakingVersion 3.0.0 switched the package build to ESM (ECMAScript Modules) only. CommonJS `require()` statements will fail, leading to `TypeError: QGISStyleParser is not a constructor` or similar import errors in Node.js environments.
fix
Migrate your project to use ES modules (`import`/`export`) or use a bundler (like Webpack, Rollup, Parcel, Vite) that transpiles ESM to CommonJS if backward compatibility is strictly required. Ensure your `package.json` specifies `"type": "module"` for direct Node.js execution of ESM.
affects: >=3.0.0
breakingVersion 2.0.0 introduced a significant breaking change: the parser now strictly expects and outputs GeoStyler styles compliant with `geostyler-style` version 7. Older GeoStyler styles (pre-v7) or those from other parsers relying on older `geostyler-style` versions may not be compatible, leading to parsing errors or incorrect conversions.
fix
Ensure that all GeoStyler-related dependencies, especially `geostyler-style`, are updated to compatible versions. If using `geostyler-qgis-parser` v2.x, ensure `geostyler-style` is at least `^7.0.0`. For v3.x and above, refer to `geostyler-qgis-parser`'s `package.json` for the exact `geostyler-style` peer dependency.
affects: >=2.0.0 <3.0.0
breakingVersion 4.0.0 updated the `QGISStyleParser` to output QGIS 3.28 compliant QML styles. While this improves compatibility with newer QGIS versions, it may cause issues or unexpected behavior when interacting with older QGIS installations or systems expecting older QML formats.
fix
Test conversion results thoroughly with your target QGIS version. If interoperability with older QGIS versions (pre-3.28) is critical, you might need to use an older version of `geostyler-qgis-parser` or manually adjust the output QML for compatibility, though the latter is complex.
affects: >=4.0.0
gotchaSupport for `fontweight`, `fontItalic` style properties, and `PointPat` symbols was added in version 4.1.0. Older versions of the parser will not correctly interpret or write these specific QGIS style properties, potentially losing styling information during conversion.
fix
Upgrade to `geostyler-qgis-parser` version 4.1.0 or newer to ensure full support for these QGIS style features. If upgrading is not possible, be aware that these properties will be dropped or ignored during style parsing and writing.
affects: <4.1.0
Errors
Common errors & fixes
TypeError: QGISStyleParser is not a constructor
Attempting to use `require()` to import `QGISStyleParser` in a CommonJS environment after the package switched to ESM only in v3.0.0.
fix
Update your import statement to use ES module syntax: `import { QGISStyleParser } from 'geostyler-qgis-parser';`. If running in Node.js, ensure your environment supports ESM (e.g., by setting `"type": "module"` in `package.json` or using `.mjs` file extensions).
Error: Invalid GeoStyler style format detected. Expected GeoStyler Style version X, got version Y.
The `geostyler-qgis-parser` expects a specific version of the `geostyler-style` format. This error indicates a mismatch between the input GeoStyler style object's version and what the parser expects, often due to an outdated `geostyler-style` dependency or style object from another parser.
fix
Update `geostyler-style` to the version specified as a peer dependency by your `geostyler-qgis-parser` version. Also, ensure any GeoStyler style objects passed to the parser are generated by compatible GeoStyler components or parsers.
Upgrade
Version history
4.1.0latest on npm
Audit
Dependencies
geostyler-stylerequiredCore dependency defining the GeoStyler internal style format for conversion. All GeoStyler parsers rely on this common interface.
geostyler-cql-parserrequiredUsed for parsing and writing CQL (Common Query Language) filter expressions, which are often embedded within QGIS styles.
@xmldom/xmldomrequiredRuntime dependency for parsing QGIS XML (.qml) style files.
core-jsrequiredProvides polyfills for ECMAScript features, ensuring broader compatibility across different JavaScript environments.
Agent activity
2 hits · last 30 days
node
2
Resources
geostyler-qgis-parser — npm install geostyler-qgis-parser · libregistry