Code Monkey home page Code Monkey logo

reverse-geocoder's Introduction

Reverse Geocoder

A Python library for offline reverse geocoding. It improves on an existing library called reverse_geocode developed by Richard Penman.

UPDATE (08-Jul-16): v1.4 released! See release notes below.

About

Ajay Thampi | @thampiman | opensignal.com | ajaythampi.com

Features

  1. Besides city/town and country code, this library also returns the nearest latitude and longitude and also administrative regions 1 and 2.
  2. This library also uses a parallelised implementation of K-D trees which promises an improved performance especially for large inputs.

The K-D tree is populated with cities that have a population > 1000. The source of the data is GeoNames.

Installation

For first time installation,

$ pip install reverse_geocoder

Or upgrade an existing installation using,

$ pip install --upgrade reverse_geocoder

Package can be found on PyPI.

Dependencies

  1. scipy
  2. numpy

Release Notes

  1. v1.0 (27-Mar-15) - First version with support for only Python2
  2. v1.1 (28-Mar-15) - Fix for issue #1 by Brandon
  3. v1.2 (30-Mar-15) - Support for Python 3, conversion of Geodetic coordinates to ECEF for use in K-D trees to find nearest neighbour using the Euclidean distance function. This release fixes issues #2 and #8. Special thanks to David for his help in partly fixing #2.
  4. v1.3 (11-Apr-15) - This release fixes issues #9, #10, #11 and #12. License has been changed from MIT to LGPL (see #12).
  5. v1.4 (08-Jul-16) - Included numpy and scipy as dependencies in setup.

Usage

The library supports two modes:

  1. Mode 1: Single-threaded K-D Tree (similar to reverse_geocode)
  2. Mode 2: Multi-threaded K-D Tree (default)
import reverse_geocoder as rg

coordinates = (51.5214588,-0.1729636),(9.936033, 76.259952),(37.38605,-122.08385)

results = rg.search(coordinates) # default mode = 2

print results

The above code will output the following:

	[{'name': 'Bayswater', 
      'cc': 'GB', 
      'lat': '51.51116',
      'lon': '-0.18426', 
      'admin1': 'England', 
      'admin2': 'Greater London'}, 
     {'name': 'Cochin', 
      'cc': 'IN', 
      'lat': '9.93988',
      'lon': '76.26022', 
      'admin1': 'Kerala', 
      'admin2': 'Ernakulam'},
     {'name': 'Mountain View', 
      'cc': 'US', 
      'lat': '37.38605',
      'lon': '-122.08385', 
      'admin1': 'California', 
      'admin2': 'Santa Clara County'}]

If you'd like to use the single-threaded K-D tree, set mode = 1 as follows:

results = rg.search(coordinates,mode=1)

Performance

The performance of modes 1 and 2 are plotted below for various input sizes.

Performance Comparison

Mode 2 runs ~2x faster for very large inputs (10M coordinates).

Acknowledgements

  1. Major inspiration is from Richard Penman's reverse_geocode library
  2. Parallelised implementation of K-D Trees is extended from this article by Sturla Molden
  3. Geocoded data is from GeoNames

License

Copyright (c) 2015 Ajay Thampi and contributors. This code is licensed under the LGPL License.

reverse-geocoder's People

Contributors

thampiman avatar godfoder avatar bdon avatar davidjfelix avatar gfairchild avatar mehdilauters avatar

Watchers

Taylor Hubbard avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.