[R-sig-Geo] r-sig-geo maybe from r-project.org

David Romero rod@romero @end|ng |rom gm@||@com
Thu Jun 30 15:29:33 CEST 2022


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]]



More information about the R-sig-Geo mailing list