Returns all the coordinate tuples from a geometry or feature.
(obj: Any)
| 280 | |
| 281 | |
| 282 | def iter_coords(obj: Any) -> Iterator[Tuple[float, ...]]: |
| 283 | """ |
| 284 | Returns all the coordinate tuples from a geometry or feature. |
| 285 | |
| 286 | """ |
| 287 | if isinstance(obj, (tuple, list)): |
| 288 | coords = obj |
| 289 | elif "features" in obj: |
| 290 | coords = [ |
| 291 | geom["geometry"]["coordinates"] |
| 292 | for geom in obj["features"] |
| 293 | if geom["geometry"] |
| 294 | ] |
| 295 | elif "geometry" in obj: |
| 296 | coords = obj["geometry"]["coordinates"] if obj["geometry"] else [] |
| 297 | elif ( |
| 298 | "geometries" in obj |
| 299 | and obj["geometries"][0] |
| 300 | and "coordinates" in obj["geometries"][0] |
| 301 | ): |
| 302 | coords = obj["geometries"][0]["coordinates"] |
| 303 | else: |
| 304 | coords = obj.get("coordinates", obj) |
| 305 | for coord in coords: |
| 306 | if isinstance(coord, (float, int)): |
| 307 | yield tuple(coords) |
| 308 | break |
| 309 | else: |
| 310 | yield from iter_coords(coord) |
| 311 | |
| 312 | |
| 313 | def get_bounds( |