coord2country

package module
v0.0.0-...-ab2a99e Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 10 Imported by: 1

README

coord2country

A simple solution to query for point in polygon, very fast, mainly for countries polygons but could serve any enclosed regions.

Embedding data from Natural Earth, load precomputed data for fast loading with index into memory using s2.

Usage

idx, err := coord2country.OpenIndex()
if err != nil {
	panic(err)
}

fmt.Printf("%v", idx.Query(48.8, 2.2))

Data

Natural Earth Countries 10M is embedded in the library.

You can use your own data, use cmd/gendata to create your data file.

Speed

Around 320 ns per query, when contained in a Polygon, around 190 ns in a dead zone.

RSS Memory is around 230MB for the 10M world countries.

Projects Using coord2country

  • geo-benthos a GIS plugin for Benthos, a stream processing tool, to enrich stream from coordinates.
  • ovr the optional -tags geo build with the country command returns the country of centroid.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeomFromLoop

func GeomFromLoop(l *s2.Loop) geom.Geometry

func LoopFromPolygon

func LoopFromPolygon(g geom.Polygon) *s2.Loop

LoopFromPolygon creates an s2 loop from the external ring (no holes)

Types

type Index

type Index struct {
	*s2.ShapeIndex
	*s2.ContainsPointQuery
}

func NewIndex

func NewIndex() *Index

func OpenIndex

func OpenIndex() (*Index, error)

func OpenIndexFromData

func OpenIndexFromData(r io.Reader) (*Index, error)

OpenIndexFromData reads the index from a file as follow: uint8 <- size of string Data separated by |, DATA uint32 <- size of s2 polygon encoded, DATA

func OpenIndexFromGeoJSON

func OpenIndexFromGeoJSON(r io.Reader) (*Index, error)

func OpenIndexFromGeoJSONSeq

func OpenIndexFromGeoJSONSeq(r io.Reader) (*Index, error)

func (*Index) IndexFeature

func (idx *Index) IndexFeature(f geom.GeoJSONFeature)

func (*Index) Query

func (idx *Index) Query(lat, lng float64) []IndexedLoop

type IndexedLoop

type IndexedLoop struct {
	*s2.Loop
	Name, Country string
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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