Give satellite imagery, terrain data, buildings, streetview photos to your LLM
Make missing regional file data non-breaking
Belluxx49205cae9c4a
diff --git a/src/capture.py b/src/capture.pyindex ab66155..5eb00f9 100644--- a/src/capture.py+++ b/src/capture.py@@ -43,7 +43,7 @@ DEFAULT_OPTIONS = dict(OSM_NOTES = {"map": "OSM XML from Geofabrik with original tags and topology; coordinates are WGS84. Contributor names, IDs and changeset IDs are omitted by Geofabrik.",- "selection": "Bounding-box selection with complete ways and directly selected multipolygons, including outer boundaries and holes. Other relations retain their original references and may remain incomplete. Objects may extend outside the rectangle; crossings without inside nodes and enclosing polygons may be absent.",+ "selection": "Selected ways are complete. Selected multipolygons include all available outer boundaries and holes, but members missing from the regional file remain unresolved. Other relations may also be incomplete. Objects may extend outside the rectangle; crossings without inside nodes and enclosing polygons may be absent.","terrain": "Float32 heights in meters, EPSG:3857. Original compressed blocks retained without resampling. Full edge tiles extend beyond the rectangle. Tiles are checkpointed individually; terrain.tif is built after all terrain tiles are saved.","quality": "Terrain resolution, dates, accuracy and vertical reference vary by source. Higher zoom does not guarantee more detail.",}@@ -296,7 +296,7 @@ def capture_osm(stage, area, folder, client, progress):failure = errorsaved = sum("x" in item for item in stage["results"])count = stage["grid"]["rows"] * stage["grid"]["columns"]- label = "Downloading terrain tiles" if failure is None else "Downloading terrain tiles (OSM unavailable)"+ label = "Downloading terrain tiles" if failure is None else f"Downloading terrain tiles (map failed: {failure})"progress(label, saved, count)for i, tile in enumerate(tiles(stage["grid"])):if i < saved:diff --git a/src/pbf.py b/src/pbf.pyindex 5f4915d..0ad0f48 100644--- a/src/pbf.py+++ b/src/pbf.py@@ -672,7 +672,7 @@ class PBF:tasks = ((self.path, entry, xml, None) for entry in entries)way_blocks = []results = self.parallel(scan_ways, tasks, spatial_nodes, (array("q", spatial),))- for entry, (bounds, selected) in zip(entries, results):+ for entry, (bounds, selected) in zip(entries, results, strict=True):if xml:identities, refs, chunk = selectedways.update(identities)@@ -714,6 +714,7 @@ class PBF:if xml:# Revisit only blocks containing missing polygon members. Keep the# existing XML and merge added ways in ID order without duplicates.+ # Members absent from the regional file keep their original references.missing = sorted(extra_ways - ways)tasks, entries = [], []for entry, (first, last) in way_blocks:@@ -729,8 +730,6 @@ class PBF:merged = sorted(chain(zip(previous, original.splitlines(keepends=True)),zip(identities, chunk.splitlines(keepends=True))))self.way_xml[entry[0]] = (), b"".join(part for _, part in merged)- if not extra_ways <= ways:- raise ValueError("PBF source is missing multipolygon member ways.")return nodes, ways, relationsdef nodes(self, wanted, mode="points"):diff --git a/tests/test_capture.py b/tests/test_capture.pyindex 0a8ac0e..434cc9b 100644--- a/tests/test_capture.py+++ b/tests/test_capture.py@@ -209,7 +209,12 @@ class CaptureRecoveryTests(unittest.TestCase):dict(include=["osm"], terrain_zoom=1), self.progress)failure = OSError("Geofabrik unavailable")self.client.maps.export.side_effect = failure- self.client.get.side_effect = [terrain_bytes(1, 0, 1)]++ def download_terrain(address):+ self.progress.assert_called_with("Downloading terrain tiles (map failed: Geofabrik unavailable)", 0, 1)+ return terrain_bytes(1, 0, 1)++ self.client.get.side_effect = download_terrainwith self.assertRaises(OSError) as raised:capture.download(run, self.folder, self.client, self.progress)self.assertIs(raised.exception, failure)diff --git a/tests/test_pbf.py b/tests/test_pbf.pyindex 0bea085..c74f01c 100644--- a/tests/test_pbf.py+++ b/tests/test_pbf.py@@ -163,12 +163,15 @@ class PBFTests(unittest.TestCase):self.assertEqual(geometry["type"], "MultiPolygon")self.assertEqual(len(geometry["coordinates"][0]), 2) # Closed outer and courtyard.- def test_missing_multipolygon_way_preserves_previous_output(self):+ def test_missing_multipolygon_way_keeps_available_geometry_and_original_references(self):self.path.write_bytes(multipolygon_snapshot(missing_way=True))- self.output.write_bytes(b"previous")- with self.assertRaisesRegex(ValueError, "missing multipolygon member ways"):- PBF(self.path).export((-.0011, -.0011, -.0009, -.0009), self.output)- self.assertEqual(self.output.read_bytes(), b"previous")+ PBF(self.path).export((-.0011, -.0011, -.0009, -.0009), self.output)+ root = ET.parse(self.output).getroot()+ self.assertEqual([int(w.attrib["id"]) for w in root.findall("way")], [10, 15, 30])+ self.assertIsNotNone(root.find("relation[@id='100']/member[@ref='20']"))+ nodes = {n.attrib["id"] for n in root.findall("node")}+ self.assertTrue(all(nd.attrib["ref"] in nodes for nd in root.findall("way/nd")))+ self.assertEqual(display_osm(self.output)["features"], []) # Do not invent the missing outline.def test_standalone_script_runs_without_site_packages(self):source = Path(__file__).parent / "data" / "dense.osm.pbf"