[R-sig-Geo] extract the attributes, lines to point
marta azores
martazores at gmail.com
Wed Feb 1 16:25:55 CET 2017
Hi everyone,
I have to overlap points and lines, with the aim to get a data frame or
similar with the results of the intersection. For example:
Points Overlap
p1 Line1
p1 Line2
p2 Line1
p4 Line1
I have two dataset (lixo and boats) with location points and other
attributes.
I created spatial points data frame (sightings-"lixo") with the lixo
dataset and spatial lines data frame (transect boats-"line")
with the boat dataset. I used the function rgeos:gInstersect and I buffer
the lines, to get the intersections I expect.
But the gIntersect only says If the intersection is happening, true or
false. I saw the function gUnion,
but it seems to get the area of the intersection, and not to extract
information from the attributes of the objects.
I though that may be I can use the function over with the line.buffer
because they are spatialpolygon.
However, I can't because my original database (11 spatial points) has
different row number than the final polygon (1 feature).
I think, I'm complicating the process. Is it possible to extract the
attributes between this kind of spatial objects?
Thanks in advance,
Marta
#script
##############
lixo <- read.table(paste0(path_data,"lixo4pontosDT.csv"), header=TRUE,
sep=",", na.strings="NA", dec=".", strip.white=TRUE)
sp::coordinates(lixo) <- ~Long1+Lat
sp::proj4string(lixo) <-CRS("+proj=longlat +datum=WGS84 +no_defs")
lixo<-sp::spTransform(lixo, CRS("+proj=laea +lat_0=30 +lon_0=-30 +x_0=0
+y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"))
raster::plot(lixo,add=TRUE)
str(lixo)
lixo
lixo
int <- gIntersects(line,lixo, byid = TRUE) # find which poinTs intersect
#Error: is.logical(byid) is not TRUE
class(int) # it's outputed a matrix
plot(gBuffer(line,width=0.002))
plot(int)
plot(lixo,add=TRUE)
line.buf<-gBuffer(line,width=0.002)
line.buf
#intersects works
int.buf <- gIntersects(line.buf,lixo, byid = TRUE) # find which poinTs
intersect
int.buf
Pnt_union <- gUnion(line.buf,lixo)
Pnt_union<- rgeos::gUnion(line.buf, lixo)
Pnt_union
plot(int.buf)
plot(line)
plot(line.buf,col='blue',add=TRUE);
plot(line,add=TRUE)
plot(Sptsdf,add=TRUE,pch=16,axes=TRUE)
title(paste("Intersects:",gIntersects(line.buf,Sptsdf),
"\nDisjoint:",gDisjoint(line,Sptsdf)))
library(rgeos)
#############
lixo#SpatialPointsDataFrame
line.buf#SpatialPolygons
str(line.buf)
pos
poldf = SpatialPolygonsDataFrame(line.buf, pos)#not make senses line.buf (1
feature), pos( 11 features)
join <- over(lixo, line.buf)
join
# Integrate this vegetation data into the SpatialPoints object
ptsrand <- SpatialPointsDataFrame(lixo, join)
head(ptsrand)
##################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170201/0a7cc8f7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: boat2905.csv
Type: text/csv
Size: 585 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170201/0a7cc8f7/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lixo4pontosDT.csv
Type: text/csv
Size: 196 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170201/0a7cc8f7/attachment-0001.bin>
More information about the R-sig-Geo
mailing list