Hi,

Hmmm... I think I can see what you are trying, but the mailing list
mangles HTML messages (switch your email to client to plain text mode
for this list).  Mifght you share what you get when you run,

dput(head(base))

in R?  That way each of us would have a small sample of your data.
And also resend the code to the list in plain text so we don't have to
to yoga moves to read the code?

Best wishes,
Ben


On Thu, Jun 30, 2022 at 9:30 AM David Romero <rodarom...@gmail.com> wrote:
>
> Hello,
> How can I construct an sf polyline object directly in sf? I have a data
> frame with 3 pairs of coordinates and need for each row a 2 segment line.
>
> I did it with sp but would like to migrate to sf:
>
> base$ID<-seq(1,nrow(base),1)
> base_lines <- apply(base,1,function(x){
>   points <- data.frame(lng=as.numeric(c(x["LONG1"],x["LONG2"],x["LONG3"])),
>
>  lat=as.numeric(c(x["LAT1"],x["LAT2"],x["LAT3"])),stringsAsFactors = F)
>   coordinates(points) <- c("lng","lat")
>   Lines(Line(points),ID=as.numeric(x["ID"]))})
> row.names(base) <- base$ID
> base_lines <- SpatialLinesDataFrame(SpatialLines(base_lines),base)
> sflines<-st_as_sf(base_lines)
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



-- 
Ben Tupper (he/him)
Bigelow Laboratory for Ocean Science
East Boothbay, Maine
http://www.bigelow.org/
https://eco.bigelow.org

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to