Git Product home page Git Product logo

reverse-country-code's Introduction

Reverse Country Code Build Status Coverage Status Maven Central

A reverse geocoder that converts latitude and longitude coordinates to country information such as names, ISO codes and locales.

Usage

ReverseGeocoder geocoder = new ReverseGeocoder();
geocoder.getCountry(51.507222, -0.1275).ifPresent(country -> {
    System.out.println(country.iso());        // GB
    System.out.println(country.iso3());       // GBR
    System.out.println(country.isoNumeric()); // 826
    System.out.println(country.name());       // United Kingdom
    System.out.println(country.area());       // 244820.0
    System.out.println(country.population()); // 62348447
    System.out.println(country.continent());  // EU
    List<Locale> locales = country.locales();
    System.out.println(locales.get(0));       // en_GB
    System.out.println(locales.get(1));       // cy_GB
    System.out.println(locales.get(2));       // gd
});

Dataset

Country information and boundary data comes from GeoNames.

Accuracy

97.92% when ran against the GeoNames data set for cities with a population > 15000.

Performance

~3 μs average to look up city from the GeoNames data set on a 13" MacBook Pro (i5-5257U) using a single thread. The retained heap size for ReverseGeocoder is ~7.5 MB.

Algorithms

Country bounding boxes are loaded into R-Trees using the Sort-Tile-Recursive algorithm. Determining if a point lies within a polygon is performed using the PNPOLY algorithm.

Gradle tasks

Build jar:

./gradlew assemble

Download new Geonames data:

./gradlew updateCountryInfo updateShapes

Run benchmarks:

./gradlew jmh

Generate new baseline test data:

./gradlew generateBaseline

reverse-country-code's People

Contributors

bencampion 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.