Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/adrianulbona/cloc

Self-contained Java Library for Country Localization of GeoHashes
https://github.com/adrianulbona/cloc

apache-spark borders country geohash gis gps java scala

Last synced: 2 months ago
JSON representation

Self-contained Java Library for Country Localization of GeoHashes

Awesome Lists containing this project

README

        

# cloc

[![Build Status](https://travis-ci.org/adrianulbona/cloc.svg?branch=master)](https://travis-ci.org/adrianulbona/cloc)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.adrianulbona/cloc/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.adrianulbona/cloc)

This is a self-contained Java library able to do country localization based on [geohashes](https://en.wikipedia.org/wiki/Geohash).

The project puts together [discretized borders](http://adrianulbona.github.io/2017/01/25/borders.html) in a [trie](https://en.wikipedia.org/wiki/Trie) data structure.

## Gradle

```groovy
compile 'io.github.adrianulbona:cloc:0.3.2'
```

## Maven
```xml

io.github.adrianulbona
cloc
0.3.2

```
## Code sample - Java
```java
final CountryLocator countryLocator = CountryLocator.create();
final List countries = countryLocator.locate("u10hb1"); // ["United Kingdom"]
```

## Code sample - Scala - Spark
```scala
val locator = spark.sparkContext.broadcast(CountryLocator.create())
val locate = udf { (geohash: String) => locator.value.locate(geohash).asScala }

val pointsDF: DataFrame = Seq(
Point("u10hb1", 51.47, 0.00),
Point("u33ff3", 52.52, 13.81)).toDF

pointsDF.withColumn("countries", locate($"geohash"))
.show()

// +-------+-----+-----+----------------+
// |geohash| lat| lon| countries|
// +-------+-----+-----+----------------+
// | u10hb1|51.47| 0.0|[United Kingdom]|
// | u33ff3|52.52|13.81| [Germany]|
// +-------+-----+-----+----------------+
```