Javascript CLI and library to format RDF data using the GeoJSON-LD vocabulary into proper GeoJSON for visualization purposes. It uses JSON-LD compaction (based on a given @context) and framing (base on a given frame) to format the data into JSON-LD with the proper GeoJSON aliases.
Install it running the following command:
npm install rdf2geojson
Run rdf2geojson -h
to see the usage options:
Usage: rdf2geojson-ld [options]
Options:
-s, --source <source> Path to source RDF file
-q, --query <query> Path to file containing a SPARQL CONSTRUCT query
-e, --endpoint <endpoint> SPARQL engine HTTP endpoint
-o, --output <output> Path to output file that will contain the formatted GeoJSON-LD data
-h, --help display help for command
This tool allows to format either existing RDF files (both local and remote) and RDF data resulting from a given SPARQL CONSTRUCT query.
To format an existing RDF file using the GeoJSON-LD vocabulary, run the following command:
rdf2geojson -s (http://)path/to/file
To format the result of a SPARQL CONSTRUCT query, run the following command:
rdf2geojson -q path/to/query/file -e https://triplestore-address/sparql
By default, the transformed data will be written to the standard output, but a specific target path can be given with the -o
parameter.
Two functions are exported for formatting files and SPARQL CONSTRUCT results respectively:
import { fromRDFFile, fromQuery } from "rdf2geojson";
async function format() {
const geojson1 = await fromRDFFile("/path/to/file.nt");
const geojson2 = await fromQuery("/path/to/query.rq", "https://triplestore-address/sparql");
}
format();
Some real usage example can be seen in the tests.