osmapi.node
Node operations for the OpenStreetMap API.
1""" 2Node operations for the OpenStreetMap API. 3""" 4 5from typing import Any, Optional, 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( 56 self: "OsmApi", node_data: dict[str, Any] 57 ) -> Optional[dict[str, Any]]: 58 """ 59 Creates a node based on the supplied `node_data` dict: 60 61 #!python 62 { 63 'lat': latitude of node, 64 'lon': longitude of node, 65 'tag': {}, 66 } 67 68 Returns updated `node_data` (without timestamp): 69 70 #!python 71 { 72 'id': id of node, 73 'lat': latitude of node, 74 'lon': longitude of node, 75 'tag': dict of tags, 76 'changeset': id of changeset of last change, 77 'version': version number of node, 78 'user': username of last change, 79 'uid': id of user of last change, 80 'visible': True|False 81 } 82 83 If no authentication information are provided, 84 `OsmApi.UsernamePasswordMissingError` is raised. 85 86 If there is no open changeset, 87 `OsmApi.NoChangesetOpenError` is raised. 88 89 If the supplied information contain an existing node, 90 `OsmApi.OsmTypeAlreadyExistsError` is raised. 91 92 If the changeset is already closed, 93 `OsmApi.ChangesetClosedApiError` is raised. 94 """ 95 return self._do("create", "node", node_data) 96 97 def node_update( 98 self: "OsmApi", node_data: dict[str, Any] 99 ) -> Optional[dict[str, Any]]: 100 """ 101 Updates node with the supplied `node_data` dict: 102 103 #!python 104 { 105 'id': id of node, 106 'lat': latitude of node, 107 'lon': longitude of node, 108 'tag': {}, 109 'version': version number of node, 110 } 111 112 Returns updated `node_data` (without timestamp): 113 114 #!python 115 { 116 'id': id of node, 117 'lat': latitude of node, 118 'lon': longitude of node, 119 'tag': dict of tags, 120 'changeset': id of changeset of last change, 121 'version': version number of node, 122 'user': username of last change, 123 'uid': id of user of last change, 124 'visible': True|False 125 } 126 127 If no authentication information are provided, 128 `OsmApi.UsernamePasswordMissingError` is raised. 129 130 If there is no open changeset, 131 `OsmApi.NoChangesetOpenError` is raised. 132 133 If there is already an open changeset, 134 `OsmApi.ChangesetAlreadyOpenError` is raised. 135 136 If the changeset is already closed, 137 `OsmApi.ChangesetClosedApiError` is raised. 138 """ 139 return self._do("modify", "node", node_data) 140 141 def node_delete( 142 self: "OsmApi", node_data: dict[str, Any] 143 ) -> Optional[dict[str, Any]]: 144 """ 145 Delete node with `node_data`: 146 147 #!python 148 { 149 'id': id of node, 150 'lat': latitude of node, 151 'lon': longitude of node, 152 'tag': dict of tags, 153 'version': version number of node, 154 } 155 156 Returns updated `node_data` (without timestamp): 157 158 #!python 159 { 160 'id': id of node, 161 'lat': latitude of node, 162 'lon': longitude of node, 163 'tag': dict of tags, 164 'changeset': id of changeset of last change, 165 'version': version number of node, 166 'user': username of last change, 167 'uid': id of user of last change, 168 'visible': True|False 169 } 170 171 If no authentication information are provided, 172 `OsmApi.UsernamePasswordMissingError` is raised. 173 174 If there is no open changeset, 175 `OsmApi.NoChangesetOpenError` is raised. 176 177 If the changeset is already closed, 178 `OsmApi.ChangesetClosedApiError` is raised. 179 """ 180 return self._do("delete", "node", node_data) 181 182 def node_history(self: "OsmApi", node_id: int) -> dict[int, dict[str, Any]]: 183 """ 184 Returns dict with version as key: 185 186 #!python 187 { 188 1: dict of node version 1, 189 2: dict of node version 2, 190 ... 191 } 192 193 If the requested element can not be found, 194 `OsmApi.ElementNotFoundApiError` is raised. 195 """ 196 uri = f"/api/0.6/node/{node_id}/history" 197 data = self._session._get(uri) 198 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 199 result = {} 200 for node in node_list: 201 node_data = dom.dom_parse_node(node) 202 result[node_data["version"]] = node_data 203 return result 204 205 def node_ways(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 206 """ 207 Returns list of dicts of ways that use the node with `node_id`: 208 209 #!python 210 [ 211 { 212 'id': id of way, 213 'nd': list of node ids, 214 'tag': dict of tags, 215 'changeset': id of changeset of last change, 216 'version': version number of way, 217 'user': username of user that made the last change, 218 'uid': id of user that made the last change, 219 'timestamp': timestamp of last change, 220 'visible': True|False 221 }, 222 ... 223 ] 224 225 If the requested element can not be found, 226 `OsmApi.ElementNotFoundApiError` is raised. 227 """ 228 uri = f"/api/0.6/node/{node_id}/ways" 229 data = self._session._get(uri) 230 way_list = cast( 231 list[Element], dom.OsmResponseToDom(data, tag="way", allow_empty=True) 232 ) 233 return [dom.dom_parse_way(way) for way in way_list] 234 235 def node_relations(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 236 """ 237 Returns list of dicts of relations that use the node with `node_id`: 238 239 #!python 240 [ 241 { 242 'id': id of relation, 243 'member': [ 244 { 245 'ref': reference id, 246 'role': role, 247 'type': node|way|relation 248 }, 249 ... 250 ], 251 'tag': dict of tags, 252 'changeset': id of changeset of last change, 253 'version': version number of relation, 254 'user': username of user that made the last change, 255 'uid': id of user that made the last change, 256 'timestamp': timestamp of last change, 257 'visible': True|False 258 }, 259 ... 260 ] 261 262 If the requested element can not be found, 263 `OsmApi.ElementNotFoundApiError` is raised. 264 """ 265 uri = f"/api/0.6/node/{node_id}/relations" 266 data = self._session._get(uri) 267 relation_list = cast( 268 list[Element], dom.OsmResponseToDom(data, tag="relation", allow_empty=True) 269 ) 270 return [dom.dom_parse_relation(rel) for rel in relation_list] 271 272 def nodes_get(self: "OsmApi", node_id_list: list[int]) -> dict[int, dict[str, Any]]: 273 """ 274 Returns dict with id as key: 275 276 #!python 277 { 278 node_id: dict of node, 279 ... 280 } 281 282 If the requested element can not be found, 283 `OsmApi.ElementNotFoundApiError` is raised. 284 """ 285 nodes = ",".join([str(x) for x in node_id_list]) 286 uri = f"/api/0.6/nodes?nodes={nodes}" 287 data = self._session._get(uri) 288 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 289 result = {} 290 for node in node_list: 291 node_data = dom.dom_parse_node(node) 292 result[node_data["id"]] = node_data 293 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( 57 self: "OsmApi", node_data: dict[str, Any] 58 ) -> Optional[dict[str, Any]]: 59 """ 60 Creates a node based on the supplied `node_data` dict: 61 62 #!python 63 { 64 'lat': latitude of node, 65 'lon': longitude of node, 66 'tag': {}, 67 } 68 69 Returns updated `node_data` (without timestamp): 70 71 #!python 72 { 73 'id': id of node, 74 'lat': latitude of node, 75 'lon': longitude of node, 76 'tag': dict of tags, 77 'changeset': id of changeset of last change, 78 'version': version number of node, 79 'user': username of last change, 80 'uid': id of user of last change, 81 'visible': True|False 82 } 83 84 If no authentication information are provided, 85 `OsmApi.UsernamePasswordMissingError` is raised. 86 87 If there is no open changeset, 88 `OsmApi.NoChangesetOpenError` is raised. 89 90 If the supplied information contain an existing node, 91 `OsmApi.OsmTypeAlreadyExistsError` is raised. 92 93 If the changeset is already closed, 94 `OsmApi.ChangesetClosedApiError` is raised. 95 """ 96 return self._do("create", "node", node_data) 97 98 def node_update( 99 self: "OsmApi", node_data: dict[str, Any] 100 ) -> Optional[dict[str, Any]]: 101 """ 102 Updates node with the supplied `node_data` dict: 103 104 #!python 105 { 106 'id': id of node, 107 'lat': latitude of node, 108 'lon': longitude of node, 109 'tag': {}, 110 'version': version number of node, 111 } 112 113 Returns updated `node_data` (without timestamp): 114 115 #!python 116 { 117 'id': id of node, 118 'lat': latitude of node, 119 'lon': longitude of node, 120 'tag': dict of tags, 121 'changeset': id of changeset of last change, 122 'version': version number of node, 123 'user': username of last change, 124 'uid': id of user of last change, 125 'visible': True|False 126 } 127 128 If no authentication information are provided, 129 `OsmApi.UsernamePasswordMissingError` is raised. 130 131 If there is no open changeset, 132 `OsmApi.NoChangesetOpenError` is raised. 133 134 If there is already an open changeset, 135 `OsmApi.ChangesetAlreadyOpenError` is raised. 136 137 If the changeset is already closed, 138 `OsmApi.ChangesetClosedApiError` is raised. 139 """ 140 return self._do("modify", "node", node_data) 141 142 def node_delete( 143 self: "OsmApi", node_data: dict[str, Any] 144 ) -> Optional[dict[str, Any]]: 145 """ 146 Delete node with `node_data`: 147 148 #!python 149 { 150 'id': id of node, 151 'lat': latitude of node, 152 'lon': longitude of node, 153 'tag': dict of tags, 154 'version': version number of node, 155 } 156 157 Returns updated `node_data` (without timestamp): 158 159 #!python 160 { 161 'id': id of node, 162 'lat': latitude of node, 163 'lon': longitude of node, 164 'tag': dict of tags, 165 'changeset': id of changeset of last change, 166 'version': version number of node, 167 'user': username of last change, 168 'uid': id of user of last change, 169 'visible': True|False 170 } 171 172 If no authentication information are provided, 173 `OsmApi.UsernamePasswordMissingError` is raised. 174 175 If there is no open changeset, 176 `OsmApi.NoChangesetOpenError` is raised. 177 178 If the changeset is already closed, 179 `OsmApi.ChangesetClosedApiError` is raised. 180 """ 181 return self._do("delete", "node", node_data) 182 183 def node_history(self: "OsmApi", node_id: int) -> dict[int, dict[str, Any]]: 184 """ 185 Returns dict with version as key: 186 187 #!python 188 { 189 1: dict of node version 1, 190 2: dict of node version 2, 191 ... 192 } 193 194 If the requested element can not be found, 195 `OsmApi.ElementNotFoundApiError` is raised. 196 """ 197 uri = f"/api/0.6/node/{node_id}/history" 198 data = self._session._get(uri) 199 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 200 result = {} 201 for node in node_list: 202 node_data = dom.dom_parse_node(node) 203 result[node_data["version"]] = node_data 204 return result 205 206 def node_ways(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 207 """ 208 Returns list of dicts of ways that use the node with `node_id`: 209 210 #!python 211 [ 212 { 213 'id': id of way, 214 'nd': list of node ids, 215 'tag': dict of tags, 216 'changeset': id of changeset of last change, 217 'version': version number of way, 218 'user': username of user that made the last change, 219 'uid': id of user that made the last change, 220 'timestamp': timestamp of last change, 221 'visible': True|False 222 }, 223 ... 224 ] 225 226 If the requested element can not be found, 227 `OsmApi.ElementNotFoundApiError` is raised. 228 """ 229 uri = f"/api/0.6/node/{node_id}/ways" 230 data = self._session._get(uri) 231 way_list = cast( 232 list[Element], dom.OsmResponseToDom(data, tag="way", allow_empty=True) 233 ) 234 return [dom.dom_parse_way(way) for way in way_list] 235 236 def node_relations(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 237 """ 238 Returns list of dicts of relations that use the node with `node_id`: 239 240 #!python 241 [ 242 { 243 'id': id of relation, 244 'member': [ 245 { 246 'ref': reference id, 247 'role': role, 248 'type': node|way|relation 249 }, 250 ... 251 ], 252 'tag': dict of tags, 253 'changeset': id of changeset of last change, 254 'version': version number of relation, 255 'user': username of user that made the last change, 256 'uid': id of user that made the last change, 257 'timestamp': timestamp of last change, 258 'visible': True|False 259 }, 260 ... 261 ] 262 263 If the requested element can not be found, 264 `OsmApi.ElementNotFoundApiError` is raised. 265 """ 266 uri = f"/api/0.6/node/{node_id}/relations" 267 data = self._session._get(uri) 268 relation_list = cast( 269 list[Element], dom.OsmResponseToDom(data, tag="relation", allow_empty=True) 270 ) 271 return [dom.dom_parse_relation(rel) for rel in relation_list] 272 273 def nodes_get(self: "OsmApi", node_id_list: list[int]) -> dict[int, dict[str, Any]]: 274 """ 275 Returns dict with id as key: 276 277 #!python 278 { 279 node_id: dict of node, 280 ... 281 } 282 283 If the requested element can not be found, 284 `OsmApi.ElementNotFoundApiError` is raised. 285 """ 286 nodes = ",".join([str(x) for x in node_id_list]) 287 uri = f"/api/0.6/nodes?nodes={nodes}" 288 data = self._session._get(uri) 289 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 290 result = {} 291 for node in node_list: 292 node_data = dom.dom_parse_node(node) 293 result[node_data["id"]] = node_data 294 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( 57 self: "OsmApi", node_data: dict[str, Any] 58 ) -> Optional[dict[str, Any]]: 59 """ 60 Creates a node based on the supplied `node_data` dict: 61 62 #!python 63 { 64 'lat': latitude of node, 65 'lon': longitude of node, 66 'tag': {}, 67 } 68 69 Returns updated `node_data` (without timestamp): 70 71 #!python 72 { 73 'id': id of node, 74 'lat': latitude of node, 75 'lon': longitude of node, 76 'tag': dict of tags, 77 'changeset': id of changeset of last change, 78 'version': version number of node, 79 'user': username of last change, 80 'uid': id of user of last change, 81 'visible': True|False 82 } 83 84 If no authentication information are provided, 85 `OsmApi.UsernamePasswordMissingError` is raised. 86 87 If there is no open changeset, 88 `OsmApi.NoChangesetOpenError` is raised. 89 90 If the supplied information contain an existing node, 91 `OsmApi.OsmTypeAlreadyExistsError` is raised. 92 93 If the changeset is already closed, 94 `OsmApi.ChangesetClosedApiError` is raised. 95 """ 96 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 authentication information are provided,
OsmApi.UsernamePasswordMissingError 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.
98 def node_update( 99 self: "OsmApi", node_data: dict[str, Any] 100 ) -> Optional[dict[str, Any]]: 101 """ 102 Updates node with the supplied `node_data` dict: 103 104 #!python 105 { 106 'id': id of node, 107 'lat': latitude of node, 108 'lon': longitude of node, 109 'tag': {}, 110 'version': version number of node, 111 } 112 113 Returns updated `node_data` (without timestamp): 114 115 #!python 116 { 117 'id': id of node, 118 'lat': latitude of node, 119 'lon': longitude of node, 120 'tag': dict of tags, 121 'changeset': id of changeset of last change, 122 'version': version number of node, 123 'user': username of last change, 124 'uid': id of user of last change, 125 'visible': True|False 126 } 127 128 If no authentication information are provided, 129 `OsmApi.UsernamePasswordMissingError` is raised. 130 131 If there is no open changeset, 132 `OsmApi.NoChangesetOpenError` is raised. 133 134 If there is already an open changeset, 135 `OsmApi.ChangesetAlreadyOpenError` is raised. 136 137 If the changeset is already closed, 138 `OsmApi.ChangesetClosedApiError` is raised. 139 """ 140 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 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.
142 def node_delete( 143 self: "OsmApi", node_data: dict[str, Any] 144 ) -> Optional[dict[str, Any]]: 145 """ 146 Delete node with `node_data`: 147 148 #!python 149 { 150 'id': id of node, 151 'lat': latitude of node, 152 'lon': longitude of node, 153 'tag': dict of tags, 154 'version': version number of node, 155 } 156 157 Returns updated `node_data` (without timestamp): 158 159 #!python 160 { 161 'id': id of node, 162 'lat': latitude of node, 163 'lon': longitude of node, 164 'tag': dict of tags, 165 'changeset': id of changeset of last change, 166 'version': version number of node, 167 'user': username of last change, 168 'uid': id of user of last change, 169 'visible': True|False 170 } 171 172 If no authentication information are provided, 173 `OsmApi.UsernamePasswordMissingError` is raised. 174 175 If there is no open changeset, 176 `OsmApi.NoChangesetOpenError` is raised. 177 178 If the changeset is already closed, 179 `OsmApi.ChangesetClosedApiError` is raised. 180 """ 181 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 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.
183 def node_history(self: "OsmApi", node_id: int) -> dict[int, dict[str, Any]]: 184 """ 185 Returns dict with version as key: 186 187 #!python 188 { 189 1: dict of node version 1, 190 2: dict of node version 2, 191 ... 192 } 193 194 If the requested element can not be found, 195 `OsmApi.ElementNotFoundApiError` is raised. 196 """ 197 uri = f"/api/0.6/node/{node_id}/history" 198 data = self._session._get(uri) 199 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 200 result = {} 201 for node in node_list: 202 node_data = dom.dom_parse_node(node) 203 result[node_data["version"]] = node_data 204 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.
206 def node_ways(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 207 """ 208 Returns list of dicts of ways that use the node with `node_id`: 209 210 #!python 211 [ 212 { 213 'id': id of way, 214 'nd': list of node ids, 215 'tag': dict of tags, 216 'changeset': id of changeset of last change, 217 'version': version number of way, 218 'user': username of user that made the last change, 219 'uid': id of user that made the last change, 220 'timestamp': timestamp of last change, 221 'visible': True|False 222 }, 223 ... 224 ] 225 226 If the requested element can not be found, 227 `OsmApi.ElementNotFoundApiError` is raised. 228 """ 229 uri = f"/api/0.6/node/{node_id}/ways" 230 data = self._session._get(uri) 231 way_list = cast( 232 list[Element], dom.OsmResponseToDom(data, tag="way", allow_empty=True) 233 ) 234 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.
236 def node_relations(self: "OsmApi", node_id: int) -> list[dict[str, Any]]: 237 """ 238 Returns list of dicts of relations that use the node with `node_id`: 239 240 #!python 241 [ 242 { 243 'id': id of relation, 244 'member': [ 245 { 246 'ref': reference id, 247 'role': role, 248 'type': node|way|relation 249 }, 250 ... 251 ], 252 'tag': dict of tags, 253 'changeset': id of changeset of last change, 254 'version': version number of relation, 255 'user': username of user that made the last change, 256 'uid': id of user that made the last change, 257 'timestamp': timestamp of last change, 258 'visible': True|False 259 }, 260 ... 261 ] 262 263 If the requested element can not be found, 264 `OsmApi.ElementNotFoundApiError` is raised. 265 """ 266 uri = f"/api/0.6/node/{node_id}/relations" 267 data = self._session._get(uri) 268 relation_list = cast( 269 list[Element], dom.OsmResponseToDom(data, tag="relation", allow_empty=True) 270 ) 271 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.
273 def nodes_get(self: "OsmApi", node_id_list: list[int]) -> dict[int, dict[str, Any]]: 274 """ 275 Returns dict with id as key: 276 277 #!python 278 { 279 node_id: dict of node, 280 ... 281 } 282 283 If the requested element can not be found, 284 `OsmApi.ElementNotFoundApiError` is raised. 285 """ 286 nodes = ",".join([str(x) for x in node_id_list]) 287 uri = f"/api/0.6/nodes?nodes={nodes}" 288 data = self._session._get(uri) 289 node_list = cast(list[Element], dom.OsmResponseToDom(data, tag="node")) 290 result = {} 291 for node in node_list: 292 node_data = dom.dom_parse_node(node) 293 result[node_data["id"]] = node_data 294 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.