Advertisement
Guest User

Untitled

a guest
Jul 15th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. library(ggplot2)
  2. library(gstat)
  3. library(sp)
  4. library(maptools)
  5. library(rgdal)
  6. library(zoo)
  7. library(xts)
  8. library(RPostgreSQL)
  9. library(spacetime)
  10. library(raster)
  11. library(foreign)
  12. dbname = "postgis"
  13. user = "postgres"
  14. password = "***"
  15. #password = ""
  16.  
  17. drv <- dbDriver("PostgreSQL")
  18. con <- dbConnect(drv, dbname="BDDMeteo", user=user, password="***",host='localhost', port='5432')
  19. estonia_air_temperature_2=dbGetQuery(con,"select lat,lon,temperature from observation, station, date where id_s=nom_ville AND id_d=id_date")
  20.  
  21. estonia_air_temperature_2_test <- estonia_air_temperature_2 # duplicate air temp. data file
  22. estonia_air_temperature_2_test$x <- estonia_air_temperature_2_test$lon # define x & y as longitude and latitude
  23. estonia_air_temperature_2_test$y <- estonia_air_temperature_2_test$lat
  24. coordinates(estonia_air_temperature_2_test) = ~x + y
  25.  
  26. plot(estonia_air_temperature_2_test)
  27. x.range <- as.numeric(c(-8.5, 9.5)) # min/max longitude of the interpolation area
  28. y.range <- as.numeric(c(26.97, 37)) # min/max latitude of the interpolation area
  29. grd <- expand.grid(x = seq(from = x.range[1], to = x.range[2], by = 0.1), y = seq(from = y.range[1],
  30. to = y.range[2], by = 0.1)) # expand points to grid
  31. coordinates(grd) <- ~x + y
  32. gridded(grd) <- TRUE
  33. plot(grd, cex = 1.5, col = "grey")
  34. points(estonia_air_temperature_2_test, pch = 1, col = "red", cex = 0.4)
  35.  
  36. idw <- idw(formula = temperature ~ 1, locations = estonia_air_temperature_2_test,
  37. newdata = grd) # apply idw model for the data
  38. residual_grid = raster(idw, "var1.pred")
  39. plot(residual_grid)
  40. x <- rasterToContour(residual_grid)
  41. class(x)
  42. plot(residual_grid)
  43. plot(x, add=TRUE)
  44. writeSpatialShape(x, "/interpolate/contour/contourline")
  45.  
  46. > ogrDrivers()
  47. name write
  48. 1 AeronavFAA FALSE
  49. 2 ARCGEN FALSE
  50. 3 AVCBin FALSE
  51. 4 AVCE00 FALSE
  52. 5 BNA TRUE
  53. 6 CSV TRUE
  54. 7 DGN TRUE
  55. 8 DXF TRUE
  56. 9 EDIGEO FALSE
  57. 10 ESRI Shapefile TRUE
  58. 11 Geoconcept TRUE
  59. 12 GeoJSON TRUE
  60. 13 Geomedia FALSE
  61. 14 GeoRSS TRUE
  62. 15 GML TRUE
  63. 16 GMT TRUE
  64. 17 GPSBabel TRUE
  65. 18 GPSTrackMaker TRUE
  66. 19 GPX TRUE
  67. 20 HTF FALSE
  68. 21 Idrisi FALSE
  69. 22 KML TRUE
  70. 23 MapInfo File TRUE
  71. 24 Memory TRUE
  72. 25 MSSQLSpatial TRUE
  73. 26 ODBC TRUE
  74. 27 ODS TRUE
  75. 28 OpenAir FALSE
  76. 29 OpenFileGDB FALSE
  77. 30 PCIDSK TRUE
  78. 31 PDF TRUE
  79. 32 PDS FALSE
  80. 33 PGDump TRUE
  81. 34 PGeo FALSE
  82. 35 REC FALSE
  83. 36 S57 TRUE
  84. 37 SDTS FALSE
  85. 38 SEGUKOOA FALSE
  86. 39 SEGY FALSE
  87. 40 SUA FALSE
  88. 41 SVG FALSE
  89. 42 SXF FALSE
  90. 43 TIGER TRUE
  91. 44 UK .NTF FALSE
  92. 45 VRT FALSE
  93. 46 Walk FALSE
  94. 47 WAsP TRUE
  95. 48 XLSX TRUE
  96. 49 XPlane FALSE
  97.  
  98. #R code assumes library(rgdal)
  99. writeOGR(x, "PG:dbname='BDDMeteo' user=user password="zina",host='localhost', port='5432' ", layer_options = "geometry_name=geom",
  100. "newtablename", "PostgreSQL")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement