[R-sig-Geo] Change Lines'IDs within a SpatialLines object
marta azores
martazores at gmail.com
Tue Feb 7 18:01:28 CET 2017
Hello everyone,
I would like to change the ID of SpatialLinesDataFrame (SLDF), by the value
of one variable (in my case splndf$Idkey).
I read the answer of Roger Bivand in this link:
https://stat.ethz.ch/pipermail/r-sig-geo/2015-December/023809.html
This works well when I write an specific number. However, I can't change
the id of my SLDF by my Idkey value.
At first the value in the SLDF was an integer and I converted to a numeric
value. I don't understand why works with a number and not when I define the
number from the SLDF.
Any idea?
Thanks in advance,
Marta
#######################################################################
##script
########change the ID's SLDF
#Please use row.names(), so here:
row.names(L1) <- c("c", "d")
#If L1 was a SpatialLinesDataFrame, the row.names of the data slot would
also
#be updated.
###################################################
row.names(splndf)
#[1] "1"
#1) First, I try manually to change the id (works)
row.names(splndf) <- ("2905")
str(splndf)#@ ID : chr "2905"
str(2905)
#num 2905
is.numeric(2905)
2905
#2) Second, I try extract the Idkey value and convert into the SLDF's ID.
k<-splndf at data$Idkey
str(k)
#int 2905
k <- as.numeric(k)
k
#[1] 2905
str(k)
# num 2905
is.numeric(k)
#TRUE
k
row.names(splndf) <- (k)
#Error in (function (classes, fdef, mtable) :
#unable to find an inherited method for function ‘spChFIDs’ for signature
‘"SpatialLinesDataFrame", "numeric"’
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list