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

geometry.Poly{}.Valid() does check if the polygon is valid #25

Open
nico-bock opened this issue Aug 23, 2023 · 2 comments
Open

geometry.Poly{}.Valid() does check if the polygon is valid #25

nico-bock opened this issue Aug 23, 2023 · 2 comments

Comments

@nico-bock
Copy link

Description

geometry.Poly{}.Valid() check only if the Exterior and the holes are valid Series, not if they are a valid polygon.

Therefore Polygons with missing Points, intersecting edges etc. are not detected.

Is this intended or just not necessary till now?

Exmaple:

package main

import (
	"github.com/tidwall/geojson"
	"github.com/tidwall/geojson/geometry"
)

func main() {
	polygon := geometry.NewPoly([]geometry.Point{
		{
			8.88242492198438,
			47.85972404073712,
		},
		{
			6.003023836249525,
			47.467582223811604,
		},
		{
			10.561998072355692,
			45.71873204889732,
		},
		{
			6.738413586888328,
			48.35187757503576,
		},
		{
			8.88242492198438,
			47.85972404073712,
		},
	}, nil, nil)

	print(polygon.Valid()) //Expected to be false

	geojsonPolygon := geojson.NewPolygon(polygon)
	print(geojsonPolygon.Valid()) //Expected to be false

	geojsonPolygonFeature := geojson.NewFeature(geojsonPolygon, "")
	print(geojsonPolygonFeature.Valid()) //Expected to be False

	geojsonPolygonFeatureJson := geojsonPolygonFeature.JSON()
	print(geojsonPolygonFeatureJson)

}

Screenshot 2023-08-23 at 11 33 33

@tidwall
Copy link
Owner

tidwall commented Aug 24, 2023

A more robust Valid operation would be nice, but it's not something I've gotten around to.

@nico-bock
Copy link
Author

If you want to, I could make a PR for this.

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