Skip to content

Commit

Permalink
feat: add support for lyrx and openlayers
Browse files Browse the repository at this point in the history
lyrx can only be read
openlayers-style can only be written
  • Loading branch information
KaiVolland committed Sep 12, 2024
1 parent 0be9b5e commit ed434d0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 60 deletions.
60 changes: 11 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ between various formats for styling of geographic data.
## tl;dr

```
npx geostyler-cli --output new-qgis-style.qml my-existing.sld
bunx geostyler-cli --output new-qgis-style.qml my-existing.sld
```

## Requirements
Expand All @@ -15,7 +15,7 @@ npx geostyler-cli --output new-qgis-style.qml my-existing.sld

## Standalone application

Binaries are available for Linux, MacOS, and Windows on the
Binaries are available for Linux, MacOS, and Windows on the
[Releases](https://github.com/geostyler/geostyler-cli/releases) page.
Download the zip file for your operating system, unzip, navigate to the folder
and run the `geostyler` command:
Expand All @@ -26,50 +26,13 @@ geostyler-cli --output new-qgis-style.qml my-existing.sld

## Usage without installation ⚡

`Node.js` includes [npx](https://docs.npmjs.com/cli/v10/commands/npx), this
`Bun` includes [bunx](https://bun.sh/docs/cli/bunx), this
allows you to run commands from an npm package without having to install it.

```
npx geostyler-cli -s sld -t qgis -o output.qml input.sld
bunx geostyler-cli -s sld -t qgis -o output.qml input.sld
```

## Global installation

### Installation 💾

`Node.js` includes [npm](https://docs.npmjs.com/cli/v10/commands/npm) - the
JavaScript package manager. To install the `geostyler` command globally:

```
npm install -g geostyler-cli
```

You can then use the new `geostyler-cli` command, e.g.:

```
geostyler-cli -s sld -t qgis -o output.qml input.sld
```

To process a folder of files:

```
geostyler-cli -s sld -t qgis -o /outputdir /inputdir
```


### Update 🚀

```
npm update -g geostyler-cli
```

### Uninstalling 😔

```
npm uninstall -g geostyler-cli
```


## Syntax and examples

To convert a single file:
Expand Down Expand Up @@ -106,12 +69,12 @@ geostyler-cli -t sld testdata/point_simple.qml
* `-h` / `--help` Display the help and exit.
* `-o` / `--output` Output filename or directory. Required when the source is a directory.
For a file leave this empty to write to `stdout`. [string]
* `-s` / `--source` Source parser, either `mapbox`, `mapfile` or `map`,
* `-s` / `--source` Source parser, either `mapbox` (`maplibre`), `lyrx`, `mapfile` or `map`,
`sld` or `se` for SLD - the parser will read the version from the file,
and `qgis` or `qml` for QGIS QML files. If not given, it will be guessed from the extension of the input file.
and `qgis` (`qml`) for QGIS QML files. If not given, it will be guessed from the extension of the input file.
Mandatory if the the target is a directory.
* `-t` / `--target` Target parser, either `mapbox`, `sld` (for SLD 1.0), `se` (for SLD 1.1),
and `qgis` or `qml` for QGIS QML files. If not given, it will be guessed from
* `-t` / `--target` Target parser, either `mapbox` (`maplibre`), `ol`, `sld` (for SLD 1.0), `se` (for SLD 1.1),
and `qgis` (`qml`) for QGIS QML files. If not given, it will be guessed from
the extension of the output file. Mapfiles are not currently supported as target.
Mandatory if the the target is a directory.
* `-v` / `--version` Display the version of the program.
Expand All @@ -121,10 +84,10 @@ Mandatory if the the target is a directory.
In your clone of the repo, in the root directory:

```bash
npm install # get dependencies
npm run build # build from possibly changed source
bun install # get dependencies
bun run build # build from possibly changed source
# now you can call your build like this:
npm start -- -s sld -t qgis -o output.qml testdata/point_simplepoint.sld
bun run start -- -s sld -t qgis -o output.qml testdata/point_simplepoint.sld
```

## <a name="funding"></a>Funding & financial sponsorship
Expand All @@ -133,4 +96,3 @@ Maintenance and further development of this code can be funded through the
[GeoStyler Open Collective](https://opencollective.com/geostyler). All contributions and
expenses can transparently be reviewed by anyone; you see what we use the donated money for.
Thank you for any financial support you give the GeoStyler project 💞

33 changes: 22 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env node

import SLDParser from 'geostyler-sld-parser';
import QGISParser from 'geostyler-qgis-parser';
// import OpenLayersParser from "geostyler-openlayers-parser";
import OpenLayersParser from 'geostyler-openlayers-parser';
import MapfileParser from 'geostyler-mapfile-parser';
import MapboxParser from 'geostyler-mapbox-parser';
import ArcGISParser from 'geostyler-lyrx-parser';
import { StyleParser } from 'geostyler-style';

import {
existsSync,
lstatSync,
Expand All @@ -13,7 +14,6 @@ import {
readdirSync
} from 'fs';
import minimist from 'minimist';
import { StyleParser } from 'geostyler-style';
import ora, { Ora } from 'ora';
import {
logHelp,
Expand All @@ -33,10 +33,10 @@ const getParserFromFormat = (inputString: string): StyleParser | undefined => {
throw new Error('No input');
}
switch (inputString.toLowerCase()) {
// case 'openlayers':
// case 'ol':
// return new OpenLayersParser();
case 'lyrx':
return new ArcGISParser();
case 'mapbox':
case 'maplibre':
return new MapboxParser();
case 'mapfile':
case 'map':
Expand All @@ -62,9 +62,12 @@ const getParserFromFilename = (fileName: string): StyleParser | undefined => {
return undefined;
}
switch (fileEnding.toLowerCase()) {
// case 'ol':
// return new OpenLayersParser();
case 'ol':
return new OpenLayersParser();
case 'lyrx':
return new ArcGISParser();
case 'mapbox':
case 'maplibre':
return new MapboxParser();
case 'map':
return new MapfileParser();
Expand Down Expand Up @@ -158,13 +161,21 @@ function collectPaths(basePath: string, isFile: boolean): string[] {
}

async function writeFile(
sourceFile: string, sourceParser: StyleParser,
targetFile: string, targetParser: StyleParser | undefined,
sourceFile: string, sourceParser: Exclude<StyleParser, OpenLayersParser>,
targetFile: string, targetParser: Exclude<StyleParser, ArcGISParser | MapfileParser> | undefined,
oraIndicator: Ora
) {
const inputFileData = await promises.readFile(sourceFile, 'utf-8');
const indicator = oraIndicator; // for linter.

if (sourceParser instanceof OpenLayersParser) {
throw new Error('OpenLayers is not supported as source.');
}

if (targetParser instanceof ArcGISParser || targetParser instanceof MapfileParser) {
throw new Error('ArcGIS (lyrx) and MapFile are not supported as target.');
}

try {
indicator.text = `Reading from ${sourceFile}`;
const {
Expand Down

0 comments on commit ed434d0

Please sign in to comment.