geojson

package
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 38

Documentation

Index

Constants

View Source
const (
	PointType              = "point"
	MultiPointType         = "multipoint"
	LineStringType         = "linestring"
	MultiLineStringType    = "multilinestring"
	PolygonType            = "polygon"
	MultiPolygonType       = "multipolygon"
	GeometryCollectionType = "geometrycollection"
	CircleType             = "circle"
	EnvelopeType           = "envelope"
)
View Source
const (
	PointTypePrefix              = byte(1)
	MultiPointTypePrefix         = byte(2)
	LineStringTypePrefix         = byte(3)
	MultiLineStringTypePrefix    = byte(4)
	PolygonTypePrefix            = byte(5)
	MultiPolygonTypePrefix       = byte(6)
	GeometryCollectionTypePrefix = byte(7)
	CircleTypePrefix             = byte(8)
	EnvelopeTypePrefix           = byte(9)
)

These are the byte prefixes for identifying the shape contained within the doc values byte slice while decoding the contents during the query filtering phase.

Variables

View Source
var GlueBytes = []byte("##")

GlueBytes primarily for quicker filtering of docvalues during the filtering phase.

Functions

func DeduplicateTerms

func DeduplicateTerms(terms []string) []string

func ExtractShapesFromBytes added in v0.2.6

func ExtractShapesFromBytes(targetShapeBytes []byte, r **bytes.Reader, bufPool *s2.GeoBufferPool) (
	index.GeoJSON, error)

ExtractShapesFromBytes unmarshal the bytes to retrieve the embedded geojson shape.

func FilterGeoShapesOnRelation

func FilterGeoShapesOnRelation(shape index.GeoJSON, targetShapeBytes []byte,
	relation string, reader **bytes.Reader, bufPool *s2.GeoBufferPool) (bool, error)

FilterGeoShapesOnRelation extracts the shapes in the document, apply the `relation` filter and confirms whether the shape in the document satisfies the given relation.

func NewGeoCircle

func NewGeoCircle(points []float64,
	radius string) index.GeoJSON

func NewGeoEnvelope

func NewGeoEnvelope(points [][]float64) index.GeoJSON

func NewGeoJsonLinestring

func NewGeoJsonLinestring(points [][]float64) index.GeoJSON

NewGeoJsonLinestring instantiates a LineString from the given coordinates.

func NewGeoJsonMultiPoint

func NewGeoJsonMultiPoint(v [][]float64) index.GeoJSON

func NewGeoJsonMultiPolygon

func NewGeoJsonMultiPolygon(points [][][][]float64) index.GeoJSON

func NewGeoJsonMultilinestring

func NewGeoJsonMultilinestring(points [][][]float64) index.GeoJSON

NewGeoJsonMultilinestring instantiates a MultiLineString from the given coordinates.

func NewGeoJsonPoint

func NewGeoJsonPoint(v []float64) index.GeoJSON

func NewGeoJsonPolygon

func NewGeoJsonPolygon(points [][][]float64) index.GeoJSON

func NewGeoJsonShape

func NewGeoJsonShape(coordinates [][][][]float64, typ string) (
	index.GeoJSON, []byte, error)

NewGeoJsonShape instantiate a geojson shape/circle or an envelope from the given coordinates and type.

func NewGeometryCollection

func NewGeometryCollection(shapes []*GeoShape) (
	index.GeoJSON, []byte, error)

NewGeometryCollection instantiate a geometrycollection and prefix the byte contents with certain glue bytes that can be used later while filtering the doc values.

func ParseDistance

func ParseDistance(d string) (float64, error)

ParseDistance attempts to parse a distance string and return distance in meters. Example formats supported: "5in" "5inch" "7yd" "7yards" "9ft" "9feet" "11km" "11kilometers" "3nm" "3nauticalmiles" "13mm" "13millimeters" "15cm" "15centimeters" "17mi" "17miles" "19m" "19meters" If the unit cannot be determined, the entire string is parsed and the unit of meters is assumed. If the number portion cannot be parsed, 0 and the parse error are returned.

func ParseGeoJSONShape

func ParseGeoJSONShape(input []byte) (index.GeoJSON, error)

