Skip to content

Commit

Permalink
geo/geoindex: interface for geometry and geography indexing, and
Browse files Browse the repository at this point in the history
implementation of those interfaces by s2GeometryIndex and
s2GeographyIndex

Both implementations use the S2 library to map 2D space to a
single dimension.

The implementations have TODOs regarding heuristics that will
be addressed after we have end-to-end benchmarks. The geometry
index abuses S2 by using face 0 of the unit cube that will be
projected to the unit sphere, to index the rectangular bounding
box of the index. This introduces two distortions:
rectangle => square, and square side of unit cube => unit sphere.
Geometries that exceed the bounding box are clipped, and indexed
both as clipped, and under a special cellid that is unused by S2.

Index acceleration is restricted to three relationships:
Covers, CoveredBy, Intersection. Other relationships will need
to be expressed using these. CoveredBy uses an "inner covering"
to deal with the fact that coverings do not have the strong
properties of bounding boxes. The CoveredBy produces an expression
involving set unions and intersections that is factored to
eliminate common sub-expressions and output in Reverse Polish
notation. How to compute this expression during query execution is
an open topic.

More tests will be added in subsequent PRs, as indicated in TODOs.

Release note: None
  • Loading branch information
sumeerbhola committed Apr 14, 2020
1 parent 359d336 commit 22dc8eb
Show file tree
Hide file tree
Showing 14 changed files with 2,688 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/geo/geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func (g *Geometry) AsGeography() (*Geography, error) {
return NewGeography(geopb.EWKB(ret)), nil
}

// AsGeomT returns the geometry as a geom.T object.
func (g *Geometry) AsGeomT() (geom.T, error) {
return ewkb.Unmarshal(g.ewkb)
}

// Geography is a spherical spatial object.
type Geography struct {
spatialObjectBase
Expand Down
3 changes: 1 addition & 2 deletions pkg/geo/geo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"fmt"
"testing"

"github.com/cockroachdb/cockroach/pkg/geo/geopb"
"github.com/cockroachdb/cockroach/pkg/geo/geos"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/datadriven"
Expand Down Expand Up @@ -187,7 +186,7 @@ func TestClipEWKBByRect(t *testing.T) {
d.ScanArgs(t, "xmax", &xMax)
d.ScanArgs(t, "ymax", &yMax)
ewkb, err := geos.ClipEWKBByRect(
geopb.WKB(g.ewkb), float64(xMin), float64(yMin), float64(xMax), float64(yMax))
g.ewkb, float64(xMin), float64(yMin), float64(xMax), float64(yMax))
if err != nil {
return err.Error()
}
Expand Down
Loading

0 comments on commit 22dc8eb

Please sign in to comment.