[GRASS-user] How to get a list of maps from a group in python script

Dear list members,
I know this is more a python question than a GRASS question, bot for sure some of you knows the ansewer and is able to help me…

I need to get a python list with the maps from a group, like [“map1”,“map2”,“map”]

But by using gscript.read_command… i get string, not a list.

gscript.read_command(“i.group”, group=groupname, flags=“l” )
‘group <LE72270902002150EDC00_toar> references the following raster maps\n-------------\nLE72270902002150EDC00_toar.1@landsat \nLE72270902002150EDC00_toar.2@landsat \nLE72270902002150EDC00_toar.3@landsat \nLE72270902002150EDC00_toar.4@landsat \nLE72270902002150EDC00_toar.5@landsat \nLE72270902002150EDC00_toar.7@landsat \n-------------\n’

Your help is appreciated!
Leo

···

Dr. Leonardo A. Hardtke
Laboratorio de Teledetección y S.I.G.
Centro Nacional Patagónico (CONICET)
Bvd. Brown 2825, 9120
Puerto Madryn, Chubut, Argentina

Hello,

Try the .splitlines() method on the string.

Cheers,
Laurent

El abr. 5, 2016 19:52, “Leonardo Hardtke” <leohardtke@gmail.com> escribió:

Dear list members,
I know this is more a python question than a GRASS question, bot for sure some of you knows the ansewer and is able to help me…

I need to get a python list with the maps from a group, like [“map1”,“map2”,“map”]

But by using gscript.read_command… i get string, not a list.

gscript.read_command(“i.group”, group=groupname, flags=“l” )
‘group <LE72270902002150EDC00_toar> references the following raster maps\n-------------\nLE72270902002150EDC00_toar.1@landsat \nLE72270902002150EDC00_toar.2@landsat \nLE72270902002150EDC00_toar.3@landsat \nLE72270902002150EDC00_toar.4@landsat \nLE72270902002150EDC00_toar.5@landsat \nLE72270902002150EDC00_toar.7@landsat \n-------------\n’

Your help is appreciated!
Leo

Dr. Leonardo A. Hardtke
Laboratorio de Teledetección y S.I.G.
Centro Nacional Patagónico (CONICET)
Bvd. Brown 2825, 9120
Puerto Madryn, Chubut, Argentina


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Thanks Laurent for your help,
it worked to split the string to a list…but now I have to remove the 1 line(group <LE72270902002150EDC00_toar> references the following raster maps), line 2 (‘-------------’), the last line (‘-------------’) and the “<>” around the names…
I know how to do that… but is this the best way to deal with outputs of i.group -l in python?

···

2016-04-06 11:02 GMT+10:00 Laurent C. <lrntct@gmail.com>:

Hello,

Try the .splitlines() method on the string.

Cheers,
Laurent

El abr. 5, 2016 19:52, “Leonardo Hardtke” <leohardtke@gmail.com> escribió:

Dear list members,
I know this is more a python question than a GRASS question, bot for sure some of you knows the ansewer and is able to help me…

I need to get a python list with the maps from a group, like [“map1”,“map2”,“map”]

But by using gscript.read_command… i get string, not a list.

gscript.read_command(“i.group”, group=groupname, flags=“l” )
‘group <LE72270902002150EDC00_toar> references the following raster maps\n-------------\nLE72270902002150EDC00_toar.1@landsat \nLE72270902002150EDC00_toar.2@landsat \nLE72270902002150EDC00_toar.3@landsat \nLE72270902002150EDC00_toar.4@landsat \nLE72270902002150EDC00_toar.5@landsat \nLE72270902002150EDC00_toar.7@landsat \n-------------\n’

Your help is appreciated!
Leo

Dr. Leonardo A. Hardtke
Laboratorio de Teledetección y S.I.G.
Centro Nacional Patagónico (CONICET)
Bvd. Brown 2825, 9120
Puerto Madryn, Chubut, Argentina


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Dr. Leonardo A. Hardtke
Laboratorio de Teledetección y S.I.G.
Centro Nacional Patagónico (CONICET)
Bvd. Brown 2825, 9120
Puerto Madryn, Chubut, Argentina

On Tue, Apr 5, 2016 at 9:15 PM, Leonardo Hardtke <leohardtke@gmail.com> wrote:

Thanks Laurent for your help,
it worked to split the string to a list....but now I have to remove the 1
line(group <LE72270902002150EDC00_toar> references the following raster
maps), line 2 ('-------------'), the last line ('-------------') and the
"<>" around the names...
I know how to do that.... but is this the best way to deal with outputs of
i.group -l in python?

