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 <mailto:r-sig-geo-requ...@r-project.org> wrote:
Message: 1
Date: Wed, 27 May 2020 19:55:26 +
From: "Poling, William" <mailto:poli...@aetna.com>
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] 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 <mailto:r-sig-geo-requ...@r-project.org> wrote:
Message: 1
Date: Wed, 27 May 2020 19:55:26 +
From: "Poling, William" <mailto:poli...@aetna.com>
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] Help with geocode() & get_map() please

2020-05-27 Thread Poling, William via R-sig-Geo
Hello:

#RStudio Version Version 1.2.1335 
sessionInfo() 
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows 10 x64 (build 17763)

library(ggmap)
library(sp)
library(rgdal)
library(rgeos)


I am trying to follow along with this stack-reference and recreate the 
recommended solution, then apply my data
https://gis.stackexchange.com/questions/133693/geographic-heatmaps-with-concentric-circles-by-distance?rq=1


I hope I have provided enough information below to reproduce or identify my 
errors.

Thank you for any assistance.

1. I am having trouble with geocode() 

nyc <- geocode("New York")
No such file or directory failed to load external entity 
"http://maps.google.com/maps/api/geocode/xml?address=New+York=false;
Error : 1: No such file or directory2: failed to load external entity 
"http://maps.google.com/maps/api/geocode/xml?address=New+York=false;
Error in .geocode(xx$place, oneRecord = oneRecord, extent = extent, progress = 
progress) : 
  object 'doc' not found


AND


2. I am having trouble with get_map()

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

Source : 
https://maps.googleapis.com/maps/api/staticmap?center=New%20York=8=640x640=2=terrain=en-EN=[012819-836529-634EA5]
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 

I have researched these errors and still do not seem to understand what I am 
doing wrong, or missing?

I have an API key and I believe I have initiated it correctly

I found this reference or a similar problem and followed the advice provided.
https://cran.r-project.org/web/packages/ggmap/ggmap.pdf


As suggested I went out to https://console.cloud.google.com/
and initiated suggested API's.

I manage to get through the next steps: 

#create the circles with gBuffer and then reproject them into WGS84 for ggmap.

# create spatialPoint object
coordinates(clus3) <- ~ lon + lat
proj4string(clus3) <- CRS("+init=epsg:4326")


# reproject to Google Mercator (meters)
clus3.mrc <- spTransform(clus3, CRS = CRS("+init=epsg:3857"))

# concentric rings (in miles):
dist.miles <-  seq(15, 25, 30)

# create a dataframe with the circle coordinates function
circ.df <- do.call(rbind,
   lapply(dist.miles, function(n) {
 circ <- gBuffer(clus3.mrc, width = n * 1609.344, 
quadsegs=20)
 circ.wgs <- spTransform(circ, CRS=CRS("+init=epsg:4326"))
 coords <- lapply(circ.wgs@polygons, function(x) 
{x@Polygons[[1]]@coords})
 data.frame(x=coords[[1]][,1], y=coords[[1]][,2], 
distance=n)
   }))

# text positions
text.pos <- cbind(aggregate( y ~ distance, data=circ.df, FUN=min), x=clus3$lon, 
row.names = NULL)


# fake a heatmap
set.seed(1)
xy2 <- data.frame(x=runif(100, -74.5, -73.5),y=runif(100, 40.2, 41.2))


But I can get no further at this point due to get_map():

# get basemap
#ny.map <- get_map("New York", zoom = 8) 
https://cran.r-project.org/web/packages/ggmap/ggmap.pdf
#Source : 
https://maps.googleapis.com/maps/api/staticmap?center=New%20York=8=640x640=2=terrain=en-EN=[012819-836529-634EA5]
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

I tried to use this in the plot below and of course it errors out --#Error: 
ggmap plots objects of class ggmap, see ?get_map
ny.map <- ggplot2::map_data("state", region = c('new york', 'new jersey'))

ny.map <- get_map("state", region = c('new york', 'new jersey'))
#ERROR:
Source : 
https://maps.googleapis.com/maps/api/staticmap?center=state=10=640x640=2=terrain=en-EN=[012819-836529-634EA5]
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

# ny.map <- map('state', region = c('new york', 'new jersey'),
# xlim=c(-74.12,-73.85), ylim=c(40.58,40.87)) 


# plot
ggmap(ny.map) + 
  stat_density2d(data=xy2, mapping=aes(x=x, y=y, fill=..level..), 
geom="polygon", alpha=0.2) +
  scale_fill_gradient(low = "blue", high = "red") +
  geom_path(data=circ.df, aes(x=x, y=y, group=distance), alpha=0.5) +
  geom_text(data=text.pos, aes(x=x, y=y, label=paste0(distance,"mi")))
#Error: ggmap plots objects of class ggmap, see ?get_map


#Here is the dataset I would like to use in the solution provided by this 
reference
https://gis.stackexchange.com/questions/133693/geographic-heatmaps-with-concentric-circles-by-distance?rq=1

dput(clus3)
new("SpatialPointsDataFrame", data = structure(list(ID = c(3L, 
57L, 87L, 141L, 173L, 286L, 287L, 335L, 553L, 574L, 598L, 634L, 
653L, 661L, 676L, 683L, 684L, 687L, 732L, 742L, 753L, 779L, 785L, 
793L, 798L,