[R-sig-Geo] Fwd: extract the attributes, lines to point

marta azores martazores at gmail.com
Fri Feb 3 20:30:50 CET 2017


---------- Forwarded message ----------
From: marta azores <martazores at gmail.com>
Date: 2017-02-03 18:30 GMT-01:00
Subject: Re: [R-sig-Geo] extract the attributes, lines to point
To: Vilem Ded <Ded.V at seznam.cz>


Thanks for your answer, it works.

Yesterday I tried get the list without success... and in the process I
discovered that with the function gDistance I can get similar information.
Also, the manipulation data it's easy with the results in a data.frame.
Because I don't know how change the id of the polygon. It's always build
with the id "buffer". It would be great if it take the name each time a
different name, or one of their attributes. Do you know how do that?



> join2$buffer
  Species  Date      Time
2     sp2 42229 0.6097222


>gDistance




  V1
  V2
  V3
  V4
  V5
  PolyID
  PDist
  coords.x1
  coords.x2


  1
  18
  42229
  0.50625
  38.51872
  -27.763
  1
  242280
  195132.4
  948393.2


  2
  19
  42229
  0.609722
  37.50883
  -25.0114
  1
  187.785
  440703.9
  844490.8







































V1 V2 V3 V4 V5 PolyID PDist coords.x1 coords.x2
1 18 42229 0.50625 38.51872 -27.763 1 242280 195132.4 948393.2
2 19 42229 0.609722 37.50883 -25.0114 1 187.785 440703.9 844490.8



2017-02-03 17:18 GMT-01:00 Vilem Ded <Ded.V at seznam.cz>:

> Hi,
> I think you are almost there. What about to try
>
> over( sp1, sp2, ... , returnList = TRUE)
>
> I hope it helped.
>
> Cheers
> Vil
>
>
> ---------- Původní zpráva ----------
> Od: marta azores <martazores at gmail.com>
> Komu: r-sig-geo <r-sig-geo at r-project.org>
> Datum: 1. 2. 2017 16:26:55
> Předmět: [R-sig-Geo] extract the attributes, lines to point
>
> 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)
> ##################################
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list