Shapefile Creator Website Using Cherrypy

8 Nov

I showed how to create a shapefile using python, now I want to make the tool public with a web based front-end. My python web framework of choice is Cherrypy. -a minimal web framework.

My website will allow you to enter Longitude, Latitude and a comment. I am working on a text area where you can paste data. Here ie my website:

And when you submit, you can download a ZIP of your shapefile.

Pretty simple. I don’t really know what the use case is – if you have GIS and Long/Lat you would just import it directly. And if you don’t have GIS, why do you need a shapefile? But I guess this shows how you can perform GIS data functions through the web using python. Maybe connect some toolboxes and use Arcpy to allow people to run your models with their data – without giving your model and logic away.

My code is not pretty and no built for production – it is built to work. Here it is.

import cherrypy
import shapefile
from cherrypy.lib.static import serve_file
import zipfile

class SHP(object):

def index(self):
<BODY><FORM NAME=’shp’ action=’paul’>Latitude: <input type=’text’ name=’lat’><BR>Longitude: <input type=’text’ name=’long’>
<BR>Comment: <input type=’text’ name=’comment’><BR><input type=’submit’ Value=’SUBMIT’>
</FORM></BODY></HTML>””” = True

def paul(self,lat,long,comment):
w = shapefile.Writer(shapefile.POINT)
w.point(Flong, Flat)
prj = open(“Web.prj”, “w”)
epsg = ‘GEOGCS[“WGS 84”,’
epsg += ‘DATUM[“WGS_1984”,’
epsg += ‘SPHEROID[“WGS 84”,6378137,298.257223563]]’
epsg += ‘,PRIMEM[“Greenwich”,0],’
epsg += ‘UNIT[“degree”,0.0174532925199433]]’
zipped = zipfile.ZipFile(‘’, mode=’w’)
return “Download Shapefile: <a href=’/get?filepath=C:\Documents and Settings\user\Desktop\’>YourShapefile</a>” = True

def get(self, filepath):
return serve_file(filepath, “application/x-download”, “attachment”) = True

cherrypy.config.update({‘server.socket_host’: ‘’,
‘server.socket_port’: 8000,



2 Responses to “Shapefile Creator Website Using Cherrypy”

  1. grow lights August 17, 2014 at 2:49 pm #

    Great info. Lucky me I recently found your blog by
    accident (stumbleupon). I have book-marked it for later!


  1. Calling Python From PHP: A GIS Example « Architecture and Planning - November 12, 2012

    […] showed in a past post how you could use Python and CherrPy to make web based GIS applications. While I think this is a great way to develop, I currently have […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: