[GRASS-user] map calculator in python loop
st_kiefer at web.de
st_kiefer at web.de
Wed Dec 12 04:36:44 PST 2018
Hi Alessandro,
actually, I have no experience and no idea of the scripting modul of grass. But I believe you need something like this:
script.core.list_strings(type, pattern=None, mapset=None, exclude=None, flag='')[source]
List of elements as strings.
Returns the output from running g.list, as a list of qualified names.
Parameters:
type (str) – element type (raster, vector, raster_3d, region, ...)
pattern (str) – pattern string
mapset (str) – mapset name (if not given use search path)
exclude (str) – pattern string to exclude maps from the research
flag (str) – pattern type: ‘r’ (basic regexp), ‘e’ (extended regexp), or ‘’ (glob pattern)
Returns:
list of elements
You find more here:
https://grass.osgeo.org/grass72/manuals/libpython/script.html?highlight=list_strings#script.core.list_strings
regards
Stefan
> Alessandro Sebastiani <alessandro.sebastiani at uniroma1.it> hat am 12. Dezember 2018 um 12:59 geschrieben:
>
>
> dear all,
> i'm dealing this time with r.mapcalc. I have different rasters which i
> grouped using g.list.
> Now r_list contains all my raster. I want to multiply those rasters to
> another raster (called "costante") in order to obtain a new map, that i
> want to call as r followed by the letter "k"
> Here it is what i've done:
> import grass.script as gscript
> >>> r_list = gscript.read_command("g.list" , type = "rast"
> ).strip().split("\n")
> >>> c = " costante"
> >>> for r in r_list:
> >>> gscript.mapcalc ( " %s = %s * %s " % ((r+"k") , r , c))
>
> i get the following traceback message:
>
> Invalid map <1>
> parse error
> ERROR: parse error
> ERROR: An error occurred while running r.mapcalc
> I don't really know where i'm wrong!
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user
More information about the grass-user
mailing list