3

I have a map based web application using geodjango. I needed to display the crime hotspots within a selected polygon area. I found that v.kernel is very good for generating heatmaps/hotspots. So in my application I ran this command through python subprocess and created the raster map showing point density. I displayed this raster map over the polygon area in grass. But when I try to run the command through python using d.out.file command, error is raised.

command5 = "d.mon start=x1" 
command6 = "d.mon select=x1"
command7 = "d.mon unlock=x1"
command8 = "r.colors byr"
command9 = "d.rast crimes_"+str(pname)
command10 = "d.vect "+str(pname)+" type=line,boundary"
command11 = "d.out.file output="+str(pname)+" format=png size=800,600"
command12 = "d.mon stop=x1"

saveCommands = [command4,command5,command6,command7]

for sc in saveCommands:
    s = subprocess.Popen(sc,shell=True,env=environ) 
    s.wait()

Error is :

ERROR: Graph_Set: can't open Display
ERROR: Unable to get GIS_LOCK enviroment variable value
Problem selecting x1. Will try once more
ERROR: Unable to get GIS_LOCK enviroment variable value
d.mon select=x1
Exception AttributeError: AttributeError("'_DummyThread' object has no attribute '_Thread__block'",) in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored
ERROR: Unable to get GIS_LOCK enviroment variable value

All I need is to export the grass vector and raster layer to an image.

2
  • command4 is included in saveCommands but not shown in the example.
    – steko
    Commented Mar 8, 2013 at 11:05
  • Hi I have added environ['GIS_LOCK'] = '.gislock' before running subprocess but same error persists...
    – user12757
    Commented Mar 13, 2013 at 10:56

2 Answers 2

1

Are you sure that you can open a X11 display in a Python process like this. In your case, better use the PNG driver:

d.mon start=PNG
...

See also this manual page: http://grass.osgeo.org/grass64/manuals/pngdriver.html

0

The error is likely occurring in your command6.

To solve the specific error, you could set the GIS_LOCK environment variable and add it to the environ before it is passed to subprocess.Popen.

environ['GIS_LOCK'] = 'default' # any value should do
1
  • Hi I have added environ['GIS_LOCK'] = '.gislock' before running subprocess but same error persists...
    – user12757
    Commented Mar 13, 2013 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.