[OpenLayers-Users] Getting/downloading shapefile from Openlayer/Web page and saving to local disk

Nicholas Efremov-Kendall n.e.kendall at gmail.com
Thu Jul 7 09:19:53 EDT 2011


Hi Mustafa,

To my knowledge (which is limited) OL doesn't do this natively, from my
limited reading on the subject  the easiest way to do this e probably going
to be to use a python script  on the server-side. You should look into the
python shp file library http://code.google.com/p/pyshp/. Doing this manually
would be kind of complicated, because as you probably know, the shp file
format is actually a collection of files (shp, shx, dbf, prj). I attach a
sample python script below, but it's up to you to tailor it to your needs.
My best guess is that the process would look like this:

*Client-Side:*

1) select geometry pass it to server-side script with projection/attribute
info

*Server-side: process CS data pass it to python script*

2) produce shp file

3) save it to storage location on the server

*Client-Side Again*

3) ??? (joke!)
4) prompt user to DL zipped shp file

5) Desktop-happiness (profit)


>From what I've read, the best/easiest way to do this is with a database
involved, both because python will talk to the database, and it will let you
organize your information for the end-user (i.e. pre-populate the attribute
data as necessary). If you're using geoserver, you probably already have
PostGIS and PostGRES on the backend which have some native shp file support,
but I don't know enough about that to be of any practical use to you.

I hope this helps, python script is below (from the HTML5 geolocation book)

# Include the Python Shapefile Library
import shapefile as sf
# Name of the shapefile to create
filename = 'shapefiles/geolocation'
# Create a /point/ shapefile, and turn on autoBalance
sf_w = sf.Writer(sf.POINT)
sf_w.autoBalance = 1
# Add the points
sf_w.point(-90.185278, 38.624722, 212)
sf_w.point(-89.788221, 38.4233, 18)
sf_w.point(-90.123129, 37.992331, 25)
# Create attribute information
sf_w.field('Name', 'C', 20)
sf_w.field('Description', 'C', 80)
sf_w.field('Timestamp', 'D')
sf_w.field('Accuracy', 'N', 4, 0)
sf_w.field('AltitudeAccuracy', 'N', 4, 0)
sf_w.field('Heading', 'N', 9, 6)
sf_w.field('Speed', 'N', 7, 4)
# Add attribute information
sf_w.record('Point 000000', 'This is the first point collected.', \
'2011-04-06T23:24:12+06:00', 20, 100, None, 0)
sf_w.record('Point 000001', 'This is the second point collected.', \
'2011-04-07T00:15:37+06:00', 10, 10, 37, 15.6464)
sf_w.record('Point 000002', 'This is the third point collected.', \
'2011-04-07T11:49:03+06:00', 60, 80, 147, 31.2928)
# Save the file
sf_w.save(filename)
# Create a projection file
prj = open("%s.prj" % filename, 'w')
epsg = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137, \
298.257223563]],PRIMEM["Greenwich",0],UNIT["degree", \
0.0174532925199433]]'
prj.write(epsg)

On Thu, Jul 7, 2011 at 3:37 AM, Mustafa646 <noorcs22 at gmail.com> wrote

> I have developed a web application where i am using GeoServer and
> Openlayers.
> I have displayed some Layers over Google map in a ASP.Net Web Page. I want
> to know is there any Method or Script available in Openlayer for
> downloading
> and saving shapefile (the shapefile which is displayed over Google map in
> Web page) from web interface.
>
> Actually the user wants to download the shapefile from Web interface and
> open it in his Dektop GIS (ArcView) system.
>
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/Getting-downloading-shapefile-from-Openlayer-Web-page-and-saving-to-local-disk-tp6557574p6557574.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110707/10f2ab4d/attachment-0001.html


More information about the Users mailing list