I am looking to develop a python script that triggers every time the user zooms or pans to a new map extent. The script I have in mind will clip a raster to the visible extent thus reclassifying the colour ramp and hopefully revealing more subtle anomalies in, for example, a raster of elevation data.

My question is how to go about 'triggering' the script when the view extent is altered by the user. My intention was to access a variable that describes the extent of the currently visible map display in GRASS 7.x. A while loop could be executed that would continuously check this variable for changes and trigger the rest of the script.

I thought the variable could be accessed by the;

d.info -g

command, however this appears to be returning the co-ordinates of the current grass region as opposed to the visible extent of the map.

Problem: I cannot access the visible extent of the map in the monitor display Reproduce: Try to create a python object that contains the visible extent of the map in the monitor display.

After launching grass with the wxGUI I have so far tried launching and selecting a new monitor using the following commands:

import grass.script as grass
grass.run_command("d.mon", start='wx0')
grass.run_command("d.mon", select='wx0')
grass.run_command("d.rast", map='elevation')

This open as new map display window and displays an elevation raster. Then I retrieve some information re the the new display using;

info = grass.read_command("d.info", flags='r')
>> screen rectangle: 0.000000 640.000000 0.000000 480.000000

Then I resize the display window manually and rerun;

info = grass.read_command("d.info", flags='r')

The output remains the same, despite me having manually resized the display window. The same problem occurs when I run d.info with any of its flags though (I'm not entirely sure what each flag does).

  • I can't even access the most basic variable I need: the extent of the currently visible map display. As far as I can see there is no add-in that has this functionality. – Beeman Jan 14 '17 at 18:41
  • Discussion in this thread seems to indicate that I can't access this variable in GRASS osgeo-org.1560.x6.nabble.com/… - perhaps better suited to QGIS? – Beeman Jan 15 '17 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.