[R-sig-Geo] package sp, extract values points-lines

marta azores martazores at gmail.com
Thu Nov 24 19:40:46 CET 2016


Hi Roger,

Thanks for the tip. I tried with only one track the function gIntersects
and gbuffer . It works.
I created my spatiallines from a data frame , and now I was looking for how
create the spatiallines by categories (1 variable of the data.frame).
I have only one spatial line with all the coordinates, and I would like to
have 1000 different lines separates by the IdkeyL. It's that possible??


My spatial data frame:
coordinates IdkeyL  Date
1 (-24.54572, 37.30128)  2815L 42229
2 (-24.59933, 37.32453)  2815L 42229
3 (-24.68027, 37.36087)  2815L 42229


I checked the sp and rgeos manual, and I look into the forums, but in every
example they only use a few lines, which are defined one by one.
l1 <- cbind(c(1, 2, 3), c(3, 2, 2)) l2 <- cbind(c(1, 2, 3), c(1, 1.5, 1))
Sl1 <- Line(l1) Sl2 <- Line(l2) S1 <- Lines(list(Sl1), ID = "a") S2 <- Lines
(list(Sl2), ID = "b") Sl <- SpatialLines(list(S1, S2))

Thanks in advance
Marta


2016-11-24 13:12 GMT-01:00 Roger Bivand <Roger.Bivand at nhh.no>:

> On Thu, 24 Nov 2016, rolandh at uni-muenster.de wrote:
>
> Hi Marta,
>>
>> by ?sp::over you will see that SpatialLines are not supported.
>>
>> Moreover it says:
>> "over methods that involve SpatialLines objects, or pairs of
>> SpatialPolygons require package rgeos, and use gIntersects."
>>
>> So, try gIntersects ...
>>
>
> Right, and note that the precision model will bite painfully (the points
> may appear to be on the lines, but given the precision model may not
> actually intersect in the default representation (think one thousandth of a
> millimetre). You may need to buffer either points or lines to get the
> intersections you expect.
>
> Roger
>
>
>
>> Cheers,
>> Roland
>>
>> marta azores schrieb am 2016-11-24:
>>
>>> Hi everyone,
>>>
>>
>> I need to join two datasets, one with survey boats and other with
>>> sightings. There are different boats in the same area.
>>> First I've created the tracks with the gps information, and give to each
>>> track an ID number(column) .
>>> Second, I would like to join by time and space the sightings with the
>>> track
>>> of the boats.
>>> I'm trying the"over" function of the package sp.
>>>
>>
>> The first test was try to join only by space, but the function say there
>>> aren't overlap. I don't know why, because the points of the sightings are
>>> over the line.
>>>
>>
>> Any idea?
>>> Thanks in advance
>>> Marta
>>>
>>
>> #boat data
>>> boat <- read.table("path/.csv", header=TRUE, sep=",", na.strings="NA",
>>> dec=".", strip.white=TRUE)#
>>> boatdf<-as.data.frame(boat)
>>> #sighting data
>>> sght <- read.table("path/.csv.csv", header=TRUE, sep=",",
>>> na.strings="NA",
>>> dec=".", strip.white=TRUE)#
>>>
>>
>> #Spatial points
>>> #sightings
>>> Sxy = cbind(sght$LONG,sght$LAT)
>>> Spts = SpatialPoints(Sxy)
>>> sghtdf<-as.data.frame(sght)
>>> #boats
>>> xy = cbind(boat$Long1,boat$Lat1)
>>> pts = SpatialPoints(xy)
>>>
>>
>> # dataframe
>>> ptsdf = SpatialPointsDataFrame(pts, boatdf)#data frame barcos
>>> Sptsdf = SpatialPointsDataFrame(Spts, sghtdf)#data frame species
>>>
>>
>> #Line
>>> line<-as(ptsdf, "SpatialLines")
>>>
>>
>> #
>>> #extract values
>>> over(Sptsdf, line)# NA?
>>>
>>
>>         [[alternative HTML version deleted]]
>>>
>>
>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 91 00
> e-mail: Roger.Bivand at nhh.no
> http://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
> http://depsy.org/person/434412
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list