Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/golang/geo
S2 geometry library in Go
https://github.com/golang/geo
geometry geometry-library go sphere
Last synced: 4 days ago
JSON representation
S2 geometry library in Go
- Host: GitHub
- URL: https://github.com/golang/geo
- Owner: golang
- License: apache-2.0
- Created: 2014-12-03T23:02:15.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-08-14T09:57:22.000Z (4 months ago)
- Last Synced: 2024-12-02T16:05:58.826Z (11 days ago)
- Topics: geometry, geometry-library, go, sphere
- Language: Go
- Size: 1.01 MB
- Stars: 1,703
- Watchers: 80
- Forks: 181
- Open Issues: 29
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - S2 geometry - S2 geometry library in Go. (Geographic / Search and Analytic Databases)
- awesome-go - S2 geometry - S2 geometry library in Go. Stars:`1.7K`. (Geographic / Search and Analytic Databases)
- awesome-go - geo - S2 geometry library in Go - โ 746 (Geographic)
- awesome-go-extra - geo - 12-03T23:02:15Z|2022-08-23T01:10:03Z| (Geographic / Advanced Console UIs)
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](https://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](https://github.com/google/s2geometry), 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## [โยน](https://godoc.org/github.com/golang/geo/r1) - One-dimensional Cartesian coordinates
C++ Type | Go
:--------- | ---
R1Interval | โ## [โยฒ](https://godoc.org/github.com/golang/geo/r2) - Two-dimensional Cartesian coordinates
C++ Type | Go
:------- | ---
R2Point | โ
R2Rect | โ## [โยณ](https://godoc.org/github.com/golang/geo/r3) - Three-dimensional Cartesian coordinates
C++ Type | Go
:------------ | ---
R3Vector | โ
R3ExactVector | โ
Matrix3x3 | โ## [Sยน](https://godoc.org/github.com/golang/geo/s1) - Circular Geometry
C++ Type | Go
:----------- | ---
S1Angle | โ
S1ChordAngle | โ
S1Interval | โ## [Sยฒ](https://godoc.org/github.com/golang/geo/s2) - 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.