spatial interpolation error using idw

后端 未结 1 2043
遥遥无期
遥遥无期 2021-01-07 04:54

I am trying to spatially interpolate a dataset of seawater pH by lat & long:

sample<-read.csv(file=\"Station locations 2016.csv\", header=TRUE, sep=\         


        
相关标签:
1条回答
  • 2021-01-07 05:00
    library(gstat)
    library(sp)
    
    
    lat <-  c(-23.49174, -23.49179, -23.49182, -23.49183, -23.49185, -23.49187)
    long <- c(152.0718, 152.0718, 152.0717, 152.0717, 152.0717, 152.0717)
    pH <- c(8.222411, 8.19931, 8.140428, 8.100752, 8.068141, 8.048852)
    sample <- data.frame(lat, long, pH)
    
    
    x.range <- range(sample$long)
    y.range <- range(sample$lat)
    
    
    x<-seq(x.range[1], x.range[2], length.out=20)
    y<-seq(y.range[1], y.range[2], length.out=20)
    grd<-expand.grid(x,y)
    
    
    coordinates(sample) = ~long+lat
    coordinates(grd) <- ~ Var1+Var2
    gridded(grd) <- TRUE
    
    proj4string(sample) <- CRS("+proj=longlat +datum=WGS84")
    proj4string(grd) <- CRS("+proj=longlat +datum=WGS84")
    
    plot(grd, cex=1.5)
    

    dat.idw <- idw(formula=pH ~ 1, locations = sample, newdata = grd, idp = 2.0)
    #> [inverse distance weighted interpolation]
    
    plot(dat.idw)
    

    0 讨论(0)
提交回复
热议问题