osmapi.way
Way operations for the OpenStreetMap API.
This module provides pythonic (snake_case) methods for working with OSM ways.
1""" 2Way operations for the OpenStreetMap API. 3 4This module provides pythonic (snake_case) methods for working with OSM ways. 5""" 6 7from typing import Any, Optional, TYPE_CHECKING, cast 8from xml.dom.minidom import Element 9 10from . import dom, parser 11 12if TYPE_CHECKING: 13 from .OsmApi import OsmApi 14 15 16class WayMixin: 17 """Mixin providing way-related operations with pythonic method names.""" 18 19 def way_get(self: "OsmApi", way_id: int, way_version: int = -1) -> dict[str, Any]: 20 """ 21 Returns way with `way_id` as a dict: 22 23 #!python 24 { 25 'id': id of way, 26 'tag': {} tags of this way, 27 'nd': [] list of nodes belonging to this way 28 'changeset': id of changeset of last change, 29 'version': version number of way, 30 'user': username of user that made the last change, 31 'uid': id of user that made the last change, 32 'timestamp': timestamp of last change, 33 'visible': True|False 34 } 35 36 If `way_version` is supplied, this specific version is returned, 37 otherwise the latest version is returned. 38 39 If the requested element has been deleted, 40 `OsmApi.ElementDeletedApiError` is raised. 41 42 If the requested element can not be found, 43 `OsmApi.ElementNotFoundApiError` is raised. 44 """ 45 uri = f"/api/0.6/way/{way_id}" 46 if way_version != -1: 47 uri += f"/{way_version}" 48 data = self._session._get(uri) 49 way = cast(Element, dom.OsmResponseToDom(data, tag="way", single=True)) 50 return dom.dom_parse_way(way) 51 52 def way_create( 53 self: "OsmApi", way_data: dict[str, Any] 54 ) -> Optional[dict[str, Any]]: 55 """ 56 Creates a way based on the supplied `way_data` dict: 57 58 #!python 59 { 60 'nd': [] list of nodes, 61 'tag': {} dict of tags, 62 } 63 64 Returns updated `way_data` (without timestamp): 65 66 #!python 67 { 68 'id': id of node, 69 'nd': [] list of nodes, 70 'tag': {} dict of tags, 71 'changeset': id of changeset of last change, 72 'version': version number of way, 73 'user': username of last change, 74 'uid': id of user of last change, 75 'visible': True|False 76 } 77 78 If no authentication information are provided, 79 `OsmApi.UsernamePasswordMissingError` is raised. 80 81 If the supplied information contain an existing node, 82 `OsmApi.OsmTypeAlreadyExistsError` is raised. 83 84 If there is no open changeset, 85 `OsmApi.NoChangesetOpenError` is raised. 86 87 If there is already an open changeset, 88 `OsmApi.ChangesetAlreadyOpenError` is raised. 89 90 If the changeset is already closed, 91 `OsmApi.ChangesetClosedApiError` is raised. 92 """ 93 return self._do("create", "way", way_data) 94 95 def way_update( 96 self: "OsmApi", way_data: dict[str, Any] 97 ) -> Optional[dict[str, Any]]: 98 """ 99 Updates way with the supplied `way_data` dict: 100 101 #!python 102 { 103 'id': id of way, 104 'nd': [] list of nodes, 105 'tag': {}, 106 'version': version number of way, 107 } 108 109 Returns updated `way_data` (without timestamp): 110 111 #!python 112 { 113 'id': id of node, 114 'nd': [] list of nodes, 115 'tag': {} dict of tags, 116 'changeset': id of changeset of last change, 117 'version': version number of way, 118 'user': username of last change, 119 'uid': id of user of last change, 120 'visible': True|False 121 } 122 123 If no authentication information are provided, 124 `OsmApi.UsernamePasswordMissingError` is raised. 125 126 If there is no open changeset, 127 `OsmApi.NoChangesetOpenError` is raised. 128 129 If there is already an open changeset, 130 `OsmApi.ChangesetAlreadyOpenError` is raised. 131 132 If the changeset is already closed, 133 `OsmApi.ChangesetClosedApiError` is raised. 134 """ 135 return self._do("modify", "way", way_data) 136 137 def way_delete( 138 self: "OsmApi", way_data: dict[str, Any] 139 ) -> Optional[dict[str, Any]]: 140 """ 141 Delete way with `way_data`: 142 143 #!python 144 { 145 'id': id of way, 146 'nd': [] list of nodes, 147 'tag': dict of tags, 148 'version': version number of way, 149 } 150 151 Returns updated `way_data` (without timestamp): 152 153 #!python 154 { 155 'id': id of way, 156 'nd': [] list of nodes, 157 'tag': dict of tags, 158 'changeset': id of changeset of last change, 159 'version': version number of way, 160 'user': username of last change, 161 'uid': id of user of last change, 162 'visible': True|False 163 } 164 165 If no authentication information are provided, 166 `OsmApi.UsernamePasswordMissingError` is raised. 167 168 If there is no open changeset, 169 `OsmApi.NoChangesetOpenError` is raised. 170 171 If the changeset is already closed, 172 `OsmApi.ChangesetClosedApiError` is raised. 173 """ 174 return self._do("delete", "way", way_data) 175 176 def way_history(self: "OsmApi", way_id: int) -> dict[int, dict[str, Any]]: 177 """ 178 Returns dict with version as key: 179 180 #!python 181 { 182 1: dict of way version 1, 183 2: dict of way version 2, 184 ... 185 } 186 187 If the requested element can not be found, 188 `OsmApi.ElementNotFoundApiError` is raised. 189 """ 190 uri = f"/api/0.6/way/{way_id}/history" 191 data = self._session._get(uri) 192 ways = cast(list[Element], dom.OsmResponseToDom(data, tag="way")) 193 result: dict[int, dict[str, Any]] = {} 194 for way in ways: 195 way_data = dom.dom_parse_way(way) 196 result[way_data["version"]] = way_data 197 return result 198 199 def way_relations(self: "OsmApi", way_id: int) -> list[dict[str, Any]]: 200 """ 201 Returns a list of dicts of relation data containing way `way_id`: 202 203 #!python 204 [ 205 { 206 'id': id of Relation, 207 'member': [ 208 { 209 'ref': ID of referenced element, 210 'role': optional description of role in relation 211 'type': node|way|relation 212 }, 213 { 214 ... 215 } 216 ] 217 'tag': {} dict of tags, 218 'changeset': id of changeset of last change, 219 'version': version number of Way, 220 'user': username of user that made the last change, 221 'uid': id of user that made the last change, 222 'visible': True|False 223 }, 224 { 225 ... 226 }, 227 ] 228 229 The `way_id` is a unique identifier for a way. 230 """ 231 uri = f"/api/0.6/way/{way_id}/relations" 232 data = self._session._get(uri) 233 relations = cast( 234 list[Element], dom.OsmResponseToDom(data, tag="relation", allow_empty=True) 235 ) 236 result: list[dict[str, Any]] = [] 237 for relation in relations: 238 relation_data = dom.dom_parse_relation(relation) 239 result.append(relation_data) 240 return result 241 242 def way_full(self: "OsmApi", way_id: int) -> list[dict[str, Any]]: 243 """ 244 Returns the full data for way `way_id` as list of dicts: 245 246 #!python 247 [ 248 { 249 'type': node|way|relation, 250 'data': {} data dict for node|way|relation 251 }, 252 { ... } 253 ] 254 255 The `way_id` is a unique identifier for a way. 256 257 If the requested element has been deleted, 258 `OsmApi.ElementDeletedApiError` is raised. 259 260 If the requested element can not be found, 261 `OsmApi.ElementNotFoundApiError` is raised. 262 """ 263 uri = f"/api/0.6/way/{way_id}/full" 264 data = self._session._get(uri) 265 return parser.parse_osm(data) 266 267 def ways_get(self: "OsmApi", way_id_list: list[int]) -> dict[int, dict[str, Any]]: 268 """ 269 Returns dict with the id of the way as a key for 270 each way in `way_id_list`: 271 272 #!python 273 { 274 '1234': dict of way data, 275 '5678': dict of way data, 276 ... 277 } 278 279 `way_id_list` is a list containing unique identifiers for multiple ways. 280 """ 281 way_list = ",".join([str(x) for x in way_id_list]) 282 uri = f"/api/0.6/ways?ways={way_list}" 283 data = self._session._get(uri) 284 ways = cast(list[Element], dom.OsmResponseToDom(data, tag="way")) 285 result: dict[int, dict[str, Any]] = {} 286 for way in ways: 287 way_data = dom.dom_parse_way(way) 288 result[way_data["id"]] = way_data 289 return result
17class WayMixin: 18 """Mixin providing way-related operations with pythonic method names.""" 19 20 def way_get(self: "OsmApi", way_id: int, way_version: int = -1) -> dict[str, Any]: 21 """ 22 Returns way with `way_id` as a dict: 23 24 #!python 25 { 26 'id': id of way, 27 'tag': {} tags of this way, 28 'nd': [] list of nodes belonging to this way 29 'changeset': id of changeset of last change, 30 'version': version number of way, 31 'user': username of user that made the last change, 32 'uid': id of user that made the last change, 33 'timestamp': timestamp of last change, 34 'visible': True|False 35 } 36 37 If `way_version` is supplied, this specific version is returned, 38 otherwise the latest version is returned. 39 40 If the requested element has been deleted, 41 `OsmApi.ElementDeletedApiError` is raised. 42 43 If the requested element can not be found, 44 `OsmApi.ElementNotFoundApiError` is raised. 45 """ 46 uri = f"/api/0.6/way/{way_id}" 47 if way_version != -1: 48 uri += f"/{way_version}" 49 data = self._session._get(uri) 50 way = cast(Element, dom.OsmResponseToDom(data, tag="way", single=True)) 51 return dom.dom_parse_way(way) 52 53 def way_create( 54 self: "OsmApi", way_data: dict[str, Any] 55 ) -> Optional[dict[str, Any]]: 56 """ 57 Creates a way based on the supplied `way_data` dict: 58 59 #!python 60 { 61 'nd': [] list of nodes, 62 'tag': {} dict of tags, 63 } 64 65 Returns updated `way_data` (without timestamp): 66 67 #!python 68 { 69 'id': id of node, 70 'nd': [] list of nodes, 71 'tag': {} dict of tags, 72 'changeset': id of changeset of last change, 73 'version': version number of way, 74 'user': username of last change, 75 'uid': id of user of last change, 76 'visible': True|False 77 } 78 79 If no authentication information are provided, 80 `OsmApi.UsernamePasswordMissingError` is raised. 81 82 If the supplied information contain an existing node, 83 `OsmApi.OsmTypeAlreadyExistsError` is raised. 84 85 If there is no open changeset, 86 `OsmApi.NoChangesetOpenError` is raised. 87 88 If there is already an open changeset, 89 `OsmApi.ChangesetAlreadyOpenError` is raised. 90 91 If the changeset is already closed, 92 `OsmApi.ChangesetClosedApiError` is raised. 93 """ 94 return self._do("create", "way", way_data) 95 96 def way_update( 97 self: "OsmApi", way_data: dict[str, Any] 98 ) -> Optional[dict[str, Any]]: 99 """ 100 Updates way with the supplied `way_data` dict: 101 102 #!python 103 { 104 'id': id of way, 105 'nd': [] list of nodes, 106 'tag': {}, 107 'version': version number of way, 108 } 109 110 Returns updated `way_data` (without timestamp): 111 112 #!python 113 { 114 'id': id of node, 115 'nd': [] list of nodes, 116 'tag': {} dict of tags, 117 'changeset': id of changeset of last change, 118 'version': version number of way, 119 'user': username of last change, 120 'uid': id of user of last change, 121 'visible': True|False 122 } 123 124 If no authentication information are provided, 125 `OsmApi.UsernamePasswordMissingError` is raised. 126 127 If there is no open changeset, 128 `OsmApi.NoChangesetOpenError` is raised. 129 130 If there is already an open changeset, 131 `OsmApi.ChangesetAlreadyOpenError` is raised. 132 133 If the changeset is already closed, 134 `OsmApi.ChangesetClosedApiError` is raised. 135 """ 136 return self._do("modify", "way", way_data) 137 138 def way_delete( 139 self: "OsmApi", way_data: dict[str, Any] 140 ) -> Optional[dict[str, Any]]: 141 """ 142 Delete way with `way_data`: 143 144 #!python 145 { 146 'id': id of way, 147 'nd': [] list of nodes, 148 'tag': dict of tags, 149 'version': version number of way, 150 } 151 152 Returns updated `way_data` (without timestamp): 153 154 #!python 155 { 156 'id': id of way, 157 'nd': [] list of nodes, 158 'tag': dict of tags, 159 'changeset': id of changeset of last change, 160 'version': version number of way, 161 'user': username of last change, 162 'uid': id of user of last change, 163 'visible': True|False 164 } 165 166 If no authentication information are provided, 167 `OsmApi.UsernamePasswordMissingError` is raised. 168 169 If there is no open changeset, 170 `OsmApi.NoChangesetOpenError` is raised. 171 172 If the changeset is already closed, 173 `OsmApi.ChangesetClosedApiError` is raised. 174 """ 175 return self._do("delete", "way", way_data) 176 177 def way_history(self: "OsmApi", way_id: int) -> dict[int, dict[str, Any]]: 178 """ 179 Returns dict with version as key: 180 181 #!python 182 { 183 1: dict of way version 1, 184 2: dict of way version 2, 185 ... 186 } 187 188 If the requested element can not be found, 189 `OsmApi.ElementNotFoundApiError` is raised. 190 """ 191 uri = f"/api/0.6/way/{way_id}/history" 192 data = self._session._get(uri) 193 ways = cast(list[Element], dom.OsmResponseToDom(data, tag="way")) 194 result: dict[int, dict[str, Any]] = {} 195 for way in ways: 196 way_data = dom.dom_parse_way(way) 197 result[way_data["version"]] = way_data 198 return result 199 200 def way_relations(self: "OsmApi", way_id: int) -> list[dict[str, Any]]: 201 """ 202 Returns a list of dicts of relation data containing way `way_id`: 203 204 #!python 205 [ 206 { 207 'id': id of Relation, 208 'member': [ 209 { 210 'ref': ID of referenced element, 211 'role': optional description of role in relation 212 'type': node|way|relation 213 }, 214 { 215 ... 216 } 217 ] 218 'tag': {} dict of tags, 219 'changeset': id of changeset of last change, 220 'version': version number of Way, 221 'user': username of user that made the last change, 222 'uid': id of user that made the last change, 223 'visible': True|False 224 }, 225 { 226 ... 227 }, 228 ] 229 230 The `way_id` is a unique identifier for a way. 231 """ 232 uri = f"/api/0.6/way/{way_id}/relations" 233 data = self._session._get(uri) 234 relations = cast( 235 list[Element], dom.OsmResponseToDom(data, tag="relation", allow_empty=True) 236 ) 237 result: list[dict[str, Any]] = [] 238 for relation in relations: 239 relation_data = dom.dom_parse_relation(relation) 240 result.append(relation_data) 241 return result 242 243 def way_full(self: "OsmApi", way_id: int) -> list[dict[str, Any]]: 244 """ 245 Returns the full data for way `way_id` as list of dicts: 246 247 #!python 248 [ 249 { 250 'type': node|way|relation, 251 'data': {} data dict for node|way|relation 252 }, 253 { ... } 254 ] 255 256 The `way_id` is a unique identifier for a way. 257 258 If the requested element has been deleted, 259 `OsmApi.ElementDeletedApiError` is raised. 260 261 If the requested element can not be found, 262 `OsmApi.ElementNotFoundApiError` is raised. 263 """ 264 uri = f"/api/0.6/way/{way_id}/full" 265 data = self._session._get(uri) 266 return parser.parse_osm(data) 267 268 def ways_get(self: "OsmApi", way_id_list: list[int]) -> dict[int, dict[str, Any]]: 269 """ 270 Returns dict with the id of the way as a key for 271 each way in `way_id_list`: 272 273 #!python 274 { 275 '1234': dict of way data, 276 '5678': dict of way data, 277 ... 278 } 279 280 `way_id_list` is a list containing unique identifiers for multiple ways. 281 """ 282 way_list = ",".join([str(x) for x in way_id_list]) 283 uri = f"/api/0.6/ways?ways={way_list}" 284 data = self._session._get(uri) 285 ways = cast(list[Element], dom.OsmResponseToDom(data, tag="way")) 286 result: dict[int, dict[str, Any]] = {} 287 for way in ways: 288 way_data = dom.dom_parse_way(way) 289 result[way_data["id"]] = way_data 290 return result
Mixin providing way-related operations with pythonic method names.
20 def way_get(self: "OsmApi", way_id: int, way_version: int = -1) -> dict[str, Any]: 21 """ 22 Returns way with `way_id` as a dict: 23 24 #!python 25 { 26 'id': id of way, 27 'tag': {} tags of this way, 28 'nd': [] list of nodes belonging to this way 29 'changeset': id of changeset of last change, 30 'version': version number of way, 31 'user': username of user that made the last change, 32 'uid': id of user that made the last change, 33 'timestamp': timestamp of last change, 34 'visible': True|False 35 } 36 37 If `way_version` is supplied, this specific version is returned, 38 otherwise the latest version is returned. 39 40 If the requested element has been deleted, 41 `OsmApi.ElementDeletedApiError` is raised. 42 43 If the requested element can not be found, 44 `OsmApi.ElementNotFoundApiError` is raised. 45 """ 46 uri = f"/api/0.6/way/{way_id}" 47 if way_version != -1: 48 uri += f"/{way_version}" 49 data = self._session._get(uri) 50 way = cast(Element, dom.OsmResponseToDom(data, tag="way", single=True)) 51 return dom.dom_parse_way(way)
Returns way with way_id as a dict:
#!python
{
'id': id of way,
'tag': {} tags of this way,
'nd': [] list of nodes belonging to this way
'changeset': id of changeset of last change,
'version': version number of way,
'user': username of user that made the last change,
'uid': id of user that made the last change,
'timestamp': timestamp of last change,
'visible': True|False
}
If way_version is supplied, this specific version is returned,
otherwise the latest version is returned.
If the requested element has been deleted,
OsmApi.ElementDeletedApiError is raised.
If the requested element can not be found,
OsmApi.ElementNotFoundApiError is raised.
53 def way_create( 54 self: "OsmApi", way_data: dict[str, Any] 55 ) -> Optional[dict[str, Any]]: 56 """ 57 Creates a way based on the supplied `way_data` dict: 58 59 #!python 60 { 61 'nd': [] list of nodes, 62 'tag': {} dict of tags, 63 } 64 65 Returns updated `way_data` (without timestamp): 66 67 #!python 68 { 69 'id': id of node, 70 'nd': [] list of nodes, 71 'tag': {} dict of tags, 72 'changeset': id of changeset of last change, 73 'version': version number of way, 74 'user': username of last change, 75 'uid': id of user of last change, 76 'visible': True|False 77 } 78 79 If no authentication information are provided, 80 `OsmApi.UsernamePasswordMissingError` is raised. 81 82 If the supplied information contain an existing node, 83 `OsmApi.OsmTypeAlreadyExistsError` is raised. 84 85 If there is no open changeset, 86 `OsmApi.NoChangesetOpenError` is raised. 87 88 If there is already an open changeset, 89 `OsmApi.ChangesetAlreadyOpenError` is raised. 90 91 If the changeset is already closed, 92 `OsmApi.ChangesetClosedApiError` is raised. 93 """ 94 return self._do("create", "way", way_data)
Creates a way based on the supplied way_data dict:
#!python
{
'nd': [] list of nodes,
'tag': {} dict of tags,
}
Returns updated way_data (without timestamp):
#!python
{
'id': id of node,
'nd': [] list of nodes,
'tag': {} dict of tags,
'changeset': id of changeset of last change,
'version': version number of way,
'user': username of last change,
'uid': id of user of last change,
'visible': True|False
}
If no authentication information are provided,
OsmApi.UsernamePasswordMissingError is raised.
If the supplied information contain an existing node,
OsmApi.OsmTypeAlreadyExistsError is raised.
If there is no open changeset,
OsmApi.NoChangesetOpenError is raised.
If there is already an open changeset,
OsmApi.ChangesetAlreadyOpenError is raised.
If the changeset is already closed,
OsmApi.ChangesetClosedApiError is raised.
96 def way_update( 97 self: "OsmApi", way_data: dict[str, Any] 98 ) -> Optional[dict[str, Any]]: 99 """ 100 Updates way with the supplied `way_data` dict: 101 102 #!python 103 { 104 'id': id of way, 105 'nd': [] list of nodes, 106 'tag': {}, 107 'version': version number of way, 108 } 109 110 Returns updated `way_data` (without timestamp): 111 112 #!python 113 { 114 'id': id of node, 115 'nd': [] list of nodes, 116 'tag': {} dict of tags, 117 'changeset': id of changeset of last change, 118 'version': version number of way, 119 'user': username of last change, 120 'uid': id of user of last change, 121 'visible': True|False 122 } 123 124 If no authentication information are provided, 125 `OsmApi.UsernamePasswordMissingError` is raised. 126 127 If there is no open changeset, 128 `OsmApi.NoChangesetOpenError` is raised. 129 130 If there is already an open changeset, 131 `OsmApi.ChangesetAlreadyOpenError` is raised. 132 133 If the changeset is already closed, 134 `OsmApi.ChangesetClosedApiError` is raised. 135 """ 136 return self._do("modify", "way", way_data)
Updates way with the supplied way_data dict:
#!python
{
'id': id of way,
'nd': [] list of nodes,
'tag': {},
'version': version number of way,
}
Returns updated way_data (without timestamp):
#!python
{
'id': id of node,
'nd': [] list of nodes,
'tag': {} dict of tags,
'changeset': id of changeset of last change,
'version': version number of way,
'user': username of last change,
'uid': id of user of last change,
'visible': True|False
}
If no authentication information are provided,
OsmApi.UsernamePasswordMissingError is raised.
If there is no open changeset,
OsmApi.NoChangesetOpenError is raised.
If there is already an open changeset,
OsmApi.ChangesetAlreadyOpenError is raised.
If the changeset is already closed,
OsmApi.ChangesetClosedApiError is raised.
138 def way_delete( 139 self: "OsmApi", way_data: dict[str, Any] 140 ) -> Optional[dict[str, Any]]: 141 """ 142 Delete way with `way_data`: 143 144 #!python 145 { 146 'id': id of way, 147 'nd': [] list of nodes, 148 'tag': dict of tags, 149 'version': version number of way, 150 } 151 152 Returns updated `way_data` (without timestamp): 153 154 #!python 155 { 156 'id': id of way, 157 'nd': [] list of nodes, 158 'tag': dict of tags, 159 'changeset': id of changeset of last change, 160 'version': version number of way, 161 'user': username of last change, 162 'uid': id of user of last change, 163 'visible': True|False 164 } 165 166 If no authentication information are provided, 167 `OsmApi.UsernamePasswordMissingError` is raised. 168 169 If there is no open changeset, 170 `OsmApi.NoChangesetOpenError` is raised. 171 172 If the changeset is already closed, 173 `OsmApi.ChangesetClosedApiError` is raised. 174 """ 175 return self._do("delete", "way", way_data)
Delete way with way_data:
#!python
{
'id': id of way,
'nd': [] list of nodes,
'tag': dict of tags,
'version': version number of way,
}
Returns updated way_data (without timestamp):
#!python
{
'id': id of way,
'nd': [] list of nodes,
'tag': dict of tags,
'changeset': id of changeset of last change,
'version': version number of way,
'user': username of last change,
'uid': id of user of last change,
'visible': True|False
}
If no authentication information are provided,
OsmApi.UsernamePasswordMissingError is raised.
If there is no open changeset,
OsmApi.NoChangesetOpenError is raised.
If the changeset is already closed,
OsmApi.ChangesetClosedApiError is raised.
177 def way_history(self: "OsmApi", way_id: int) -> dict[int, dict[str, Any]]: 178 """ 179 Returns dict with version as key: 180 181 #!python 182 { 183 1: dict of way version 1, 184 2: dict of way version 2, 185 ... 186 } 187 188 If the requested element can not be found, 189 `OsmApi.ElementNotFoundApiError` is raised. 190 """ 191 uri = f"/api/0.6/way/{way_id}/history" 192 data = self._session._get(uri) 193 ways = cast(list[Element], dom.OsmResponseToDom(data, tag="way")) 194 result: dict[int, dict[str, Any]] = {} 195 for way in ways: 196 way_data = dom.dom_parse_way(way) 197 result[way_data["version"]] = way_data 198 return result
Returns dict with version as key:
#!python
{
1: dict of way version 1,
2: dict of way version 2,
...
}
If the requested element can not be found,
OsmApi.ElementNotFoundApiError is raised.
200 def way_relations(self: "OsmApi", way_id: int) -> list[dict[str, Any]]: 201 """ 202 Returns a list of dicts of relation data containing way `way_id`: 203 204 #!python 205 [ 206 { 207 'id': id of Relation, 208 'member': [ 209 { 210 'ref': ID of referenced element, 211 'role': optional description of role in relation 212 'type': node|way|relation 213 }, 214 { 215 ... 216 } 217 ] 218 'tag': {} dict of tags, 219 'changeset': id of changeset of last change, 220 'version': version number of Way, 221 'user': username of user that made the last change, 222 'uid': id of user that made the last change, 223 'visible': True|False 224 }, 225 { 226 ... 227 }, 228 ] 229 230 The `way_id` is a unique identifier for a way. 231 """ 232 uri = f"/api/0.6/way/{way_id}/relations" 233 data = self._session._get(uri) 234 relations = cast( 235 list[Element], dom.OsmResponseToDom(data, tag="relation", allow_empty=True) 236 ) 237 result: list[dict[str, Any]] = [] 238 for relation in relations: 239 relation_data = dom.dom_parse_relation(relation) 240 result.append(relation_data) 241 return result
Returns a list of dicts of relation data containing way way_id:
#!python
[
{
'id': id of Relation,
'member': [
{
'ref': ID of referenced element,
'role': optional description of role in relation
'type': node|way|relation
},
{
...
}
]
'tag': {} dict of tags,
'changeset': id of changeset of last change,
'version': version number of Way,
'user': username of user that made the last change,
'uid': id of user that made the last change,
'visible': True|False
},
{
...
},
]
The way_id is a unique identifier for a way.
243 def way_full(self: "OsmApi", way_id: int) -> list[dict[str, Any]]: 244 """ 245 Returns the full data for way `way_id` as list of dicts: 246 247 #!python 248 [ 249 { 250 'type': node|way|relation, 251 'data': {} data dict for node|way|relation 252 }, 253 { ... } 254 ] 255 256 The `way_id` is a unique identifier for a way. 257 258 If the requested element has been deleted, 259 `OsmApi.ElementDeletedApiError` is raised. 260 261 If the requested element can not be found, 262 `OsmApi.ElementNotFoundApiError` is raised. 263 """ 264 uri = f"/api/0.6/way/{way_id}/full" 265 data = self._session._get(uri) 266 return parser.parse_osm(data)
Returns the full data for way way_id as list of dicts:
#!python
[
{
'type': node|way|relation,
'data': {} data dict for node|way|relation
},
{ ... }
]
The way_id is a unique identifier for a way.
If the requested element has been deleted,
OsmApi.ElementDeletedApiError is raised.
If the requested element can not be found,
OsmApi.ElementNotFoundApiError is raised.
268 def ways_get(self: "OsmApi", way_id_list: list[int]) -> dict[int, dict[str, Any]]: 269 """ 270 Returns dict with the id of the way as a key for 271 each way in `way_id_list`: 272 273 #!python 274 { 275 '1234': dict of way data, 276 '5678': dict of way data, 277 ... 278 } 279 280 `way_id_list` is a list containing unique identifiers for multiple ways. 281 """ 282 way_list = ",".join([str(x) for x in way_id_list]) 283 uri = f"/api/0.6/ways?ways={way_list}" 284 data = self._session._get(uri) 285 ways = cast(list[Element], dom.OsmResponseToDom(data, tag="way")) 286 result: dict[int, dict[str, Any]] = {} 287 for way in ways: 288 way_data = dom.dom_parse_way(way) 289 result[way_data["id"]] = way_data 290 return result
Returns dict with the id of the way as a key for
each way in way_id_list:
#!python
{
'1234': dict of way data,
'5678': dict of way data,
...
}
way_id_list is a list containing unique identifiers for multiple ways.