Re: [R-sig-Geo] Comparing 2 rasterbricks using functions from TSdist package

2020-05-28 Thread Frederico Faleiro
Hi Jackson,

you could use the complete.cases function to remove the pairs with NA
before run the distance function as bellow.

# CorDistance function does not handle NAs
x <- cbind(as.vector(s[[1]]), as.vector(s2[[1]]))
select.rows <- complete.cases(x)
CorDistance(x[select.rows, ] )

Cheers!
-- 
Frederico Faleiro
Postdoctoral Researcher in the INCT-EECBio (https://www.eecbio.ufg.br/)
Department of Ecology | Institute of Biological Science | Federal
University of Goiás | Brazil
RG: https://www.researchgate.net/profile/Frederico_Faleiro
CV: http://lattes.cnpq.br/4926404840659003

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Help with geocode() & get_map() please

2020-05-28 Thread Poling, William via R-sig-Geo
Hello again.

With Google help chat I discovered that I (we all) have a cloud billing Key and 
an API key.

I had everything correct in the cloud dashboard in terms of enabled API's, 
however, I was repeatedly trying to register the billing key and getting the 
errors after running the scripts, UGH!

register_google(key = "00-00-000AA0", write = TRUE) Billing Key NO GOOD
register_google(key = "Blahblah0BBLLAAHHblahlllaaabb00blah", write = TRUE) API 
Key from credentials GOOD

I hope this helps someone else down stream

Thank you Kent!

WHP

From: Kent Johnson  
Sent: Thursday, May 28, 2020 7:52 AM
To: r-sig-geo@r-project.org; Poling, William 
Subject: [EXTERNAL] Re: Help with geocode() & get_map() please

 External Email - Use Caution 
On Thu, May 28, 2020 at 6:03 AM  wrote:
Message: 1
Date: Wed, 27 May 2020 19:55:26 +
From: "Poling, William" 
Subject: [R-sig-Geo] Help with geocode()  & get_map() please
 
2. I am having trouble with get_map()

ny.map <- get_map("New York", zoom = 8)

Source : 
https://urldefense.proofpoint.com/v2/url?u=https-3A__maps.googleapis.com_maps_api_staticmap-3Fcenter-3DNew-2520York-26zoom-3D8-26size-3D640x640-26scale-3D2-26maptype-3Dterrain-26language-3Den-2DEN-26key-3D-5B012819-2D836529-2D634EA5-5D=DwMFaQ=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY=CsMl9LHpa9ULoNXKdkrUT6ekC9fM5srAwGtqAbNgep0=l5KYIQUC-rz6VESNkigtwbi7rx-YYayVqIrdsrN0prE=
Error in aperm.default(map, c(2, 1, 3)) : 
invalid first argument, must be an array
In addition: Warning message:
In get_googlemap(center = location, zoom = zoom, maptype = maptype,  :
  HTTP 400 Bad Request 

This looks like the problem described here:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_dkahle_ggmap_issues_262=DwMFaQ=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY=CsMl9LHpa9ULoNXKdkrUT6ekC9fM5srAwGtqAbNgep0=TegKIx-xo3fzI61Ul_ejBvccaNAV2c0cHSrQV5-5rNg=

It is a problem with your Google credentials. 

Kent 

Proprietary

NOTICE TO RECIPIENT OF INFORMATION:
This e-mail may contain confidential or privileged information. If you think 
you have received this e-mail in error, please advise the sender by reply 
e-mail and then delete this e-mail immediately.  
This e-mail may also contain protected health information (PHI) with 
information about sensitive medical conditions, including, but not limited to, 
treatment for substance use disorders, behavioral health, HIV/AIDS, or 
pregnancy. This type of information may be protected by various federal and/or 
state laws which prohibit any further disclosure without the express written 
consent of the person to whom it pertains or as otherwise permitted by law. Any 
unauthorized further disclosure may be considered a violation of federal and/or 
state law. A general authorization for the release of medical or other 
information may NOT be sufficient consent for release of this type of 
information.
Thank you. Aetna
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] ggplot grids polygons, points and lines with sperate legens

2020-05-28 Thread Bede-Fazekas Ákos

Hello Harry,
it is not the final solution, just one a part of it:

fill_levels <- unique(c(polys$Fill, pts$Value))
polys$Fill <- factor(x = polys$Fill, levels = fill_levels)
pts$Value <- factor(x = pts$Value, levels = fill_levels)
ponts$Value <- as.factor(ponts$Value)
ggplot()+
    geom_tile(data=pts, aes(x=X,y=Y,fill=Value), show.legend=F) +
    geom_sf(data=polys, aes(fill=Fill), alpha=0.5, 
size=2,show.legend="polygon")+

    geom_sf(data=lins, aes(color=Line),show.legend="line", size=5) +
    geom_sf(data=ponts, aes(shape=Value), size=10, show.legend="point") +
    scale_fill_manual("Grid",values=c(ptscols,polycols)) +
    scale_color_manual("Lines",values=lncols) +
scale_shape_manual("Points",values=as.numeric(levels(ponts$Value))) +
    guides(fill = guide_legend(override.aes = list(linetype = 0, shape 
= 0)), color = guide_legend(override.aes = list(shape = 0, linetype = 
"solid", size=5)), shape = guide_legend(override.aes = list(linetype = 
0, size=10)))


HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences

2020.05.28. 17:10 keltezéssel, Herr, Alexander (L, Black Mountain) írta:

Hi,

I am unsuccessfully trying to adjust the legend for a multiple feature plot of 
geom_tile, and geom_sf (with polygons, lines and points).  I would like to have 
1) the geom_tile legend separate from the geom_sf polygon legend and also 2) 
have the legend descriptors ordered descending and 3) each legend for polygon, 
line and point should have the respective pattern/color, that is rectangle for 
polygons, lines for lines and shapes for points.

