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