1 unstable release

0.1.0 Oct 11, 2018

#73 in Geospatial

97 stars & 7 watchers

4KB
78 lines

Rust Reverse Geocoder

A fast reverse geocoder in Rust. Inspired by Python reverse-geocoder.

Description

rrgeo takes a latitude and longitude as input and returns the closest city, country, latitude, and longitude, using a k-d tree to efficiently find the nearest neighbour based on a known list of locations. This can be useful if you need to reverse geocode a large number of coordinates quickly, or just need the rough location of coordinates but don't want the expense or complication of an online reverse geocoder.

This crate is implemented as a library, an Actix REST API, a Warp REST API, and as a command-line utility, thanks to Cargo workspaces.

Usage

Example usage:

> cargo run -p rrgeo-cmd --release 40 -73
0 ms to search
Location: (40.72788, -73.09761): West Sayville, New York, Suffolk County, US
Distance: 0.539337006499999

Actix Web Server

Example usage:

cargo run -p rrgeo-actix --release

Navigate to the local web server.

Warp Web Server

Example usage:

cargo run -p rrgeo-warp --release

Navigate to the local web server.

Benchmarks

Benchmarked on Apple M1.

  • Core library benchmarked with cargo bench and criterion
  • Web servers benchmarked with oha

Core library:

> cargo bench
search                  time:   [416.30 ns 416.39 ns 416.49 ns]

Served via Axum:

> cargo run -p rrgeo-axum --release
>  oha http://localhost:3000/\?lat\=40\&long\=\-73 -z 5sec
Summary:
  Success rate:	1.0000
  Total:	5.0017 secs
  Slowest:	0.0259 secs
  Fastest:	0.0000 secs
  Average:	0.0003 secs
  Requests/sec:	186333.9800

  Total data:	134.21 MiB
  Size/request:	151 B
  Size/sec:	26.83 MiB

Response time histogram:
  0.000 [19568]  |■■
  0.000 [100727] |■■■■■■■■■■■■
  0.000 [259463] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.000 [252285] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.000 [173138] |■■■■■■■■■■■■■■■■■■■■■
  0.000 [81145]  |■■■■■■■■■■
  0.001 [29013]  |■■■
  0.001 [10079]  |0.001 [3434]   |
  0.001 [1350]   |
  0.001 [1789]   |

Latency distribution:
  10% in 0.0002 secs
  25% in 0.0002 secs
  50% in 0.0003 secs
  75% in 0.0003 secs
  90% in 0.0004 secs
  95% in 0.0004 secs
  99% in 0.0006 secs

Details (average, fastest, slowest):
  DNS+dialup:	0.0015 secs, 0.0012 secs, 0.0017 secs
  DNS-lookup:	0.0000 secs, 0.0000 secs, 0.0001 secs

Status code distribution:
  [200] 931991 responses

Served via Actix Web:

> cargo run --release --bin rrgeo-actix
> oha http://localhost:3000/\?lat\=40\&long\=\-73 -z 5sec
Summary:
  Success rate:	1.0000
  Total:	5.0008 secs
  Slowest:	0.2505 secs
  Fastest:	0.0000 secs
  Average:	0.0003 secs
  Requests/sec:	164159.8709

  Total data:	86.90 MiB
  Size/request:	111 B
  Size/sec:	17.38 MiB

Response time histogram:
  0.000 [395294] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.000 [209631] |■■■■■■■■■■■■■■■■
  0.000 [88554]  |■■■■■■■
  0.000 [53553]  |■■■■
  0.000 [30225]  |■■
  0.000 [13830]  |0.001 [7100]   |
  0.001 [4594]   |
  0.001 [3040]   |
  0.001 [1890]   |
  0.001 [13218]  |■

Latency distribution:
  10% in 0.0000 secs
  25% in 0.0001 secs
  50% in 0.0001 secs
  75% in 0.0002 secs
  90% in 0.0003 secs
  95% in 0.0004 secs
  99% in 0.0012 secs

Details (average, fastest, slowest):
  DNS+dialup:	0.0017 secs, 0.0013 secs, 0.0020 secs
  DNS-lookup:	0.0000 secs, 0.0000 secs, 0.0003 secs

Status code distribution:
  [200] 820929 responses

Served via Warp:

> cargo run --release --bin rrgeo-warp
> oha http://localhost:3000/\?lat\=40\&long\=\-73 -z 5sec
Summary:
  Success rate:	1.0000
  Total:	5.0022 secs
  Slowest:	0.0158 secs
  Fastest:	0.0000 secs
  Average:	0.0003 secs
  Requests/sec:	183796.4070

  Total data:	132.40 MiB
  Size/request:	151 B
  Size/sec:	26.47 MiB

Response time histogram:
  0.000 [20392]  |■■
  0.000 [102885] |■■■■■■■■■■■■
  0.000 [269371] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.000 [242570] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.000 [159505] |■■■■■■■■■■■■■■■■■■
  0.000 [71758]  |■■■■■■■■
  0.001 [27128]  |■■■
  0.001 [11721]  |0.001 [5919]   |
  0.001 [3213]   |
  0.001 [4918]   |

Latency distribution:
  10% in 0.0002 secs
  25% in 0.0002 secs
  50% in 0.0003 secs
  75% in 0.0003 secs
  90% in 0.0004 secs
  95% in 0.0005 secs
  99% in 0.0007 secs

Details (average, fastest, slowest):
  DNS+dialup:	0.0017 secs, 0.0010 secs, 0.0019 secs
  DNS-lookup:	0.0000 secs, 0.0000 secs, 0.0002 secs

Status code distribution:
  [200] 919380 responses

License

Licensed under either of

at your option.

Dependencies

~19–26MB
~534K SLoC