Git Product home page Git Product logo

polylinesplitter's Introduction

polylineSplitter

Install Instructions

install.packages("devtools")
devtools::install_github("jmt2080ad/polylineSplitter")

Usage

Polyline/polygon splitter tools for R. These functions will allow a user to pass SpatialLines or SpatialPolygons and split the line or polygon edge by a specific distance returning either points or line segments depending on which functions are used.

Usage can be see in the test.r file. These tools were designed for tasks were precise measurements along lines or polygon perimeters are required. This might include tasks like defining river miles along river lines, defining sample locations along excavation sidewalls, or changing the shapes of lines or polygons based on even distances along those shapes (a form of simplification).

Here are some examples:

This graphic shows how a polyline can be split into parts that are even length plus a remainder. The resulting line segments are shown in different colors.

line_splitting

This graphic shows how a polygon edge can be sampled at an even distance along its perimeter.

polygon_sampling

This graphic shows how a polygon can be simplified by taking even measurements along the perimeter, then converting those points back to a polygon. This example is not ideal. A better example might be a single contour output from a spatial interpolation or a trail path line from a GPS.

polygon_simplification.png

polylinesplitter's People

Contributors

jmt2080ad avatar dblodgett-usgs avatar

Stargazers

Anup Dahal avatar  avatar HarryZhu avatar Anna Pede avatar Paul Jung avatar Justin avatar Sam Boysel avatar

Watchers

 avatar

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.