[GRASS-stats] Identifing lines with cats in SpatialLinesDataFrame
Roger Bivand
Roger.Bivand at nhh.no
Fri Mar 7 04:04:09 EST 2008
On Fri, 7 Mar 2008, Jaros?aw Jasiewicz wrote:
> Hi!
>
> problem concern lines imported to from GRASS, we assume that every line has
> its own category
>
> As I rot in the one of the sp man, lines ARE NOT coneted with its atributes
> so this means that are not identified by its category, but I tried on small
> sample where I calculate generalised direction of line:
Why? SpatialLinesDataFrames are like SpatialPolygonsDataFrames, with
agreement between
sapply(slot(v, "lines"), function(x) slot(x, "ID"))
and
rownames(slot(v, "data"))
But a Lines object with an ID may contain more than one Line object, and
they do not have IDs.
>
> dirs=c()
> for (i in 1:length(v at lines)) {
> tv=coordinates(v)[[i]][[1]]
You are assuming that there is only one Line object in each Lines object
> tl=lm(tv[,1]~tv[,2]) #dir as coef
> td=atan(coef(tl)[2])*(180/pi) #coef to degrees
> dirs=c(dirs,td) vector with degrees
> ... }
>
Extending with c() is much slower than saying
dir <- numeric(length(slot(v, "lines")))
by the way.
> lins=data.frame(v$cat,dirs)
>
> I checked direcitons and its look that categories are well subsripted to its
> lines
>
> Is that assumption correct? - I of course every line have its own category??
> And what about identifing lines with its ID it is its ID from GRASS???
Look at ?"spChFIDs-methods" in maptools to set as.character(cat) as the ID
- the current ID is the shapefile FID. Maybe look at ?"spCbind-methods"
too, to add the dirs vector to v.
Roger
> suppose not.
>
> Jarek
>
> P.S here is piece of SpatialLinesDataFrame:
>
> Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots
> ..@ data :'data.frame': 30 obs. of 3 variables:
> .. ..$ cat : num [1:30] 10 107 115 140 158 191 206 207 210 227 ...
> .. ..$ rzad : num [1:30] 1 1 3 1 3 1 2 1 1 1 ...
> .. ..$ link_to: num [1:30] 11 107 11 140 115 191 158 207 210 227 ...
> ..@ lines :List of 30
> .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
> .. .. .. ..@ Lines:List of 1
> .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slots
> .. .. .. .. .. .. ..@ coords: num [1:5, 1:2] 3592150 3592130 3592110
> 3592090 3591850 ...
> .. .. .. ..@ ID : chr "0"
> .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
> .. .. .. ..@ Lines:List of 1
> .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slots
> .. .. .. .. .. .. ..@ coords: num [1:6, 1:2] 3590210 3590210 3590190
> 3590190 3590170 ...
> .. .. .. ..@ ID : chr "1"
> .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
> .. .. .. ..@ Lines:List of 1
> .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slots
> .. .. .. .. .. .. ..@ coords: num [1:8, 1:2] 3592110 3591930 3591930
> 3591910 3591910 ...
> .. .. .. ..@ ID : chr "2"
> .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
> .. .. .. ..@ Lines:List of 1
> .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slots
> .. .. .. .. .. .. ..@ coords: num [1:5, 1:2] 3590430 3590350 3590210
> 3590190
> _______________________________________________
> grass-stats mailing list
> grass-stats at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-stats
>
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the grass-stats
mailing list