diff --git a/CHANGELOG.md b/CHANGELOG.md index c0e9d1a0..1fd3005d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## 0.9.0 (2024-04-23) + +### Feat + +- create new entities-based xlsforms for registration/buildings + +### Refactor + +- move existing xlsforms to archived dir (replace with entities) + ## 0.8.2 (2024-04-19) ### Fix diff --git a/Makefile b/Makefile index d68b44fb..a699ed83 100755 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ PACKAGE := org.osm_fieldwork.py NAME := osm-fieldwork -VERSION := 0.8.2 +VERSION := 0.9.0 # All python source files FILES := $(wildcard ./osm_fieldwork/*.py) diff --git a/osm_fieldwork/__version__.py b/osm_fieldwork/__version__.py index deded324..3e2f46a3 100644 --- a/osm_fieldwork/__version__.py +++ b/osm_fieldwork/__version__.py @@ -1 +1 @@ -__version__ = "0.8.2" +__version__ = "0.9.0" diff --git a/osm_fieldwork/basemapper.py b/osm_fieldwork/basemapper.py index d81d54dc..c344ce77 100755 --- a/osm_fieldwork/basemapper.py +++ b/osm_fieldwork/basemapper.py @@ -331,17 +331,20 @@ def makeBbox( return bbox -def tileid_from_y_tile(filepath: Union[Path | str]): +def tileid_from_tms_path(filepath: Union[Path, str]): """Helper function to get the tile id from a tile in z/x/y directory structure. Args: filepath (Union[Path, str]): The path to the y tile in /z/x/y.jpg structure. """ - # Get final two dirs + tile filename - parts = list(Path(filepath).parts[-3:]) - # strip extension from y tile filename - parts[-1] = str(Path(parts[-1]).stem) - z, x, y = map(int, parts) + # Extract the final 3 parts from the TMS file path + zxy_path = Path(filepath).parts[-3:] + # Extract filename without extension + y_tile_filename = Path(zxy_path[-1]).stem + # If filename contains a dot, take the part before the dot as 'y' + y = int(y_tile_filename.split(".")[0]) if "." in y_tile_filename else int(y_tile_filename) + # Extract z and x values + z, x = map(int, zxy_path[:-1]) return zxy_to_tileid(z, x, y) @@ -379,7 +382,7 @@ def tile_dir_to_pmtiles(outfile: str, tile_dir: str, bbox: tuple, attribution: s for tile_path in tile_dir.rglob("*"): if tile_path.is_file(): - tile_id = tileid_from_y_tile(tile_path) + tile_id = tileid_from_tms_path(tile_path) with open(tile_path, "rb") as tile: writer.write_tile(tile_id, tile.read()) @@ -415,7 +418,7 @@ def create_basemap_file( zooms="12-17", outdir=None, source="esri", -): +) -> None: """Create a basemap with given parameters. Args: diff --git a/pyproject.toml b/pyproject.toml index 31b35b36..4d930bdf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ asyncio_mode="auto" [tool.commitizen] name = "cz_conventional_commits" -version = "0.8.2" +version = "0.9.0" version_files = [ "pyproject.toml:version", "osm_fieldwork/__version__.py", diff --git a/tests/test_basemap.py b/tests/test_basemap.py index 7ee678b7..155daae5 100755 --- a/tests/test_basemap.py +++ b/tests/test_basemap.py @@ -22,8 +22,12 @@ import logging import os import shutil +from pathlib import Path -from osm_fieldwork.basemapper import BaseMapper +from pmtiles.reader import MemorySource +from pmtiles.reader import Reader as PMTileReader + +from osm_fieldwork.basemapper import BaseMapper, create_basemap_file from osm_fieldwork.sqlite import DataFile log = logging.getLogger(__name__) @@ -66,5 +70,25 @@ def test_create(): assert hits == 2 +def test_pmtiles(): + """Test PMTile creation via helper function.""" + create_basemap_file( + boundary="-4.730494 41.650541 -4.725634 41.652874", + outfile=f"{rootdir}/../test.pmtiles", + zooms="12-14", + outdir=f"{rootdir}/../", + source="esri", + ) + tiles = Path(f"{rootdir}/../test.pmtiles") + assert tiles.exists() + # Test reading + with open(tiles, "rb") as pmtile_file: + data = pmtile_file.read() + pmtile = PMTileReader(MemorySource(data)) + data_length = pmtile.header().get("tile_data_length", 0) + assert data_length > 2000 and data_length < 80000 + assert len(pmtile.metadata().keys()) == 1 + + if __name__ == "__main__": test_create()