From dd76720bef6bdf94511baa15cb4c74dc898287aa Mon Sep 17 00:00:00 2001 From: "Daniel J. H" Date: Fri, 15 Dec 2023 08:21:39 +0100 Subject: [PATCH] Fixes units in Python writer default bounds (#311) When there are no user-provided bounds provided in the writer (as in: min/max_lat/lng_e7 properties) the writer mistakenly defaults to -180,-90,180,90 for these properties. https://github.com/protomaps/PMTiles/blob/e1228f5df1a4ac852e0117dc08c8813089a5c8af/python/pmtiles/tile.py#L277-L283 But these properties need to be multiplied by 10000000 as seen e.g. in this examples and as indicated by the "_e7" https://github.com/protomaps/PMTiles/blob/e1228f5df1a4ac852e0117dc08c8813089a5c8af/python/examples/create_raster_example.py#L29-L32 Without this fix we were seeing pmtiles with bounds around null island, because the order of magnitude was wrong. --- python/pmtiles/tile.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/pmtiles/tile.py b/python/pmtiles/tile.py index aa3397f..0143256 100644 --- a/python/pmtiles/tile.py +++ b/python/pmtiles/tile.py @@ -274,13 +274,13 @@ def serialize_header(h): write_uint8(h["tile_type"].value) write_uint8(h["min_zoom"]) write_uint8(h["max_zoom"]) - min_lon_e7 = h.get("min_lon_e7",-180) + min_lon_e7 = h.get("min_lon_e7", int(-180 * 10000000)) write_int32(min_lon_e7) - min_lat_e7 = h.get("min_lat_e7",-90) + min_lat_e7 = h.get("min_lat_e7", int(-90 * 10000000)) write_int32(min_lat_e7) - max_lon_e7 = h.get("max_lon_e7",180) + max_lon_e7 = h.get("max_lon_e7", int(180 * 10000000)) write_int32(max_lon_e7) - max_lat_e7 = h.get("max_lat_e7",90) + max_lat_e7 = h.get("max_lat_e7", int(90 * 10000000)) write_int32(max_lat_e7) write_uint8(h.get("center_zoom",h["min_zoom"])) write_int32(h.get("center_lon_e7", round((min_lon_e7 + max_lon_e7) / 2)))