From 9ccdeac2257d73a7a38979577210c5bfbaffa856 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Sat, 14 Aug 2021 12:23:33 +1200 Subject: [PATCH 1/3] add NZTM2000Quad tile matrix set --- README.md | 1 + docs/cli.md | 3 + docs/usage.md | 1 + morecantile/data/NZTM2000Quad.json | 307 +++++++++++++++++++++++++++++ 4 files changed, 312 insertions(+) create mode 100644 morecantile/data/NZTM2000Quad.json diff --git a/README.md b/README.md index 0f44462..e6bfdd1 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ $ pip install git+https://github.com/developmentseed/morecantile.git - **EuropeanETRS89_LAEAQuad**: ETRS89-extended / LAEA Europe - EPGS:3035 - **LINZAntarticaMapTilegrid**: LINZ Antarctic Map Tile Grid (Ross Sea Region) - EPSG:5482 - **NZTM2000**: LINZ NZTM2000 Map Tile Grid - EPSG:2193 +- **NZTM2000Quad**: LINZ NZTM2000 Map Tile Grid - EPSG:2193 - **UPSAntarcticWGS84Quad**: Universal Polar Stereographic WGS 84 Quad for Antarctic - EPSG:5042 - **UPSArcticWGS84Quad**: Universal Polar Stereographic WGS 84 Quad for Arctic - EPSG:5041 - **UTM31WGS84Quad**: Example of UTM grid - EPSG:32631 diff --git a/docs/cli.md b/docs/cli.md index 8ace9d0..f9baace 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -51,6 +51,7 @@ Options: - CanadianNAD83_LCC - UPSArcticWGS84Quad - NZTM2000 + - NZTM2000Quad - UTM31WGS84Quad - UPSAntarcticWGS84Quad - WorldMercatorWGS84Quad @@ -91,6 +92,7 @@ Options: - CanadianNAD83_LCC - UPSArcticWGS84Quad - NZTM2000 + - NZTM2000Quad - UTM31WGS84Quad - UPSAntarcticWGS84Quad - WorldMercatorWGS84Quad @@ -149,6 +151,7 @@ Options: - CanadianNAD83_LCC - UPSArcticWGS84Quad - NZTM2000 + - NZTM2000Quad - UTM31WGS84Quad - UPSAntarcticWGS84Quad - WorldMercatorWGS84Quad diff --git a/docs/usage.md b/docs/usage.md index fe5decd..a1d8487 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -10,6 +10,7 @@ print(morecantile.tms.list()) 'CanadianNAD83_LCC', 'UPSArcticWGS84Quad', 'NZTM2000', + 'NZTM2000Quad', 'UTM31WGS84Quad', 'UPSAntarcticWGS84Quad', 'WorldMercatorWGS84Quad', diff --git a/morecantile/data/NZTM2000Quad.json b/morecantile/data/NZTM2000Quad.json new file mode 100644 index 0000000..2614858 --- /dev/null +++ b/morecantile/data/NZTM2000Quad.json @@ -0,0 +1,307 @@ +{ + "type": "TileMatrixSetType", + "title": "LINZ NZTM2000Quad Map Tile Grid", + "abstract": "See https://github.com/linz/NZTM2000TileMatrixSet", + "identifier": "NZTM2000Quad", + "supportedCRS": "https://www.opengis.net/def/crs/EPSG/0/2193", + "boundingBox": { + "type": "BoundingBoxType", + "crs": "https://www.opengis.net/def/crs/EPSG/0/2193", + "lowerCorner": [ + 419435.9938, + -3260586.7284 + ], + "upperCorner": [ + 10438190.1652, + 6758167.443 + ] + }, + "tileMatrix": [ + { + "type": "TileMatrixType", + "identifier": "0", + "scaleDenominator": 139770566.007179, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 1, + "matrixHeight": 1 + }, + { + "type": "TileMatrixType", + "identifier": "1", + "scaleDenominator": 69885283.0035895, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 2, + "matrixHeight": 2 + }, + { + "type": "TileMatrixType", + "identifier": "2", + "scaleDenominator": 34942641.50179475, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 4, + "matrixHeight": 4 + }, + { + "type": "TileMatrixType", + "identifier": "3", + "scaleDenominator": 17471320.750897374, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 8, + "matrixHeight": 8 + }, + { + "type": "TileMatrixType", + "identifier": "4", + "scaleDenominator": 8735660.375448687, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 16, + "matrixHeight": 16 + }, + { + "type": "TileMatrixType", + "identifier": "5", + "scaleDenominator": 4367830.1877243435, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 32, + "matrixHeight": 32 + }, + { + "type": "TileMatrixType", + "identifier": "6", + "scaleDenominator": 2183915.0938621718, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 64, + "matrixHeight": 64 + }, + { + "type": "TileMatrixType", + "identifier": "7", + "scaleDenominator": 1091957.5469310859, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 128, + "matrixHeight": 128 + }, + { + "type": "TileMatrixType", + "identifier": "8", + "scaleDenominator": 545978.7734655429, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 256, + "matrixHeight": 256 + }, + { + "type": "TileMatrixType", + "identifier": "9", + "scaleDenominator": 272989.38673277147, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 512, + "matrixHeight": 512 + }, + { + "type": "TileMatrixType", + "identifier": "10", + "scaleDenominator": 136494.69336638573, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 1024, + "matrixHeight": 1024 + }, + { + "type": "TileMatrixType", + "identifier": "11", + "scaleDenominator": 68247.34668319287, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 2048, + "matrixHeight": 2048 + }, + { + "type": "TileMatrixType", + "identifier": "12", + "scaleDenominator": 34123.67334159643, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 4096, + "matrixHeight": 4096 + }, + { + "type": "TileMatrixType", + "identifier": "13", + "scaleDenominator": 17061.836670798217, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 8192, + "matrixHeight": 8192 + }, + { + "type": "TileMatrixType", + "identifier": "14", + "scaleDenominator": 8530.918335399108, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 16384, + "matrixHeight": 16384 + }, + { + "type": "TileMatrixType", + "identifier": "15", + "scaleDenominator": 4265.459167699554, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 32768, + "matrixHeight": 32768 + }, + { + "type": "TileMatrixType", + "identifier": "16", + "scaleDenominator": 2132.729583849777, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 65536, + "matrixHeight": 65536 + }, + { + "type": "TileMatrixType", + "identifier": "17", + "scaleDenominator": 1066.3647919248886, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 131072, + "matrixHeight": 131072 + }, + { + "type": "TileMatrixType", + "identifier": "18", + "scaleDenominator": 533.1823959624443, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 262144, + "matrixHeight": 262144 + }, + { + "type": "TileMatrixType", + "identifier": "19", + "scaleDenominator": 266.59119798122214, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 524288, + "matrixHeight": 524288 + }, + { + "type": "TileMatrixType", + "identifier": "20", + "scaleDenominator": 133.29559899061107, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 1048576, + "matrixHeight": 1048576 + }, + { + "type": "TileMatrixType", + "identifier": "21", + "scaleDenominator": 66.64779949530553, + "topLeftCorner": [ + 10438190.1652, + -3260586.7284 + ], + "tileWidth": 256, + "tileHeight": 256, + "matrixWidth": 2097152, + "matrixHeight": 2097152 + } + ] +} \ No newline at end of file From b14070c53d7aafe74fc61bb0733f22ec94ef9e87 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Mon, 16 Aug 2021 10:08:40 +1200 Subject: [PATCH 2/3] fix failing tests --- tests/test_morecantile.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/test_morecantile.py b/tests/test_morecantile.py index 102a844..9c402ff 100644 --- a/tests/test_morecantile.py +++ b/tests/test_morecantile.py @@ -10,10 +10,12 @@ from .conftest import gdal_version, requires_gdal3, requires_gdal_lt_3 +DEFAULT_GRID_COUNT = 11 + def test_default_grids(): """Morecantile.default_grids should return the correct list of grids.""" - assert len(morecantile.tms.list()) == 10 + assert len(morecantile.tms.list()) == DEFAULT_GRID_COUNT with pytest.raises(InvalidIdentifier): morecantile.tms.get("ANotValidName") @@ -21,21 +23,21 @@ def test_default_grids(): def test_register(): """Test register a new grid.""" - assert len(morecantile.tms.list()) == 10 + assert len(morecantile.tms.list()) == DEFAULT_GRID_COUNT crs = CRS.from_epsg(3031) extent = [-948.75, -543592.47, 5817.41, -3333128.95] # From https:///epsg.io/3031 tms = morecantile.TileMatrixSet.custom(extent, crs, identifier="MyCustomGrid3031") _ = morecantile.tms.register(tms) - assert len(morecantile.tms.list()) == 10 + assert len(morecantile.tms.list()) == DEFAULT_GRID_COUNT defaults = morecantile.tms.register(tms) - assert len(defaults.list()) == 11 + assert len(defaults.list()) == DEFAULT_GRID_COUNT + 1 assert "MyCustomGrid3031" in defaults.list() defaults = morecantile.tms.register([tms]) - assert len(defaults.list()) == 11 + assert len(defaults.list()) == DEFAULT_GRID_COUNT + 1 assert "MyCustomGrid3031" in defaults.list() # Check it will raise an exception if TMS is already registered @@ -44,22 +46,22 @@ def test_register(): # Do not raise is overwrite=True defaults = defaults.register(tms, overwrite=True) - assert len(defaults.list()) == 11 + assert len(defaults.list()) == DEFAULT_GRID_COUNT + 1 # make sure the default morecantile TMS are not overwriten - assert len(morecantile.defaults.default_tms.keys()) == 10 + assert len(morecantile.defaults.default_tms.keys()) == DEFAULT_GRID_COUNT # add tms in morecantile defaults (not something to do anyway) epsg3031 = morecantile.TileMatrixSet.custom(extent, crs, identifier="epsg3031") morecantile.defaults.default_tms["epsg3031"] = epsg3031 - assert len(morecantile.defaults.default_tms.keys()) == 11 + assert len(morecantile.defaults.default_tms.keys()) == DEFAULT_GRID_COUNT + 1 # make sure updating the default_tms dict has no effect on the default TileMatrixSets - assert len(morecantile.tms.list()) == 10 + assert len(morecantile.tms.list()) == DEFAULT_GRID_COUNT # Update internal TMS dict morecantile.tms.tms["MyCustomGrid3031"] = tms - assert len(morecantile.tms.list()) == 11 + assert len(morecantile.tms.list()) == DEFAULT_GRID_COUNT + 1 # make sure it doesn't propagate to the default dict assert "MyCustomGrid3031" not in morecantile.defaults.default_tms From 65549df0cc978388cc987e2cfa0ec6682117ee08 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Mon, 16 Aug 2021 10:28:25 +1200 Subject: [PATCH 3/3] add nztm2000quad tests --- tests/test_models.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_models.py b/tests/test_models.py index 0e6be1b..8b3116e 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -170,6 +170,31 @@ def test_custom_tms_bounds_user_crs(): assert custom_tms.bounds(0, 0, 0) == (-120, 30, -110, 40) +def test_nztm_quad_is_quad(): + tms = morecantile.tms.get("NZTM2000Quad") + bound = tms.xy_bounds(morecantile.Tile(0, 0, 0)) + expected = (-3260586.7284, 419435.9938, 6758167.443, 10438190.1652) + for a, b in zip(expected, bound): + assert round(a - b, 4) == 0 + + +# NZTM2000Quad should use all the WebMercatorQuad zoom scales +def test_nztm_quad_scales(): + nztm_tms = morecantile.tms.get("NZTM2000Quad") + google_tms = morecantile.tms.get("WebMercatorQuad") + print(dir(google_tms)) + + for z in range(2, nztm_tms.maxzoom + 2): + assert ( + round( + google_tms.matrix(z).scaleDenominator + - nztm_tms.matrix(z - 2).scaleDenominator, + 4, + ) + == 0 + ) + + def test_InvertedLatLonGrids(): """Check Inverted LatLon grids.""" tms = morecantile.tms.get("NZTM2000")