geonames

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2019 License: Apache-2.0 Imports: 8 Imported by: 2

README

Geonames

Golang parsing library for the geonames.org database dump.

Features

  • Parse data directly without downloading and unzipping
  • Read line by line with low memory consumption

Implemented data

status archive comment
xx.zip GetGeonames; See readme
admin1CodesASCII.txt GetAdminDivisions
admin2Codes.txt GetAdminSubdivisions
adminCode5.zip GetAdminCodes5
allCountries.zip GetGeonames
⚠️ alternateNames.zip depricated, use alternateNamesV2.zip instead
alternateNamesDeletes-xxxx-xx-xx.txt GetAlternateNameDeletes
alternateNamesModifications-xxxx-xx-xx.txt GetAlternateNameModifications
alternateNamesV2.zip GetAlternateNames
alternatenames/xx.zip GetAlternateNames; See readme
cities1000.zip GetGeonames
cities15000.zip GetGeonames
cities500.zip GetGeonames
cities5000.zip GetGeonames
countryInfo.txt GetCountries
deletes-xxxx-xx-xx.txt GetDeletes
featureCodes_bg.txt GetFeatureCodes
featureCodes_en.txt GetFeatureCodes
featureCodes_nb.txt GetFeatureCodes
featureCodes_nn.txt GetFeatureCodes
featureCodes_no.txt GetFeatureCodes
featureCodes_ru.txt GetFeatureCodes
featureCodes_sv.txt GetFeatureCodes
hierarchy.zip GetHierarchy
iso-languagecodes.txt GetLanguages
modifications-xxxx-xx-xx.txt GetModifications
no-country.zip GetGeonames
shapes_all_low.zip GetShapes
⚠️ shapes_simplified_low.json.zip I don't see the point in geojson parsing
timeZones.txt GetTimeZones
userTags.zip GetUserTags

Installation

$ go get github.com/mkrou/geonames

Quick start

Parsing cities

package main

import (
    "fmt"
    "github.com/mkrou/geonames"
    "github.com/mkrou/geonames/models"
    "log"
)

func main() {
    p := geonames.NewParser()
    
    //print all cities with a population greater than 5000
    err := p.GetGeonames(geonames.Cities5000, func(geoname *models.Geoname) error {
    fmt.Println(geoname.Name)
        return nil
    })
    if err != nil {
        log.Fatal(err)
    }
}

Parsing alternames
package main

import (
    "fmt"
    "github.com/mkrou/geonames"
    "github.com/mkrou/geonames/models"
    "log"
)
func main() {
    p := geonames.NewParser()
    
    err := p.GetAlternateNames(geonames.AlternateNames, func(geoname *models.AlternateName) error {
        fmt.Println(geoname.Name)
        return nil
    })
    if err != nil {
        log.Fatal(err)
    }
}
Parsing alphabetical list of archives
package main

import (
    "fmt"
    "github.com/mkrou/geonames"
    "github.com/mkrou/geonames/models"
    "log"
)
func main() {
    p := geonames.NewParser()
    
    err := p.GetGeonames("AD.zip", func(geoname *models.Geoname) error {
        fmt.Println(geoname.Name)
        return nil
    })
    if err != nil {
        log.Fatal(err)
    }
    
    err = p.GetAlternateNames("alternames/AD.zip", func(geoname *models.AlternateName) error {
        fmt.Println(geoname.Name)
        return nil
    })
    if err != nil {
        log.Fatal(err)
    }
}

Documentation

Index

Constants