ParseGeoJSONShape unmarshals the geojson/circle/envelope shape embedded in the given bytes.

func StripCoveringTerms

func StripCoveringTerms(terms []string) []string

Types

type Circle

type Circle struct {
	Typ      string    `json:"type"`
	Vertices []float64 `json:"coordinates"`
	Radius   string    `json:"radius"`
	// contains filtered or unexported fields
}

Circle represents a custom circle type and it implements the index.GeoJSON interface.

func NewGeoCircleShape

func NewGeoCircleShape(cp []float64,
	radius string) (*Circle, []byte, error)

NewGeoCircleShape instantiate a circle shape and prefix the byte contents with certain glue bytes that can be used later while filtering the doc values.

func (*Circle) BoundingBox added in v0.2.6

func (c *Circle) BoundingBox() index.GeoJSON

func (*Circle) Contains

func (c *Circle) Contains(other index.GeoJSON) (bool, error)

func (*Circle) IndexCells added in v0.2.6

func (c *Circle) IndexCells() (inner, cross []uint64)

IndexCells returns the circle's covering partitioned into inner cells (fully contained in the cap built from the center and radiusInMeters) and cross cells (overlapping the cap's boundary).

func (*Circle) IndexTokens

func (c *Circle) IndexTokens(s *s2.RegionTermIndexer) []string

func (*Circle) Intersects

func (c *Circle) Intersects(other index.GeoJSON) (bool, error)

func (*Circle) Marshal

func (c *Circle) Marshal() ([]byte, error)

func (*Circle) QueryCells added in v0.2.6

func (c *Circle) QueryCells() (inner, cross []uint64)

QueryCells returns the circle's query-time covering, partitioned the same way as IndexCells.

func (*Circle) QueryTokens

func (c *Circle) QueryTokens(s *s2.RegionTermIndexer) []string

func (*Circle) Type

func (c *Circle) Type() string

func (*Circle) UnmarshalJSON

func (c *Circle) UnmarshalJSON(data []byte) error

func (*Circle) Value added in v0.1.13

func (c *Circle) Value() ([]byte, error)

type Envelope

type Envelope struct {
	Typ      string      `json:"type"`
	Vertices [][]float64 `json:"coordinates"`
	// contains filtered or unexported fields
}

Envelope represents the envelope/bounding box type and it implements the index.GeoJSON interface.

func (*Envelope) BoundingBox added in v0.2.6

func (e *Envelope) BoundingBox() index.GeoJSON

func (*Envelope) Contains

func (e *Envelope) Contains(other index.GeoJSON) (bool, error)

func (*Envelope) IndexCells added in v0.2.6

func (e *Envelope) IndexCells() (inner, cross []uint64)

IndexCells returns the envelope's covering partitioned into inner cells (fully contained in the rectangle) and cross cells (overlapping its boundary).

func (*Envelope) IndexTokens

func (e *Envelope) IndexTokens(s *s2.RegionTermIndexer) []string

func (*Envelope) Intersects

func (e *Envelope) Intersects(other index.GeoJSON) (bool, error)

func (*Envelope) Marshal

func (e *Envelope) Marshal() ([]byte, error)

func (*Envelope) QueryCells added in v0.2.6

func (e *Envelope) QueryCells() (inner, cross []uint64)

QueryCells returns the envelope's query-time covering, partitioned the same way as IndexCells.

func (*Envelope) QueryTokens

func (e *Envelope) QueryTokens(s *s2.RegionTermIndexer) []string

func (*Envelope) Type

func (e *Envelope) Type() string

func (*Envelope) Value added in v0.1.13

func (e *Envelope) Value() ([]byte, error)

type GeoShape added in v0.2.3

type GeoShape struct {
	// Type of the shape
	Type string

	// Coordinates of the shape
	// Used for all shapes except Circles
	Coordinates [][][][]float64

	// Radius of the circle
	Radius string

	// Center of the circle
	Center []float64
}

type GeometryCollection

type GeometryCollection struct {
	Typ    string          `json:"type"`
	Shapes []index.GeoJSON `json:"geometries"`
}

GeometryCollection represents the geoJSON geometryCollection type and it implements the index.GeoJSON interface as well as the compositeShape interface.

