0

I have two binary files with the same dimensions: the first represents correlation between xm and df and the second represents also correlation between xm and gh data.I want to create one map out of these two representing the best correlations.for instance: 1- read the first pixel in the correlation map between xm and df and the corresponding pixel in the correlation map between xm and gh.

2- take the best correlation value and make it blue color if it comes from xm and df,otherwise make it green if it comes from xm and gh

3- do the same for all pixels

4- get something like the map associated

Here are the two files:

  1- to read the first file correlation map:![enter image description here][1]

   conn <- file("C:\\corr.bin","rb")![enter image description here][2]
  corr<- readBin(conn, numeric(), size=4,  n=1440*720, signed=TRUE)
  y<-t(matrix((data=corr), ncol=720, nrow=1440))
    image(y)

2- to read the second file land cover map:

  conne <- file("C:\\cor06.bin","rb")
  over<-readBin(conne, numeric(), size=4,  n=1440*720, signed=TRUE)
  y1<-t(matrix((data=over), ncol=720, nrow=1440))
  image(y1)

3-to write the results:

     to.write = file(paste("/orcomplete.bin",sep=""),"wb")
     writeBin(as.double(results), to.write, size = 4)

enter image description here

4

2 回答 2

1

If the dimensions of your data are the same (which in your case this is true) then you can use the raster package like so:

r <-raster(t(matrix((data=corr), ncol=720, nrow=1440)))
r1 <- raster(t(matrix((data=over), ncol=720, nrow=1440)))
m <- r > r1 #Compare the two rasters
image( m , col = c("#EF8A62" , "#67A9CF" ) ) #Hexadecimal colour specification
legend( "bottomleft" , legend = c( "Y" , "Y1") , fill = c("#EF8A62" , "#67A9CF" ) , border = "#D9D9D9" , bty = "n")

enter image description here

于 2013-03-03T15:18:58.007 回答
1

An example with base R:

## example data
set.seed(1)
cor1 <- runif(100)
cor2 <- runif(100)

## find max correlation
maxCor <- pmax(cor1, cor2)
## find correct color
col <- ifelse(maxCor==cor1, "blue", "green")
于 2013-03-03T15:27:30.540 回答