flatrtree

package module
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MIT Imports: 10 Imported by: 0

README

Flatrtree - Go

Flatrtree is a serialization format and set of libraries for reading and writing R-trees. It's directly inspired by Flatbush and FlatGeobuf, and aims to make tiny, portable R-trees accessible in new contexts.

  • Store R-trees to disk or transport them over a network.
  • Build R-trees in one language and query them in another.
  • Query R-trees before reading the data they index.

Installation

Requires Go 1.18 or later.

$ go get github.com/flatrtree/flatrtree-go

Usage

Flatrtree separates building and querying behavior. The builder doesn’t know how to query an index and the index doesn’t know how it was built. This is inspired by FlatBuffers.


Serialization

Flatrtree uses protocol buffers for serialization, taking advantage of varint encoding to reduce the output size in bytes. There are many tradeoffs to explore for serialization and this seems like a good place to start. It wouldn’t be hard to roll your own format with something like FlatBuffers if that better fit your needs.


Documentation

Index

Constants

View Source
const DefaultDegree int = 10

Variables

This section is empty.

Functions

func GeodeticBoxDist

func GeodeticBoxDist(pLon, pLat, minLon, minLat, maxLon, maxLat float64) (meters float64)

GeodeticBoxDist returns the distance in meters between the point and rect

func PlanarBoxDist

func PlanarBoxDist(pX, pY, minX, minY, maxX, maxY float64) float64

PlanarBoxDist returns the squared distance between the given point and rect

func Serialize

func Serialize(index *RTree, precision uint32) ([]byte, error)

Types

type Builder

type Builder interface {
	Add(ref int64, minX, minY, maxX, maxY float64)
	Finish(degree int) (*RTree, error)
}

type HilbertBuilder

type HilbertBuilder struct {
	// contains filtered or unexported fields
}

func NewHilbertBuilder

func NewHilbertBuilder() *HilbertBuilder

func (*HilbertBuilder) Add

func (b *HilbertBuilder) Add(ref int64, minX, minY, maxX, maxY float64)

func (*HilbertBuilder) Finish

func (b *HilbertBuilder) Finish(degree int) (*RTree, error)

type OMTBuilder

type OMTBuilder struct {
	// contains filtered or unexported fields
}

func NewOMTBuilder

func NewOMTBuilder() *OMTBuilder

func (*OMTBuilder) Add

func (b *OMTBuilder) Add(ref int64, minX, minY, maxX, maxY float64)

func (*OMTBuilder) Finish

func (b *OMTBuilder) Finish(degree int) (*RTree, error)

type RTree

type RTree struct {
	// contains filtered or unexported fields
}

func Deserialize

func Deserialize(b []byte) (*RTree, error)

func (*RTree) Count

func (r *RTree) Count() int

Count returns the number of items in the index

func (*RTree) Neighbors

func (r *RTree) Neighbors(
	x, y float64,
	iterf func(ref int64, dist float64) (next bool),
	boxDist func(pX, pY, minX, minY, maxX, maxY float64) (dist float64),
	itemDist func(pX, pY float64, ref int64) (dist float64),
)

Neighbors calls the iterf function for all items in ascending order of distance to the given coordinates. If iterf returns false the search will terminate.

Distances are calculated with the boxDist function. The itemDist function can optionally be supplied to calculate a more accurate distance to items in the index. Take care that itemDist and boxDist return distances in the same units.

func (*RTree) Search

func (r *RTree) Search(
	minX, minY, maxX, maxY float64,
	iterf func(ref int64) (next bool),
)

Search calls the iterf function for all items intersecting the search box. If iterf returns false the search will terminate.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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