You should use i.group -g (Print in shell script style)

Anna

2016-04-06 11:02 GMT+10:00 Laurent C. <lrntct@gmail.com>:

Hello,

Try the .splitlines() method on the string.

Cheers,
Laurent

El abr. 5, 2016 19:52, "Leonardo Hardtke" <leohardtke@gmail.com> escribió:

Dear list members,
I know this is more a python question than a GRASS question, bot for sure
some of you knows the ansewer and is able to help me....

I need to get a python list with the maps from a group, like
["map1","map2","map"]

But by using gscript.read_command.... i get string, not a list.

gscript.read_command("i.group", group=groupname, flags="l" )
'group <LE72270902002150EDC00_toar> references the following raster
maps\n-------------\n<LE72270902002150EDC00_toar.1@landsat>
\n<LE72270902002150EDC00_toar.2@landsat>
\n<LE72270902002150EDC00_toar.3@landsat>
\n<LE72270902002150EDC00_toar.4@landsat>
\n<LE72270902002150EDC00_toar.5@landsat>
\n<LE72270902002150EDC00_toar.7@landsat> \n-------------\n'

Your help is appreciated!
Leo
--
Dr. Leonardo A. Hardtke
Laboratorio de Teledetección y S.I.G.
Centro Nacional Patagónico (CONICET)
Bvd. Brown 2825, 9120
Puerto Madryn, Chubut, Argentina

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
Dr. Leonardo A. Hardtke
Laboratorio de Teledetección y S.I.G.
Centro Nacional Patagónico (CONICET)
Bvd. Brown 2825, 9120
Puerto Madryn, Chubut, Argentina

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Oh!
Thanks “g” flag combined with .split() worked!!!

Leo

···

2016-04-06 11:59 GMT+10:00 Anna Petrášová <kratochanna@gmail.com>:

On Tue, Apr 5, 2016 at 9:15 PM, Leonardo Hardtke <leohardtke@gmail.com> wrote:

Thanks Laurent for your help,
it worked to split the string to a list…but now I have to remove the 1
line(group <LE72270902002150EDC00_toar> references the following raster
maps), line 2 (‘-------------’), the last line (‘-------------’) and the
“<>” around the names…
I know how to do that… but is this the best way to deal with outputs of
i.group -l in python?

You should use i.group -g (Print in shell script style)

Anna

2016-04-06 11:02 GMT+10:00 Laurent C. <lrntct@gmail.com>:

Hello,

Try the .splitlines() method on the string.

Cheers,
Laurent

El abr. 5, 2016 19:52, “Leonardo Hardtke” <leohardtke@gmail.com> escribió:

Dear list members,
I know this is more a python question than a GRASS question, bot for sure
some of you knows the ansewer and is able to help me…

I need to get a python list with the maps from a group, like
[“map1”,“map2”,“map”]

But by using gscript.read_command… i get string, not a list.

gscript.read_command(“i.group”, group=groupname, flags=“l” )
‘group <LE72270902002150EDC00_toar> references the following raster
maps\n-------------\nLE72270902002150EDC00_toar.1@landsat
\nLE72270902002150EDC00_toar.2@landsat
\nLE72270902002150EDC00_toar.3@landsat
\nLE72270902002150EDC00_toar.4@landsat
\nLE72270902002150EDC00_toar.5@landsat
\nLE72270902002150EDC00_toar.7@landsat \n-------------\n’

Your help is appreciated!
Leo

Dr. Leonardo A. Hardtke
Laboratorio de Teledetección y S.I.G.
Centro Nacional Patagónico (CONICET)
Bvd. Brown 2825, 9120
Puerto Madryn, Chubut, Argentina


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Dr. Leonardo A. Hardtke
Laboratorio de Teledetección y S.I.G.
Centro Nacional Patagónico (CONICET)
Bvd. Brown 2825, 9120
Puerto Madryn, Chubut, Argentina


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Dr. Leonardo A. Hardtke
Laboratorio de Teledetección y S.I.G.
Centro Nacional Patagónico (CONICET)
Bvd. Brown 2825, 9120
Puerto Madryn, Chubut, Argentina

On Wed, Apr 6, 2016 at 4:03 AM, Leonardo Hardtke <leohardtke@gmail.com> wrote:

Oh!
Thanks "g" flag combined with .split() worked!!!!

great!
Please consider to add such solutions to the related Wiki page.

Markus