questions on spatial interpolation exercise(NL)
On 25-11-2014 21:41, Mengxi Yang wrote:
attached file is monv_201301.Please have a look.
Janurary has 31 days hence you need to adjust the number of rows in that
table:
> tmp <- readLines(paste(getwd(), "/", "monv_201301.txt", sep=""))
> tmp <- gsub(pattern=' . ', replacement=' 0.0 ', tmp, fixed = TRUE)
> tmp <- gsub(pattern='[[:space:]]{2,7}', replacement=',', tmp)
> tmp[8]
[1] "#
NR,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,I,NORM,II,NORM,III,NORM,MND,NORM"
> write.table(t(matrix(unlist(strsplit(tmp, ",")[-c(1:8)]), nrow=42)),
"tmp.txt", col.names=FALSE, row.names=FALSE)
> monv_201301 <- read.table("tmp.txt", col.names=c("empty1", "NR",
paste("D", 1:31, sep=""), "I", "NORM", "II", "NORM", "III", "NORM",
"MND", "NORM", "Locatie"))
> monv_201301$empty1 <- NULL
> monv_201301$Locatie <- as.factor(gsub(pattern='[[:space:]]+$',
replacement='', monv_201301$Locatie))
> str(monv_201301)
'data.frame': 325 obs. of 41 variables:
$ NR : int 760 458 680 572 89 664 678 560 910 441 ...
$ D1 : num 7.2 17.2 10 9.6 12 11.9 10.2 14.3 13.6 15.5 ...
$ D2 : num 0.4 2.8 4.7 2.7 3.2 4.5 3 2.8 0.8 3.2 ...
$ D3 : num 0.9 0.9 1.7 0.5 0.5 1.4 1 0.5 0.9 0.2 ...
...
From here on you can continue running the code from
http://spatial-analyst.net/wiki/index.php?title=Spatial_interpolation_exercises_(NL)
by the way, I want to do interpolation in different spatial resolution. I download the grid file from Worldclim project. But it is different from the exercise you provided. In the exercise, the prec6.asc is predicted long-term precipitation for June based on the Worldclim project page. could you please tell me how to do this?
You need to download some long term rainfall map (climatic) for January (I've used the one from http://worldclim.org/current) and then resample it to the Dutch projection system. I am sure if you search a bit you can find even more up-to-date maps of long term precipitation (climatic images) for Europe. all the best with your work, T. Hengl
Thanks very much.
On Mon, Nov 24, 2014 at 7:24 PM, Tomislav Hengl
<hengl at spatial-analyst.net <mailto:hengl at spatial-analyst.net>> wrote:
You need to provide access to "monv_201310.txt" so that we can see
what is the structure of that file. The original file with rainfall
data from that URL is simply a text file from the KNMI website
(without any tabular structure) so that e.g.:
...
write.table(t(matrix(unlist(__strsplit(tmp, ",")[-c(1:8)]),
nrow=41)), "tmp.txt", col.names=FALSE, row.names=FALSE)
...
monv_200906 <- read.table("tmp.txt", col.names=c("empty1", "NR",
paste("D", 1:30, sep=""), "I", "NORM", "II", "NORM", "III", "NORM",
"MND", "NORM", "Locatie"))
creates structure based on what is in the text object (hence I first
open the text file and then figure out the code to read the values).
Of course, the structure of the raw KNMI files could have changed
from 2009.
If you are planning to interpolate monthly rainfall data take also a
look at the two geostatistical packages that elaborate geostatistics
with skewed values / variables with skewed distributions (I have not
updated the
http://spatial-analyst.net/__wiki/index.php?title=Spatial___interpolation_exercises_(NL)
<http://spatial-analyst.net/wiki/index.php?title=Spatial_interpolation_exercises_(NL)>
pages for a long time; sorry for that):
http://cran.r-project.org/__package=georob
<http://cran.r-project.org/package=georob>
http://cran.r-project.org/__package=geostatsp
<http://cran.r-project.org/package=geostatsp>
described in -> http://pbrown.ca/geostatsp/__document-rev.pdf
<http://pbrown.ca/geostatsp/document-rev.pdf>
HTH,
T. Hengl
On 23-11-2014 23:51, Mengxi Yang wrote:
Dear list,
I have a question on write.table. I found an nice exercise on
spatial
interpolation from
http://spatial-analyst.net/__wiki/index.php?title=Spatial___interpolation_exercises_(NL)#__Spatial_prediction_of_daily___precipitation_in_the___Netherlands
<http://spatial-analyst.net/wiki/index.php?title=Spatial_interpolation_exercises_(NL)#Spatial_prediction_of_daily_precipitation_in_the_Netherlands>
In this exercise, the date is 200906. but when I change to
201310. there is
a wrong message like:
tmp <- readLines(paste(getwd(), "/", "monv_201310.txt", sep=""))
tmp <- gsub(pattern=' . ', replacement=' 0.0 ', tmp, fixed =
TRUE)
tmp <- gsub(pattern='[[:space:]]{2,7}__', replacement=',', tmp)
write.table(t(matrix(unlist(__strsplit(tmp, ",")[-c(1:8)]),
nrow=41)),
"tmp.txt", col.names=FALSE, row.names=FALSE)
Warning message:
In matrix(unlist(strsplit(tmp, ",")[-c(1:8)]), nrow = 41) :
data length [13625] is not a sub-multiple or multiple of the
number of
rows [41]
I checked several month, some success but some not.
Does anyone know what is the wrong with it? should I change
something?
Thank you very much.
Mengxi Yang
[[alternative HTML version deleted]]
_________________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org <mailto:R-sig-Geo at r-project.org>
https://stat.ethz.ch/mailman/__listinfo/r-sig-geo
<https://stat.ethz.ch/mailman/listinfo/r-sig-geo>