Learn R Programming

berryFunctions (version 1.4)

showAttribute: Show attribute of ESRI-Shapefile line segment selected by mouseclick

Description

Click near a line segment of a shapefile, and it's attribute(s) are displayed in the console. Currently only works for objects of class SpatialLinesDataFrame.

Usage

showAttribute(object, object_psp=as.psp(object),
coltoshow=1:ncol(object), ID_col=1, notify=TRUE)

Arguments

object
object of class SpatialLinesDataFrame. Not tested for other objects yet!
object_psp
convert SpatialLinesDataFrame to line segment pattern. slow conversion, rather define it outside the function, especially when using the function more than once. DEFAULT: as.psp(object)
coltoshow
character vector. column(s) of attribute table to be showed. Should technically work with number(s) as well, not tested yet. DEFAULT: 1:ncol(object)
ID_col
Column to be used for identification. Not fully understood yet... DEFAULT: 1
notify
logical. Are you to be told what to do in the console?. DEFAULT: TRUE

Value

  • none returned. prints attrributes of selected item.

Background

My colleague argues that arcGIS is better than R, because you can click on a line segment and see it's attributes. I took on the challenge to prove that R can do this just as well...

See Also

changeAttribute, shapeZoom, readShapeSpatial in the package maptools.

Examples

Run this code
# see ?changeAttribute for more information
# Read Shapefile:

library(maptools)
library(spatstat)
xx <- readShapeLines(system.file("shapes/fylk-val.shp", package="maptools")[1],
                     proj4string=CRS("+proj=utm +zone=33 +datum=WGS84"))
xx_psp <- as.psp(xx) # slow for bigger shapefiles, so take it out of the function
# if object_psp is not given, it will be calculated each time...

plot(xx)
showAttribute(xx)
showAttribute(xx, xx_psp)
showAttribute(xx, xx_psp, 3:6)
showAttribute(xx, xx_psp, notify=FALSE) # Finish with "Enter"

Run the code above in your browser using DataLab