From 1ad2e4976ae508314413c98c092c9505cbf50556 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Mar 2024 04:22:54 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- osm_fieldwork/basemapper.py | 23 +++++++++++------------ outreachy.py | 5 +++-- tests/test_basemap.py | 3 ++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/osm_fieldwork/basemapper.py b/osm_fieldwork/basemapper.py index b46b957a4..134466644 100755 --- a/osm_fieldwork/basemapper.py +++ b/osm_fieldwork/basemapper.py @@ -26,9 +26,9 @@ import re import sys import threading +from io import BytesIO from pathlib import Path from typing import Union -from io import BytesIO import geojson import mercantile @@ -127,7 +127,7 @@ class BaseMapper(object): def __init__( self, - boundary: Union[str, BytesIO], # Updated type hint to accept BytesIO + boundary: Union[str, BytesIO], # Updated type hint to accept BytesIO base: str, source: str, xy: bool, @@ -135,7 +135,7 @@ def __init__( """Create an tile basemap for ODK Collect. Args: - boundary (Union[str, BytesIO]): The boundary for the area you want. + boundary (Union[str, BytesIO]): The boundary for the area you want. Can be a BBOX string, or GeoJSON file of the AOI or BytesIO object containing GeoJSON data. The GeoJSON can contain multiple geometries. base (str): The base directory to cache map tile in @@ -275,7 +275,7 @@ def tileExists( def makeBbox( self, - boundary: Union[str, BytesIO], + boundary: Union[str, BytesIO], ) -> tuple[float, float, float, float]: """Make a bounding box from a shapely geometry. @@ -321,19 +321,18 @@ def makeBbox( # Process BytesIO object try: boundary.seek(0) - geojson_data = boundary.read().decode('utf-8') + geojson_data = boundary.read().decode("utf-8") poly = geojson.loads(geojson_data) return self.extract_bbox(poly) except Exception as e: log.error(e) raise ValueError("Failed to decode GeoJSON data from BytesIO object") from e else: - raise ValueError(f"Invalid boundary type: {type(boundary)}. It must be a BBOX string or (.json, .geojson) flie or BytesIO object") + raise ValueError( + f"Invalid boundary type: {type(boundary)}. It must be a BBOX string or (.json, .geojson) flie or BytesIO object" + ) - - def extract_bbox( - self, poly: Union[BaseGeometry, None] - ) -> tuple[float, float, float, float]: + def extract_bbox(self, poly: Union[BaseGeometry, None]) -> tuple[float, float, float, float]: """Extract bounding box from GeoJSON polygon.""" if "features" in poly: geometry = shape(poly["features"][0]["geometry"]) @@ -355,7 +354,7 @@ def extract_bbox( bbox = geometry.bounds # left, bottom, right, top # minX, minY, maxX, maxY - return bbox + return bbox def tileid_from_y_tile(filepath: Union[Path | str]): @@ -448,7 +447,7 @@ def create_basemap_file( Args: verbose (bool, optional): Enable verbose output if True. - boundary (Union[str, BytesIO], optional): The boundary for the area you want. + boundary (Union[str, BytesIO], optional): The boundary for the area you want. tms (str, optional): Custom TMS URL. xy (bool, optional): Swap the X & Y coordinates when using a custom TMS if True. diff --git a/outreachy.py b/outreachy.py index c60541617..01f9722ec 100644 --- a/outreachy.py +++ b/outreachy.py @@ -1,9 +1,10 @@ from io import BytesIO + from osm_fieldwork.basemapper import create_basemap_file with open("D:\\customers\\osm-fieldwork\\tests\\testdata\\Rollinsville.geojson", "rb") as f: - boundary = f.read() # Read the file into memory - boundary_bytesio = BytesIO(boundary) # Convert the file into a BytesIO object + boundary = f.read() # Read the file into memory + boundary_bytesio = BytesIO(boundary) # Convert the file into a BytesIO object create_basemap_file( diff --git a/tests/test_basemap.py b/tests/test_basemap.py index 54774343e..490d557eb 100755 --- a/tests/test_basemap.py +++ b/tests/test_basemap.py @@ -90,7 +90,8 @@ def test_create_with_byteio(): os.remove(outfile) shutil.rmtree(base) - assert hits == 2 + assert hits == 2 + if __name__ == "__main__": test_create()