ropensci / rnoaa

R interface to many NOAA data APIs
https://docs.ropensci.org/rnoaa
Other
330 stars 84 forks source link

Is there a way to generate a bounding box co-ordiantes ? #255

Closed udayguntupalli closed 6 years ago

udayguntupalli commented 6 years ago
Session Info ```r R version 3.4.3 (2017-11-30) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200) Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] leaflet_1.1.0 lawn_0.4.2 ggmap_2.6.1 ggplot2_2.2.1 rnoaa_0.7.0 httr_1.3.1 xml2_1.1.1 [8] jsonlite_1.5 loaded via a namespace (and not attached): [1] purrr_0.2.4 reshape2_1.4.3 lattice_0.20-35 V8_1.5 colorspace_1.3-2 [6] htmltools_0.3.6 yaml_2.1.16 XML_3.98-1.9 rlang_0.1.6 pillar_1.0.1 [11] glue_1.2.0 rappdirs_0.3.1 sp_1.2-7 bindrcpp_0.2 jpeg_0.1-8 [16] bindr_0.1 plyr_1.8.4 stringr_1.2.0 munsell_0.4.3 gtable_0.2.0 [21] htmlwidgets_0.9 RgoogleMaps_1.4.1 mapproj_1.2-5 httpuv_1.3.5 crosstalk_1.0.0 [26] curl_3.1 hoardr_0.2.0 proto_1.0.0 Rcpp_0.12.14 xtable_1.8-2 [31] geosphere_1.5-7 scales_0.5.0 mime_0.5 gridExtra_2.3 rjson_0.2.15 [36] png_0.1-7 digest_0.6.13 stringi_1.1.6 dplyr_0.7.4 shiny_1.0.5 [41] grid_3.4.3 tools_3.4.3 magrittr_1.5 maps_3.2.0 lazyeval_0.2.1 [46] tibble_1.4.1 tidyr_0.7.2 pkgconfig_2.0.1 lubridate_1.7.1 assertthat_0.2.0 [51] R6_2.2.2 compiler_3.4.3 Lat <- 33.67 Lon <- -111.9 Rad <- 0.95 BBox <- ggmap::make_bbox(lon = Lon,lat = Lat,f = Rad) BBoxDF <- as.data.frame(BBox) ```

@sckott ,

I am following the tutorial you have kindly put together here (https://recology.info/2015/07/weather-data-with-rnoaa/) . I like the idea of scouring for available stations within a bounding box . However, it is not clear how the bounding box vertices were generated.

I looked around to come up with the code below :

Lat <- 33.67 

Lon <- -111.9

Rad <- 0.95 

BBox <- ggmap::make_bbox(lon = Lon,lat = Lat,f = Rad)

BBoxDF <- as.data.frame(BBox)

lawn_bbox_polygon(c(BBoxDF$BBox[1],BBoxDF$BBox[2],BBoxDF$BBox[3],BBoxDF$BBox[4])) %>% view

However, the fraction argument of the make_bbox function is unclear. Are you adapting a similar function ? If yes - can you provide an example on how to generate a bounding box within 10 miles radius of the input coordinates . Appreciate your guidance and help.

sckott commented 6 years ago

thanks for your question @udayguntupalli

what NOAA data do you want to get, because some of the data sources have ability to do that search for you

udayguntupalli commented 6 years ago

@sckott , I am primarily interested in the daily summaries, monthly summaries and precipitation data (both 15 minute and hourly)

sckott commented 6 years ago

from NCDC? (i.e., the rnoaa::ncdc functions)

udayguntupalli commented 6 years ago

@sckott , Yes . I am looking at this tutorial you put together. https://recology.info/2015/07/weather-data-with-rnoaa/.

Is there a better function or resource to pull out the data that is made available ?

Best Uday

udayguntupalli commented 6 years ago

@sckott , Is there a difference between isd_stations() vs rnoaa::ncdc ? It seems more prudent to have one function call to isd_stations() to retrieve a master list and then match by geocoding the desired station for a chosen latitude and longitude `AvailStations <- rnoaa::isd_stations()

USStations <- AvailStations[AvailStations$ctry == "US",]

` I am presuming - something like this provides me the list of all available weather stations in the NOAA dataset that are in USA .

sckott commented 6 years ago

so you can search for NCDC stations using extent param like ncdc_stations(extent=c(47.5204,-122.2047,47.6139,-122.1065))

but that doesn't answer the question of how to get a bounding box

sckott commented 6 years ago

The isd data is from an FTP server, while the ncdc functions pull from that API that you got a token for. So the data access is different. FTP is better for when you need A LOT of data.

There is some overlap between the two data sources I think, but I'm not sure on the details.

udayguntupalli commented 6 years ago

@sckott , I have learned to leverage your inbuilt functions like meteo_nearby_stations to avoid the need for a bounding box. So I am able to address this issue.

sckott commented 6 years ago

great, glad you sorted it out!

sckott commented 6 years ago

@udayguntupalli i've stared a little pkg to make it easier to get a bounding box https://github.com/ropensci/bbox if it helps at all