Open atombender opened 3 years ago
Thank you @atombender for opening this issue :)
This library effectively contains three parts: a Go-friendly representation for geometry types, a set of packages to serialize and deserialize those types, and packages (like xy
) that perform operations on geometries. The first two are solid, fast, and widely used. The third part, the xy
package, is a contributed port of code from the Java Topology Suite. Sadly the xy
package has not seen much love in the last few years.
The fix depends on your requirements:
If you're looking for a robust available-now implementation of polygon intersection and polygon-contains-polygon then I would recommend using cgo to bind to either of the excellent GEOS or CGAL libraries. The code in these libraries is battle-hardened but the cgo overhead can be significant. go-geom
can help you translate geometries into a format (hint: WKB) that these libraries can consume.
If you want a pure Go implementation of these algorithms, then I would be very happy to guide you in contributing a PR to go-geom
.
Thanks for responding! After I wrote the comment, I went hunting for bindings to either GEOS or GDAL, and I ended up on this decent maintained fork of an old, abandoned set of bindings to GEOS, which seems like an absolutely solid library.
Your support for WKT/WKB was a life-saver. So now I read GeoSON into go-geom, then convert to GEOS to perform operations like the ones I need. Having to go through WKB is not optimal, but fortunately this is not on a fast path, and it looks like it would be feasible to write a translator if we should need more speed. My only complaint with this solution is the fact that the GEOS library is now a build dependency.
Geometry/geography libs for Go are lacking. I poked through so many pure Go libraries that provide a lot of trivial functionality (such as reading and writing GeoJSON), but fall short when it comes to the actual hard stuff. If you ever feel like sitting down and making the xy
package more complete, that would be very cool indeed.
@atombender You could give godal
a try https://github.com/airbusgeo/godal/blob/main/godal.go#L2700
I'm looking for a way to use this library to check, using Cartesian coordinates:
I'm not seeing any exported functions for doing this. Is there any support for it, or should I look somewhere else?
From what I can tell, checking if a point is contained in a polygon can be accomplished this way:
Or? I'm not too familiar with rings or if this is how they're intended to be used. Either way, such a function would be a useful addition to this library, I think.