func (*GeometryCollection) BoundingBox added in v0.2.6

func (gc *GeometryCollection) BoundingBox() index.GeoJSON

func (*GeometryCollection) Contains

func (gc *GeometryCollection) Contains(other index.GeoJSON) (bool, error)

func (*GeometryCollection) IndexCells added in v0.2.6

func (gc *GeometryCollection) IndexCells() (inner, cross []uint64)

IndexCells returns the union of the member shapes' coverings, deduplicated and reconciled (see aggregateCells).

func (*GeometryCollection) Intersects

func (gc *GeometryCollection) Intersects(other index.GeoJSON) (bool, error)

func (*GeometryCollection) Marshal

func (gc *GeometryCollection) Marshal() ([]byte, error)

func (*GeometryCollection) Members

func (gc *GeometryCollection) Members() []index.GeoJSON

func (*GeometryCollection) QueryCells added in v0.2.6

func (gc *GeometryCollection) QueryCells() (inner, cross []uint64)

QueryCells returns the union of the member shapes' query-time coverings, deduplicated and reconciled (see aggregateCells).

func (*GeometryCollection) Type

func (gc *GeometryCollection) Type() string

func (*GeometryCollection) UnmarshalJSON

func (gc *GeometryCollection) UnmarshalJSON(data []byte) error

func (*GeometryCollection) Value added in v0.1.13

func (gc *GeometryCollection) Value() ([]byte, error)

type LineString

type LineString struct {
	Typ      string      `json:"type"`
	Vertices [][]float64 `json:"coordinates"`
	// contains filtered or unexported fields
}

LineString represents the geoJSON linestring type and it implements the index.GeoJSON interface.

func (*LineString) BoundingBox added in v0.2.6

func (ls *LineString) BoundingBox() index.GeoJSON

func (*LineString) Contains

func (ls *LineString) Contains(other index.GeoJSON) (bool, error)

func (*LineString) Coordinates

func (ls *LineString) Coordinates() [][]float64

func (*LineString) IndexCells added in v0.2.6

func (ls *LineString) IndexCells() (inner, cross []uint64)

IndexCells returns the linestring's covering: a polyline has no area, so every covering cell is a cross cell and inner is always nil.

func (*LineString) IndexTokens

func (ls *LineString) IndexTokens(s *s2.RegionTermIndexer) []string

func (*LineString) Intersects

func (ls *LineString) Intersects(other index.GeoJSON) (bool, error)

func (*LineString) Marshal

func (ls *LineString) Marshal() ([]byte, error)

func (*LineString) QueryCells added in v0.2.6

func (ls *LineString) QueryCells() (inner, cross []uint64)

QueryCells returns the linestring's query-time covering; like IndexCells, it can only contain cross cells.

func (*LineString) QueryTokens

func (ls *LineString) QueryTokens(s *s2.RegionTermIndexer) []string

func (*LineString) Type

func (ls *LineString) Type() string

func (*LineString) Value added in v0.1.13

func (ls *LineString) Value() ([]byte, error)

type MultiLineString

type MultiLineString struct {
	Typ      string        `json:"type"`
	Vertices [][][]float64 `json:"coordinates"`
	// contains filtered or unexported fields
}

-------------------------------------------------------- MultiLineString represents the geoJSON multilinestring type and it implements the index.GeoJSON interface as well as the compositeShape interface.

func (*MultiLineString) BoundingBox added in v0.2.6

func (mls *MultiLineString) BoundingBox() index.GeoJSON

func (*MultiLineString) Contains

func (mls *MultiLineString) Contains(other index.GeoJSON) (bool, error)

func (*MultiLineString) Coordinates

func (mls *MultiLineString) Coordinates() [][][]float64

func (*MultiLineString) IndexCells added in v0.2.6

func (mls *MultiLineString) IndexCells() (inner, cross []uint64)

IndexCells returns the multilinestring's covering, computed as a single covering of the union of its polylines. Polylines have no area, so every covering cell is a cross cell and inner is always nil.

func (*MultiLineString) IndexTokens

func (mls *MultiLineString) IndexTokens(s *s2.RegionTermIndexer) []string

