package resample
import "github.com/paulmach/orb/resample"
Package resample has a couple functions for resampling line geometry into more or less evenly spaces points.
Index ¶
- func Resample(ls orb.LineString, df orb.DistanceFunc, totalPoints int) orb.LineString
- func ToInterval(ls orb.LineString, df orb.DistanceFunc, dist float64) orb.LineString
Examples ¶
Functions ¶
func Resample ¶
func Resample(ls orb.LineString, df orb.DistanceFunc, totalPoints int) orb.LineString
Resample converts the line string into totalPoints-1 evenly spaced segments.
This function will modify the linestring input.
Code:play
Output:Example¶
package main
import (
"fmt"
"github.com/paulmach/orb"
"github.com/paulmach/orb/planar"
"github.com/paulmach/orb/resample"
)
func main() {
ls := orb.LineString{
{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0},
{5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {10, 0},
}
// downsample in this case so there are 2.5 units between points
ls = resample.ToInterval(ls, planar.Distance, 2.5)
fmt.Println(ls)
}
[[0 0] [2.5 0] [5 0] [7.5 0] [10 0]]
func ToInterval ¶
func ToInterval(ls orb.LineString, df orb.DistanceFunc, dist float64) orb.LineString
ToInterval coverts the line string into evenly spaced points of
about the given distance.
This function will modify the linestring input.
Code:play
Output:Example¶
package main
import (
"fmt"
"github.com/paulmach/orb"
"github.com/paulmach/orb/planar"
"github.com/paulmach/orb/resample"
)
func main() {
ls := orb.LineString{{0, 0}, {10, 0}}
// upsample so there are 6 total points
ls = resample.Resample(ls, planar.Distance, 6)
fmt.Println(ls)
}
[[0 0] [2 0] [4 0] [6 0] [8 0] [10 0]]
Source Files ¶
- Version
- v0.11.1 (latest)
- Published
- Jan 29, 2024
- Platform
- js/wasm
- Imports
- 1 packages
- Last checked
- 1 day ago –
Tools for package owners.