Skip to main content

Library for working with GeoNames dump

Project description

Library to query places from GeoName dumps (http://download.geonames.org/export/dump/).

Installation

geonames requires Python 2.7 or 3.5+ as well as numpy and pandas packages. It can be installed with,

pip install geonames

Usage

The best way to search for a specific location is to have a “filter” value and then the place’s name. The filter will reduce the number of rows to check considerably. For example, when searching for a location in the US there are (currently) 2237584 entries. However, once a state is specified (e.g. West Virigina) the number drops down to 35932; 1/60th of the original number of rows.

import geonames
import io
import urllib.request as request
import zipfile

name = 'Bath(Berkeley Springs)'  # (Berkeley Springs, West Virgina)

# Download US geonames dataset
US = request.urlopen('http://download.geonames.org/export/dump/US.zip')
zipfile = zipfile.ZipFile(io.BytesIO(US.read()))

# Load data
geo = geonames.GeoNames(zipfile.open('US.txt'))

# Search with state specified (`admin1code` filters by state)
location = next(geo.search(name=name, admin1code='WV'))
print(location)

Which (if all goes well) should output:

geonameid                                              4.7987e+06
name                                             Berkeley Springs
asciiname                                        Berkeley Springs
alternatenames      Berkeley Spring,Berkeley Springs,Warm Springs
latitude                                                  39.6264
longitude                                                -78.2292
featureclass                                                    H
featurecode                                                  SPNG
countrycode                                                    US
countrycode2                                                  NaN
admin1code                                                     WV
admin2code                                                    065
admin3code                                                    NaN
admin4code                                                    NaN
population                                                      0
elevation                                                     185
dem                                                           194
timezone                                         America/New_York
modificationdate                                       2011-12-12
certainty                                                      86
Name: 741633, dtype: object

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geonames-lib-0.4.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geonames_lib-0.4-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file geonames-lib-0.4.tar.gz.

File metadata

  • Download URL: geonames-lib-0.4.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

File hashes

Hashes for geonames-lib-0.4.tar.gz
Algorithm Hash digest
SHA256 145c93e41ea9e6ed592648b2f8c19aab3f96ff8ae65d362aef05712446ca07a3
MD5 cd45008669af25815ddd47fad481483e
BLAKE2b-256 d8ddef9956fa6bf2d9f375dc8a8dae7151a6fbfb46022a38a1bad5ad2c3680c8

See more details on using hashes here.

File details

Details for the file geonames_lib-0.4-py3-none-any.whl.

File metadata

  • Download URL: geonames_lib-0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

File hashes

Hashes for geonames_lib-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3c9ca9147ed97f24733cc947833f2e4877ea1986079e3e21a1623ce5b317dfc9
MD5 0645dc254e50b3bd884df83033a211d7
BLAKE2b-256 63ca5ef8772746a00420ac37cefe2fa9ab6c46d9b45bbbfee6e19774496f47ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page