Code Monkey home page Code Monkey logo

atlas's Introduction

Atlas   Build Status

Atlas, an offline reverse Geo-coding library written in Java, inspired by reverse-geocoder.

The index is a double SortedMap<Double, Set<City>> that keeps an index on both the latitudes and longitudes of the cities.

using Atlas

Clone this repository and add the library to your local Maven repos:

git clone https://github.com/bkiers/atlas.git
cd altas
mvn clean install

Add the following dependency to your project:

<dependency>
  <groupId>nl.big-o</groupId>
  <artifactId>atlas</artifactId>
  <version>0.2.1</version>
</dependency>

and use the library as follows:

// (lat, lng) somewhere in Venice
double lat = 45.436636;
double lng = 12.326413;

// Find a single city
City city = new Atlas().find(lat, lng);

System.out.println(city);
//    City{
//      geoNameId=3164603
//      name='Venice'
//      latitude=45.43713
//      longitude=12.33265
//      countryCode='IT'
//      timeZone='Europe/Rome'
//      admin1='Veneto'
//      admin2='Provincia di Venezia'
//    }

// Finds 3 cities around the (lat,lng) in a radius of 5 kilometers
List<City> cities = new Atlas()
    .withLimit(3)
    .withMaxDistance(5000)
    .findAll(lat, lng);

for (City c : cities) {
  System.out.println(c);
}
//      City{
//        geoNameId=3164603
//        name='Venice'
//        latitude=45.43713
//        longitude=12.33265
//        countryCode='IT'
//        timeZone='Europe/Rome'
//        admin1='Veneto'
//        admin2='Provincia di Venezia'
//      }
//      City{
//        geoNameId=3175265
//        name='Giudecca'
//        latitude=45.42477
//        longitude=12.32906
//        countryCode='IT'
//        timeZone='Europe/Rome'
//        admin1='Veneto'
//        admin2='Provincia di Venezia'
//      }
//      City{
//        geoNameId=3172456
//        name='Murano'
//        latitude=45.45857
//        longitude=12.35683
//        countryCode='IT'
//        timeZone='Europe/Rome'
//        admin1='Veneto'
//        admin2='Provincia di Venezia'
//      }

(re) creating the index

In order to recreate the index, download the cities1000.zip and unzip it in this project's ./data folder. Optionally also copy the files: admin1CodesASCII.txt and admin2Codes.txt to the ./data folder.

You can also run update.sh in the ./data folder, which downloads these files via curl.

To create a new index containing all cities, simply run:

mvn -q exec:java
mvn package

which will create a JAR file, atlas-VERSION.jar, inside the ./target folder of approximately 5.6 Megabytes containing the entire index of all cities.

If you don't need all cities, you can create a smaller index. For example, if you want to create an index of the counties Spain and Portugal, do the following:

mvn -q exec:java -Dexec.args="ES,PT"
mvn package

credits

  • data from GeoNames
  • blazing fast (de)serialization using Kryo

license

MIT

atlas's People

Contributors

bkiers avatar tholu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

atlas's Issues

atlas library missing from maven

Hello, we noticed atlas library is missing from maven:

[error] (update) sbt.librarymanagement.ResolveException: Error downloading nl.big-o:atlas:0.2.0
[error]   Not found
[error]   Not found
[error]   not found: /root/.ivy2/local/nl.big-o/atlas/0.2.0/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/nl/big-o/atlas/0.2.0/atlas-0.2.0.pom
[error]   not found: /root/.m2/repository/nl/big-o/atlas/0.2.0/atlas-0.2.0.pom
[error]   not found: https://oss.sonatype.org/content/repositories/snapshots/nl/big-o/atlas/0.2.0/atlas-0.2.0.pom

Is there a new location to get it ?

Thank you in advance !

Less Information

Please is there a way to get more information like suburb and road? Thanks

java.lang.IndexOutOfBoundsException while running in Spark application

Hi ! I'm a new user of this library.
When trying to run this code using Spark (+ Fat Jar)

object main extends App {
        val city = new Atlas().find(48.0000, 2.000);
        println(city)
}

I had this error:

	at main$.delayedEndpoint$main$1(main.scala:10)
	at main$delayedInit$body.apply(main.scala:9)
	at scala.Function0.apply$mcV$sp(Function0.scala:39)
	at scala.Function0.apply$mcV$sp$(Function0.scala:39)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
	at scala.App.$anonfun$main$1$adapted(App.scala:80)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at scala.App.main(App.scala:80)
	at scala.App.main$(App.scala:78)
	at main$.main(main.scala:9)
	at main.main(main.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
	at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:928)
	at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:180)
	at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:203)
	at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:90)
	at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:1007)
	at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:1016)
	at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.RuntimeException: java.lang.IndexOutOfBoundsException: Index: 10, Size: 0
	at atlas.Utils.deserialize(Utils.java:67)
	at atlas.Atlas.<clinit>(Atlas.java:12)
	... 23 more
Caused by: java.lang.IndexOutOfBoundsException: Index: 10, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	at java.util.ArrayList.get(ArrayList.java:433)
	at com.esotericsoftware.kryo.util.MapReferenceResolver.getReadObject(MapReferenceResolver.java:60)
	at com.esotericsoftware.kryo.Kryo.readReferenceOrNull(Kryo.java:857)
	at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:707)
	at atlas.Utils.deserialize(Utils.java:63)
	... 24 more

It works well using sbt run, but not running it inside Spark application (itself using sbt assembly to generate a Fat Jar)..

Wondering what's wrong here, looks related to kryo serializer.
I'd be glad if you can help me !

Thanks,

Antoine

Update index

Can a new release with recent data from geonames.org be provided? I'll try to do it and will provide a pull request.

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.