Changeset 8586 in josm for trunk/test/unit


Ignore:
Timestamp:
2015-07-08T23:06:52+02:00 (9 years ago)
Author:
wiktorn
Message:
  • (WMTS) Added Style support
  • (WMTS) Added MatrixHeight and MatrixWidth support
  • (WMTS) Corrected best zoom calcu

Closes: #10623 - Walonnie WMTS finally works.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java

    r8585 r8586  
    1111import org.junit.BeforeClass;
    1212import org.junit.Test;
    13 import org.openstreetmap.gui.jmapviewer.TileXY;
    1413import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource;
    1514import org.openstreetmap.josm.JOSMFixture;
     
    7069        assertEquals("TileXMax", 2, testSource.getTileXMax(2));
    7170        assertEquals("TileYMax", 2, testSource.getTileYMax(2));
    72         assertEquals("TileXMax", 5, testSource.getTileXMax(3));
     71        assertEquals("TileXMax", 4, testSource.getTileXMax(3));
    7372        assertEquals("TileYMax", 4, testSource.getTileYMax(3));
    7473
     
    7978        Main.setProjection(Projections.getProjectionByCode("EPSG:31370"));
    8079        WMTSTileSource testSource = new WMTSTileSource(testImageryWALLONIE);
     80        assertEquals("http://geoservices.wallonie.be/arcgis/rest/services/DONNEES_BASE/FOND_PLAN_ANNOTATIONS_2012_RW_NB/"
     81                + "MapServer/WMTS/tile/1.0.0/DONNEES_BASE_FOND_PLAN_ANNOTATIONS_2012_RW_NB/default/default028mm/5/1219/1063.png",
     82                testSource.getTileUrl(6, 1063, 1219));
     83
     84        // +bounds=2.54,49.51,6.4,51.5
    8185        Bounds wallonieBounds = new Bounds(
    8286                new LatLon(49.485372459967245, 2.840548314430268),
    8387                new LatLon(50.820959517561256, 6.427849693016202)
    8488                );
    85         verifyBounds(wallonieBounds, testSource, 10, 20324, 17724);
     89        verifyBounds(wallonieBounds, testSource, 6, 1063, 1219);
     90        verifyBounds(wallonieBounds, testSource, 11, 17724, 20324);
     91        LatLon ll = new LatLon(testSource.tileXYToLatLon(1063, 1219, 6));
    8692
    8793    }
    8894
    8995    private void verifyBounds(Bounds bounds, WMTSTileSource testSource, int z, int x, int y) {
    90         LatLon ret = new LatLon(testSource.tileXYToLatLon(y, y, z));
     96        LatLon ret = new LatLon(testSource.tileXYToLatLon(x, y, z));
    9197        assertTrue(ret.toDisplayString() + " doesn't lie within: " + bounds.toString(), bounds.contains(ret));
     98        int tileXmax = testSource.getTileXMax(z);
     99        int tileYmax = testSource.getTileYMax(z);
     100        assertTrue("tile x: " + x + " is greater than allowed max: " + tileXmax, tileXmax >= x);
     101        assertTrue("tile y: " + y + " is greater than allowed max: " + tileYmax, tileYmax >= y);
    92102    }
    93103
     
    96106        Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    97107        WMTSTileSource testSource = new WMTSTileSource(testImageryWIEN);
    98         int zoomOffset = 10;
    99 
    100         // Linz - 11/1105/709.png
     108        int zoomOffset = 9;
     109
    101110        verifyMercatorTile(testSource, 0, 0, 1, zoomOffset);
    102111        verifyMercatorTile(testSource, 1105, 709, 2, zoomOffset);
     
    106115        verifyMercatorTile(testSource, 1, 1, 2, zoomOffset);
    107116
    108 
    109         LatLon ll = new LatLon(testSource.tileXYToLatLon(500,  500, 1));
    110 
    111         TileXY xy = testSource.latLonToTileXY(new LatLon(48.21, 14.24).toCoordinate(), 1);
    112         assertTrue("X index is negative: " + xy.getXIndex(), xy.getXIndex() > 0);
    113         assertTrue(xy.getYIndex() > 0);
    114117        for (int x = 0; x < 4; x++) {
    115118            for (int y = 0; y < 4; y++) {
     
    119122        for (int x = 0; x < 8; x++) {
    120123            for (int y = 0; y < 4; y++) {
    121                 verifyMercatorTile(testSource, x, y, zoomOffset);
    122             }
    123         }
    124 
    125         verifyMercatorTile(testSource, 2 << 9 - 1, 2 << 8 - 1, zoomOffset);
    126 
    127         assertEquals("TileXMax", 1, testSource.getTileXMax(1));
    128         assertEquals("TileYMax", 1, testSource.getTileYMax(1));
    129         assertEquals("TileXMax", 2, testSource.getTileXMax(2));
    130         assertEquals("TileYMax", 2, testSource.getTileYMax(2));
    131         assertEquals("TileXMax", 4, testSource.getTileXMax(3));
    132         assertEquals("TileYMax", 4, testSource.getTileYMax(3));
     124                verifyMercatorTile(testSource, x, y, 4, zoomOffset);
     125            }
     126        }
     127
     128        verifyMercatorTile(testSource, 2 << 9 - 1, 2 << 8 - 1, 2, zoomOffset);
     129
     130        verifyMercatorMax(testSource, 1, zoomOffset);
     131        verifyMercatorMax(testSource, 2, zoomOffset);
     132        verifyMercatorMax(testSource, 3, zoomOffset);
     133    }
     134
     135    private void verifyMercatorMax(WMTSTileSource testSource, int zoom, int zoomOffset) {
     136        TemplatedTMSTileSource verifier = new TemplatedTMSTileSource(testImageryTMS);
     137        int result = testSource.getTileXMax(zoom);
     138        int expected = verifier.getTileXMax(zoom + zoomOffset);
     139        assertTrue("TileXMax expected: " + expected + " got: " + result, Math.abs(result - expected) < 5);
     140        result = testSource.getTileYMax(zoom);
     141        expected = verifier.getTileYMax(zoom + zoomOffset);
     142        assertTrue("TileYMax expected: " + expected + " got: " + result, Math.abs(result - expected) < 5);
    133143    }
    134144
     
    141151        verifyTile(new LatLon(51.1268639, 16.8731360), testSource, 1, 1, 2);
    142152
    143         assertEquals("TileXMax", 37, testSource.getTileXMax(1));
    144         assertEquals("TileYMax", 19, testSource.getTileYMax(1));
    145         assertEquals("TileXMax", 74, testSource.getTileXMax(2));
    146         assertEquals("TileYMax", 37, testSource.getTileYMax(2));
    147         assertEquals("TileXMax", 148, testSource.getTileXMax(3));
    148         assertEquals("TileYMax", 74, testSource.getTileYMax(3));
     153        assertEquals("TileXMax", 2, testSource.getTileXMax(1));
     154        assertEquals("TileYMax", 1, testSource.getTileYMax(1));
     155        assertEquals("TileXMax", 3, testSource.getTileXMax(2));
     156        assertEquals("TileYMax", 2, testSource.getTileYMax(2));
     157        assertEquals("TileXMax", 6, testSource.getTileXMax(3));
     158        assertEquals("TileYMax", 4, testSource.getTileYMax(3));
    149159        assertEquals(
    150160                "http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/TOPO?SERVICE=WMTS&REQUEST=GetTile&"
    151                 + "VERSION=1.0.0&LAYER=MAPA TOPOGRAFICZNA&STYLE=&FORMAT=image/jpeg&tileMatrixSet=EPSG:4326&"
     161                + "VERSION=1.0.0&LAYER=MAPA TOPOGRAFICZNA&STYLE=default&FORMAT=image/jpeg&tileMatrixSet=EPSG:4326&"
    152162                + "tileMatrix=EPSG:4326:0&tileRow=1&tileCol=1",
    153163                testSource.getTileUrl(1,  1,  1));
     
    159169        WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
    160170        verifyTile(new LatLon(53.5993712684958, 19.560669777688176), testSource, 12412, 3941, 14);
    161 
    162171        verifyTile(new LatLon(49.783096954497786, 22.79034127751704), testSource, 17714, 10206, 14);
    163172    }
     
    187196        LatLon result = new LatLon(testSource.tileXYToLatLon(x, y, z));
    188197        LatLon expected = new LatLon(verifier.tileXYToLatLon(x, y, z + zoomOffset));
    189         System.out.println(z + "/" + x + "/" + y + " - result: " + result.toDisplayString() + " osmMercator: " +  expected.toDisplayString());
     198        //System.out.println(z + "/" + x + "/" + y + " - result: " + result.toDisplayString() + " osmMercator: " +  expected.toDisplayString());
    190199        assertEquals("Longitude" , expected.lon(), result.lon(), 1e-04);
    191200        assertEquals("Latitude", expected.lat(), result.lat(), 1e-04);
    192         //assertTrue("result: " + result.toDisplayString() + " osmMercator: " +  expected.toDisplayString(), result.equalsEpsilon(expected));
    193 //        LatLon tileCenter = new Bounds(result, new LatLon(testSource.tileXYToLatLon(x+1, y+1, z))).getCenter();
    194 //        TileXY backwardsResult = testSource.latLonToTileXY(tileCenter.toCoordinate(), z);
    195         //assertEquals(x, backwardsResult.getXIndex());
    196         //assertEquals(y, backwardsResult.getYIndex());
    197201    }
    198202}
Note: See TracChangeset for help on using the changeset viewer.