RCaller: Interpolate Points to Raster Through Kriging

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2020.0

Introduction

The RCaller transformer allows for much more statistical analysis than the StatisticsCalculator transformer. This example shows how the RCaller can be used to create a raster from points. Kriging, an interpolation method, is used to create an estimated surface from cell signal point data.

 

Requirements

Required R packages:

  • sqldf
  • geoR
  • sp
  • raster

As of FME 2019.0, you can output an R raster object directly from the RCaller for further use in FME, as shown in the example below. This scenario is ideal for users who want to conduct raster processing with R packages and then continue in an FME workflow. A similar result is technically also possible in earlier versions of FME, but you will not be able to directly output a raster object from RCaller. Instead, you have to write a temporary raster (using e.g. the raster package's writeRaster() function) and then read it back into the workspace using a FeatureReader and a file path attribute.

More information on installing R and R packages.
 

Source Data

Cell signal point data in CSV format.

 

Step-by-Step Instructions

1. Read source data
Read the DataPoints.csv using a CSV Reader, set the Coord. System to LL84. 
 
2. Reproject 
Reproject the data from lat/long (degree) to UTM83-10 (meter) using the Reprojector.
 
3. Extract coordinate values
The CoordinateExtractor transformer extracts the x and y coordinate values of the points and adds them as attributes named easting (x) and northing (y). Easting and northing will be used to create a map and for kriging in the RCaller.
 
4. Add RCaller and R script
Connect an RCaller to the CoordinateExtractor. In the parameters, set the Table to CellSignals then select Quality, easting, and northing as the Column set their types to float. 


The R script interpolates points with the Kriging method and creates a RasterLayer object using the raster package. Then the RasterLayer object is added to the fmeOutput data frame in a column called raster (i.e. fmeOutput$raster). For the R script, please specify the following:

# Read in the sp and geoR libraries
library(sp)
library(geoR)

# SpatialPointsDataFrame - create an object of class SpatialPointsDataFrame. 
map = SpatialPointsDataFrame(data=CellSignals, coords=cbind(CellSignals$easting,CellSignals$northing))

pred.grid <- expand.grid(
    seq(min(CellSignals$easting),max(CellSignals$easting),50),seq(min(CellSignals$northing),max(CellSignals$northing),50)
    )
    
# likfit, maximum likelihood (ML) or restricted maximum likelihood (REML) parameter estimation for (transformed) Gaussian random fields
ml=likfit(coords=coordinates(map), data=map$Quality, ini=c(10000,10000), nug=10)

# krige.conv performs spatial prediction for fixed covariance parameters using global neighbourhood
kc <- krige.conv(coords=coordinates(map), data=map$Quality, loc=pred.grid, krige=krige.control(obj.m=ml))

# Create raster using raster package
rasterdata <- cbind(pred.grid, kc$predict)
r <- rasterFromXYZ(rasterdata)

#Specify a value for the NoData cells
NAvalue(r) <- -999

# Put raster object into data.frame as column named raster for FME.
fmeOutput <- data.frame(matrix(ncol=1,nrow=1))
colnames(fmeOutput) <- c("raster")
fmeOutput$raster <- c(r)



Finally, for Attributes to Expose type in Raster. 



5. Reset the coordinate system
Add a CoordinateSystemSetter to the canvas and connect it to the Output port on the RCaller. In the parameters, reset the coordinate system to UTM83-10 which was lost in the RCaller.
 
6. View the result in Visual Preview
Add an Inspector to the CoordinateSystemSetter, then run the workspace. View the output in Visual Preview where you should have a raster of your data points. 

 

Data Attribution

The data used here originates from data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.