Geo Save

S2 geometry library in Go

Project README

Overview

S2 is a library for spherical geometry that aims to have the same robustness, flexibility, and performance as the best planar geometry libraries.

This is a library for manipulating geometric shapes. Unlike many geometry libraries, S2 is primarily designed to work with spherical geometry, i.e., shapes drawn on a sphere rather than on a planar 2D map. (In fact, the name S2 is derived from the mathematical notation for the unit sphere Sยฒ.) This makes it especially suitable for working with geographic data.

More details about S2 in general are available on the S2 Geometry Website s2geometry.io.

Scope

The library provides the following:

  • Representations of angles, intervals, latitude-longitude points, unit vectors, and so on, and various operations on these types.

  • Geometric shapes over the unit sphere, such as spherical caps ("discs"), latitude-longitude rectangles, polylines, and polygons. These are collectively known as "regions".

  • A hierarchical decomposition of the sphere into regions called "cells". The hierarchy starts with the six faces of a projected cube and recursively subdivides them in a quadtree-like fashion.

  • Robust constructive operations (e.g., union) and boolean predicates (e.g., containment) for arbitrary collections of points, polylines, and polygons.

  • Fast in-memory indexing of collections of points, polylines, and polygons.

  • Algorithms for measuring distances and finding nearby objects.

  • Robust algorithms for snapping and simplifying geometry (with accuracy and topology guarantees).

  • A collection of efficient yet exact mathematical predicates for testing relationships among geometric objects.

  • Support for spatial indexing, including the ability to approximate regions as collections of discrete "S2 cells". This feature makes it easy to build large distributed spatial indexes.

On the other hand, the following are outside the scope of S2:

  • Planar geometry.

  • Conversions to/from common GIS formats.

Robustness

What do we mean by "robust"?

In the S2 library, the core operations are designed to be 100% robust. This means that each operation makes strict mathematical guarantees about its output, and is implemented in such a way that it meets those guarantees for all possible valid inputs. For example, if you compute the intersection of two polygons, not only is the output guaranteed to be topologically correct (up to the creation of degeneracies), but it is also guaranteed that the boundary of the output stays within a user-specified tolerance of true, mathematically exact result.

Robustness is very important when building higher-level algorithms, since unexpected results from low-level operations can be very difficult to handle. S2 achieves this goal using a combination of techniques from computational geometry, including conservative error bounds, exact geometric predicates, and snap rounding.

The implementation attempts to be precise both in terms of mathematical definitions (e.g. whether regions include their boundaries, and how degeneracies are handled) and numerical accuracy (e.g. minimizing cancellation error).

Note that the intent of this library is to represent geometry as a mathematical abstraction. For example, although the unit sphere is obviously a useful approximation for the Earth's surface, functions that are specifically related to geography are not part of the core library (e.g. easting/northing conversions, ellipsoid approximations, geodetic vs. geocentric coordinates, etc).

See http://godoc.org/github.com/golang/geo for specific package documentation.

For an analogous library in C++, see https://github.com/google/s2geometry, in Java, see https://github.com/google/s2-geometry-library-java, and Python, see https://github.com/google/s2geometry/tree/master/src/python

Status of the Go Library

This library is principally a port of the C++ S2 library, adapting to Go idioms where it makes sense. We detail the progress of this port below relative to that C++ library.

Legend:

  • โœ… - Feature Complete
  • ๐ŸŸก - Mostly Complete
  • โŒ - Not available

โ„ยน - One-dimensional Cartesian coordinates

C++ Type Go
R1Interval โœ…

โ„ยฒ - Two-dimensional Cartesian coordinates

C++ Type Go
R2Point โœ…
R2Rect โœ…

โ„ยณ - Three-dimensional Cartesian coordinates

C++ Type Go
R3Vector โœ…
R3ExactVector โœ…
Matrix3x3 โœ…

Sยน - Circular Geometry

C++ Type Go
S1Angle โœ…
S1ChordAngle โœ…
S1Interval โœ…

Sยฒ - Spherical Geometry

Basic Types

C++ Type Go
S2Cap โœ…
S2Cell โœ…
S2CellId โœ…
S2CellIdVector โŒ
S2CellIndex ๐ŸŸก
S2CellUnion โœ…
S2Coords โœ…
S2DensityTree โŒ
S2DistanceTarget โœ…
S2EdgeVector โœ…
S2LatLng โœ…
S2LatLngRect โœ…
S2LaxLoop ๐ŸŸก
S2LaxPolygon ๐ŸŸก
S2LaxPolyline ๐ŸŸก
S2Loop โœ…
S2PaddedCell โœ…
S2Point โœ…
S2PointIndex โŒ
S2PointSpan โŒ
S2PointRegion โŒ
S2PointVector โœ…
S2Polygon ๐ŸŸก
S2Polyline โœ…
S2R2Rect โŒ
S2Region โœ…
S2RegionCoverer โœ…
S2RegionIntersection โŒ
S2RegionUnion โœ…
S2Shape โœ…
S2ShapeIndex โœ…
S2ShapeIndexRegion โŒ
EncodedLaxPolygon โŒ
EncodedLaxPolyline โŒ
EncodedShapeIndex โŒ
EncodedStringVector โŒ
EncodedUintVector โŒ
IdSetLexicon โŒ
ValueSetLexicon โŒ
SequenceLexicon โŒ
LaxClosedPolyline โŒ
VertexIDLaxLoop โŒ

Query Types

C++ Type Go
S2ChainInterpolation โŒ
S2ClosestCell โŒ
S2FurthestCell โŒ
S2ClosestEdge โœ…
S2FurthestEdge โœ…
S2ClosestPoint โŒ
S2FurthestPoint โŒ
S2ContainsPoint โœ…
S2ContainsVertex โœ…
S2ConvexHull โœ…
S2CrossingEdge โœ…
S2HausdorffDistance โŒ
S2ShapeNesting โŒ

Supporting Types

C++ Type Go
S2BooleanOperation โŒ
S2BufferOperation โŒ
S2Builder โŒ
S2BuilderClosedSetNormalizer โŒ
S2BuilderFindPolygonDegeneracies โŒ
S2BuilderGraph โŒ
S2BuilderLayers โŒ
S2BuilderSnapFunctions โŒ
S2BuilderTesting โŒ
S2Builderutil* โŒ
S2Coder โŒ
S2EdgeClipping โœ…
S2EdgeCrosser โœ…
S2EdgeCrossings โœ…
S2EdgeDistances โœ…
S2EdgeTessellator โœ…
S2LoopMeasures โŒ
S2Measures โœ…
S2MemoryTracker โŒ
S2Metrics โŒ
S2PointUtil ๐ŸŸก
S2PolygonBuilder โŒ
S2PolylineAlignment โŒ
S2PolylineMeasures โœ…
S2PolylineSimplifier โŒ
S2Predicates โœ…
S2Projections โŒ
S2rectBounder โŒ
S2RegionTermIndexer โŒ
S2ShapeIndexMeasures โŒ
S2ShapeIndexUtil* ๐ŸŸก
S2ShapeMeasures โŒ
S2ShapeUtil* ๐ŸŸก
S2Stats โŒ
S2Testing โœ…
S2TextFormat โœ…
S2WedgeRelations โœ…
S2WindingOperation โŒ

Encode/Decode

Encoding and decoding of S2 types is fully implemented and interoperable with C++ and Java.

Open Source Agenda is not affiliated with "Geo" Project. README Source: golang/geo
Stars
1,640
Open Issues
23
Last Commit
9 months ago
Repository
License

Open Source Agenda Badge

Open Source Agenda Rating