osm_rs/
lib.rs

1//! # osm-rs
2//!
3//! Query OSM objects with Overpass and Nominatim.
4//!
5//! **Use with absolute caution.** Querying OSM can hog down
6//! an Overpass server easily. I am not responsible for any damage this
7//! tool may cause.
8//!
9//! # Bounding Boxes
10//! ```rust
11//! use osm_rs::overpass::{BoundingBox, Config};
12//!
13//! #[tokio::main]
14//! async fn main() {
15//!   let c: Config = Config {
16//!       url: "https://overpass-api.de/api/interpreter".to_string(),
17//!       timeout: 25,
18//!       key: "amenity".to_string(),
19//!       val: "cafe".to_string(),
20//!   };
21//!
22//!   let b: BoundingBox = BoundingBox {
23//!       xmin: 51.305219521963295,
24//!       ymin: -0.7690429687500001,
25//!       xmax: 51.82219818336938,
26//!       ymax: 0.5273437500000064,
27//!   };
28//!
29//!   let resp = b.search(&c).await.expect("failed query");
30//! }
31//! ```
32//! # Geocode
33//! ```rust
34//! use osm_rs::nominatim::{Config, Geocode};
35//!
36//! #[tokio::main]
37//! async fn main() {
38//!     let c: Config = Config {
39//!         url: "https://nominatim.openstreetmap.org/search".to_string(),
40//!         timeout: 25,
41//!     };
42//!
43//!     let g = Geocode {
44//!         q: Some("Boston".to_string()),
45//!         street: None,
46//!         city: None,
47//!         county: None,
48//!         state: None,
49//!         country: None,
50//!         postalcode: None,
51//!     };
52//!
53//!     let resp = g.search(&c).await.unwrap();
54//!     assert_eq!(resp[0].lat, 42.3554334);
55//!     assert_eq!(resp[0].lon, -71.060511);
56//! }
57//! ```
58//! # Reverse geocode
59//! ```rust
60//! use osm_rs::nominatim::{Config, ReverseGeocode};
61//! #[tokio::main]
62//! async fn main() {
63//!    let c: Config = Config {
64//!        url: "https://nominatim.openstreetmap.org/reverse".to_string(),
65//!        timeout: 25,
66//!    };
67//!
68//!    let g = ReverseGeocode {
69//!        lat: 42.3554334,
70//!        lon: -71.060511,
71//!    };
72//!
73//!    let resp = g.search(&c).await.unwrap();
74//!    assert_eq!(resp.osm_id, 5331978048);
75//! }
76//! ```
77
78pub mod nominatim;
79pub mod overpass;