[GRASS-user] Values from multiple raster - "to link" together

Hello everyone.
I have to solve a problem already discussed here:
http://osgeo-org.1803224.n2.nabble.com/r-mapcalc-concatenates-values-td1884970.html#a1884973

In summary, I have for example 3 maps A, B, C.
I need to combine the values of the overlapping cells. For example if I have
a cell in the map "A" with value 11, in the corresponding cell of the map
"B" I have 2222 and the corresponding cell of the map "C" is 3333.
In output I would like to have a map that has a value in that cell
1122223333.
I tried with r.mapcalc, but without Successfully.

Help?

Thanks

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5741032.html
Sent from the Grass - Users mailing list archive at Nabble.com.

On 11/15/2010 10:59 AM, Gabriele N. wrote:

Hello everyone.
I have to solve a problem already discussed here:
http://osgeo-org.1803224.n2.nabble.com/r-mapcalc-concatenates-values-td1884970.html#a1884973

In summary, I have for example 3 maps A, B, C.
I need to combine the values of the overlapping cells. For example if I have
a cell in the map "A" with value 11, in the corresponding cell of the map
"B" I have 2222 and the corresponding cell of the map "C" is 3333.
In output I would like to have a map that has a value in that cell
1122223333.
I tried with r.mapcalc, but without Successfully.

Help?

Thanks

Gabriele

The quick way to do this classically is using reclassification
techniques. Are the number of digits the same for all of A, B and C?
If so
(A * 100000000)+ (B*10000)+C would get you that answer

Usually with Raster processing you have to think of ways to solve using
only math, hence concatenation not working. Now if you converted your
grids to polygons that would be totally different.

Thanks,
Alex

Excellent Alex:). The maps are as follows:
A -> value 0, 1, 2, ... 19
B -> value 0, 1001, 1002, 1003 .... 3351
C -> value from 0, 1, 2, 3, 4 ...... 15

So, I did as you suggested:
r.mapcalc "output" = "(( "A" *1000000)+( "B" *100)+ "C" )"
right?
And .... if I had decimal numbers or strings instead of numbers?

Thanks

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5741794.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Am 15.11.2010 23:10, schrieb Gabriele N.:

Excellent Alex:). The maps are as follows:
A -> value 0, 1, 2, ... 19
B -> value 0, 1001, 1002, 1003 .... 3351
C -> value from 0, 1, 2, 3, 4 ...... 15

So, I did as you suggested:
r.mapcalc "output" = "(( "A" *1000000)+( "B" *100)+ "C" )"
right?
And .... if I had decimal numbers or strings instead of numbers?

Thanks

Gabriele

Strings in a raster map?
With decimal numbers it works the same way. Or you multiply the map with number of digits and handle it as an integer map (maybe that does not work because of limited bit information per pixel).

Achim

Hi Achim.
Returning to the problem of the three maps in some cases remain the problem
(for example for the map "C"), because some numbers are 2 digits and another
with 1 digit.
For example, with values A = 12 B = 3323 C = 1 instead of 1233231 I have
12332301
:confused:
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5741869.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Am 15.11.2010 23:36, schrieb Gabriele N.:

Hi Achim.
Returning to the problem of the three maps in some cases remain the problem
(for example for the map "C"), because some numbers are 2 digits and another
with 1 digit.
  For example, with values A = 12 B = 3323 C = 1 instead of 1233231 I have
12332301
:confused:

Sorry, but I dont understand the problem. How do you know the origin number later when eg C has sometimes length 1 and sometimes more?

Sorry, I have not explained well.
The problem was related to the value of C map. That is, I take the example
above. If the value of C map is equal to 1, I get a result -> A =12 B=3323
C=1 =12332301 (8 digit number) and instead could be useful 1233231 (number
7-digit).
However I checked and I need a value to 8 digits ..... so ok:)

Thank you very much

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5744524.html
Sent from the Grass - Users mailing list archive at Nabble.com.

I'm coming in a bit late in the discussion but doesn't r.cross solves
your problem?

http://grass.osgeo.org/grass65/manuals/html65_user/r.cross.html

Daniel

On Tue, Nov 16, 2010 at 2:51 PM, Gabriele N. <gis.gn@libero.it> wrote:

Sorry, I have not explained well.
The problem was related to the value of C map. That is, I take the example
above. If the value of C map is equal to 1, I get a result -> A =12 B=3323
C=1 =12332301 (8 digit number) and instead could be useful 1233231 (number
7-digit).
However I checked and I need a value to 8 digits ..... so ok:)

Thank you very much

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5744524.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

Hy Daniel.
I do not think that r.cross can solve the problem.
With r.cross I could get a concatenation of label:
For example, with values A = 12 B = 3323 C = 1 the result with the label
"category 12, category 3323, category 1"
However, if you know a chance I can prove otherwise.
As a result, the value of cell in the raster output should be 12332301

Ciao

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5766350.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Ok, I misunderstood your problem. You want the concatenated values,
not just the map of the different crossings. Maybe use r.cross and
then some grep magic in the raster category file

Daniel

