daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(raster)
  2. library(leaflet)
  3.  
  4. ph <- getData("GADM", country = "PHL", level = 1)
  5.  
  6. leaflet(data = ph) %>%
  7.   addProviderTiles("OpenWeatherMap.Precipitation") %>%
  8.   addPolygons(fillColor = "red",
  9.               fillOpacity = 1,
  10.               color = "#FFFFFF",
  11.               weight = 1.3)
  12.    
  13. library(mapview)
  14. m <- mapview(ph, map.types = "OpenWeatherMap.Precipitation")
  15. m
  16.    
  17. library(rgdal)
  18. library(RCurl)
  19. library(httr)
  20. library(jsonlite)
  21. library(leaflet)
  22. library(mapview)
  23. library(owmr)
  24. library(raster)
  25. library(RColorBrewer)
  26. setwd("D:/Works/Fernando/CRS/R/shapes/")
  27. getwd()
  28. file.exists(".","contorno.shp")
  29. ph <- raster::getData('worldclim',var='tmin',res=0.5, lon=-86.921641,lat=14.761664)
  30. pais<-rgdal::readOGR(dsn=getwd(),layer="contorno")
  31. zona<-rgdal::readOGR(dsn=getwd(),layer="La_Paz_Valle")
  32. #newproj <- "+proj=longlat +datum=WGS84"
  33. crs(ph$tmin1_23)
  34. crs(pais)
  35. prj<-"+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"
  36. pais2<-spTransform(pais,crs(prj))
  37. zona2<-spTransform(zona,crs(prj))
  38. crs(pais2)
  39. cp<-crop(ph$tmin1_23,pais2)
  40. s<-stack(ph$tmin1_23)
  41. coors<-read.csv("sequia.csv")
  42. coords<-data.frame(lon=coors$LONGITUDE, lat=coors$LATITUDE)
  43. coordinates(coords)<-c("lon","lat")
  44. val<-extract(x=ph$tmin1_23, y=coords)
  45. #proj4string(xy) <- CRS(prj)  ## for example
  46. #sfc<-st_sfc(xy,prj)
  47. #xy<-data.frame(x=coors$LONGITUDE,Y=coors$LATITUDE)
  48. #require(sf)
  49. #res<-SpatialPoints(cbind(coors$LONGITUDE, -coors$LATITUDE), proj4string=CRS("+proj=longlat"))
  50. #as(res,"SpatialPoints")
  51. #rasValue<-lapply(ph$tmin1_23,extract, res)
  52. colores <- c('red', 'green', 'blue', 'chocolate', 'deeppink', 'grey')
  53. at <- seq(0, 4800, 800)
  54. cb <- colorBin(palette = colores, bins = at, domain = at)
  55. m<-leaflet() %>%
  56.   addTiles()%>%
  57.   addRasterImage(cp,opacity = 0.8)%>%
  58.   addLegend(pal = cb, values = at)%>%
  59.   addPolygons(data = zona2,fillColor = "#ff0000",opacity = 0.1)
  60. m<-addMarkers(m,lng=coors$LONGITUDE,lat=coors$LATITUDE,popup=paste("Region:",coors$Municipality,"<br>",
  61.                                                                    "Precipitacion:","<br>",
  62.                                                                    val,"mm/mes"))
  63. #m<-addMarkers(m,lng=-87.8333,lat = 14.1167,popup=paste("Guajiquiro","prec:",val,sep = " "))
  64. #m<-addMarkers(m,lng = -87.7,lat = 13.9667,popup="San Juan")
  65. #m<-addMarkers(m,lng = -87.95,lat = 14.0667,popup = "Santa Ana")
  66. #m<-addMarkers(m,lng = -87.5333,lat = 13.65,popup = "San Francisco de Coray")
  67. #m<-addMarkers(m,lng = -87.6525,lat = 13.62083,popup = "Langue")
  68. #m<-addMarkers(m,lng = -87.7167,lat = 13.7333,popup = "Aramecina")
  69. #m %>% mapview(ph, map.types = "OpenWeatherMap.Precipitation")
  70. m
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top