Git Product home page Git Product logo

polylinesplitter's Issues

Error for small dist argument

Really useful code! However, when I try splitting up a polyline into very small segments, I get an error. For example:

rivsplit <- splitLines(riv, dist = 1000) # this is OK
rivsplit <- splitLines(riv, dist = 10) # this results in an error

riv is a SpatialLine object with one feature. It is about 33 km long.
The error occurs at line 125 of polylineSplitter, at split(xydf,dist)

"Error in data.frame(x = x, y = y, end = end) : arguments imply differing number of rows: 7055, 7056"

Keep original dataset

Hi, nice set of functions. However, data on the sp object input is deleted. I'd like to keep the original data within the output, ie. duplicating rows.

I tried this, where Name is the original ID, however, it throws the folllowing Error object 'Name' not found:

splitLines2<- function(spobj, dist, start = T, sf = F){ xydf<-coordBuild(spobj) if (start == F){ xydf<-xydf[rev(rownames(xydf)),] } spoints <- split(xydf, dist) linelist <- list() lineslist <- list() id <- 1 Name <- Name if(!sf) { j <- 1 for(i in 1:(nrow(spoints)-1)){ linelist[j] <- Line(spoints[c(i, i + 1), c(1:2)]) j = j + 1 if(spoints[i+1,3] == 1){ lineslist[id]<-Lines(linelist, ID = id) id = id+1 Name = Name linelist<-list() j = 1 } } return(SpatialLinesDataFrame(SpatialLines(lineslist), data = data.frame(id = 0:(length(lineslist)-1), Name = Name))) } else { start <- 1 for(i in 1:(nrow(spoints)-1)){ if(spoints[i+1,3] == 1){ lineslist[[id]] <- sf::st_linestring(as.matrix(spoints[c(start:(i + 1)), c(1:2)], ncol = 2)) id <- id + 1 Name <- Name start <- i + 1 } } return(sf::st_sf(id = 1:length(lineslist), Name = Name, geom = sf::st_sfc(lineslist))) } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.