[GRASS-user] question on r.out.gdal in a loop

Nikos Alexandris nik at nikosalexandris.net
Wed Jul 11 01:00:06 PDT 2018


* Nikos Alexandris <nik at nikosalexandris.net> [2018-07-11 09:14:47 +0200]:

>
>Gabriel Cotlier wrote:
>>
>>    I'm using grass 7.4.1 trying to export  all raster layers in the current
>>    mapset out of grass to a folder as GeoTiff files though a for loop from
>>    the python shell  as follows and I'm getting the error in red...
>>    What could be the problem?
>>    Thanks a lot in advance.
>>    Regards,
>>    Gabriel
>>    >>>import grass.script as gscript
>>    >>>rastlist=grass.read_command("g.list",type="rast")
>>    >>>rastlist
>>    F121996
>>    F121997
>>    F141999
>>    F142000
>
>Micha Silver:
>>  Try:
>>  rastlist=grass.read_command("g.list",type="rast").split()
>
>[..]

>For me it works like:
>
>rasters=grass.read_command('g.list', type='raster', separator='comma').split(',')

For splitting on newlines, there is splitlines(), i.e.

```
rasters = grass.read_command('g.list', type='raster').splitlines()
for raster in rasters:
    print "Raster:", raster
    raster += '.tif'
    print "Raster with extension:", raster
```

See https://docs.python.org/2/library/stdtypes.html#str.splitlines

Nikos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20180711/9bb068fa/attachment.sig>


More information about the grass-user mailing list