osmapi.node
Node operations for the OpenStreetMap API.
1""" 2Node operations for the OpenStreetMap API. 3""" 4 5from typing import Any, TYPE_CHECKING, cast 6from xml.dom.minidom import Element 7 8from . import dom 9 10if TYPE_CHECKING: 11 from .OsmApi import OsmApi 12 13 14class NodeMixin: 15 """Mixin providing node-related operations with pythonic method names.""" 16 17 def node_get( 18 self: "OsmApi", node_id: int, node_version: int = -1 19 ) -> dict[str, Any]: 20 """ 21 Returns node with `node_id` as a dict: 22 23 #!python 24 { 25 'id': id of node, 26 'lat': latitude of node, 27 'lon': longitude of node, 28 'tag': {}, 29 'changeset': id of changeset of last change, 30 'version': version number of node, 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 `node_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/node/{node_id}" 47 if node_version != -1: 48 uri += f"/{node_version}" 49 data = self._session._get(uri) 50 node_element = cast( 51 Element, dom.OsmResponseToDom(data, tag="node", single=True) 52 ) 53 return dom.dom_parse_node(node_element) 54 55 def node_create(self: "OsmApi", node_data: dict[str, Any]) -> dict[str, Any] | None: 56 """ 57 Creates a node based on the supplied `node_data` dict: 58 59 #!python 60 { 61 'lat': latitude of node, 62 'lon': longitude of node, 63 'tag': {}, 64 } 65 66 Returns updated `node_data` (without timestamp): 67 68 #!python 69 { 70 'id': id of node, 71 'lat': latitude of node, 72 'lon': longitude of node, 73 'tag': dict of tags, 74 'changeset': id of changeset of last change, 75 'version': version number of node, 76 'user': username of last change, 77 'uid': id of user of last change, 78 'visible': True|False 79 } 80 81 If no session is provided to authenticate the request, 82 `OsmApi.AuthenticationMissingError` is raised. 83 84 If there is no open changeset, 85 `OsmApi.NoChangesetOpenError` is raised. 86 87 If the supplied information contain an existing node, 88 `OsmApi.OsmTypeAlreadyExistsError` is raised. 89 90 If the changeset is already closed, 91 `OsmApi.ChangesetClosedApiError` is raised. 92 """ 93 return self._do("create", "node", node_data) 94 95 def node_update(self: "OsmApi", node_data: dict[str, Any]) -> dict[str, Any] | None: 96 """ 97 Updates node with the supplied `node_data` dict: 98 99 #!python 100 { 101 'id': id of node, 102 'lat': latitude of node, 103 'lon': longitude of node, 104 'tag': {}, 105 'version': version number of node, 106 } 107 108 Returns updated `node_data` (without timestamp): 109 110 #!python 111 { 112 'id': id of node, 113 'lat': latitude of node, 114 'lon': longitude of node, 115 'tag': dict of tags, 116 'changeset': id of changeset of last change, 117 'version': version number of node, 118 'user': username of last change, 119 'uid': id of user of last change, 120 'visible': True|False 121 } 122 123 If no session is provided to authenticate the request, 124 `OsmApi.AuthenticationMissingError` 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", "node", node_data) 136 137 def node_delete(self: "OsmApi", node_data: dict[str, Any]) -> dict[str, Any] | None: 138 """ 139 Delete node with `node_data`: 140 141 #!python 142 { 143 'id': id of node, 144 'lat': latitude of node, 145 'lon': longitude of node, 146 'tag': dict of tags, 147 'version': version number of node, 148 } 149 150 Returns updated `node_data` (without timestamp): 151 152 #!python 153 { 154 'id': id of node, 155 'lat': latitude of node, 156 'lon': longitude of node, 157 'tag': dict of tags, 158 'changeset': id of changeset of last change, 159 'version': version number of node, 160 'user': username of last change, 161 'uid': id of user of last change, 162 'visible': True|False 163 } 164 165 If no session is provided to authenticate the request, 166 `OsmApi.AuthenticationMissingError` 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", "node", node_data) 175 176 def node_history(self: "OsmApi", node_id: int) -> dict[int, dict[str, Any]]: 177 """ 178 Returns dict with version as key: 179 180 #!python 181 { 182 1: dict of node version 1, 183 2: dict of node 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/node/{node_id}/history" 191 data = self._session._get(uri) 192 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 193 result = {} 194 for node in node_list: 195 node_data = dom.dom_parse_node(node) 196 result[node_data["version"]] = node_data 197 return result 198 199 def node_ways(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 200 """ 201 Returns list of dicts of ways that use the node with `node_id`: 202 203 #!python 204 [ 205 { 206 'id': id of way, 207 'nd': list of node ids, 208 'tag': dict of tags, 209 'changeset': id of changeset of last change, 210 'version': version number of way, 211 'user': username of user that made the last change, 212 'uid': id of user that made the last change, 213 'timestamp': timestamp of last change, 214 'visible': True|False 215 }, 216 ... 217 ] 218 219 If the requested element can not be found, 220 `OsmApi.ElementNotFoundApiError` is raised. 221 """ 222 uri = f"/api/0.6/node/{node_id}/ways" 223 data = self._session._get(uri) 224 way_list = cast( 225 list[Element], dom.OsmResponseToDom(data, tag="way", allow_empty=True) 226 ) 227 return [dom.dom_parse_way(way) for way in way_list] 228 229 def node_relations(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 230 """ 231 Returns list of dicts of relations that use the node with `node_id`: 232 233 #!python 234 [ 235 { 236 'id': id of relation, 237 'member': [ 238 { 239 'ref': reference id, 240 'role': role, 241 'type': node|way|relation 242 }, 243 ... 244 ], 245 'tag': dict of tags, 246 'changeset': id of changeset of last change, 247 'version': version number of relation, 248 'user': username of user that made the last change, 249 'uid': id of user that made the last change, 250 'timestamp': timestamp of last change, 251 'visible': True|False 252 }, 253 ... 254 ] 255 256 If the requested element can not be found, 257 `OsmApi.ElementNotFoundApiError` is raised. 258 """ 259 uri = f"/api/0.6/node/{node_id}/relations" 260 data = self._session._get(uri) 261 relation_list = cast( 262 list[Element], dom.OsmResponseToDom(data, tag="relation", allow_empty=True) 263 ) 264 return [dom.dom_parse_relation(rel) for rel in relation_list] 265 266 def nodes_get(self: "OsmApi", node_id_list: list[int]) -> dict[int, dict[str, Any]]: 267 """ 268 Returns dict with id as key: 269 270 #!python 271 { 272 node_id: dict of node, 273 ... 274 } 275 276 If the requested element can not be found, 277 `OsmApi.ElementNotFoundApiError` is raised. 278 """ 279 nodes = ",".join([str(x) for x in node_id_list]) 280 uri = f"/api/0.6/nodes?nodes={nodes}" 281 data = self._session._get(uri) 282 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 283 result = {} 284 for node in node_list: 285 node_data = dom.dom_parse_node(node) 286 result[node_data["id"]] = node_data 287 return result
15class NodeMixin: 16 """Mixin providing node-related operations with pythonic method names.""" 17 18 def node_get( 19 self: "OsmApi", node_id: int, node_version: int = -1 20 ) -> dict[str, Any]: 21 """ 22 Returns node with `node_id` as a dict: 23 24 #!python 25 { 26 'id': id of node, 27 'lat': latitude of node, 28 'lon': longitude of node, 29 'tag': {}, 30 'changeset': id of changeset of last change, 31 'version': version number of node, 32 'user': username of user that made the last change, 33 'uid': id of user that made the last change, 34 'timestamp': timestamp of last change, 35 'visible': True|False 36 } 37 38 If `node_version` is supplied, this specific version is returned, 39 otherwise the latest version is returned. 40 41 If the requested element has been deleted, 42 `OsmApi.ElementDeletedApiError` is raised. 43 44 If the requested element can not be found, 45 `OsmApi.ElementNotFoundApiError` is raised. 46 """ 47 uri = f"/api/0.6/node/{node_id}" 48 if node_version != -1: 49 uri += f"/{node_version}" 50 data = self._session._get(uri) 51 node_element = cast( 52 Element, dom.OsmResponseToDom(data, tag="node", single=True) 53 ) 54 return dom.dom_parse_node(node_element) 55 56 def node_create(self: "OsmApi", node_data: dict[str, Any]) -> dict[str, Any] | None: 57 """ 58 Creates a node based on the supplied `node_data` dict: 59 60 #!python 61 { 62 'lat': latitude of node, 63 'lon': longitude of node, 64 'tag': {}, 65 } 66 67 Returns updated `node_data` (without timestamp): 68 69 #!python 70 { 71 'id': id of node, 72 'lat': latitude of node, 73 'lon': longitude of node, 74 'tag': dict of tags, 75 'changeset': id of changeset of last change, 76 'version': version number of node, 77 'user': username of last change, 78 'uid': id of user of last change, 79 'visible': True|False 80 } 81 82 If no session is provided to authenticate the request, 83 `OsmApi.AuthenticationMissingError` is raised. 84 85 If there is no open changeset, 86 `OsmApi.NoChangesetOpenError` is raised. 87 88 If the supplied information contain an existing node, 89 `OsmApi.OsmTypeAlreadyExistsError` is raised. 90 91 If the changeset is already closed, 92 `OsmApi.ChangesetClosedApiError` is raised. 93 """ 94 return self._do("create", "node", node_data) 95 96 def node_update(self: "OsmApi", node_data: dict[str, Any]) -> dict[str, Any] | None: 97 """ 98 Updates node with the supplied `node_data` dict: 99 100 #!python 101 { 102 'id': id of node, 103 'lat': latitude of node, 104 'lon': longitude of node, 105 'tag': {}, 106 'version': version number of node, 107 } 108 109 Returns updated `node_data` (without timestamp): 110 111 #!python 112 { 113 'id': id of node, 114 'lat': latitude of node, 115 'lon': longitude of node, 116 'tag': dict of tags, 117 'changeset': id of changeset of last change, 118 'version': version number of node, 119 'user': username of last change, 120 'uid': id of user of last change, 121 'visible': True|False 122 } 123 124 If no session is provided to authenticate the request, 125 `OsmApi.AuthenticationMissingError` 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", "node", node_data) 137 138 def node_delete(self: "OsmApi", node_data: dict[str, Any]) -> dict[str, Any] | None: 139 """ 140 Delete node with `node_data`: 141 142 #!python 143 { 144 'id': id of node, 145 'lat': latitude of node, 146 'lon': longitude of node, 147 'tag': dict of tags, 148 'version': version number of node, 149 } 150 151 Returns updated `node_data` (without timestamp): 152 153 #!python 154 { 155 'id': id of node, 156 'lat': latitude of node, 157 'lon': longitude of node, 158 'tag': dict of tags, 159 'changeset': id of changeset of last change, 160 'version': version number of node, 161 'user': username of last change, 162 'uid': id of user of last change, 163 'visible': True|False 164 } 165 166 If no session is provided to authenticate the request, 167 `OsmApi.AuthenticationMissingError` 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", "node", node_data) 176 177 def node_history(self: "OsmApi", node_id: int) -> dict[int, dict[str, Any]]: 178 """ 179 Returns dict with version as key: 180 181 #!python 182 { 183 1: dict of node version 1, 184 2: dict of node 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/node/{node_id}/history" 192 data = self._session._get(uri) 193 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 194 result = {} 195 for node in node_list: 196 node_data = dom.dom_parse_node(node) 197 result[node_data["version"]] = node_data 198 return result 199 200 def node_ways(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 201 """ 202 Returns list of dicts of ways that use the node with `node_id`: 203 204 #!python 205 [ 206 { 207 'id': id of way, 208 'nd': list of node ids, 209 'tag': dict of tags, 210 'changeset': id of changeset of last change, 211 'version': version number of way, 212 'user': username of user that made the last change, 213 'uid': id of user that made the last change, 214 'timestamp': timestamp of last change, 215 'visible': True|False 216 }, 217 ... 218 ] 219 220 If the requested element can not be found, 221 `OsmApi.ElementNotFoundApiError` is raised. 222 """ 223 uri = f"/api/0.6/node/{node_id}/ways" 224 data = self._session._get(uri) 225 way_list = cast( 226 list[Element], dom.OsmResponseToDom(data, tag="way", allow_empty=True) 227 ) 228 return [dom.dom_parse_way(way) for way in way_list] 229 230 def node_relations(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 231 """ 232 Returns list of dicts of relations that use the node with `node_id`: 233 234 #!python 235 [ 236 { 237 'id': id of relation, 238 'member': [ 239 { 240 'ref': reference id, 241 'role': role, 242 'type': node|way|relation 243 }, 244 ... 245 ], 246 'tag': dict of tags, 247 'changeset': id of changeset of last change, 248 'version': version number of relation, 249 'user': username of user that made the last change, 250 'uid': id of user that made the last change, 251 'timestamp': timestamp of last change, 252 'visible': True|False 253 }, 254 ... 255 ] 256 257 If the requested element can not be found, 258 `OsmApi.ElementNotFoundApiError` is raised. 259 """ 260 uri = f"/api/0.6/node/{node_id}/relations" 261 data = self._session._get(uri) 262 relation_list = cast( 263 list[Element], dom.OsmResponseToDom(data, tag="relation", allow_empty=True) 264 ) 265 return [dom.dom_parse_relation(rel) for rel in relation_list] 266 267 def nodes_get(self: "OsmApi", node_id_list: list[int]) -> dict[int, dict[str, Any]]: 268 """ 269 Returns dict with id as key: 270 271 #!python 272 { 273 node_id: dict of node, 274 ... 275 } 276 277 If the requested element can not be found, 278 `OsmApi.ElementNotFoundApiError` is raised. 279 """ 280 nodes = ",".join([str(x) for x in node_id_list]) 281 uri = f"/api/0.6/nodes?nodes={nodes}" 282 data = self._session._get(uri) 283 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 284 result = {} 285 for node in node_list: 286 node_data = dom.dom_parse_node(node) 287 result[node_data["id"]] = node_data 288 return result
Mixin providing node-related operations with pythonic method names.
18 def node_get( 19 self: "OsmApi", node_id: int, node_version: int = -1 20 ) -> dict[str, Any]: 21 """ 22 Returns node with `node_id` as a dict: 23 24 #!python 25 { 26 'id': id of node, 27 'lat': latitude of node, 28 'lon': longitude of node, 29 'tag': {}, 30 'changeset': id of changeset of last change, 31 'version': version number of node, 32 'user': username of user that made the last change, 33 'uid': id of user that made the last change, 34 'timestamp': timestamp of last change, 35 'visible': True|False 36 } 37 38 If `node_version` is supplied, this specific version is returned, 39 otherwise the latest version is returned. 40 41 If the requested element has been deleted, 42 `OsmApi.ElementDeletedApiError` is raised. 43 44 If the requested element can not be found, 45 `OsmApi.ElementNotFoundApiError` is raised. 46 """ 47 uri = f"/api/0.6/node/{node_id}" 48 if node_version != -1: 49 uri += f"/{node_version}" 50 data = self._session._get(uri) 51 node_element = cast( 52 Element, dom.OsmResponseToDom(data, tag="node", single=True) 53 ) 54 return dom.dom_parse_node(node_element)
Returns node with node_id as a dict:
#!python
{
'id': id of node,
'lat': latitude of node,
'lon': longitude of node,
'tag': {},
'changeset': id of changeset of last change,
'version': version number of node,
'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 node_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.
56 def node_create(self: "OsmApi", node_data: dict[str, Any]) -> dict[str, Any] | None: 57 """ 58 Creates a node based on the supplied `node_data` dict: 59 60 #!python 61 { 62 'lat': latitude of node, 63 'lon': longitude of node, 64 'tag': {}, 65 } 66 67 Returns updated `node_data` (without timestamp): 68 69 #!python 70 { 71 'id': id of node, 72 'lat': latitude of node, 73 'lon': longitude of node, 74 'tag': dict of tags, 75 'changeset': id of changeset of last change, 76 'version': version number of node, 77 'user': username of last change, 78 'uid': id of user of last change, 79 'visible': True|False 80 } 81 82 If no session is provided to authenticate the request, 83 `OsmApi.AuthenticationMissingError` is raised. 84 85 If there is no open changeset, 86 `OsmApi.NoChangesetOpenError` is raised. 87 88 If the supplied information contain an existing node, 89 `OsmApi.OsmTypeAlreadyExistsError` is raised. 90 91 If the changeset is already closed, 92 `OsmApi.ChangesetClosedApiError` is raised. 93 """ 94 return self._do("create", "node", node_data)
Creates a node based on the supplied node_data dict:
#!python
{
'lat': latitude of node,
'lon': longitude of node,
'tag': {},
}
Returns updated node_data (without timestamp):
#!python
{
'id': id of node,
'lat': latitude of node,
'lon': longitude of node,
'tag': dict of tags,
'changeset': id of changeset of last change,
'version': version number of node,
'user': username of last change,
'uid': id of user of last change,
'visible': True|False
}
If no session is provided to authenticate the request,
OsmApi.AuthenticationMissingError is raised.
If there is no open changeset,
OsmApi.NoChangesetOpenError is raised.
If the supplied information contain an existing node,
OsmApi.OsmTypeAlreadyExistsError is raised.
If the changeset is already closed,
OsmApi.ChangesetClosedApiError is raised.
96 def node_update(self: "OsmApi", node_data: dict[str, Any]) -> dict[str, Any] | None: 97 """ 98 Updates node with the supplied `node_data` dict: 99 100 #!python 101 { 102 'id': id of node, 103 'lat': latitude of node, 104 'lon': longitude of node, 105 'tag': {}, 106 'version': version number of node, 107 } 108 109 Returns updated `node_data` (without timestamp): 110 111 #!python 112 { 113 'id': id of node, 114 'lat': latitude of node, 115 'lon': longitude of node, 116 'tag': dict of tags, 117 'changeset': id of changeset of last change, 118 'version': version number of node, 119 'user': username of last change, 120 'uid': id of user of last change, 121 'visible': True|False 122 } 123 124 If no session is provided to authenticate the request, 125 `OsmApi.AuthenticationMissingError` 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", "node", node_data)
Updates node with the supplied node_data dict:
#!python
{
'id': id of node,
'lat': latitude of node,
'lon': longitude of node,
'tag': {},
'version': version number of node,
}
Returns updated node_data (without timestamp):
#!python
{
'id': id of node,
'lat': latitude of node,
'lon': longitude of node,
'tag': dict of tags,
'changeset': id of changeset of last change,
'version': version number of node,
'user': username of last change,
'uid': id of user of last change,
'visible': True|False
}
If no session is provided to authenticate the request,
OsmApi.AuthenticationMissingError 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 node_delete(self: "OsmApi", node_data: dict[str, Any]) -> dict[str, Any] | None: 139 """ 140 Delete node with `node_data`: 141 142 #!python 143 { 144 'id': id of node, 145 'lat': latitude of node, 146 'lon': longitude of node, 147 'tag': dict of tags, 148 'version': version number of node, 149 } 150 151 Returns updated `node_data` (without timestamp): 152 153 #!python 154 { 155 'id': id of node, 156 'lat': latitude of node, 157 'lon': longitude of node, 158 'tag': dict of tags, 159 'changeset': id of changeset of last change, 160 'version': version number of node, 161 'user': username of last change, 162 'uid': id of user of last change, 163 'visible': True|False 164 } 165 166 If no session is provided to authenticate the request, 167 `OsmApi.AuthenticationMissingError` 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", "node", node_data)
Delete node with node_data:
#!python
{
'id': id of node,
'lat': latitude of node,
'lon': longitude of node,
'tag': dict of tags,
'version': version number of node,
}
Returns updated node_data (without timestamp):
#!python
{
'id': id of node,
'lat': latitude of node,
'lon': longitude of node,
'tag': dict of tags,
'changeset': id of changeset of last change,
'version': version number of node,
'user': username of last change,
'uid': id of user of last change,
'visible': True|False
}
If no session is provided to authenticate the request,
OsmApi.AuthenticationMissingError is raised.
If there is no open changeset,
OsmApi.NoChangesetOpenError is raised.
If the changeset is already closed,
OsmApi.ChangesetClosedApiError is raised.
177 def node_history(self: "OsmApi", node_id: int) -> dict[int, dict[str, Any]]: 178 """ 179 Returns dict with version as key: 180 181 #!python 182 { 183 1: dict of node version 1, 184 2: dict of node 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/node/{node_id}/history" 192 data = self._session._get(uri) 193 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 194 result = {} 195 for node in node_list: 196 node_data = dom.dom_parse_node(node) 197 result[node_data["version"]] = node_data 198 return result
Returns dict with version as key:
#!python
{
1: dict of node version 1,
2: dict of node version 2,
...
}
If the requested element can not be found,
OsmApi.ElementNotFoundApiError is raised.
200 def node_ways(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 201 """ 202 Returns list of dicts of ways that use the node with `node_id`: 203 204 #!python 205 [ 206 { 207 'id': id of way, 208 'nd': list of node ids, 209 'tag': dict of tags, 210 'changeset': id of changeset of last change, 211 'version': version number of way, 212 'user': username of user that made the last change, 213 'uid': id of user that made the last change, 214 'timestamp': timestamp of last change, 215 'visible': True|False 216 }, 217 ... 218 ] 219 220 If the requested element can not be found, 221 `OsmApi.ElementNotFoundApiError` is raised. 222 """ 223 uri = f"/api/0.6/node/{node_id}/ways" 224 data = self._session._get(uri) 225 way_list = cast( 226 list[Element], dom.OsmResponseToDom(data, tag="way", allow_empty=True) 227 ) 228 return [dom.dom_parse_way(way) for way in way_list]
Returns list of dicts of ways that use the node with node_id:
#!python
[
{
'id': id of way,
'nd': list of node ids,
'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,
'timestamp': timestamp of last change,
'visible': True|False
},
...
]
If the requested element can not be found,
OsmApi.ElementNotFoundApiError is raised.
230 def node_relations(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 231 """ 232 Returns list of dicts of relations that use the node with `node_id`: 233 234 #!python 235 [ 236 { 237 'id': id of relation, 238 'member': [ 239 { 240 'ref': reference id, 241 'role': role, 242 'type': node|way|relation 243 }, 244 ... 245 ], 246 'tag': dict of tags, 247 'changeset': id of changeset of last change, 248 'version': version number of relation, 249 'user': username of user that made the last change, 250 'uid': id of user that made the last change, 251 'timestamp': timestamp of last change, 252 'visible': True|False 253 }, 254 ... 255 ] 256 257 If the requested element can not be found, 258 `OsmApi.ElementNotFoundApiError` is raised. 259 """ 260 uri = f"/api/0.6/node/{node_id}/relations" 261 data = self._session._get(uri) 262 relation_list = cast( 263 list[Element], dom.OsmResponseToDom(data, tag="relation", allow_empty=True) 264 ) 265 return [dom.dom_parse_relation(rel) for rel in relation_list]
Returns list of dicts of relations that use the node with node_id:
#!python
[
{
'id': id of relation,
'member': [
{
'ref': reference id,
'role': role,
'type': node|way|relation
},
...
],
'tag': dict of tags,
'changeset': id of changeset of last change,
'version': version number of relation,
'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 the requested element can not be found,
OsmApi.ElementNotFoundApiError is raised.
267 def nodes_get(self: "OsmApi", node_id_list: list[int]) -> dict[int, dict[str, Any]]: 268 """ 269 Returns dict with id as key: 270 271 #!python 272 { 273 node_id: dict of node, 274 ... 275 } 276 277 If the requested element can not be found, 278 `OsmApi.ElementNotFoundApiError` is raised. 279 """ 280 nodes = ",".join([str(x) for x in node_id_list]) 281 uri = f"/api/0.6/nodes?nodes={nodes}" 282 data = self._session._get(uri) 283 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 284 result = {} 285 for node in node_list: 286 node_data = dom.dom_parse_node(node) 287 result[node_data["id"]] = node_data 288 return result
Returns dict with id as key:
#!python
{
node_id: dict of node,
...
}
If the requested element can not be found,
OsmApi.ElementNotFoundApiError is raised.