Skip to content

Instantly share code, notes, and snippets.

@TheMapSmith
Created June 8, 2016 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheMapSmith/5a231d1e90e479c8c1e8ddb238b19523 to your computer and use it in GitHub Desktop.
Save TheMapSmith/5a231d1e90e479c8c1e8ddb238b19523 to your computer and use it in GitHub Desktop.
GeoJSON to SVG
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