diff --git a/download_LoD2_from_LGL_BW.py b/download_LoD2_from_LGL_BW.py index 38f95fb35082f83bf49ee207fe3487e18a3ce905..589abf7140960be46509fc8994910e0fe35c8f1f 100644 --- a/download_LoD2_from_LGL_BW.py +++ b/download_LoD2_from_LGL_BW.py @@ -85,7 +85,7 @@ def coordinates_to_grid(longitude: float, latitude: float) -> tuple[int, int]: return (x + 1, y) -def wkt_polygon_to_grid_coords(location_name: str, wkt_str: str) -> tuple[int, int, int, int]: +def wkt_polygon_to_bounding_box(location_name: str, wkt_str: str) -> tuple[int, int, int, int]: """Returns (x, y) of lower-left and bottom-right tiles, containing a given region.""" if 'POLYGON' not in wkt_str: raise ValueError(f"wkt for {location_name} should be a WKT POLYGON or MULTIPOLYGON") @@ -262,7 +262,7 @@ def main(location_name: str, wkt_or_zipcode: str, download_only: bool = False, wkt_str = get_wkt(wkt_or_zipcode) # Get grid coordinates - x1, x2, y1, y2 = wkt_polygon_to_grid_coords(location_name, wkt_str) + x1, x2, y1, y2 = wkt_polygon_to_bounding_box(location_name, wkt_str) # Download region download_whole_region(output_folder, wkt_str, x1, x2, y1, y2) diff --git a/test_download_lod2.py b/test_download_lod2.py new file mode 100644 index 0000000000000000000000000000000000000000..e3bb1ba92b314b57ee6a16df204664636f8b0f5d --- /dev/null +++ b/test_download_lod2.py @@ -0,0 +1,48 @@ +import unittest +import tempfile +import shutil +from pathlib import Path + +import download_LoD2_from_LGL_BW as bw_data + + +class TestUtils(unittest.TestCase): + def test_simstadt_is_available(self): + self.assertIsNotNone(bw_data.find_simstadt_folder(), + "SimStadt folder should be on the Desktop in order for tests to run" + ) + + def test_coordinates_to_grid(self): + self.assertEqual(bw_data.coordinates_to_grid(9.180, 48.778), + (513, 5402)) # Stuttgart - Schloßplatz + self.assertEqual(bw_data.coordinates_to_grid(7.853, 47.990), + (413, 5314)) # Freiburg - Dreisam + + def test_get_bounding_box(self): + freiburg_to_stuttgart = "POLYGON ((7.853 47.990, 9.180 48.778, 7.853 47.990))" + self.assertEqual(bw_data.wkt_polygon_to_bounding_box("Just a line", freiburg_to_stuttgart), + (413, 513, 5314, 5402)) + + +class TestGetOpenData(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.tempFolder = Path(tempfile.mkdtemp()) + + def test_get_schlossplatz(self): + # Stuttgart - Schloßplatz + stuttgart_wkt = "POLYGON ((9.179206 48.779454, 9.179292 48.777644, 9.178498 48.776753, 9.18118 48.775933, 9.181952 48.77705, 9.182768 48.77862, 9.179206 48.779454))" + bw_data.main("Schlossplatz", stuttgart_wkt) + + def test_get_schwarzwald(self): + # Reichental + reichental_wkt = "POLYGON ((8.424282 48.745889, 8.381882 48.737286, 8.382397 48.721773, 8.439903 48.726869, 8.424282 48.745889))" + bw_data.main("Reichental", reichental_wkt) + + @classmethod + def tearDownClass(cls): + shutil.rmtree(cls.tempFolder) + + +if __name__ == '__main__': + unittest.main()