Created
June 8, 2016 14:01
-
-
Save TheMapSmith/5a231d1e90e479c8c1e8ddb238b19523 to your computer and use it in GitHub Desktop.
GeoJSON to SVG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var geojson2svg = require('geojson2svg'); | |
var turf = require('turf'); | |
var fs = require('fs'); | |
var polys = require('./Admin_0_Polygons.json'); | |
polys.features.forEach(function(poly) { | |
var Name = poly.properties.Name; | |
var extent = turf.bbox(poly); | |
var options = { | |
// viewportSize: {width: 200, height: 100}, | |
mapExtent: { | |
left: extent[0],bottom: extent[1],right: extent[2],top: extent[3] | |
}, | |
output: 'svg', | |
attributes: { | |
'fill': "#73A041", | |
'id': Name, | |
} | |
}; | |
var converter = geojson2svg(options); | |
var path = converter.convert(poly); | |
var svg = '<svg xmlns="http://www.w3.org/2000/svg">' + path; | |
options.attributes.transform = "translate(5,5)"; // WIP: Trying to add a second path with an offset for styling purposes. NOT FINISHED | |
options.attributes.fill = "#000000" | |
var converter = geojson2svg(options); | |
var path = converter.convert(poly); | |
svg += path; | |
svg += '</svg>' | |
fs.writeFileSync('svg/' + poly.properties.Name + '.svg', svg); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment