Giter Site home page Giter Site logo

panic with Union about simplefeatures HOT 9 CLOSED

akhenakh avatar akhenakh commented on July 18, 2024
panic with Union

from simplefeatures.

Comments (9)

wiki0831 avatar wiki0831 commented on July 18, 2024 2

--alternative temp fix--
You can try reducing floating point precision to 6 decimal place (which is about 111mm), this will return a valid output and preserve the overall topology.

reference implementation:

func ReducePrecision(g geom.Geometry, decimalPlace int) geom.Geometry {
	processPoint := func(xy geom.XY) geom.XY {
		ratio := math.Pow(10, float64(decimalPlace))
		x := math.Round(xy.X*ratio) / ratio
		y := math.Round(xy.Y*ratio) / ratio
		return geom.XY{X: x, Y: y}
	}
	return g.TransformXY(processPoint)
}

https://go.dev/play/p/nckAWTeE8gR

from simplefeatures.

peterstace avatar peterstace commented on July 18, 2024 1

Thank you for the detailed bug report, I should get some time to take a look at this soon.

from simplefeatures.

akhenakh avatar akhenakh commented on July 18, 2024 1

Having CGO is not too much of a problem, like on a CI it's okay, but the burden to maintain it for every developers environments, Mac windows ... is a bigger task, having the default build flag using the native not optimized Go would be the best option and a geos build tag for the CGO one.

But I remember you had a different API between geos and geom, which would make this difficult to implement it like that.

Thanks again for all the help, we are using your lib and it performs really well, most of the time using the native Go anyway.

from simplefeatures.

akhenakh avatar akhenakh commented on July 18, 2024

FYI the resulting polygon is probably invalid.

They visually look contiguous, but they are not, and they're actually only touching in 2 points.

from simplefeatures.

akhenakh avatar akhenakh commented on July 18, 2024

I've tested your fix branch on the same dataset, with success. Thank you.

from simplefeatures.

peterstace avatar peterstace commented on July 18, 2024

Thanks for testing! FYI I've created a new tag v0.42.0 that contains the panic fix.

I haven't worked out a fix for the root cause of the issue -- that's something I still intend to look into.

In the meantime, you may wish to look into using the Union wrapper from the GEOS C library. It handles those geometry without giving an error.

from simplefeatures.

peterstace avatar peterstace commented on July 18, 2024

A fix for the root cause has been added in v0.46.0.

from simplefeatures.

akhenakh avatar akhenakh commented on July 18, 2024

Thanks for the heads up, we switched to geos. Do you recommend moving back to the Go implementation?

from simplefeatures.

peterstace avatar peterstace commented on July 18, 2024

The main reasons you may wish to switch back to the Go implementation (and avoid the GEOS dependency) would be if you:

  • You wish to avoid the dependency on the GEOS C++ library (and CGO in general). The GEOS dependency can potentially be annoying to manage (depending on your setup). E.g. getting all developers on your team to install the same version locally. It can be difficult to get a recent version of GEOS if you're stuck on an older base image (assuming you're using docker for deployments).
  • CGO in general degrades much of the Go experience. Builds become slower and more complicated, cross-compilation becomes more difficult, some tools stop working (e.g. profiling).

The main reason to stay with the geos package:

  • It's faster than the Go implementation.
  • In my experience, the latest version (v3.11 and onwards) is very stable with regard to the correctness of results (earlier versions have a lot of miscellaneous problems). It's used much more widely than the Go implementation in simplefeatures, so is better battle-hardened.

If the drawbacks of the geos package and the CGO/GEOS dependency are not too bad for you, I'd recommend staying with geos.

from simplefeatures.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.