SV: SV: [GRASS-user] Raster addition -Solved
Don't know who of you led me in the right direction, but eventually the line: "C=A + if(isnull(B),0,B)" in the manual solved my issue. New_map = if(isnull(old_1),0,old_1) + if(isnull(old_2,0,old_2)) + etc and a following new_map=if(new_map>0,new_map,null()) I had four maps in my case, and that is why "new_map = if(!isnull(old_1) && !isnull(old_2), old_1+old_2, if(!isnull(old_1) && isnull(old_2), old_1, etc)" would become to long (4!=24 statements?) Thank you both Johannes and Moritz. Martin -Opprinnelig melding- Fra: Johannes Radinger [mailto:jradin...@gmx.at] Sendt: 14. april 2011 15:13 Til: Martin Album Ytre-Eide; mlenn...@club.worldonline.be Kopi: grass-user@lists.osgeo.org Emne: Re: SV: [GRASS-user] Raster addition Original-Nachricht > Datum: Thu, 14 Apr 2011 14:31:32 +0200 > Von: Martin Album Ytre-Eide > An: \'Moritz Lennert\' > CC: "grass-user@lists.osgeo.org" > Betreff: SV: [GRASS-user] Raster addition > I would like the NULL values that overlap with none NULL values to be > treated as 0, and still have NULL values where both maps have NULL > values. The combined map would be a large map with NULL values and added > values. that is possible with the r.mapcalc and a if condition like: if(map A &&& map B, 0, null()) something like that (untested) might work. the null () provides NULL values where the condition is false. The triple &&& is the logic and (treats NULL values different from double &&). see: http://grass.fbk.eu/gdp/html_grass64/r.mapcalc.html for more information. /j > > Maybe the best way is to use r.null and set NULL values to 0. Add the > maps and then convert the 0 values to NULL values? > Or could one set the value in the if statement to be a the sum of maps > somehow? I guess my biggest problem is summing with NULL values - > maybe there is a way to treat NULL values as 0? I'll have a look at > the man page > > Thanks, > > Martin > > -Opprinnelig melding- > Fra: Moritz Lennert [mailto:mlenn...@club.worldonline.be] > Sendt: 14. april 2011 14:15 > Til: Martin Album Ytre-Eide > Kopi: grass-user@lists.osgeo.org > Emne: Re: [GRASS-user] Raster addition > > On 14/04/11 13:54, Martin Album Ytre-Eide wrote: > > Hello. > > > > I am trying to add some raster maps. I thought I could do this in > > r.mapcalc, but "new_map= old_1 + old_2" seems to produce a map where > > the maps overlap and ignoring areas where only on of the maps have > > values. > > This is due to the way r.mapcalc handles NULL values. See the man > page, section NULL support for an explanation. > > > I would like to do something similar to "v.overlay operator=or". > > > > Anyone who knows how to do this? > > It depends on what you want the new map to contain as values. If you > want to add the value of old_1 to old_2 in places where they overlap, > one way would be to transform your null values to 0 using r.null null= > and then applying your formula. > > If you just want a (any) value where one of the maps is non-null, then > you can use if. Something like this (untested): > > new_map = if(!isnull(old_1) || !isnull(old_2), 1, null()) > > which should give you 1 where any of the two contains a value and a > NULL value elsewhere. > > Moritz > ___ > grass-user mailing list > grass-user@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/grass-user -- GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit gratis Handy-Flat! http://portal.gmx.net/de/go/dsl ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: SV: [GRASS-user] Raster addition
Martin Album Ytre-Eide wrote: > > I would like the NULL values that overlap with none NULL values to be > treated as 0, and still have NULL values where both maps have NULL values. > The combined map would be a large map with NULL values and added values. > hy, i guess r.patch can do that for you ... http://grass.osgeo.org/grass70/manuals/html70_user/r.patch.html r.patch ... hope that i´m not wrong cheers, tim -- View this message in context: http://osgeo-org.1803224.n2.nabble.com/Raster-addition-tp6272457p6272716.html Sent from the Grass - Users mailing list archive at Nabble.com. ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: SV: [GRASS-user] Raster addition
Original-Nachricht > Datum: Thu, 14 Apr 2011 14:31:32 +0200 > Von: Martin Album Ytre-Eide > An: \'Moritz Lennert\' > CC: "grass-user@lists.osgeo.org" > Betreff: SV: [GRASS-user] Raster addition > I would like the NULL values that overlap with none NULL values to be > treated as 0, and still have NULL values where both maps have NULL values. The > combined map would be a large map with NULL values and added values. that is possible with the r.mapcalc and a if condition like: if(map A &&& map B, 0, null()) something like that (untested) might work. the null () provides NULL values where the condition is false. The triple &&& is the logic and (treats NULL values different from double &&). see: http://grass.fbk.eu/gdp/html_grass64/r.mapcalc.html for more information. /j > > Maybe the best way is to use r.null and set NULL values to 0. Add the maps > and then convert the 0 values to NULL values? > Or could one set the value in the if statement to be a the sum of maps > somehow? I guess my biggest problem is summing with NULL values - maybe there > is a way to treat NULL values as 0? I'll have a look at the man page > > Thanks, > > Martin > > -Opprinnelig melding- > Fra: Moritz Lennert [mailto:mlenn...@club.worldonline.be] > Sendt: 14. april 2011 14:15 > Til: Martin Album Ytre-Eide > Kopi: grass-user@lists.osgeo.org > Emne: Re: [GRASS-user] Raster addition > > On 14/04/11 13:54, Martin Album Ytre-Eide wrote: > > Hello. > > > > I am trying to add some raster maps. I thought I could do this in > > r.mapcalc, but "new_map= old_1 + old_2" seems to produce a map where > > the maps overlap and ignoring areas where only on of the maps have > > values. > > This is due to the way r.mapcalc handles NULL values. See the man page, > section NULL support for an explanation. > > > I would like to do something similar to "v.overlay operator=or". > > > > Anyone who knows how to do this? > > It depends on what you want the new map to contain as values. If you want > to add the value of old_1 to old_2 in places where they overlap, one way > would be to transform your null values to 0 using r.null null= and then > applying your formula. > > If you just want a (any) value where one of the maps is non-null, then you > can use if. Something like this (untested): > > new_map = if(!isnull(old_1) || !isnull(old_2), 1, null()) > > which should give you 1 where any of the two contains a value and a NULL > value elsewhere. > > Moritz > ___ > grass-user mailing list > grass-user@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/grass-user -- GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit gratis Handy-Flat! http://portal.gmx.net/de/go/dsl ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: SV: [GRASS-user] Raster addition
On 14/04/11 14:31, Martin Album Ytre-Eide wrote: I would like the NULL values that overlap with none NULL values to be treated as 0, and still have NULL values where both maps have NULL values. The combined map would be a large map with NULL values and added values. Maybe the best way is to use r.null and set NULL values to 0. Add the maps and then convert the 0 values to NULL values? I think this is probably the easiest. Or could one set the value in the if statement to be a the sum of maps somehow? I guess my biggest problem is summing with NULL values - maybe there is a way to treat NULL values as 0? I'll have a look at the man page If you chose to do it all directly in r.mapcalc, then I guess the only option is nested if statements new_map = if(!isnull(old_1) && !isnull(old_2), old_1+old_2, if(!isnull(old_1) && isnull(old_2), old_1, etc) Moritz Thanks, Martin -Opprinnelig melding- Fra: Moritz Lennert [mailto:mlenn...@club.worldonline.be] Sendt: 14. april 2011 14:15 Til: Martin Album Ytre-Eide Kopi: grass-user@lists.osgeo.org Emne: Re: [GRASS-user] Raster addition On 14/04/11 13:54, Martin Album Ytre-Eide wrote: Hello. I am trying to add some raster maps. I thought I could do this in r.mapcalc, but "new_map= old_1 + old_2" seems to produce a map where the maps overlap and ignoring areas where only on of the maps have values. This is due to the way r.mapcalc handles NULL values. See the man page, section NULL support for an explanation. I would like to do something similar to "v.overlay operator=or". Anyone who knows how to do this? It depends on what you want the new map to contain as values. If you want to add the value of old_1 to old_2 in places where they overlap, one way would be to transform your null values to 0 using r.null null= and then applying your formula. If you just want a (any) value where one of the maps is non-null, then you can use if. Something like this (untested): new_map = if(!isnull(old_1) || !isnull(old_2), 1, null()) which should give you 1 where any of the two contains a value and a NULL value elsewhere. Moritz ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
SV: [GRASS-user] Raster addition
I would like the NULL values that overlap with none NULL values to be treated as 0, and still have NULL values where both maps have NULL values. The combined map would be a large map with NULL values and added values. Maybe the best way is to use r.null and set NULL values to 0. Add the maps and then convert the 0 values to NULL values? Or could one set the value in the if statement to be a the sum of maps somehow? I guess my biggest problem is summing with NULL values - maybe there is a way to treat NULL values as 0? I'll have a look at the man page Thanks, Martin -Opprinnelig melding- Fra: Moritz Lennert [mailto:mlenn...@club.worldonline.be] Sendt: 14. april 2011 14:15 Til: Martin Album Ytre-Eide Kopi: grass-user@lists.osgeo.org Emne: Re: [GRASS-user] Raster addition On 14/04/11 13:54, Martin Album Ytre-Eide wrote: > Hello. > > I am trying to add some raster maps. I thought I could do this in > r.mapcalc, but "new_map= old_1 + old_2" seems to produce a map where > the maps overlap and ignoring areas where only on of the maps have > values. This is due to the way r.mapcalc handles NULL values. See the man page, section NULL support for an explanation. > I would like to do something similar to "v.overlay operator=or". > > Anyone who knows how to do this? It depends on what you want the new map to contain as values. If you want to add the value of old_1 to old_2 in places where they overlap, one way would be to transform your null values to 0 using r.null null= and then applying your formula. If you just want a (any) value where one of the maps is non-null, then you can use if. Something like this (untested): new_map = if(!isnull(old_1) || !isnull(old_2), 1, null()) which should give you 1 where any of the two contains a value and a NULL value elsewhere. Moritz ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user