View Source
const (
	Cities500                   models.GeoNameFile     = "cities500.zip"
	Cities1000                  models.GeoNameFile     = "cities1000.zip"
	Cities5000                  models.GeoNameFile     = "cities5000.zip"
	Cities15000                 models.GeoNameFile     = "cities15000.zip"
	AllCountries                models.GeoNameFile     = "allCountries.zip"
	NoCountry                   models.GeoNameFile     = "no-country.zip"
	AlternateNames              models.AltNameFile     = "alternateNamesV2.zip"
	LangCodes                   models.DumpFile        = "iso-languagecodes.txt"
	TimeZones                   models.DumpFile        = "timeZones.txt"
	Countries                   models.DumpFile        = "countryInfo.txt"
	FeatureCodeBg               models.FeatureCodeFile = "featureCodes_bg.txt"
	FeatureCodeEn               models.FeatureCodeFile = "featureCodes_en.txt"
	FeatureCodeNb               models.FeatureCodeFile = "featureCodes_nb.txt"
	FeatureCodeNn               models.FeatureCodeFile = "featureCodes_nn.txt"
	FeatureCodeNo               models.FeatureCodeFile = "featureCodes_no.txt"
	FeatureCodeRu               models.FeatureCodeFile = "featureCodes_ru.txt"
	FeatureCodeSv               models.FeatureCodeFile = "featureCodes_sv.txt"
	Hierarchy                   models.DumpFile        = "hierarchy.zip"
	Shapes                      models.DumpFile        = "shapes_all_low.zip"
	UserTags                    models.DumpFile        = "userTags.zip"
	AdminDivisions              models.DumpFile        = "admin1CodesASCII.txt"
	AdminSubDivisions           models.DumpFile        = "admin2Codes.txt"
	AdminCode5                  models.DumpFile        = "adminCode5.zip"
	AlternateNamesDeletes       models.DumpFile        = "alternateNamesDeletes-%s.txt"
	AlternateNamesModifications models.DumpFile        = "alternateNamesModifications-%s.txt"
	Deletes                     models.DumpFile        = "deletes-%s.txt"
	Modifications               models.DumpFile        = "modifications-%s.txt"
)

List of dump archives

View Source
const Url = "https://download.geonames.org/export/dump/"

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser func(file string) (io.ReadCloser, error)

func NewParser

func NewParser() Parser

func (Parser) GetAdminCodes5

func (p Parser) GetAdminCodes5(handler func(*models.AdminCode5) error) error

func (Parser) GetAdminDivisions

func (p Parser) GetAdminDivisions(handler func(*models.AdminDivision) error) error

func (Parser) GetAdminSubdivisions

func (p Parser) GetAdminSubdivisions(handler func(*models.AdminSubdivision) error) error

func (Parser) GetAlternateNameDeletes

func (p Parser) GetAlternateNameDeletes(handler func(*models.AlternateNameDelete) error) error

func (Parser) GetAlternateNameModifications

func (p Parser) GetAlternateNameModifications(handler func(*models.AlternateNameModification) error) error

func (Parser) GetAlternateNames

func (p Parser) GetAlternateNames(archive models.AltNameFile, handler func(*models.AlternateName) error) error

func (Parser) GetCountries

func (p Parser) GetCountries(handler func(*models.Country) error) error

func (Parser) GetDeletes

func (p Parser) GetDeletes(handler func(*models.GeonameDelete) error) error

func (Parser) GetFeatureCodes

func (p Parser) GetFeatureCodes(file models.FeatureCodeFile, handler func(*models.FeatureCode) error) error

func (Parser) GetGeonames

func (p Parser) GetGeonames(archive models.GeoNameFile, handler func(*models.Geoname) error) error

func (Parser) GetHierarchy

func (p Parser) GetHierarchy(handler func(*models.Hierarchy) error) error

func (Parser) GetLanguages

func (p Parser) GetLanguages(handler func(*models.Language) error) error

func (Parser) GetModifications

func (p Parser) GetModifications(handler func(*models.Geoname) error) error

func (Parser) GetShapes

func (p Parser) GetShapes(handler func(*models.Shape) error) error

func (Parser) GetTimeZones

func (p Parser) GetTimeZones(handler func(*models.TimeZone) error) error

func (Parser) GetUserTags

func (p Parser) GetUserTags(handler func(*models.UserTag) error) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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