Methods to Convert .SVG File to GeoJSON

I just wrote a library that converts an SVG image to a (slightly-incorrect) GeoJSON.

svg2geojson

It requires that you hand-edit your SVG to add two XML tags that associate an SVG location with a lat/long, and it provides a command-line tool to convert the file. It will even, if you like, take all the top-level groups (which is what Illustrator exports its layers as) and export them as separate files.

Usage

# First, install Node.js

$ npm install svg2geojson -g  # install globally for easy access to executable

$ svg2geojson -h
Usage: svg2geojson [options] file.svg

Options:
 -t, --tolerance=0.1 Distance (world meters) to sample curves to. (default: 0.1)
 -l, --layers        Split top-level groups into separate files. (default: one file)
 -o, --stdout        Output GeoJSON to stdout. (default: write files with names based on the SVG/layer)
 -m, --minimal       Make the GeoJSON as small as possible (not pretty).
 -p, --precision     Number of decimal places to format JSON numbers to. (default:6, as GeoJSON recommends)
 -d, --debug         Include ids for each SVG element in the features. (default: no properties)
 -v, --version       Output the version of svg2geojson as the first line on stdout (0.7.0).
 -h, --help          Show this help message.

$ svg2geojson my.svg
Wrote my.geojson

Limitations

  • Uses a naive/incorrect un-projection technique that assumes that a rectangular region of the image corresponds to a rectangular lat/long region. For example, on a rectangle about 1 mile wide by half a mile tall near San Francisco, the bottom edge is about 4 inches longer than the top edge. This was close enough for my needs.

  • Currently does not support SVG that uses paths with quadratic Bézier or elliptical arc commands. (I'm working on adding these.)


There is a command-line tool by Phrogz mentioned below that I have not checked out:

https://gis.stackexchange.com/a/245085/35596


To anyone that comes here, the answer is: "it is quite difficult (at least for an experienced programmer but inexperienced cartographer)." It requires a more-than-superficial understanding of how the Spacial Reference Systems (SRS) work. You more or less need to geocode your .SVG using something like QGIS. How that is done? Still no clue. But the answer is:

"You cannot simply convert SVG to GeoJSON, as SVG is missing the fundamental geo references."

If you would like to proceed, begin searching on how to georeference a DXF file.

How to compute parameters for QGIS Affine transformation?

Germán Carrillo's answer there is very useful.

Tags:

Svg

Geojson

D3