gozipcode

package module
v0.0.0-...-730b1d0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2017 License: MIT Imports: 8 Imported by: 0

README

gozipcode

US ZipCode database, batteries included.

go port of https://github.com/buckmaxwell/zipcode

 go get github.com/Hendler/gozipcode

usage

Building the example

go build -o $GOBIN/gozipcode-example example/main.go

import (
    "github.com/Hendler/gozipcode"
    "fmt"
)

func main(){
    gozipcode.Init()
    fmt.Print("EXACT MATCH --- \n")
    zipcode := gozipcode.Isequal("04976")
    fmt.Printf("%v\n", *zipcode)
    zipcode = gozipcode.Isequal("adsfa")
    if (zipcode != nil){
        fmt.Printf("%v\n", *zipcode)
    }

    fmt.Print("PREFIX --- \n")
    zipcodes := gozipcode.Islike("0497%")
    for _, zipcode := range zipcodes {
        fmt.Printf("%v\n", *zipcode)
    }

    fmt.Print("RADIUS --- \n")
    skow_lat  := 44.77
    skow_long := -69.71
    zipcodes = gozipcode.Isinradius(skow_lat, skow_long, 15)
    for _, zipcode := range zipcodes {
        fmt.Printf("%v\n", *zipcode)
    }
}

TODO

  • zipcodes for all countries
  • more tests
  • configurable database location
  • performance - confirm that check_same_thread is doing something useful
  • use sql.NullString in struct

building

gozipcode optionally uses Glide (glide.lock, glide.yaml file inculded, vendor directory ommitted)

go get github.com/Masterminds/glide
go install github.com/Masterminds/glide

glide install

dependencies

In glide.yaml

github.com/mattn/go-sqlite3

investigate

github.com/golang/geo

notes

SQLite file is included in Binary via bindata

go get -u github.com/jteeuwen/go-bindata
go install github.com/jteeuwen/go-bindata
go-bindata -pkg gozipcode -o ./data/zipcode.go ./data/zipcode.db

Documentation

Index

Constants

View Source
const ASSET_FULLPATH string = "data/" + DATABASE_FILENAME
View Source
const AUTHOR string = "Jonathan Hendler"
View Source
const DATABASE_FILENAME string = "zipcode.db"
View Source
const DISTANCE_BETWEEN_LAT_DEGREES = float64(69.172)
View Source
const EARTHRADIUS = float64(6371)
View Source
const KMTOMAILES = float64(0.621371192)
View Source
const LICENSE string = "MIT"
View Source
const PACKAGE string = "zipcode"
View Source
const VERSION string = "0.9.0"

Variables

View Source
var ZipCodeDB *sql.DB
View Source
var ZipCodeDBPath string = "/tmp/" + DATABASE_FILENAME

Functions

func Cleanup

func Cleanup()

func Haversine

func Haversine(lonFrom float64, latFrom float64, lonTo float64, latTo float64) (distance float64)

* The haversine formula will calculate the spherical distance as the crow flies * between lat and lon for two given points in km * from https://play.golang.org/p/MZVh5bRWqN

func main() {
    var locationName [2]string
    var location [2][2]float64
    // York - lat,lon
    locationName[0] = "York"
    location[0][0] = 1.0803
    location[0][1] = 53.9583
    // Bristol - lat,lon
    locationName[1] = "Bristol"
    location[1][0] = 2.5833
    location[1][1] = 51.4500

    // Use haversine to get the resulting diatance between the two values
    var distance = Haversine(location[0][0], location[0][1], location[1][0], location[1][1])
    // We wish to use miles so will alter the resulting distance
    var distancemiles = distance * kmtomiles

    fmt.Printf("The distance between %s and %s is %.02f miles as the crow flies", locationName[0], locationName[1], distancemiles)
}

func Init

func Init()

Init is called automatically by each function can be called explicitly

Types

type Zipcode

type Zipcode struct {
	// The 5 digit zip code
	ZIP_CODE string
	// The type of zip code according to USPS: 'UNIQUE', 'PO BOX', or 'STANDARD'"""
	ZIP_CODE_TYPE string
	// The primary city associated with the zip code according to USPS
	CITY string
	// The state associated with the zip code according to USPS
	STATE string
	// This value will always be 'Primary'. Secondary and 'Not Acceptable' placenames have been removed.
	LOCATION_TYPE string
	// The latitude associated with the zipcode according to the National Weather Service.  This can be empty when there is no NWS Data
	LAT float64
	// The longitude associated with the zipcode according to the National Weather Service. This can be empty when there is no NWS Data
	LONG  float64
	XAXIS string
	YAXIS string
	ZAXIS string
	// This value will always be NA for North America
	WORLD_REGION string
	// This value will always be US for United States -- This includes Embassy's, Military Bases, and Territories
	COUNTRY string
	// The city with its state or territory. Example:  'Cleveland, OH' or 'Anasco, PR'
	LOCATION_TEXT string
	// "A string formatted as WORLD_REGION-COUNTRY-STATE-CITY. Example: 'NA-US-PR-ANASCO'
	LOCATION string
	// A boolean value that reveals if a zipcode is still in use
	DECOMMISIONED string
	// Number of tax returns filed for the zip code in 2008 according to the IRS
	TAX_RETURNS_FILED string
	// Estimated population in 2008 according to the IRS
	ESTIMATED_POPULATION string
	// Total wages according in 2008 according to the IRS"
	TOTAL_WAGES string
	// Not empty when there is no NWS data.
	NOTES string
}

func Isequal

func Isequal(zipcode string) *Zipcode

func Isinradius

func Isinradius(lat float64, long float64, miles float64) []*Zipcode

func Islike

func Islike(zipcode string) []*Zipcode

Takes a partial zip code and returns a list of zipcode objects with matching prefixes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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