stadfangaskra

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

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

Go to latest
Published: Mar 2, 2016 License: Apache-2.0 Imports: 16 Imported by: 2

README

stadfangaskra

stadfangaskra is a library for working with Icelandic addresses. The address data is sourced from the national registry of Iceland and distributed as part of the library.

Build Status Report Card Coverage

Installation

go get github.com/StefanKjartansson/stadfangaskra

Usage:

Filtering the dataset is done by passing in FindFilter functions with the type signature func(*stadfangaskra.Location) bool to Stadfangaskra.Find.

Example:
package main

import (
	"fmt"
	"log"

	"github.com/StefanKjartansson/stadfangaskra"
)

func main() {
	// Lists even numbered addresses in Kópavogur within 1km of
	// the Landspítalinn hospital.

	// ByDistance returns a FindFilter function.
	distance, err := stadfangaskra.ByDistance(stadfangaskra.Point{X: 64.1195478, Y: -21.8807021}, 1.0)
	if err != nil {
		log.Fatal(err)
	}
	locations, err := stadfangaskra.Stadfangaskra.Find(
		// Filter by the postcodes of Kópavogur
		func(l *stadfangaskra.Location) bool {
			return (200 <= l.Postcode && l.Postcode <= 203)
		},
		// and even numbered house numbers
		func(l *stadfangaskra.Location) bool {
			return l.Number%2 == 0
		},
		// within 1km of the hospital
		distance,
	)
	if err != nil {
		log.Fatal(err)
	}
	for _, loc := range locations {
		fmt.Printf("%s is within 1km of the hospital\n", loc.Name)
	}
}

Builtin match functions

ByDistance

Returns a FindFilter matching addresses within the given radius in km.

f, err := stadfangaskra.ByDistance(stadfangaskra.Point{X: 64.1195478, Y: -21.8807021}, 1.0)
ByLocationString

Returns a FindFilter matching the criteria of the parsed input string.

f, err := stadfangaskra.ByLocationString("Laufásvegur 12, 101 Reykjavík")
ByNumber

Returns a FindFilter matching house numbers.

f, err := stadfangaskra.ByNumber("2")
f, err := stadfangaskra.ByNumber("2a") // supports character part of house number.
ByPostCode

Returns a FindFilter matching postcode.

f, err := stadfangaskra.ByPostCode(200)
ByStreet

Returns a FindFilter matching name of street.

f, err := stadfangaskra.ByStreet("Laugavegur")
f, err := stadfangaskra.ByStreet("laugavegi") // supports dative & lowercase.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHouseNumber = errors.New("Invalid house number")
)
View Source
var (
	ErrInvalidPostCodeRange = errors.New("Invalid post code range")
)
View Source
var (
	Stadfangaskra = Locations{}
)

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

Restore an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

Restore assets under the given directory recursively

Types

type FindFilter

type FindFilter func(*Location) bool

change to bool, error is never used

func ByDistance

func ByDistance(p Point, distance float64) (FindFilter, error)

ByDistance returns a FindFilter matching addresses within the given radius in km.

func ByLocationString

func ByLocationString(s string) (FindFilter, error)

ByLocationString returns a FindFilter matching the criteria of the parsed input string.

func ByNumber

func ByNumber(number string) (FindFilter, error)

ByNumber returns a FindFilter matching house numbers.

func ByPostCode

func ByPostCode(code int) (FindFilter, error)

ByPostCode returns a FindFilter matching postcode.

func ByStreet

func ByStreet(name string) (FindFilter, error)

ByStreet returns a FindFilter matching name of street.

type Location

type Location struct {
	ID           int    `json:"id"`
	Name         string `json:"name"`
	Number       int    `json:"house_number,omitempty"`
	NumberChars  string `json:"house_characters,omitempty"`
	SpecificName string `json:"specific_name,omitempty"`
	Street       string `json:"street,omitempty"`
	StreetDative string `json:"street_dative,omitempty"`
	Postcode     int    `json:"postcode"`
	Municipality string `json:"municipality,omitempty"`
	Coordinates  Point  `json:"coordinates"`
	JSONCache    []byte `json:"-"`
}

type Locations

type Locations []*Location

func (Locations) Find

func (locs Locations) Find(filterOpts ...FindFilter) (Locations, error)

type Point

type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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