twpayne / go-geom

Package geom implements efficient geometry types for geospatial applications.
BSD 2-Clause "Simplified" License
839 stars 104 forks source link

Method to check validity of geometries #236

Closed Amogh-Bharadwaj closed 5 months ago

Amogh-Bharadwaj commented 10 months ago

Hey everyone. I was wondering if there is a way to check if an EWKB value was a valid geometry, much like PostGIS' ST_IsValid function

For example, I want to detect if a value I'm getting is a LINESTRING with only one point, or a polygon which is not closed

I am aware of this Unmarshal function:

    geo, err := ewkb.Unmarshal(MustHexDecode("010200000001000000000000000000F03F0000000000000040"))
    if err != nil {
        fmt.Println("invalid geo value. ignoring:", err)
    }

In a way wish there was a geo.IsValid() or some attribute which can be checked to deduce validity. Thanks !

twpayne commented 10 months ago

There is currently no such function in go-geom. Contributions welcome!

You may also consider github.com/twpayne/go-geos which does have such a function.