func (*MultiLineString) Intersects

func (mls *MultiLineString) Intersects(other index.GeoJSON) (bool, error)

func (*MultiLineString) Marshal

func (mls *MultiLineString) Marshal() ([]byte, error)

func (*MultiLineString) Members

func (mls *MultiLineString) Members() []index.GeoJSON

func (*MultiLineString) QueryCells added in v0.2.6

func (mls *MultiLineString) QueryCells() (inner, cross []uint64)

QueryCells returns the multilinestring's query-time covering; like IndexCells, it can only contain cross cells.

func (*MultiLineString) QueryTokens

func (mls *MultiLineString) QueryTokens(s *s2.RegionTermIndexer) []string

func (*MultiLineString) Type

func (mls *MultiLineString) Type() string

func (*MultiLineString) Value added in v0.1.13

func (mls *MultiLineString) Value() ([]byte, error)

type MultiPoint

type MultiPoint struct {
	Typ      string      `json:"type"`
	Vertices [][]float64 `json:"coordinates"`
	// contains filtered or unexported fields
}

-------------------------------------------------------- MultiPoint represents the geoJSON multipoint type and it implements the index.GeoJSON interface as well as the compositeShape interface.

func (*MultiPoint) BoundingBox added in v0.2.6

func (mp *MultiPoint) BoundingBox() index.GeoJSON

func (*MultiPoint) Contains

func (mp *MultiPoint) Contains(other index.GeoJSON) (bool, error)

func (*MultiPoint) Coordinates

func (mp *MultiPoint) Coordinates() [][]float64

func (*MultiPoint) IndexCells added in v0.2.6

func (mp *MultiPoint) IndexCells() (inner, cross []uint64)

IndexCells returns the multipoint's covering: points have no area, so the result is one maxCellLevel cross cell per distinct point cell and never any inner cells. Cells are deduplicated, since points can share a cell.

func (*MultiPoint) IndexTokens

func (mp *MultiPoint) IndexTokens(s *s2.RegionTermIndexer) []string

func (*MultiPoint) Intersects

func (mp *MultiPoint) Intersects(other index.GeoJSON) (bool, error)

func (*MultiPoint) Marshal

func (mp *MultiPoint) Marshal() ([]byte, error)

func (*MultiPoint) Members

func (mp *MultiPoint) Members() []index.GeoJSON

func (*MultiPoint) QueryCells added in v0.2.6

func (mp *MultiPoint) QueryCells() (inner, cross []uint64)

QueryCells delegates to IndexCells: each point maps to exactly one cell, so the query-time coverer would produce the same cross cells as the index-time coverer.

func (*MultiPoint) QueryTokens

func (mp *MultiPoint) QueryTokens(s *s2.RegionTermIndexer) []string

func (*MultiPoint) Type

func (mp *MultiPoint) Type() string

func (*MultiPoint) Value added in v0.1.13

func (mp *MultiPoint) Value() ([]byte, error)

type MultiPolygon

type MultiPolygon struct {
	Typ      string          `json:"type"`
	Vertices [][][][]float64 `json:"coordinates"`
	// contains filtered or unexported fields
}

-------------------------------------------------------- MultiPolygon represents the geoJSON multipolygon type and it implements the index.GeoJSON interface as well as the compositeShape interface.

func (*MultiPolygon) BoundingBox added in v0.2.6

func (mp *MultiPolygon) BoundingBox() index.GeoJSON

func (*MultiPolygon) Contains

func (mp *MultiPolygon) Contains(other index.GeoJSON) (bool, error)

func (*MultiPolygon) Coordinates

func (mp *MultiPolygon) Coordinates() [][][][]float64

func (*MultiPolygon) IndexCells added in v0.2.6

func (mp *MultiPolygon) IndexCells() (inner, cross []uint64)

IndexCells returns the multipolygon's covering, computed as a single covering of the union of its polygons and partitioned into inner and cross cells.

func (*MultiPolygon) IndexTokens

func (mp *MultiPolygon) IndexTokens(s *s2.RegionTermIndexer) []string

func (*MultiPolygon) Intersects

func (mp *MultiPolygon) Intersects(other index.GeoJSON) (bool, error)

