counties

package module
v0.0.0-...-23cc5a1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MIT Imports: 9 Imported by: 0

README

go-counties

Geo lookup for US Counties

This library uses the output generated from US County Data to identify the U.S. county by lat,lon.

Performance is aided by first identifying possible candidates by bounding box, and only checking the possible enclosing polygons of resulting candidates.

Documentation

Index

Constants

View Source
const (
	// CountyJSONFile is the default data source for county polygon info
	// as generated from github.com/paulstuart/counties
	CountyJSONFile = "county_poly.json"
	CountyGOBFile  = "county_geo.gob.gz"
)

Variables

View Source
var (

	// locations are indexed by GeoID
	CountyLookupMeta = make(map[int]Location)
)
View Source
var ErrNotFound = errors.New("not found")

Functions

func CountyCount

func CountyCount() int

func GobDump

func GobDump(filename string, obj interface{}) error

GobDump saves the object in a gzipped GOB encoded file

func GobLoad

func GobLoad(filename string, obj interface{}) error

GobLoad populates the object from a gzipped GOB encoded file

func InitCountyLookup

func InitCountyLookup(counties []CountyGeo)

InitCountyLookup prepares data for searching for counties

func LoadCachedCountyGeo

func LoadCachedCountyGeo(filename string) error

LoadCachedCountyGeo uses GOB encoded geodata to build county lookup functions

func ProcessJSONData

func ProcessJSONData(source, saved string) error

ProcessJSONData loads the json data file from the data as sourced from https://github.com/paulstuart/counties It will save it as a GOB datafile for faster loading

Types

type CountyGeo

type CountyGeo struct {
	GeoID int    `json:"geoid"`
	Name  string `json:"name"`
	Full  string `json:"fullname"`
	State string `json:"state"`
	BBox  Rect   `json:"bbox"`
	Poly  Points `json:"polygon"`
}

CountyGeo is ready for consumption

func LoadCountyJSON

func LoadCountyJSON(filename string) ([]CountyGeo, error)

LoadCountyJSON loads the json dump file from the data as prepared using https://github.com/paulstuart/counties

func (CountyGeo) Meta

func (cg CountyGeo) Meta() CountyMeta

type CountyMeta

type CountyMeta struct {
	County   string
	Fullname string
	State    string
	GeoID    int
}

CountyMeta is the principle county meta data

func FindCounty

func FindCounty(lat, lon float64) (CountyMeta, error)

FindCounty returns the county associated with the given location

type Location

type Location struct {
	Name     string
	FullName string
	State    string
}

Location is name and state of the county

type Point

type Point = polygons.Pair

Point represents Lat,Lon type Point [2]float64

type Points

type Points = polygons.PPoints

Points is a collection of geographic locations type Points []Point

type Rect

type Rect = polygons.BBox //[2]Point

Rect is the min and max verticies of a bounding box

Directories

Path Synopsis
cmd
prepare command

Jump to

Keyboard shortcuts

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