Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find intersection of two geometries? #105

Open
bertday opened this issue Feb 24, 2024 · 1 comment
Open

Find intersection of two geometries? #105

bertday opened this issue Feb 24, 2024 · 1 comment

Comments

@bertday
Copy link

bertday commented Feb 24, 2024

Hello, and thank you for this project!

Is it possible to calculate the spatial intersection of two geometries? Say, the point where two lines intersect? I wasn't able to find it in the docs.

@ewsterrenburg
Copy link

Agreed that having only the https://pkg.go.dev/github.com/spatial-go/geoos as documentation makes things a bit of a guessing game to find the right functions (and how to apply them). For an intersection, you could use the following:

package main

import (
	"fmt"

	"github.com/spatial-go/geoos/geoencoding"
	"github.com/spatial-go/geoos/planar"
)

func main() {
	polygon, _ := geoencoding.Decode([]byte(`POLYGON((0 0,0 1,0 2,0 3,1 3,1 2,1 1,2 1,2 2,3 2,3 1,4 1,4 2,5 2,5 1,5 0,4 0,3 0,2 0,1 0,0 0))`), geoencoding.WKT)
	line, _ := geoencoding.Decode([]byte(`LINESTRING(-5 0, 5 5)`), geoencoding.WKT)

	strategy := planar.NormalStrategy()
	i, _ := strategy.Intersection(polygon, line)
	fmt.Println(string(geoencoding.Encode(i, geoencoding.WKT)))
}

(prints "LINESTRING(0 2.5,1 3)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants