Create SVG from Shapefile App
Output Readme Download Replit Sel. & Copy Full

About

This repl creates an html files with SVG shapes for a collection of U.S. states using Python.

To view this on TripleLog, click here.

Setup

The packages should automatically install if using Replit. You need pyShp (import shapefile), shapely, pyproj, and flask. Install (with dependencies) any that need installing. You can also use fiona or other geo packages, but installing GDAL on Replit seems to not always work.

Running the main.py file should start a flask server that will be on the localhost or your repl.co domain. Then visit {{baseurl}} (either something.repl.co or localhost:81) or {{baseurl}}/create to choose which states to add to your SVG. This page will then redirect you to your created html file.

Python

Use the jinja2 templating to generate the files from templates/template.html. The syntax is similar to nunjucks.

We need to read the shapefile and grab the coordinates for whichever states we want to display.

You can use a different shapefile or geoJSON object, but you will need to adjust some of the early code to make everything work.

HTML

A template file called template.html is used to eventually create the HTML file with the final SVG shapes. The flask server then serves these files automatically once they are generated to the svgs directory.