Better Shapefile to SVG
Output Readme Download Replit Sel. & Copy Full

About

This repl creates SVG element with Python from a provided shapefile and then adds some editing features with JavaScript.

The Python packages should install themselves if using Replit, but you will need to make sure everything gets installed if using another method.

Use fiona version 1.8.20 (not 1.8.21 or later) for replit (and maybe elsewhere if you get errors). python3 -m poetry add fiona==1.8.20

To view this on TripleLog, click here.

HTML

Modify the template.html and/or create.html files in the templates directory.

Python

Three shapefiles are provided, but you can download more from Natural Earth, the U.S. Census, or wherever else. Other formats like geoJSON also will easily work. If the shapefiles are very complex, then you may wish to simplify the curves. If the geoType is not a polygon or multipolygon you will need to figure out what to do.

The geo data is read and a viewBox and scaled version of the desired regions are created and fed into a template.

A Flask server is started to allow for a simple UI (at the /create url by default) to dictate details of the map which gets posted to the server where the SVG is generated.

JavaScript

The Python server will create an HTML file that includes lots of JavaScript functions to edit the map. You can read/edit this JS in the script tag at the bottom of the template.html file. You might wish to create a separate JS file.