[GRASS-dev] GsoC2012: High level map interaction with python

Sören Gebbert soerengebbert at googlemail.com
Thu Apr 5 07:52:41 EDT 2012

Hi Pietro,

... [snip]
> Thank you! Although I'm new to C/C++, but I will give a closer look at
> the source code of vtk-grass-bridge!
> Do you think that this project could achieved during the Google Summer
> of Code or do you think that is not realistic, because there are a lot
> of things in the project idea that are missing?
> Would you be interested in being my mentor?

I would like to be your Mentor in this project. But actually i do not
know the GSoC procedure in detail, maybe an
experienced mentor may help me with this?

But i have to warn you, in my opinion the Python interface should use
the C-library function using the ctype-wrapper
to implement higher level functionality. That means you need to have a
deep understanding about the core libraries
and how to use the library functions, since the ctype interface simply
wraps the C-library functions. But don't worry,
i have some knowledge about this and can help you in deep detail.

I would suggest to focus first on the core and raster libraries and
all of its features. That means to create Python classes
for important concepts like modules, raster maps, rows, regions,
categories, color, segmentation and so on.
Covering this we can think about the Pythonization of these concepts.
Very simple example:

import grass.script as grass
import grass.obj as obj

region = obj.region(n=10, s=0, e=10, w=0, res=0.01)


map1 = obj.raster("precip")
map2 = obj.raster("evapo")
map3 = obj.raster("recharge")

# Simple math operation as suggested in the GSoC wiki page
# but using the ctypes interface internally

map3 = map1 - map2

# Implementing the math using the map interfaces
# which wraps ctypes functionality


for i in range(region.rows):
    # map[i] returns an object of type raster_row
    map3[i] =  map1[i] - map2[i]

# Copy categories and color table
map3.categories = map1.categories
map3.colors = map1.colors


# Opening a map in segment mode for random access
# would allow map[i][j] addressing

# Simple module chaining

slap = obj.module("r.slope.aspect")
rinfo = obj.module("r.info")

# All modules have inputs, flags and outputs
# generated from the xml module description
# Inputs and outputs are internally type checked
# Standard options are set by default

slap.in.elevation = "elevation" # string
slap.out.slope = "tmp"            # string
slap.flag.a = True                    # boolean
slap.flag.overwrite = True       # boolean

print(slap.exitstat) # integer
print(slap.stdout)   # string
print(slap.stderr)    # string

rinfo.in.input = slap.out.slope
rinfo.flag.g = True

kv = grass.parse_key_value(rinfo.stdout)


This is just a suggestion and can of course be modified.

With the focus on core and raster functionality i would say this is
doable in a GSoC project.

What do you think?

Best regards

> Best regards.
> Pietro

More information about the grass-dev mailing list