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

About

This repl creates an index.html file that includes 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 jinja2. 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.

Python

Use the jinja2 templating to generate the index.html file from 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 choose a different set of states by editing the array with state postal codes. You can also pick different colors for the states.

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 index.html file with the final SVG shapes. This file can then be used as a static file, but this repl does not serve the file automatically.