SVG 2 GeoJSON
Converts an SVG file with added geo-referencing tags into one or more GeoJSON files.
npm install svg2geojson
You must place two
GeoItems inside a Prognoz MetaInfo element as a direct child of the
<svg> element at the root of your document.
These map opposing X/Y corners in your SVG coordinate space to Longitude/Latitude coordinates on the world. Note that the SVG coordinate space has Y increasing down (toward the south), while Latitude increases upwards (towards the north).
Running the binary from the command line:
$ npm install -g svg2geojson $ svg2geojson file.svg # Writes file.geojson $ svg2geojson file.svg --layers # Writes file.geojson, file-layer1Name.geojson, … # See svg2geojson --help for more parameters
Running as a Node.js library:
const geoFromSVGFile geoFromSVGXML = ;// …reading from file on disk;// …processing SVG code as a stringconst svg = `<svg xmlns=""><!-- ... --></svg>`;;
See the output of
svg2geojson --help for the options you can pass to the functions, and their default values.
<path> elements with an arbitrary number of overlapping subpaths, with some of them being 'positive' space and some 'negative' space. In SVG these subpaths may be oriented clockwise or counter-clockwise, and added in any order.
GeoJSON only allows a
Polygon to have a single 'positive' subpath (and an arbitrary number of additional 'hole' subpaths). To make it easier for the code to detect which subpath is the 'positive' subpath you must currently:
- Have only one positive subpath per
- Ensure that the positive subpath is the first subpath in a
TODO (AKA Known Limitations)
- Support modes of projection unmapping
- Support non-rectangular, inverse bilinear unmappings
- Add more command-line options to control JSON formatting.
MultiLineStringas appropriate. Currently items within a group are flattened as individual
Featureitems in the GeoJSON.
<path>with multiple positive subpaths as a
MultiPolygon. (This requires figuring out which holes apply to which positive subpaths.)