On Mon, 15 Feb 2010, Tyler Dean Rudolph wrote:
I have searched extensively for some good examples or documentation on how
to create a SpatialLinesDataFrame and for the life of me have found zilch.
This does not mean there is no such thing available, it just means that
wherever it is it is not readily accessible through the circuitous pathways
of R help documentation or via a simple web search.
I have discussed with Achim Zeilis, who faces the same problem, the
ethical appropriateness of mentioning our book on the Spatial Task View,
and we've found until now that we shouldn't mention our own books. If
opinion is that we should, and because they are in a number of university
libraries, I can do that, and encourage Achim to do the same for
Econometrics.
If you visit the book website (http://www.asdar-book.org), you will find
links to code showing how to do this (chapter 2). In addition, under
"Additional materials", you find links to course materials, especially to
a course given at Imperial College in 2007, in which a good deal of these
questions are covered (see "Representing Spatial Data").
Because the classes were designed as interface containers, most users do
not need to know how to construct them from scratch, typically reading in
data or coercing from other classes of objects. While the help pages could
certainly be improved, we do provide a vignette that ships with the
package, and where section 6 covers Line objects etc. See:
http://cran.r-project.org/web/packages/sp/vignettes/sp.pdf
or:
vignette("sp", package="sp")
in R.
I'm sure that Mike's answer resolves your immediate problem - this is more
of an answer to your general question about where to look for information
about sp classes and how to make and use them.
Hope this helps,
Roger
As someone who
struggles daily to achieve highly technical things with scarcely the savvy
required, I wish there were more (or any?) examples in the documentation for
most of the spatial packages available. (I also wish that managing and
manipulating Spatial objects was about 65% less complicated, but for the
moment let's start with this)...
I have a data.frame (temp) containing endpoints of animal trajectories with
which I would like to create a SpatialLinesDataFrame for export into a GIS.
temp
id day x y X2 Y2
1 2002007 2005-04-04 12:01:01 -300358 748992.6 -300450.8 748764.8
2 2002007 2005-04-04 12:01:01 -300358 748992.6 -301694.2 751728.4
3 2002007 2005-04-04 12:01:01 -300358 748992.6 -299983.1 749528.8
4 2002007 2005-04-04 12:01:01 -300358 748992.6 -300569.4 749640.7
5 2002007 2005-04-04 12:01:01 -300358 748992.6 -300439.0 748308.8
I seem reasonably able to create a Lines object (though I can't get the ID
argument to work for me where there are multiple records involved)....
ranlines<-apply(temp, 1, function(x)
Lines(Line(list(rbind(as.numeric(x[7:8]), as.numeric(x[9:10]))))))
str(ranlines[[1]])
Formal class 'Lines' [package "sp"] with 2 slots
..@ Lines:List of 1
.. ..$ :Formal class 'Line' [package "sp"] with 1 slots
.. .. .. ..@ coords: num [1:2, 1:2] -300358 -300451 748993 748765
.. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. ..$ : NULL
.. .. .. .. .. ..$ : chr [1:2] "X1" "X2"
..@ ID : chr NA
Am I at least on the right track? Unfortunately now I'm clueless as to
what to do next because apparently Lines cannot be coerced to SpatialLines,
and while I am normally able to figure my way out of things there is just
nothing intuitive about this as far as I can tell. I have tried to create
SLDFs numerous times in the past and I have always been discouraged from
continuing. I can create a psp object in Spatstat but I am equally unable
to convert that into a SLDF shape. Terribly sorry about the rant but it's
difficulties like these that prevent a lot of people more clueless than me
from ever getting anywhere with R and more specifically the spatial
stuff....
Tyler
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
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.biv...@nhh.no
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo