Received date: December 28, 2016; Accepted date: January 02, 2017; Published date: January 04, 2017
Citation: Pritee K, Garg RD (2017) Interfacing Grass-GIS and R: Road Descriptive Statistical Representation based on Slope. J Remote Sensing& GIS 6:188. doi: 10.4172/2469-4134.1000188
Copyright: © 2017 Pritee K, et al. This is an open-access article distributed under the terms of the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.
Visit for more related articles at Journal of Remote Sensing & GIS
As lots of GIS (Geographic Information systems) applications for statistical purposes are available in the market but still there is lots of demand of integration of GRASS-GIS i.e., Geographic Resources Analysis support GIS with the R statistical package. Many researchers always want to explore, analyse, complex analysis of spatial data with statistical problems and dealing with large areas in less amount of time and memory within individual software but this is not possible without integration. However, the integration of GRASS-GIS and R statistical package play a very important role to fulfil all needs related to computation, analyse, retrieve, image processing, graphics production and query spatial data. GRASS is open source software freely available, used for data management, analysis of geospatial data, spatial modelling with visualization whereas R (Open Source Package) enables all statistical environments with better quality plots providing linear or non-linear modelling, time series analysis with classification and clustering. In this paper, GRASS-GIS i.e., GIS subsystem act as a simple interface for R i.e., statistical computing subsystem for both raster and vector spatial data which provides commands to GRASS program via R system () function. Integration also enables all R plotting and analytical functions i.e., kriging prediction; kernel density pattern estimation etc. and proves very beneficial with the perception of research and educational purposes. It is also capable to provide introductory knowledge of both open software’s packages with their flexibility, robustness capability. This paper also introduces an example of classification of roads on the basis of slope via box plot representation by interfacing R in GRASS Environment.
R; Grass-GIS; GDAL libraries; Mapset Raster data of roads and slope
As the demand of open-source GIS has been increased, the integration of GIS and statistical data analysis i.e., code via Comprehensive R Archive Network (CRAN) is also increasing day by day. An example of Road statistical representation based on slope has been presented in this paper to enhance the implementation of R-Grass integration by linking two complex functions. Earlier S and S-PLUS code were available for integration with Grass-GIS for raster data values but in loose coupled form. Here this integration is performed in MS windows platform but could perform in Ubuntu or Linux in future work. The interface used there is based on statistical data analysis system working under Grass-GIS environment. The basic difference in Grass-GIS and R is that former uses file system i.e., raster and vector while later is used for mapping and static memory allocation via garbage collector. Both together prove very beneficial for statistical data analysis with better visualization of file system. Grass-GIS is basically responsible for spatial modelling, visualization, graphics production with data management and image processing of raster/vector data and also termed as project of the Open source Geospatial Foundation. Grass-GIS provides more than 350 functions and tools for map rendering, image monitoring with capability to manipulate, create, store raster/vector spatial data on a both window and command line graphical interface. It works based on Location/Mapset workgroup for enabling sharing over network via keeping location with a Mapsets on a central server. Grass supports libraries i.e., GDAL for raster data and OGR for vector data analysis. R is basically used for advanced Geostatistical, mathematical and Geospatial data analysis, computing and graphics that are not possible on Grass-GIS. R is responsible for data manipulation with effective handling and storage capability of operators with the help of different tools and effective and fully functional programming language having lots of loops, recursive functions with input and output facilities. R provides powerful flexibility in statistical analysis i.e., correlation, regression, multivariate, ANOVA, generalized linear and non-linear least squares, maximum likelihood etc. along with graphical analysis i.e., box-plot, scatter plot, histogram etc. It also supports functions operated on data structures having data types i.e., characters, factors, frames, matrices etc. (Figure 1).
The different examples from different literatures have been presented to explain the application of interfaces. An interface between Grass-GIS and R statistical package has been implemented to provide gridded output i.e., kernel density patterns, bicubic spline interpolation etc. with the help of constructed R code and wrapper functions packages for plotting . An example has been presented for illustrating graphics types and statistical outputs on the basis of quantile-quantile plots for nine elements from a geochemical survey used for accessing sample populations distributions using R statistical computing language and object oriented programming environment . A methodology for the GIS via Grass-GIS and statistics via R has been proposed in metamorphic analysis using different parameters i.e., hypsometry, slope, aspect, swath profiles, lineaments and drainage density, surface roughness, isobase and hydraulic gradient etc. and some open source tools for easy access from anywhere . An intermediate analytical environment has been developed using R, Grass-GIS 5 and some libraries i.e., GDAL for interpolating data into discretised continuous surfaces via sketching some spatial data analysis i.e., point pattern, continuous surface, areal/ lattice etc. [4-6]. A modular system using GrassGIS as GIS subsystem and R as statistical subsystem has been developed to achieve efficient statistical approaches i.e., linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, cluster analysis etc. and production of publication quality graphics with both mapping and statistics functions that forms application for geomorphic research .
Interface of statistical software i.e., R and GIS software i.e., Grass- GIS, Quantum GIS etc. has been discussed earlier for metamorphic analysis and many other analysis. R-Grass interface provides two functions i.e., first to run statistical functions according to R objects in memory space by transferring Grass data to R and after that transfer the result back to R and second to use R as a scripting language for Grass using execGRASS (). Here code has been written via R as a scripting language. First of all R has been installed on the MS windows i.e., windows 7. With the installation of R, many add-ons have been prebuilt and distributed via CRAN (The Comprehensive R Archive Network) network of mirrors. Then, number of packages and views has been installed under R for Grass-GIS6 functions using install.packages () and install.views () and update.views (). Many packages e.g., sp, maptools and rgdal has been installed for spgrass6 installation. There are many interface functions that has been used there for interfacing Grass-GIS and R. Interfacing has been done through R add-on packages i.e., the spgrass6 for R-Grass6 [8-10].
Following code has been written to perform this operation:
First packages required for R-grass interface has been installed directly from internet via function i.e., install.packages.
pkgs←c(‘akima’, ‘spgrass6’, ‘RODBC’,’VR’, ‘gstat’) in case of grass6 whereas in case of grass 7, spgrass6 is replaced by rgrass7.
install.packages (pkgs, dependencies=TRUE, type=’source’)
After that spatial task view has been installed via ctv and spatial packages i.e., install.packages (“ctv”) and install.views (“spatial”) respectively.
Installation can be checked with the help of library functions i.e., library ("ctv").
Here we have used Grass 6. After installing all packages, Grass interface has been created inside R and R-interface has been created inside Grass. So, in that case R can be called from Grass and Grass can be called from R. First of all, R has been called from Grass via providing full path to the R startup executable and changing “\” to “/” in the specified path.
GRASS 6.4>C:/Users/pritee/Documents/R/R3.1.2/bin/i386/R.exe R version 3.1.2...
After checking this interface, Grass has been called from R with the help of initGRASS () within the R package spgrass6 (). After initialization, GRASS commands can be called within R.
o c ← i n i t G R A S S ( “ C : \ \ P r o g r a m F i l e s \ \ GRASS 6.4”, home= tempdir()) or loc←initGRASS(gisBase=”C:\\Program Files\\GRASS 6.4”,
GRASS 6.4.4 (Spearfish60)>g.region –d GRASS6.4.4(Spearfish60)>R library (spgrass6)
Loading required package: sp
Loading required package: XML
GRASS GIS interface loaded with grass version: grass 6.4.4. (2014) and location: Spearfish60 Warning messages:
1: package ‘spgrass6’ was built under R version 3.1.2
2: package ‘sp’ was built under R version 3.1.2
3: package ‘XML’was built under R version 3.1.2
>execGRASS(“g.ml i s t , par ame te rs = l i s t ( type=”ve c t”, pattern=”precip*”))
>my_vmaps ←execGRASS(“g.mlist, parameters=list(type=”vect”, pattern=$))
Aspect, bugsites, density, elevation.10m, elevation.dem, elevation. dted, roads, slope, geology
>Roadsslpoe ←readRAST6(c(“roads”, “slope”), cat=c(TRUE, FALSE), ignore.stderr=TRUE,
>image(roadsslope, attr = 2, col = terrain.colors(20))
> title("Road slope") (Figure 2)
|primary highway, hard surface||829||1st Qu.: 5.386|
|secondary highway, hard surface||821||Median: 9.970|
|light-duty road, improved surface||4337||Mean: 11.528|
|unimproved road||4061||3rd Qu.:16.310|
Here, a box plot for different roads with variations in slope has been represented via quartiles. Box plot is basically a simple representation of numerical data graphically via quartiles. Here, some lines in box plots extending vertically outside the boundary of lower and upper quartiles is basically termed as whiskers and that’s why this diagram is also named as box and whisker plot diagram. The spacing between different parts of box is termed as spread or degree of dispersion. Box plots consist of lower hinge i.e., 25th percentile, upper hinge i.e., 75th percentile and 50th percentile. The bottom and top of box is called as first and third quartile respectively whereas the middle between these two quartiles is basically defined as a median or second quartile and difference or variation between first and third quartile is called as an interquartile range. Any additional data between whiskers has been represented via dot, small circle etc. The whiskers are generally represented by a formula (±1.58×IQR÷√n) but the length of upper and lower whiskers can be termed as 1.5×IQR×e3MC, 1.5×IQR×e-4MC if MC≥0 && 1.5×IQR×e4MC, 1.5×IQR×e-3MC if MC≤0 respectively.
Boxplot (roadsslope$slope ~ roadsslope$roads, medlwd = 1)
Geospatial data analysis via box plot representation via GRASS-GIS and R interface were explained in this article. With the study of this integration of Grass-GIS and R, popularization of open source software has been increased in the perspective of new research development related to road having different slope related information system. R directly supports non-spatial data but Integration with Grass-GIS is needed for spatial data because it is not possible for R directly to spend a large amount of time with programming routines especially for large areas i.e., road network that is quickly confronted with memory problems. It proves very efficient for statistical approaches in different fields i.e., terrain modelling environment, road classification according to slopes and publication based quality graphics. The combination of both open source tools i.e., Grass and R in one modular system proves very beneficial for researchers for using Grass-GIS capabilities with the strength of R in case of mapping, realistic sized statistics and spatial statistics problems. Grass-GIS database structure is basically best represented via indexing the site, line or polygon by R as data frames. Future work will be extension of geospatial analysis for reading data into R directly in binary form with raster and vector data that helps in coordination with other database integration packages in R-GRASS. Extension of graphical user interfaces so that both GRASS and R users can use command line interfaces simultaneously.