func (*MultiPolygon) Marshal

func (mp *MultiPolygon) Marshal() ([]byte, error)

func (*MultiPolygon) Members

func (mp *MultiPolygon) Members() []index.GeoJSON

func (*MultiPolygon) QueryCells added in v0.2.6

func (mp *MultiPolygon) QueryCells() (inner, cross []uint64)

QueryCells returns the multipolygon's query-time covering, partitioned the same way as IndexCells.

func (*MultiPolygon) QueryTokens

func (mp *MultiPolygon) QueryTokens(s *s2.RegionTermIndexer) []string

func (*MultiPolygon) Type

func (mp *MultiPolygon) Type() string

func (*MultiPolygon) Value added in v0.1.13

func (mp *MultiPolygon) Value() ([]byte, error)

type Point

type Point struct {
	Typ      string    `json:"type"`
	Vertices []float64 `json:"coordinates"`
	// contains filtered or unexported fields
}

-------------------------------------------------------- Point represents the geoJSON point type and it implements the index.GeoJSON interface.

func (*Point) BoundingBox added in v0.2.6

func (p *Point) BoundingBox() index.GeoJSON

func (*Point) Contains

func (p *Point) Contains(other index.GeoJSON) (bool, error)

func (*Point) Coordinates

func (p *Point) Coordinates() []float64

func (*Point) IndexCells added in v0.2.6

func (p *Point) IndexCells() (inner, cross []uint64)

IndexCells returns the point's covering: a point has no area, so it is a single maxCellLevel cross cell and never an inner cell.

func (*Point) IndexTokens

func (p *Point) IndexTokens(s *s2.RegionTermIndexer) []string

func (*Point) Intersects

func (p *Point) Intersects(other index.GeoJSON) (bool, error)

func (*Point) Marshal

func (p *Point) Marshal() ([]byte, error)

func (*Point) QueryCells added in v0.2.6

func (p *Point) QueryCells() (inner, cross []uint64)

QueryCells delegates to IndexCells: a point maps to exactly one cell, so the query-time coverer would produce the same single cross cell as the index-time coverer.

func (*Point) QueryTokens

func (p *Point) QueryTokens(s *s2.RegionTermIndexer) []string

func (*Point) Type

func (p *Point) Type() string

func (*Point) Value added in v0.1.13

func (p *Point) Value() ([]byte, error)

type Polygon

type Polygon struct {
	Typ      string        `json:"type"`
	Vertices [][][]float64 `json:"coordinates"`
	// contains filtered or unexported fields
}

Polygon represents the geoJSON polygon type and it implements the index.GeoJSON interface.

func (*Polygon) BoundingBox added in v0.2.6

func (pg *Polygon) BoundingBox() index.GeoJSON

func (*Polygon) Contains

func (pg *Polygon) Contains(other index.GeoJSON) (bool, error)

func (*Polygon) Coordinates

func (pg *Polygon) Coordinates() [][][]float64

func (*Polygon) IndexCells added in v0.2.6

func (pg *Polygon) IndexCells() (inner, cross []uint64)

IndexCells returns the polygon's covering partitioned into inner cells (fully contained in the polygon, excluding any holes) and cross cells (overlapping the boundary). The hole exclusion relies on the s2 polygon being built from oriented loops, so ContainsCell is false for cells inside interior rings.

func (*Polygon) IndexTokens

func (pg *Polygon) IndexTokens(s *s2.RegionTermIndexer) []string

func (*Polygon) Intersects

func (pg *Polygon) Intersects(other index.GeoJSON) (bool, error)

func (*Polygon) Marshal

func (pg *Polygon) Marshal() ([]byte, error)

func (*Polygon) QueryCells added in v0.2.6

func (pg *Polygon) QueryCells() (inner, cross []uint64)

QueryCells returns the polygon's query-time covering, partitioned the same way as IndexCells.

func (*Polygon) QueryTokens

func (pg *Polygon) QueryTokens(s *s2.RegionTermIndexer) []string

func (*Polygon) Type

func (pg *Polygon) Type() string

func (*Polygon) Value added in v0.1.13

func (pg *Polygon) Value() ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL