library(jsonlite) library(httr) devtools::load_all() source("secrets") # Create a Bearer token header headersLIM <- add_headers( accept = "*/*", apikey = token2 ) headersPaquet <- add_headers( accept = "*/*", apikey = yearTokenPaquer ) # Test the function with dates and station ID start_date <- as.Date("2024-03-24") end_date <- as.Date("2024-08-14") station_id <- "38269004" allstations=getStations(headersLIM) allstations=read.csv("allstations.csv") #write.csv(file="allstations.csv",allstation,row.names=F) lacouch=c(45.3722971,5.6387118) alldist=dist(rbind(lacouch,cbind(allstations$Latitude,allstations$Longitude))) staupre=allstation$Id_station[which.min(as.matrix(alldist)[1,-1])] lamure=38269004 allmure=getStationData(start_date="2024-06-24",end_date="2024-08-14",station_id=lamure,headers=headersLIM) alllavaldens=getStationData(start_date="2024-06-24",end_date="2024-08-14",station_id=38207001,headers=headersLIM) paquetLamure=getStationPaquet(id_station=lamure) allcouch=getStationData(start_date="2024-06-24",end_date="2024-08-14",station_id=staupre,headers=headersLIM) allal=getStationData(start_date="2024-01-24",end_date="2024-08-13",station_id=staupre,headers=headersLIM) plot(getDate(alllavaldens[,2]),alllavaldens[,3],lwd=3,type="l",col="red") plot(getDate(allmure[,2]),allmure[,3],pch=20,type="o",col="blue",ylab="preciptitation (mm)",main="La Mure/Lavalends",ylim=range(c(alllavaldens[,3],allmure[,3]),na.rm=T),cex=2) points(getDate(alllavaldens[,2]),alllavaldens[,3],pch=20,col="red",cex=2,type="o") points(getDate(allcouch[,2]),allcouch[,3],pch=20,col="green",cex=2,type="o") legend("topleft",col=c("blue","red","green"),legend=c("La Mure","Lavaldens","St Aupre"),cex=2,pch=20) plot(allmure[,3],alllavaldens[,3],col="red") library(httr) # Token to be included in the Authorization header (example token placeholder) df <- getStations() plot(df$Longitude,df$Latitude,xlim=c(-5.1,9.6),ylim=c(41.2,51.1),pch=21) # La Mure coordinates (latitude and longitude) la_mure_latitude <- 44.9167 la_mure_longitude <- 5.8000 # Define the bounding box for the region around La Mure in Isère # Adjust these values as needed to capture the desired area lat_min <- 44.5 lat_max <- 45.5 lon_min <- 5.4 lon_max <- 6.2 # Filter data for the region around La Mure df_la_mure <- df[df$Latitude >= lat_min & df$Latitude <= lat_max & df$Longitude >= lon_min & df$Longitude <= lon_max,] # Plot Latitude and Longitude for the region around La Mure plot(df_la_mure$Longitude, df_la_mure$Latitude, main = "Region around La Mure, Isère, France Plot", xlab = "Longitude", ylab = "Latitude") text(df_la_mure$Longitude, df_la_mure$Latitude,labels=df_la_mure$Nom_usuel,pos=3) text(df_la_mure$Longitude, df_la_mure$Latitude,labels=df_la_mure$Id_station,pos=1) library(ggmap) ggmap::register_google(key="AIzaSyBF0l8LHg5kBQInFgR9sD65H1ek0qvn2Yw") # Geocode La Salle en Beaumont using the Google Maps API location <- "La Salle en Beaumont, France" la_salle_geocode <- geocode(location) # Print the latitude and longitude of La Salle en Beaumont print(la_salle_geocode) library(osmdata) # Geocode La Salle en Beaumont using OpenStreetMap location <- "La Salle en Beaumont, France" la_salle_geocode <- osm_geocode(location) # Print the latitude and longitude of La Salle en Beaumont print(la_salle_geocode) library(tmap) datetime_obj <- as.POSIXlt(as.character(allmure[,2]), format = "%Y%m%d%H%M") datetime_obj <- as.POSIXlt(as.character(alllavaldens[,2]), format = "%Y%m%d%H%M") # Create the date object using the format argument plot(datetime_obj,alllavaldens[,3],lwd=2,type="l",col=2) # Print the date object # Convert temperature from Kelvin to Celsius temperature_celsius <- temperature_kelvin - 273.15 location <- "La Couchonnier, Saint Etienne de Crossey, France" couch <- geocode(location) couch <- osm_geocode(location) # Print the latitude and longitude of La Salle en Beaumont print(la_salle_geocode) 45.3722971,5.6387118