I am creating a web application using OpenLayers. I have implemented functionality such that a user can add a point or polygon to the map that is displayed using JavaScript. I now need to save this data to a shapefile. Any ideas on how?
I am creating a web application using OpenLayers. I have implemented functionality such that a user can add a point or polygon to the map that is displayed using JavaScript. I now need to save this data to a shapefile. Any ideas on how?
Share Improve this question edited Nov 16, 2010 at 18:07 nix asked Nov 16, 2010 at 17:53 nixnix 4,8015 gold badges24 silver badges19 bronze badges3 Answers
Reset to default 2I know it's an old thread but I came here with the same question after doing a bit of googling myself to see if there was anything out there. I concluded that there wasn't but that there could be, so I wrote it:
https://code.google./p/js2shapefile/
It's the first time I've done anything along these lines in Javascript so I'm sure you'll find all kinds of oddities with my code...but, it works, for ESRI Javascript API graphics and Google Maps markers, at any rate. It could be easily extended to take OpenLayers vectors as input too, but I haven't got round to doing that.
You'll probably have to do it on the server, unless there's a javascript implementation of shapelib.
Actually, do you want the web user to get a shapefile to save or do you want to save it on the server?
There's lots of ways of doing it on a server, depending on your server language of choice. In python, you just import the ogr library and write it... You'll need to construct a web request from the client with the data in it though...
Maybe geoscript can help:
http://geoscriptblog.blogspot./2010/06/merging-shapefiles-with-javascript.html
There's a good overview on this issue here. For converting to shape using client side javascipt only, you could base you work on the JavaScript Shapefile to GeoJSON library.