#geocoding #location #latitude-longitude #geonames #zip #postcodes

geo_rust

A library for geocoding and reverse geocoding using the GeoNames dataset

5 releases (3 breaking)

0.4.2 Nov 7, 2024
0.4.1 Mar 25, 2024
0.3.0 Mar 24, 2024
0.2.0 Mar 23, 2024
0.1.0 Mar 23, 2024

#95 in Geospatial

Download history 13/week @ 2024-09-24 125/week @ 2024-11-05 6/week @ 2024-11-12 7/week @ 2024-11-19

138 downloads per month

MIT license

47KB
991 lines

GeoRust

A rust library for geocoding and reverse geocoding using the GeoNames dataset.

GitHub Release Crates.io Version Crates.io Total Downloads Crates.io License

Usage

Run

cargo add geo_rust

Then you can use the library like this:

use geo_rust::{GeoLocation, Country, get_postal_data, get_nearest_postcode};

fn main() {
    let geonames_data = get_postal_data(Country::All);

    let location = GeoLocation {
        latitude: 51.7923246977375,
        longitude: 0.629834723775309,
    };

    let nearest_postcode = get_nearest_postcode(location, &geonames_data).unwrap();
    println!("Nearest postcode: {}", nearest_postcode.postal_code);
}
use geo_rust::{GeoLocation, Country, get_gazetteer_data, get_nearest_place};

fn main() {
    let geonames_data = get_gazetteer_data(Country::GreatBritain);

    let location = GeoLocation {
        latitude: 51.7923246977375,
        longitude: 0.629834723775309,
    };

    let nearest_place = get_nearest_place(location, &geonames_data).unwrap();
    println!("Nearest place: {}", nearest_place.name);
}

Documentation is available at docs.rs

Features

  • Calculate the haversine distance between two locations
  • Get the nearest postcode to a location
  • Get the location of a postcode
  • Get all postcodes within a certain radius of a location
  • Get the nearest place to a location
  • Get the location of a place
  • Get all places within a certain radius of a location
  • Get all PostalData structs within a certain radius of a location

Configuration

The library uses a cache directory to store downloaded GeoNames data. By default, it uses a directory named geonames in the system's temporary directory. You can override this by setting the GEOCODER_CACHE_DIR environment variable.

To disable caching entirely, set the DISABLE_GEOCODER_CACHE environment variable to any value.

Please note, you are encouraged to "be a good neighbour" and use caching to reduce the load on the GeoNames servers.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Dependencies

~10–21MB
~301K SLoC