[R-sig-Geo] rainfall interpolation using ANN

Nahm Lee nlee at valleywater.org
Mon Dec 1 19:31:54 CET 2014


This is my example with idw based on a web site, # http://www.geo.ut.ee/aasa/LOOM02331/R_idw_interpolation.html.

Nahm Lee
nlee at valleywater.org<mailto:nlee at valleywater.org>



# http://www.geo.ut.ee/aasa/LOOM02331/R_idw_interpolation.html

library(ggplot2)
library(gstat)
library(sp)
library(maptools)
library(rgeos)

setwd("C:/Users/Michael/Dropbox/R/SHP")

AlertRain <- read.csv(file = "AlertRain.csv",header = TRUE)

names(AlertRain)

AlertRain_test <- AlertRain   # duplicate air temp. data file
AlertRain$x <- AlertRain$longitude  # define x & y as longitude and latitude
AlertRain$y <- AlertRain$latitude

# Set spatial coordinates to create a Spatial object:
coordinates(AlertRain_test) = ~x + y

plot(AlertRain_test)

# Define the grid extent:
#x.range <- as.numeric(c(21.76, 28.21))  # min/max longitude of the interpolation area
#y.range <- as.numeric(c(57.45, 59.72))  # min/max latitude of the interpolation area

x.range <- c(min(round(AlertRain_test$x,2)-0.1),max(round(AlertRain_test$x,2)+0.1))
y.range <- c(min(round(AlertRain_test$y,2)-0.1),max(round(AlertRain_test$y,2)+0.1))

# Create a data frame from all combinations of the supplied vectors or factors.
# See the description of the return value for precise details of the way this is done.
# Set spatial coordinates to create a Spatial object. Assign gridded structure:
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 the weather station locations and interpolation grid:
plot(grd, cex = 1.5, col = "grey")
points(AlertRain_test, pch = 1, col = "red", cex = 1)

# interpolate surface and fix the output:

idw <- idw(formula = Elevation ~ 1, locations = AlertRain_test,
    newdata = grd)  # apply idw model for the data
## [inverse distance weighted interpolation]

idw.output = as.data.frame(idw)  # output is defined as a data table
names(idw.output)[1:3] <- c("long", "lat", "var1.pred")  # give names to the modelled variables

#Plot the results:

ggplot() + geom_tile(data = idw.output, aes(x = long, y = lat, fill = var1.pred)) + scale_fill_gradient(low = "cyan", high = "orange")+
    geom_point(data = AlertRain, aes(x = longitude, y = latitude), shape = 21,
        colour = "red")+labs(title = "Elevation by rainfall station elevation")



From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Mengxi Yang
Sent: Monday, December 01, 2014 1:32 AM
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] rainfall interpolation using ANN

Dear list,
I am going to do daily rainfall interpolation using ANN. but I am not familiar with it. Can somebody give some advise or example?

my data like:
 I have 325 stations in different location.each station have unique code and coordinates. And I want to interpolate in 1km resolution. I have the mask map of NL.
[Inline image 2]

can someone give me some advice? because I want to compare ANN with Kriging and IDW.
Thank you very much.

Mengxi Yang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20141201/12a09645/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 14586 bytes
Desc: image001.png
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20141201/12a09645/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AlertRain.csv
Type: application/octet-stream
Size: 2304 bytes
Desc: AlertRain.csv
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20141201/12a09645/attachment.obj>


More information about the R-sig-Geo mailing list