Friday, April 20, 2012

Using R in Qgis - ManageR - Basic Functions

My objective is to do raster analysis on qgis of rasters representing the same forested area and the different land use types at differing resolutions.  There does not seem to be any way of doing this directly in QGIS and the best suggested method seems to be through R, An open source data manipulation and representation software. QGIS interfaces with R via a plugin called manageR developed by Peter Carson.

The interface is not very useful in itself... I can now import a raster to the interface after installing the sp and rgdal packages. I would now like to get an analysis of the different values of the raster. An idea of the relative values of the raster, be it via a count, a histogram, a percentage. I have tried the various menus and not much seems to appear. I have the name of the raster visible in the  workspace manager window.

It is possible to export the variables of the band as a table *csv and html by right clicking on the band. The resultant table does not however provide me with much information that I find useful.

Ok so after a bit of messing around I have decided to just do some basic R learning... I plot my first graph from a tutorial here. I feel powerful :) I have just created a graph in R... inside QGIS. HOwever it has nothing to do with my spatial data...
How do I reference my imported raster??
I dont know... I try more stuff from the tutorial...
Another tutorial on the basics of R: R Tutorial... I am starting to see the light!
I load a csv table that I created above... using:
  • rast = read.csv(file.choose(), header=T)
The table is stored with the variable "rast". To access this table i just type in that variable.  The table is also accessible from the workspace browser.  That is where the raster was imported to in manageR!

I realise that to do an analysis of data... it needs to be in a format that I at least understand... Which makes sense. I redirect my thoughts to defining the different values of the raster... where does the data get stored with the values for each cell of the raster? I do some looking around... I'm going to try to create a colour table for the raster... I have tried this before without much success... but I have found a good tutorial

After some R practice using the plotvals dataset I understand the interface a bit better and was quickly able to make an R plot within GIS using manageR.
However the original question was the analysis of raster data.

I found an interesting post and tried to load the "maptools" library. it was not installed so I did that.
>library(maptools)

To write the data to a tab delimited excel file:

> locat <- "~/Documents/Stellies/FS 884/Shapefiles/GIS/Correct/Grabouw/output.xls"
> write.table(za1,locat, sep="\t")