[GRASS-dev] Native GRASS support in VTK + Python and Java

Soeren Gebbert soerengebbert at googlemail.com
Fri Aug 28 04:35:31 EDT 2009


Hi,
JFYI i have implemented a small demo library which connects parts of the
grass gis library
with the Visual-Tool-Kit VTK.
It is called vtkGRASSBridge.

Additionally the VTK Python and Java wrapping mechanism have been enabled.
So the user can use the
library from C++, Python and Java.

Features:
* The library can read and write raster maps row by row, as well as regions
and the raster history.
* It can list files of the grass database.
* It can convert grass raster maps into the vtkImageData format and the
other way round.
Missing Features:
* Full raster support (categories, colors, ..)
* Imagery support (groups, ...)
* Full vector support ....
* ....

You can use every vtkDataSet processing algorithm available in VTK (more
than 50 i think)
to process the converted raster map and write it back to the grass raster
database.

You can use the VTK render functionality to display the raster map.

There are examples and tests in the library showing this functionality in
Python.

The documentation of the library can be found here:
http://www-pool.math.tu-berlin.de/~soeren/grass/files/vtkGRASSBridge/doc/html/index.html

The GPL source code is located here:

http://www-pool.math.tu-berlin.de/~soeren/grass/files/vtkGRASSBridge/vtkGRASSBridge_0.1.tar.gz

Here is a small Python code example to read and write grass raster maps in
Python (within a grass session):

##############################################
#include the VTK and vtkGRASSBridge Python libraries
from libvtkCommonPython import *
from libvtkFilteringPython import *
from libvtkGraphicsPython import *
from libvtkRenderingPython import *
from libvtkIOPython import *
from libvtkImagingPython import *
from libvtkGRASSBridgeIOPython import *
from libvtkGRASSBridgeCommonPython import *

#Initiate grass
init = vtkGRASSInit()

#The region settings
region = vtkGRASSRegion()
region.ReadCurrentRegion()
region.SetCols(10)
region.SetRows(10)
region.AdjustRegion()

#Create a new map and write some data into it
writer = vtkGRASSRasterMapWriter()
writer.SetMapTypeToCELL()
writer.SetRegion(region)
writer.UseUserDefinedRegion()
writer.OpenMap("test_cell")

#this is the row buffer
data = vtkIntArray()
data.SetNumberOfTuples(writer.GetNumberOfCols())

#iterate over each raster cell
for i in range(writer.GetNumberOfRows()):
    for j in range(writer.GetNumberOfCols()):
        data.SetTuple1(j, i + j + 100)
    writer.PutNextRow(data)

#close the map
writer.CloseMap()

#now reopen the map for reading
reader = vtkGRASSRasterMapReader()
reader.OpenMap("test_cell")

#print the cells to stdout
print " "
for i in range(reader.GetNumberOfRows()):
    data = reader.GetRow(i)
    for j in range(reader.GetNumberOfCols()):
        print data.GetTuple1(j),
    print " "

#print the range of the raster map
val = [0,0]
reader.GetRange(val);
print "Range ", val

#print the history
print reader.GetHistory()
reader.CloseMap()

#############################################


Have fun
Soeren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-dev/attachments/20090828/6c62b4bd/attachment.html


More information about the grass-dev mailing list