NoahSchiro / osmgraph

Convert OSM queries into graphs
https://crates.io/crates/osmgraph
MIT License
17 stars 0 forks source link

Include node tags #25

Open christianfosli opened 7 hours ago

christianfosli commented 7 hours ago

Hi! Nice library :smile:

I was trying it out to fetch some data about changing rooms (i.e. for changing baby diapers), and for this I need to see tags of nodes. I see currently Element in OverpassResponse only contains tags for Way, but the actual api response from overpass can include tags for Node as well.

It would be really nice if I access these tags without needing to write my own OverpassResponse, Element and Node types for deserialization.


I believe this should be sufficient for my needs:

diff --git a/src/api/overpass_response.rs b/src/api/overpass_response.rs
 #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
 #[serde(rename_all = "lowercase")]
 #[serde(tag = "type")]
 pub enum Element {
     Node {
         id: u64,
         lat: f64,
         lon: f64,
+        tags: Option<Value>,
    },
     Way {
         id: u64,
         nodes: Vec<u64>,
         tags: Option<Value>,
    },
 }

Here is an example of a node with tags (for a norwegian restaurant with a changing table available in the toilet):

{
  "type": "node",
  "id": 630733188,
  "lat": 58.3406929,
  "lon": 8.5931355,
  "tags": {
    "amenity": "cafe",
    "changing_table": "yes",
    "changing_table:fee": "no",
    "check_date": "2024-07-24",
    "contact:facebook": "https://www.facebook.com/Herlighed.Grimstad",
    "internet_access": "wlan",
    "internet_access:fee": "no",
    "level": "0",
    "name": "Herlighed",
    "opening_hours": "Mo-Fr 07:00-18:00; Sa 08:00-18:00; Su 11:00-18:00",
    "outdoor_seating": "yes",
    "shop": "bakery",
    "smoking": "no",
    "toilets": "yes",
    "toilets:access": "customers",
    "toilets:wheelchair": "designated",
    "website": "https://www.herlighed.no/",
    "wheelchair": "yes"
  }
}
NoahSchiro commented 3 hours ago

Hello! This is actually a feature I was planning on implementing but haven't gotten around to it.

Without thinking about it too deeply, I think your one liner solution works fine (see if it passes tests). If you want to put in a PR I would be happy to look it over. However if not, I can implement it and get it in but no promises on when :)