The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Ushant Suman (23) [Avatar] Offline
#1
Hi all,

I have a point shape file containing some wells lat long and a polygon shapefile I want to know the wells lying in the polygon for this I have used SetSpatialFilter and written the script:

import os
import sys
from osgeo import ogr

from ospybook.vectorplotter import VectorPlotter
ds=ogr.Open(r'C:\Python27\Lib\site-packages\well_all'+'.shp',0)
well_lyr=ds.GetLayer(0)

ds1=ogr.Open(r'C:\Python27\Lib\site-packages\tpoly.shp',0)
ml_lyr=ds1.GetLayer(0)
feat = ml_lyr.GetNextFeature()
pl_cl = feat.geometry().Clone()
well_lyr.SetSpatialFilter(ml_cl)
vp = VectorPlotter(False)
vp.plot(well_lyr,'bo')
vp.plot(ml_cl,'blue', hatch='x')

vp.draw()


# close the data source and text file
ds.Destroy()
ds1.Destroy()
It draws the plot Now the users are demanding that they should be able to download the plot in their in local desktop Is there is any external python library to publish vectorplotter in web based envoirnment so that when the users browse both the shape files from the client side and save the plot for the future reference.
Regards,
Ushant Suman
chris.garrard (26) [Avatar] Offline
#2
Instead of using draw(), you can import pyplot and save the figure. Something like this:

import matplotlib.pyplot as plt

vp = VectorPlotter(False)

# Plot your data

# Figure out some filename and save it
plt.savefig('d:/temp/testplot.png')


Assuming you save it somewhere that's accessible through your web server, the user can then download the file.