On Tue, Nov 23, 2010 at 10:02 AM, Gabriele N. <gis.gn@libero.it> wrote:

Hy Daniel.
I do not think that r.cross can solve the problem.
With r.cross I could get a concatenation of label:
For example, with values A = 12 B = 3323 C = 1 the result with the label
"category 12, category 3323, category 1"
However, if you know a chance I can prove otherwise.
As a result, the value of cell in the raster output should be 12332301

Ciao

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5766350.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

yes, maybe with grep and r.cross ... but then you think you can "convert" the
result of r.cross as cell value?

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5766761.html
Sent from the Grass - Users mailing list archive at Nabble.com.

I have a new problem, this time I would like to concatenate two maps A and B.
A is with 8 digits, B is with 4 digits. So I do as usual:

r.mapcalc "output" = "((" A "* 10000) (" B "))"

But I get strange values with negative values. I did several tests but
without resolve. Perhaps r.mapcalc may have problems with numbers greater
than 10 digits

Thanks

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5767794.html
Sent from the Grass - Users mailing list archive at Nabble.com.

It's not r.mapcalc fault. I imagine it's probably a limitation due to
the number of bits in your image. For instance, 8 bit images can have
up to 256 values. 16 bit images can have 65,535. So, if you have too
many values, you will have problems. Not sure how to avoid this in
your case but, maybe you will need to work with categories after all.
Are you planing on doing any math operations in the concatenated
values or is it more for displaying pourposes?

Cheers
Daniel

http://en.wikipedia.org/wiki/Integer_(computer_science)

On Tue, Nov 23, 2010 at 4:34 PM, Gabriele N. <gis.gn@libero.it> wrote:

I have a new problem, this time I would like to concatenate two maps A and B.
A is with 8 digits, B is with 4 digits. So I do as usual:

r.mapcalc "output" = "((" A "* 10000) (" B "))"

But I get strange values with negative values. I did several tests but
without resolve. Perhaps r.mapcalc may have problems with numbers greater
than 10 digits

Thanks

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5767794.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

Gabriele N. wrote:

I have a new problem, this time I would like to concatenate two maps A and B.
A is with 8 digits, B is with 4 digits. So I do as usual:

r.mapcalc "output" = "((" A "* 10000) (" B "))"

But I get strange values with negative values. I did several tests but
without resolve. Perhaps r.mapcalc may have problems with numbers greater
than 10 digits

CELL maps contain signed, 32-bit values using sign-bit representation,
so the range is -2147483647 to 2147483647 inclusive (i.e. -(2^31-1) to
2^31-1). So you aren't going to be able to store 12-digit numbers in a
CELL map.

DCELL maps use the C "double" type, which on most systems is IEEE-754
double precision, which has a 53-bit mantissa, plus a separate sign
bit. That can exactly represent any integer between -9007199254740992
and 9007199254740992 inclusive (i.e. almost 16 decimal digits).

However, depending upon what you want to do with the result, this may
not be an option, as not all modules can work with floating-point
data.

--
Glynn Clements <glynn@gclements.plus.com>

Hy Glynn.

Thanks for the interesting explanation.
I did then so:

r.mapcalc "A_new = (double(A)) and r.mapcalc "B_new = (double(B))

and then

r.mapcalc "output" = "(("A_new" * 10000)+("B_new" ))"

I need to check the result, but it seems that the result is right.

Thank you very much

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5768432.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Daniel Victoria wrote:

It's not r.mapcalc fault. I imagine it's probably a limitation due to
the number of bits in your image. For instance, 8 bit images can have
up to 256 values. 16 bit images can have 65,535. So, if you have too
many values, you will have problems. Not sure how to avoid this in
your case but, maybe you will need to work with categories after all.
Are you planing on doing any math operations in the concatenated
values or is it more for displaying pourposes?

Hi Daniel...

Maybe it would be useful only concatenation but I would also have the
possibility to apply tools such as r.statistics and other similar that work
on the value of cells.

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5768618.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Gabriele N. wrote:

Thanks for the interesting explanation.
I did then so:

r.mapcalc "A_new = (double(A)) and r.mapcalc "B_new = (double(B))

and then

r.mapcalc "output" = "(("A_new" * 10000)+("B_new" ))"

The same result can be achieved with one command:

  r.mapcalc "output = A * 10000.0 + B"

The multiply will cause A to be converted to double to match the other
argument (floating-point constants are double unless an explicit "f"
suffix is given), the multiply will yield a double result, and the
addition will convert B to double to match this.

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

The same result can be achieved with one command:

  r.mapcalc "output = A * 10000.0 + B"

The multiply will cause A to be converted to double to match the other
argument (floating-point constants are double unless an explicit "f"
suffix is given), the multiply will yield a double result, and the
addition will convert B to double to match this.

perfect, I tried it and it actually works:) This speeds up operations.
Now I have to combine new maps and then to reclassify the maps, I will use
r.recode ... we'll see what happens:)

Thank you Glynn

Gabriele
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Values-from-multiple-raster-to-link-together-tp5741032p5772145.html
Sent from the Grass - Users mailing list archive at Nabble.com.