lookups

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 1 Imported by: 0

README

Geo Lookups

Build PkgGoDev

Introduction

Fast and in-memory geo lookup library.

Simply add polygons and run queries. It uses Google's S2 Library for indexing and it's super fast 🚀.

Install

go get github.com/4lie/lookups

Examples

lookups_test.go contains several useful examples. You can check visualizations of them here.

Image Description
How indexing works
Simple polygon example
Polygon with holes example
Multiple polygons example

Documentation

Index

Constants

View Source
const (
	// Default level of s2 cells.
	DefaultS2CellLevel = 15
)

Variables

View Source
var (
	// Default value for geo indexer.
	DefaultGeoIndexer = NewS2Index(DefaultS2CellLevel)
)

Functions

func LoopFromCoordinates

func LoopFromCoordinates(coordinates []Coordinate) *s2.Loop

func PolygonFromCoordinates

func PolygonFromCoordinates(coordinates [][]Coordinate) *s2.Polygon

Types

type Coordinate

type Coordinate struct {
	Latitude   float64 `json:"latitude"`
	Longitude  float64 `json:"longitude"`
	SequenceID int     `json:"sequence_id"`
}

type CoordinateProps

type CoordinateProps struct {
	Props      []Props    `json:"props"`
	Coordinate Coordinate `json:"coordinate"`
}

type GeoIndex

type GeoIndex interface {
	Find(Coordinate) string
	Cover(*s2.Polygon) []string
}

GeoIndex is an interface for geo indexing.

type Lookuper

type Lookuper interface {
	Lookup(coordinates []Coordinate) []CoordinateProps
}

Lookuper is an interface for lookup services.

func New

func New(polyProps []PolyProps, geoIndex GeoIndex) Lookuper

New returns a new lookups engine instance.

type PolyProps

type PolyProps struct {
	Props   Props       `json:"props"`
	Polygon *s2.Polygon `json:"polygon"`
}

func PolyPropsFromCoordinates

func PolyPropsFromCoordinates(coordinates [][]Coordinate, props map[string]interface{}) PolyProps

type Props

type Props map[string]interface{}

type S2Index

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

S2Index is an s2-based polygon indexer.

func NewS2Index

func NewS2Index(level int) S2Index

NewS2Index returns a new s2 indexer instance.

func (S2Index) Cover

func (s S2Index) Cover(polygon *s2.Polygon) []string

Covers returns all S2 cells that cover the given polygon.

func (S2Index) Find

func (s S2Index) Find(coordinate Coordinate) string

Find returns an s2 cell that contains the given point.

func (S2Index) FindLarge

func (s S2Index) FindLarge(coordinate Coordinate, level int) []string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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