gogeos is a library for Go that provides operations on spatial data and geometric algorithms.
It provides bindings to the GEOS C library.
package main
import (
"fmt"
"github.com/paulsmith/gogeos/geos"
)
func main() {
line, _ := geos.FromWKT("LINESTRING (0 0, 10 10, 20 20)")
buf, _ := line.Buffer(2.5)
fmt.Println(buf)
// Output: POLYGON ((18.2322330470336311 21.7677669529663689, 18.61…
}
- Binary predicates - intersects, disjoint, etc.
- Topology operations - difference, union, etc.
- Polygonization, line merging, and simplification
- Prepared geometries (for better performance for common binary predicates)
- Validity checking
- DE-9IM
- Geometry info - area, length, distance, etc.
- IO - WKT & WKB read/write
gogeos is an open source project.
- Source code: GitHub project
- Issues tracker
- Mailing list: gogeos@googlegroups.com
- IRC: #gogeos on freenode
- GEOS 3.3.8 or 3.3.9
GEOS must be installed on your system to build gogeos.
$ apt-get install libgeos-dev
$ brew install geos
$ wget http://download.osgeo.org/geos/geos-3.3.8.tar.bz2
$ tar xvfj geos-3.3.8.tar.bz2
$ cd geos-3.3.8
$ ./configure
$ make
$ sudo make install
$ go get github.com/paulsmith/gogeos/geos
Let’s say you have two polygons, A (blue) and B (orange).
One of the most common things to do with a spatial data library like gogeos is compute the intersection of two or more geometries. Intersection is just a method on geometry objects in gogeos, which takes one argument, the other geometry, and computes the intersection with the receiver. The result is a new geometry, C (magenta):
C := geos.Must(A.Intersection(B))
geos.Must
is just a convenience function that takes the output of any gogeos
function or method that returns a geometry and an error. It panics if the
error is non-null, otherwise returning the geometry, making it more convenient
to use in single-value contexts. In production code, though, you’ll want to
check the error value.
(NB: these graphics weren't produced by gogeos directly - I used the excellent draw2d package to render the output of gogeos functions.)
MIT. See COPYING
.
Copyright (c) 2013 Paul Smith