HTTP error 400 on google_elevation() call
Update 14/03/2017
I've issued a fix to the development version so that google_elevation()
now accepts an encoded polyline as an argument. And it will also issue a warning if the URL length is greater than 8192 characters.
## install the development version
devtools::install_github("SymbolixAU/googleway")
library(googleway)
api_key <- "your_api_key"
map_key <- "your_map_key" ## for plotting the lines
pl1 <- "q{|aHknlv@n@Mt@IxAGb@B\\Eb@AZGRG^W`AyAPQF?NHDJFZBz@FVNPn@D`@C|@DjACv@@h@Dh@Ll@Zj@^\\`@fAx@j@r@d@n@\\ZJPNd@NbANzAFhANb@JNLHD?PKHMRGPSr@UPMXGDGJELMFCPAbBWROpAm@h@YZe@dAaC@Of@aAb@a@t@iALg@LWNQROf@IjAJnFbAv@Dr@Aj@BpBx@fFdCd@HlAHd@Pp@b@|@d@~@j@n@R~@n@\\NTCXBNEZCZKbB]rAKpDK~BO\\?NCd@?`DMz@SLO`@URCR@XLRRRVHd@NXNP\\RXf@JHXN\\Xn@ZD@Z?\\NvArA~BxA"
pl2 <- "uipaHmmcv@iBoFm@{AKQy@}B}AoDyA_CASEMGKKI]y@i@y@EOi@q@kAw@KEMAu@M]?[@WDkAZiB~@]H_@PUF]TUL_@XkAn@}CzAyAx@e@P_@JSNGROPa@Fu@[UOc@IOAu@_@WIUMIIWGu@]YEk@SoBiAc@_@gAeAg@{@]mAMq@YmBA]Oq@YuBKYUg@UQa@QiAOI@QIm@EiA[w@BSFYZ_@h@]t@o@bAOb@}@zAWn@_@jAGf@SbAKbAKXSpAS`@ICa@FSHICQ@gAHq@KSAa@I[CQ@k@KOGMKYg@aBkEs@u@k@g@_@a@{@o@W]IAYQYAsDIODc@LW\\GRKn@Ch@WtAO`BCzAIj@Wh@SRc@NS@a@KaAg@kCgAm@]iBo@w@_@UQc@S}@Ww@e@MCa@Sm@Sk@WYI{@g@IIMAMIIIm@QuBaAIGu@_@SQiAqA_AmASSYIUEqAKQBm@Im@Qe@i@k@UQBSCe@NO?[FKFYBSH_ADa@GQIw@OOSKF[b@M@gAl@i@b@{@b@OLwAj@KLWRI@yBvAuAd@m@F_@@qAEk@Kc@Oi@_@_@e@oAeBc@u@SSi@]i@We@Im@Q}@k@w@_@i@a@w@a@SQ[Qy@OeCSUGg@WSOa@e@W]MK_@i@CMMWIEMWa@m@[QEIICK@QHUTe@n@ELKFa@l@u@t@WNYLYXO?IBGHc@Tc@Ja@@{@Q{@]s@a@kBq@YOcAYs@IU?_@NU@GAu@^a@LSPg@X]^YJc@h@]PKHI@w@n@]h@AXEJMTCZc@|AS`@OVg@j@_Av@{@bA"
df_elevation <- google_elevation(polyline = pl2, key = api_key)
head(df_elevation$results)
# elevation location.lat location.lng resolution
# 1 418.8341 47.60235 9.03399 19.0879
# 2 420.8099 47.60288 9.03519 19.0879
# 3 421.0847 47.60311 9.03565 19.0879
# 4 421.1900 47.60317 9.03574 19.0879
# 5 422.5887 47.60346 9.03637 19.0879
# 6 445.3051 47.60393 9.03725 19.0879
And seeing as we're on the development version we can plot the lines on a google map
df <- data.frame(pl = c(pl1, pl2))
google_map(key = map_key) %>%
add_polylines(data = df, polyline = "pl")
Old answer
You have inadvertently found the limits of the amount of data you can pass into the API
The Google API documentation says
You may pass any number of multiple coordinates within an array or encoded polyline, as long as you don't exceed the service quotas, while still constructing a valid URL
So it seems you've found that limit.
If you reduce the amount of lat/lons you send from the second polyline you get results returned. In your example, the limit is 239 pairs of coordinates.
# head(google_elevation(decode_pl(pl2)[1:239,], key=gmap_key)$results)
# elevation location.lat location.lng resolution
# 1 418.8218 47.60235 9.033990 19.0879
# 2 420.8087 47.60288 9.035190 19.0879
# 3 421.0829 47.60311 9.035649 19.0879
# 4 421.1866 47.60317 9.035740 19.0879
# 5 422.5816 47.60346 9.036369 19.0879
# 6 445.2881 47.60393 9.037250 19.0879
google_elevation(decode_pl(pl2)[1:240,], key=gmap_key)
# Error in open.connection(con, "rb") : HTTP error 400.
I've filed this as an issue so that in the next update this will be handled with either a more helpful error, or it will automatically break up the data.frame
.
For now the solution will be to decode the polylines first, then find the elevation on subsets of the data.frame at a time.
I've gone back to the Google Elevation API documentaition and it appears you can also send an encoded polyline to the API; if you can wait a few days I'll issue a fix to the development version so you can send the polyline directly
disclaimer: I'm the googleway author
simpleError in get_soils_raster(...): http error 400
get_soils_raster
is an internal-only function - you can view it by using :::
instead of ::
, or visit the github repo.
The issue you're having appears to be with the underlying service itself though, not the wrapper code - you can tell because the same request sometimes works and sometimes does not, so the issue is not a malformed request as the error code might suggest. I can replicate the inconsistent behaviour and I'll follow up with the service provider. I note that there've been some major internet outages in Aus within the last 24 hours, so this may resolve itself.
In the meantime, you may wish to try an alternative API endpoint available at http://www.asris.csiro.au/ASRISApi#!/SLGA32Services/SLGA_DrillSLGA. I haven't built it into slga
yet - I'm still using the WCS services for my point queries.
Error quests for Google Map Elevation API
Error fixed by reducing the number of locations in a request and setting system pause for request error. Though it costs some time, it's fine for my case. For guy who have millions of GPS points, I think it's still a problem...
rentrez error HTTP failure: 400 when downloading 1/3 of records
It turns out rentrez uses 0-base counting. So the 552 records correspond to retstart
values of 0 to 551. Since my code was looking for values 1 to 552 it missed the first record (#0) and then threw an error when it looked for the non-existent record #552.
Replacing every second comma in the string in R
You can do this with gsub
and a regular expression.
string = "30.538358,-96.692008,30.538602,-96.691741,30.539737,-96.690322"
gsub("([^,]+,[^,]+),", "\\1|", string)
"30.538358,-96.692008|30.538602,-96.691741|30.539737,-96.690322"
On Button Click, Confirm and Delete
You cam use:
HTML:
<input type="chekbox" name="check_files[]" value="unique_file_id1"/>
<input type="chekbox" name="check_files[]" value="unique_file_id2"/>
PHP:
if (!emptY($_POST['check_files'])) {
foreach ($_POST['check_files'] as $checked_file) {
if(file_exists("path" . $checked_file))) {
unlink("path" . $checked_file);
}
//other logic
}
}
Related Topics
Grouped Bar Graph Custom Colours
Puzzled by Xlim/Ylim Behavior in R
Create a New Column with Non-Null Columns' Names
Empty Output When Reading a CSV File into Rstudio Using Sparkr
Removing Everything After First 'Backslash' in a String
Selecting Unique Rows in Matrix Using R
Using Predict() and Table() in R
How to Configure R-3.0.1 with --Enable-R-Shlib
Backports 1.1.1 Package Fails to Install
How to Merge Two Data Frame Based on Partial String Match with R
Use 'J' to Select the Join Column of 'X' and All Its Non-Join Columns
How to Pop Up the Graphics Window from Rscript
Ggplot Scale_X_Continuous with Symbol: Make Bold
Cannot Install Stringi Since Xcode Command Line Tools Update
Generating a Date from a String with a 'Month-Year' Format
Efficient Way to Fill Time-Series Per Group
How to Drop Factor Levels While Scraping Data Off Us Census HTML Site