A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs ›...
Transcript of A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs ›...
![Page 1: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/1.jpg)
A Process and Environment for Embedding The R Software into
TerraLib
Pedro Ribeiro de Andrade NetoPaulo Justiniano Ribeiro Junior
GeoInfo 2005
![Page 2: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/2.jpg)
Outline
● Introduction● Related Works● aRT● Process for Integration● Conclusions
![Page 3: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/3.jpg)
TerraLib● Library for building customized GIS● For programmers● Needs specialized statistics analysis
DBMS
TerraLib
Jfddfjh gfsdfgdfssf fsdf fsdfsd sdfsdfJfddfjh gfsdfgdfssf fsdf fsdfsd sdfsdf
Jfddfjh gfsdfgdfssf fsdf fsdfsd sdfsdf
![Page 4: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/4.jpg)
R Project for Statistical Computing
● Free software
● Point pattern analysis: spatstat, splancs● Geostatistics: gstat, geoR, geoRglm● Areal data analysis: DCluster, spdep
● 32 packages currently available in the Spatial Task View on the CRAN repository
● Shared library (.dll, .so)
![Page 5: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/5.jpg)
Integration
● Coupling R inside TerraLib● Can benefit from specialized spatial statistical methods:
● Point pattern analysis● Geostatistics● Areal data analysis
![Page 6: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/6.jpg)
Objective
Propose an efficient way to incorporate R analysis scripts into TerraLib
● Use R as an evolving library for building personalized TerraLib based GIS
● Meet the needs of three agents:● Statisticians● TerraLib users (programmers)● GIS users
![Page 7: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/7.jpg)
Related Works for R Users
R packages to access GIS data/functionalities:● GRASS (Bivand and Netler 2000)● RArcInfo (Gómes-Rubio 2005)● rgdal (Keith and Bivand 2004)● aRT (Andrade Neto et. al. 2005)
Problem:● They require R knowledge, and then the target is statisticians/R users
![Page 8: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/8.jpg)
Example of an R Scriptconn = openConn(user="pedro")db = openDb(conn, "dbname")thpoints = openTheme(db, "themepoints")thborder = openTheme(db, "themeborder")
points = getPoints(thpoints)border = getPolygons(thborder)data = getData(thpoints)
raster = krige(points, border, data)
l = createLayer(db, "lraster")addRaster(l, raster)thraster = createTheme(l, "themeraster")
![Page 9: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/9.jpg)
Related Works for GIS UsersGraphic interfacesto R:● Ono et. al. 2003● Tait et. al. 2004
Problems:● They describe the functionality, but not the proccess to aggregate new functionalities● They exchange information with R using files
![Page 10: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/10.jpg)
Related Works for GIS Programmers
No works...
![Page 11: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/11.jpg)
The aRT package: R-TerraLib API
● R package that can connect toTerraLib databases
● Scripts for statistical analysisof data
● Rule for aRT scripts: all datausing database
![Page 12: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/12.jpg)
aRT scriptconn = openConn(user="pedro")db = openDb(conn, "dbname")thpoints = openTheme(db, "themepoints")thborder = openTheme(db, "themeborder")
points = getPoints(thpoints)border = getPolygons(thborder)data = getData(thpoints)
raster = krige(points, border, data)
l = createLayer(db, "lraster")addRaster(l, raster)thraster = createTheme(l, "themeraster")
![Page 13: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/13.jpg)
aRT results
![Page 14: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/14.jpg)
How to integrate
● Option 1Execute R from the GIS and run the entire scriptProblem: two connections to the database, and after
that the GIS must reconnect to read metadata
● Option 2Use aRT internal functions to read from the
database and build R objects to be usedProblem: TerraLib programmers must know R and
aRT internally.
![Page 15: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/15.jpg)
TeDatabase*
How to integrate: Option 3
● Share a database connection (TeDatabase)● Require little changes in the original script
![Page 16: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/16.jpg)
Example of an aRT Scriptconn = openConn(user="pedro")db = openDb(conn, "dbname")thpoints = openTheme(db, "themepoints")thborder = openTheme(db, "themeborder")
points = getPoints(thpoints)border = getPolygons(thborder)data = getData(thpoints)
raster = krige(points, border, data)
l = createLayer(db, "lraster")addRaster(l, raster)thraster = createTheme(l, "themeraster")
![Page 17: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/17.jpg)
Wrapping an R codetlKriege = function(db, tpointsname, tcontourname, lrastername, trastername){ thpoints = openTheme(db, tpointsname) thborder = openTheme(db, tbordername)
points = getPoints(thpoints) border = getPolygons(thborder) data = getData(thpoints)
raster = krige(points, border, data)
l = createLayer(db, lrastername) addRaster(l,raster) thraster = createTheme(l, trastername) return(invisible())}
![Page 18: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/18.jpg)
TeRwrapper
● Uses MyR library● Operations:
● Initialize the environment● Declare a TeDatabase● Execute an R command
![Page 19: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/19.jpg)
TerraLib code
TeDatabase* db; char* str;TeRwrapper* Rwrapper; string error;...Rwrapper = new TeRwrapper();Rwrapper->declareDatabase(db, "db");asprintf(&str, "tlKrige(db,%s,%s,%s,%s)", themepoints.c_str(), themeborder.c_str(), layerraster.c_str(), themeraster.c_str());error = Rwrapper->execute(str);if(error != "") ...
OnPaint();
![Page 20: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/20.jpg)
Integration Diagram
![Page 21: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/21.jpg)
Results
Note that aRT alone could do that, but the focus now is how to use this functionality without any R knowledge.
![Page 22: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/22.jpg)
Conclusions
● Powerful analysis environment for statistics professionals● Follows TerraLib project purposes● Enables each agent to focus on his/her environment and skills
![Page 23: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/23.jpg)
Future Work
● TerraCitrus, developing friendly interfaces● Define a language for documentation of the functions, and try to generate part of the graphic interface for the programmers● Ideas??
![Page 24: A Process and Environment for Embedding The R Software ... › ~pedro › aRT › docs › ProccessAndEnvironment.pdf · R Project for Statistical Computing Free software Point pattern](https://reader033.fdocuments.net/reader033/viewer/2022060423/5f1940aabc9ca82ef713b0e6/html5/thumbnails/24.jpg)
A Process and Environment for Embedding The R Software into
TerraLib
Pedro Ribeiro de Andrade NetoPaulo Justiniano Ribeiro Junior
GeoInfo 2005