diff --git a/data/githooks/pre-push b/data/githooks/pre-push index f055620..2d59c3f 100755 --- a/data/githooks/pre-push +++ b/data/githooks/pre-push @@ -37,4 +37,8 @@ echo "Test element generation" python3 roentgen.py element --node amenity=bench,material=wood \ || { echo "FAIL"; exit 1; } +echo "Test tile generation" +python3 roentgen.py tile --coordinates 46.09498,10.06879 --cache test/data \ + || { echo "FAIL"; exit 1; } + exit 0 diff --git a/roentgen/osm_getter.py b/roentgen/osm_getter.py index c737303..17760a8 100644 --- a/roentgen/osm_getter.py +++ b/roentgen/osm_getter.py @@ -38,7 +38,7 @@ def get_osm( content: Optional[bytes] = get_data( "api.openstreetmap.org/api/0.6/map", - {"bbox": boundary_box}, + {"bbox": boundary_box.get_format()}, is_secure=True, ).decode("utf-8") diff --git a/roentgen/tile.py b/roentgen/tile.py index efc8e0a..5c12632 100644 --- a/roentgen/tile.py +++ b/roentgen/tile.py @@ -55,7 +55,8 @@ class Tiles: extended_boundary_box: BoundaryBox = BoundaryBox( lon_1, lat_1, lon_2, lat_2 - ) + ).round() + return cls(tiles, tile_1, tile_2, scale, extended_boundary_box) def draw(self, directory: Path, cache_path: Path) -> None: @@ -68,7 +69,7 @@ class Tiles: get_osm(self.boundary_box, cache_path) map_ = OSMReader().parse_osm_file( - cache_path / (self.boundary_box.get_format_rounded() + ".osm") + cache_path / (self.boundary_box.get_format() + ".osm") ) for tile in self.tiles: file_path: Path = tile.get_file_name(directory) @@ -86,7 +87,7 @@ class Tiles: :param cache_path: directory for temporary SVG file and OSM files """ output_path: Path = cache_path / ( - self.boundary_box.get_format_rounded() + ".svg" + self.boundary_box.get_format() + ".svg" ) if not output_path.exists(): content = get_osm(self.boundary_box, cache_path) @@ -95,7 +96,7 @@ class Tiles: return None map_: Map = OSMReader().parse_osm_file( - cache_path / (self.boundary_box.get_format_rounded() + ".osm") + cache_path / (self.boundary_box.get_format() + ".osm") ) lat_2, lon_1 = self.tile_1.get_coordinates() lat_1, lon_2 = Tile( @@ -129,9 +130,7 @@ class Tiles: with output_path.open("w+") as output_file: svg.write(output_file) - png_path: Path = ( - cache_path / f"{self.boundary_box.get_format_rounded()}.png" - ) + png_path: Path = cache_path / f"{self.boundary_box.get_format()}.png" if not png_path.exists(): rasterize(output_path, png_path) @@ -189,14 +188,12 @@ class Tile: self.x + 1, self.y + 1, self.scale ).get_coordinates() - # FIXME: check negative values + lat_2 = point_1[0] + lon_1 = point_1[1] + lat_1 = point_2[0] + lon_2 = point_2[1] - lat_2 = int(point_1[0] * 1000) / 1000 + 0.002 - lon_1 = int(point_1[1] * 1000) / 1000 - 0.001 - lat_1 = int(point_2[0] * 1000) / 1000 - 0.001 - lon_2 = int(point_2[1] * 1000) / 1000 + 0.002 - - return BoundaryBox(lon_1, lat_1, lon_2, lat_2) + return BoundaryBox(lon_1, lat_1, lon_2, lat_2).round() def load_map(self, cache_path: Path) -> Map: """ @@ -208,7 +205,7 @@ class Tile: get_osm(boundary_box, cache_path) return OSMReader().parse_osm_file( - cache_path / f"{boundary_box.format()}.osm" + cache_path / f"{boundary_box.get_format()}.osm" ) def get_file_name(self, directory_name: Path) -> Path: diff --git a/roentgen/ui.py b/roentgen/ui.py index dae0ad2..a88ccea 100644 --- a/roentgen/ui.py +++ b/roentgen/ui.py @@ -257,16 +257,18 @@ class BoundaryBox: """Get right bottom corner of the boundary box.""" return self.bottom, self.right - def get_format_rounded(self) -> str: + def round(self) -> "BoundaryBox": """ - Get text representation of the boundary box: - ,,,. Coordinates are - rounded to three digits after comma. + Round boundary box. """ - return ( - f"{self.left - 0.001:.3f},{self.bottom - 0.001:.3f}," - f"{self.right + 0.001:.3f},{self.top + 0.001:.3f}" - ) + # FIXME: check negative values + + self.left = int(self.left * 1000) / 1000 - 0.001 + self.bottom = int(self.bottom * 1000) / 1000 - 0.001 + self.right = int(self.right * 1000) / 1000 + 0.002 + self.top = int(self.top * 1000) / 1000 + 0.002 + + return self def get_format(self) -> str: """ diff --git a/test/data/10.066,46.093,10.070,46.097.osm b/test/data/10.066,46.093,10.070,46.097.osm new file mode 100644 index 0000000..607ae6c --- /dev/null +++ b/test/data/10.066,46.093,10.070,46.097.osm @@ -0,0 +1,10 @@ + + + + + + + + + +