package clip
import "github.com/paulmach/orb/clip"
Package clip is a library for clipping geometry to a bounding box.
Index ¶
- func Bound(b, bound orb.Bound) orb.Bound
- func Collection(b orb.Bound, c orb.Collection) orb.Collection
- func Geometry(b orb.Bound, g orb.Geometry) orb.Geometry
- func LineString(b orb.Bound, ls orb.LineString, opts ...Option) orb.MultiLineString
- func MultiLineString(b orb.Bound, mls orb.MultiLineString, opts ...Option) orb.MultiLineString
- func MultiPoint(b orb.Bound, mp orb.MultiPoint) orb.MultiPoint
- func MultiPolygon(b orb.Bound, mp orb.MultiPolygon) orb.MultiPolygon
- func Polygon(b orb.Bound, p orb.Polygon) orb.Polygon
- func Ring(b orb.Bound, r orb.Ring) orb.Ring
- type Option
Examples ¶
Functions ¶
func Bound ¶
Bound intersects the two bounds. May result in an empty/degenerate bound.
func Collection ¶
func Collection(b orb.Bound, c orb.Collection) orb.Collection
Collection clips each element in the collection to the bounding box. It will exclude elements if they don't intersect the bounding box. This operation will modify the input of '2d geometry' by using as a scratch space so clone if necessary.
func Geometry ¶
Geometry will clip the geometry to the bounding box using the
correct functions for the type.
This operation will modify the input of '1d or 2d geometry' by using as a
scratch space so clone if necessary.
Code:play
Output:Example¶
package main
import (
"fmt"
"github.com/paulmach/orb"
"github.com/paulmach/orb/clip"
)
func main() {
bound := orb.Bound{Min: orb.Point{0, 0}, Max: orb.Point{30, 30}}
ls := orb.LineString{
{-10, 10}, {10, 10}, {10, -10}, {20, -10}, {20, 10},
{40, 10}, {40, 20}, {20, 20}, {20, 40}, {10, 40},
{10, 20}, {5, 20}, {-10, 20}}
// returns an orb.Geometry interface.
clipped := clip.Geometry(bound, ls)
fmt.Println(clipped)
}
[[[0 10] [10 10] [10 0]] [[20 0] [20 10] [30 10]] [[30 20] [20 20] [20 30]] [[10 30] [10 20] [5 20] [0 20]]]
func LineString ¶
func LineString(b orb.Bound, ls orb.LineString, opts ...Option) orb.MultiLineString
LineString clips the linestring to the bounding box.
func MultiLineString ¶
func MultiLineString(b orb.Bound, mls orb.MultiLineString, opts ...Option) orb.MultiLineString
MultiLineString clips the linestrings to the bounding box and returns a linestring union.
func MultiPoint ¶
func MultiPoint(b orb.Bound, mp orb.MultiPoint) orb.MultiPoint
MultiPoint returns a new set with the points outside the bound removed.
func MultiPolygon ¶
func MultiPolygon(b orb.Bound, mp orb.MultiPolygon) orb.MultiPolygon
MultiPolygon clips the multi polygon to the bounding box excluding any polygons if they don't intersect the bounding box. This operation will modify the input by using as a scratch space so clone if necessary.
func Polygon ¶
Polygon clips the polygon to the bounding box excluding the inner rings if they do not intersect the bounding box. This operation will modify the input by using as a scratch space so clone if necessary.
func Ring ¶
Ring clips the ring to the bounding box and returns another ring. This operation will modify the input by using as a scratch space so clone if necessary.
Types ¶
type Option ¶
type Option func(*options)
An Option is a possible parameter to the clip operations.
func OpenBound ¶
OpenBound is an option to treat the bound as open. i.e. any lines along the bound sides will be removed and a point on boundary will cause the line to be split.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
clip/smartclip | Package smartclip performs a more advanced clipping algorithm so it can deal with correctly oriented open rings and polygon. |
- Version
- v0.11.1 (latest)
- Published
- Jan 29, 2024
- Platform
- js/wasm
- Imports
- 3 packages
- Last checked
- 1 day ago –
Tools for package owners.