Reproducible code below. Any suggestions?
Thanks
Herry


require(sf)
require(sp)

pols<-st_as_sf(spPolygons(rbind(c(1,1),c(1,10),c(10,10),c(10,1),c(1,1
p1 =st_sfc((st_polygon(list(rbind(c(0,0), c(0,10), c(10,10), c(10,0), 
c(0,0))
pts<-as.data.frame(st_coordinates(st_make_grid(p1,cellsize=1,what='centers')) 
)%>%mutate(Value=unlist(lapply(1:10,function(x) sample.int(10,n=3, replace=T))) )
lins<-st_as_sf(rbind(spLines(rbind(c(2,3),c(9,9))),spLines(rbind(c(2,7),c(8,1)%>%
   transmute(Line=c("6","7"))
p2<-st_as_sf(spPolygons(rbind(c(1,1),c(9,9),c(9,4),c(1,1
p3<-st_as_sf(spPolygons(rbind(c(1,1),c(1,7),c(7,7),c(7,5),c(1,1
polys<-st_as_sf(rbind(p2,p3))%>%transmute(Fill=c("4","5"))
ponts<-st_as_sf(pts,coords=c("X","Y") )

ptscols<-c("salmon","light blue","orange")
polycols<-c("dark red","aquamarine")
lncols<-c("deepskyblue","gold")

ggplot()+geom_tile(data=pts, aes(x=X,y=Y,fill=as.character(Value)), 
show.legend=T )  +
  geom_sf(data=polys, aes(fill=as.character(Fill)), alpha=0.5, 
size=2,show.legend=T)+
  geom_sf(data=lins, aes(color=Line),legend=T, size=5) +
  geom_sf(data=ponts, aes(shape=as.character(Value)), size=10, 
show.legend=T)+
  scale_fill_manual("Grid",values=c(ptscols,polycols),
   breaks = c(as.character(unique(pts$Value)),polys$Fill),
 guide = guide_legend(overrid.aes=list(linetype = NULL, 
shape=NULL))) +
   scale_color_manual("Lines",values=lncols, breaks = lins$Line,
 guide = guide_legend(override.aes = list(linetype = 
"solid", size=5)))   +
   
scale_shape_manual("Points",values=unique(as.character(ponts$Value)), breaks = 
ponts$Value,
 guide = guide_legend(override.aes = list(size=10)))


[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] ggplot grids polygons, points and lines with sperate legens

2020-05-28 Thread Herr, Alexander (L, Black Mountain)
Hi,

I am unsuccessfully trying to adjust the legend for a multiple feature plot of 
geom_tile, and geom_sf (with polygons, lines and points).  I would like to have 
1) the geom_tile legend separate from the geom_sf polygon legend and also 2) 
have the legend descriptors ordered descending and 3) each legend for polygon, 
line and point should have the respective pattern/color, that is rectangle for 
polygons, lines for lines and shapes for points.

Reproducible code below. Any suggestions?
Thanks
Herry


require(sf)
require(sp)

pols<-st_as_sf(spPolygons(rbind(c(1,1),c(1,10),c(10,10),c(10,1),c(1,1
p1 =st_sfc((st_polygon(list(rbind(c(0,0), c(0,10), c(10,10), c(10,0), 
c(0,0))
pts<-as.data.frame(st_coordinates(st_make_grid(p1,cellsize=1,what='centers')) 
)%>%mutate(Value=unlist(lapply(1:10,function(x) sample.int(10,n=3, replace=T))) 
)
lins<-st_as_sf(rbind(spLines(rbind(c(2,3),c(9,9))),spLines(rbind(c(2,7),c(8,1)%>%
  transmute(Line=c("6","7"))
p2<-st_as_sf(spPolygons(rbind(c(1,1),c(9,9),c(9,4),c(1,1
p3<-st_as_sf(spPolygons(rbind(c(1,1),c(1,7),c(7,7),c(7,5),c(1,1
polys<-st_as_sf(rbind(p2,p3))%>%transmute(Fill=c("4","5"))
ponts<-st_as_sf(pts,coords=c("X","Y") )

ptscols<-c("salmon","light blue","orange")
polycols<-c("dark red","aquamarine")
lncols<-c("deepskyblue","gold")

ggplot()+geom_tile(data=pts, aes(x=X,y=Y,fill=as.character(Value)), 
show.legend=T )  +
 geom_sf(data=polys, aes(fill=as.character(Fill)), alpha=0.5, 
size=2,show.legend=T)+
 geom_sf(data=lins, aes(color=Line),legend=T, size=5) +
 geom_sf(data=ponts, aes(shape=as.character(Value)), size=10, 
show.legend=T)+
 scale_fill_manual("Grid",values=c(ptscols,polycols),
  breaks = c(as.character(unique(pts$Value)),polys$Fill),
guide = guide_legend(overrid.aes=list(linetype = NULL, 
shape=NULL))) +
  scale_color_manual("Lines",values=lncols, breaks = lins$Line,
guide = guide_legend(override.aes = list(linetype = 
"solid", size=5)))   +
  
scale_shape_manual("Points",values=unique(as.character(ponts$Value)), breaks = 
ponts$Value,
guide = guide_legend(override.aes = list(size=10)))


[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Help with geocode() & get_map() please

2020-05-28 Thread Poling, William via R-sig-Geo
Ok, thank you, I suspected that and was unsure how to proceed beyond what I had 
described originally.

I will review your reference.

Thank you for your response Kent, much appreciated.

WHP

From: Kent Johnson  
Sent: Thursday, May 28, 2020 7:52 AM
To: r-sig-geo@r-project.org; Poling, William 
Subject: [EXTERNAL] Re: Help with geocode() & get_map() please

 External Email - Use Caution 
On Thu, May 28, 2020 at 6:03 AM  wrote:
Message: 1
Date: Wed, 27 May 2020 19:55:26 +
From: "Poling, William" 
Subject: [R-sig-Geo] Help with geocode()  & get_map() please
 
2. I am having trouble with get_map()

ny.map <- get_map("New York", zoom = 8)

Source : 
https://urldefense.proofpoint.com/v2/url?u=https-3A__maps.googleapis.com_maps_api_staticmap-3Fcenter-3DNew-2520York-26zoom-3D8-26size-3D640x640-26scale-3D2-26maptype-3Dterrain-26language-3Den-2DEN-26key-3D-5B012819-2D836529-2D634EA5-5D=DwMFaQ=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY=CsMl9LHpa9ULoNXKdkrUT6ekC9fM5srAwGtqAbNgep0=l5KYIQUC-rz6VESNkigtwbi7rx-YYayVqIrdsrN0prE=
Error in aperm.default(map, c(2, 1, 3)) : 
invalid first argument, must be an array
In addition: Warning message:
In get_googlemap(center = location, zoom = zoom, maptype = maptype,  :
  HTTP 400 Bad Request 

This looks like the problem described here:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_dkahle_ggmap_issues_262=DwMFaQ=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY=CsMl9LHpa9ULoNXKdkrUT6ekC9fM5srAwGtqAbNgep0=TegKIx-xo3fzI61Ul_ejBvccaNAV2c0cHSrQV5-5rNg=

It is a problem with your Google credentials. 

Kent 

Proprietary

NOTICE TO RECIPIENT OF INFORMATION:
This e-mail may contain confidential or privileged information. If you think 
you have received this e-mail in error, please advise the sender by reply 
e-mail and then delete this e-mail immediately.  
This e-mail may also contain protected health information (PHI) with 
information about sensitive medical conditions, including, but not limited to, 
treatment for substance use disorders, behavioral health, HIV/AIDS, or 
pregnancy. This type of information may be protected by various federal and/or 
state laws which prohibit any further disclosure without the express written 
consent of the person to whom it pertains or as otherwise permitted by law. Any 
unauthorized further disclosure may be considered a violation of federal and/or 
state law. A general authorization for the release of medical or other 
information may NOT be sufficient consent for release of this type of 
information.
Thank you. Aetna
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] rgdal 1.5-8 released on CRAN

2020-05-28 Thread Roger Bivand
With sp 1.4-2 and rgdal 1.5-8, those using GDAL 3 and PROJ 6 (including 
users of the CRAN Windows binary when it comes) will be part of the big 
migration to WKT2 from Proj4 strings for CRS representation. See


https://cran.r-project.org/web/packages/rgdal/vignettes/CRS_projections_transformations.html

or for a better rendering of "\phi" and bib-handling:

https://rgdal.r-forge.r-project.org/articles/CRS_projections_transformations.html

for background and https://www.r-spatial.org/r/2020/03/17/wkt.html for the 
full sf and sp story.


You will see lots of warnings, they should grab your attention, that is 
what they are for. We need your attention to be as sure as we can be that 
your results - if affected by the transition - have been checked by you.


I plan to flip the warnings to default off from rgdal 1.6-*, and sp 1.5-*. 
In some weeks but before flipping the defaults, I'll follow up showing 
ways of muting them, but we really need to be confident that this 
necessary and future-proofing change isn't silently destroying your work 
first. So please don't treat the many warnings as just pesky and nagging - 
they are priming your immune system to check for unwanted consequences of 
your legacy CRS representation choices.


I'd also like to thank the maintainers of packages importing 
from/depending on sp/rgdal for largely positive responses to issues raised 
and emails sent, often less polite than they might have been, but grabbing 
attention was more important. From over 70 broken reverse dependency 
packages we are now well under 20, and I've contacted all of those, with 
only a couple not responding. Edzer has seen similar responsiveness for 
the parallel migration of sf.


Enjoy!

Roger

--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: roger.biv...@nhh.no
https://orcid.org/-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0J=en

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Comparing 2 rasterbricks using functions from TSdist package

2020-05-28 Thread Loïc Dutrieux

Hi Jackson,

calc is meant to apply a function pixel wise on a single raster object. 
Its equivalent for multiple raster objects is overlay.


Kind regards,
Loïc

On 05/28/2020 09:05 AM, Bede-Fazekas Ákos wrote:

Dear Jackson,

I think this is what you are searching for:
new_s3 <- setValues(r, sapply(1:ncell(r), function(i) 
fun(as.vector(s[i]), as.vector(s2[i]

plot(new_s3, colNA = "red")

HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences



2020.05.28. 0:18 keltezéssel, Jackson Rodrigues írta:

Dear all,

Few days ago I got a important help from this list and I am really 
thankful

for that.
Today I have a similar challenge with 2 rasterbrick files.

I would like to compare 2 rasterbricks using any similarity function 
(let's

take CorDistance) from package TSdist.
In my real data, both rasterbricks came from the same region but using
different measurement techniques.

I am trying to adapt the suggestion I got from here rather than 
looping on

each cell, but no matter what I try I always get an error related to NA.
It seems to be very simples but I am stuck since last Monday.

I have played with several conditional ("ifelse", "if", "if else" etc) 
and

logical tests ("|", "||", "&" etc) but I got nothing so far.

Could someone help me and show me a path to go through?
Below there is the cleanest code I have tried.

Best regards

Jackson

##
library(raster)
library(TSdist)

set.seed(12)
r <- raster(nrow=10, ncol=10)
s <- lapply(1:200, function(i) setValues(r, rnorm(ncell(r),
   sample.int(5,1), 
0.5)))

s <- stack(s)
s[s < 0] <- NA
s2<-s^2

# Visualize that some pixels have NAs and other don't
hasna <- stackApply(s, indices = 1, fun = function(x, na.rm){anyNA(x)})
hasna2 <- stackApply(s2, indices = 1, fun = function(x, na.rm){anyNA(x)})

par(mfrow=c(1,2))
plot(hasna);plot(hasna2)

# CorDistance function does not handle NAs
CorDistance(as.vector(s[1]),as.vector(s2[1]))
[1] 0.2192382

CorDistance(as.vector(s[2]),as.vector(s2[2]))

   [1] NA

fun <- function(x,y){
   out <- ifelse(anyNA(x) | anyNA(y),
 yes = NA,
 no = unname(CorDistance(x,y)))
   return(out)
}

# Check that it works
fun(as.vector(s[1]),as.vector(s2[1]))
[1] 0.2192382

# Check that it does not work
fun(as.vector(s[2]),as.vector(s2[2]))
[1] NA

new_s1 <- fun(s,s2)


# Check that it does not work with calc
new_s2 <- calc(s,s2, fun = fun)
Error in .calcTest(x[1:5], fun, na.rm, forcefun, forceapply) :
   cannot use this function

plot(s_out)
#





___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Comparing 2 rasterbricks using functions from TSdist package

2020-05-28 Thread Bede-Fazekas Ákos

Dear Jackson,

I think this is what you are searching for:
new_s3 <- setValues(r, sapply(1:ncell(r), function(i) 
fun(as.vector(s[i]), as.vector(s2[i]

plot(new_s3, colNA = "red")

HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences



2020.05.28. 0:18 keltezéssel, Jackson Rodrigues írta:

Dear all,

Few days ago I got a important help from this list and I am really thankful
for that.
Today I have a similar challenge with 2 rasterbrick files.

I would like to compare 2 rasterbricks using any similarity function (let's
take CorDistance) from package TSdist.
In my real data, both rasterbricks came from the same region but using
different measurement techniques.

I am trying to adapt the suggestion I got from here rather than looping on
each cell, but no matter what I try I always get an error related to NA.
It seems to be very simples but I am stuck since last Monday.

I have played with several conditional ("ifelse", "if", "if else" etc) and
logical tests ("|", "||", "&" etc) but I got nothing so far.

Could someone help me and show me a path to go through?
Below there is the cleanest code I have tried.

Best regards

Jackson

##
library(raster)
library(TSdist)

set.seed(12)
r <- raster(nrow=10, ncol=10)
s <- lapply(1:200, function(i) setValues(r, rnorm(ncell(r),
   sample.int(5,1), 0.5)))
s <- stack(s)
s[s < 0] <- NA
s2<-s^2

# Visualize that some pixels have NAs and other don't
hasna <- stackApply(s, indices = 1, fun = function(x, na.rm){anyNA(x)})
hasna2 <- stackApply(s2, indices = 1, fun = function(x, na.rm){anyNA(x)})

par(mfrow=c(1,2))
plot(hasna);plot(hasna2)

# CorDistance function does not handle NAs
CorDistance(as.vector(s[1]),as.vector(s2[1]))
[1] 0.2192382

CorDistance(as.vector(s[2]),as.vector(s2[2]))

   [1] NA

fun <- function(x,y){
   out <- ifelse(anyNA(x) | anyNA(y),
 yes = NA,
 no = unname(CorDistance(x,y)))
   return(out)
}

# Check that it works
fun(as.vector(s[1]),as.vector(s2[1]))
[1] 0.2192382

# Check that it does not work
fun(as.vector(s[2]),as.vector(s2[2]))
[1] NA

new_s1 <- fun(s,s2)


# Check that it does not work with calc
new_s2 <- calc(s,s2, fun = fun)
Error in .calcTest(x[1:5], fun, na.rm, forcefun, forceapply) :
   cannot use this function

plot(s_out)
#



___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo