source: josm/trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java@ 8568

Last change on this file since 8568 was 8568, checked in by wiktorn, 9 years ago

Basic WMTS support.

  • added information about units and to_meter to EPSG projection definitions (needed for WMTS)
  • added WMTSTileSource and WMTSLayer classes
  • a bit of cleanup of AbstractTileSourceLayer and align so it will work properly with WMTS tile definitions
  • added Imagery Preferences panel for WMTS and icon for button
  • added removal of wms: / tms: / wmts: prefix, if user will paste them into the field
  • CachedFile - added possibility to send custom headers with request
  • added support for unit and to_meter in CustomProjection
  • AbstractTMSTileSource cleanups (change of Coordinate to ICoordinate)
  • moved JCSCachedTileLoaderJob.read() to Utils

Addresses: #10623

Tested with Polish WMTS service proivders, Walonnie needs still some debugging, as it is not working right now.

File size: 5.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery;
3
4import static org.junit.Assert.assertEquals;
5
6import java.io.File;
7import java.io.IOException;
8import java.net.MalformedURLException;
9
10import org.junit.BeforeClass;
11import org.junit.Test;
12import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource;
13import org.openstreetmap.josm.JOSMFixture;
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.data.coor.LatLon;
16import org.openstreetmap.josm.data.projection.Projections;
17
18public class WMTSTileSourceTest {
19
20 private ImageryInfo testImageryTMS = new ImageryInfo("test imagery", "http://localhost", "tms", null, null);
21 private ImageryInfo testImageryPSEUDO_MERCATOR = getImagery("test/data/wmts/getcapabilities-pseudo-mercator.xml");
22 private ImageryInfo testImageryTOPO_PL = getImagery("test/data/wmts/getcapabilities-TOPO.xml");
23 private ImageryInfo testImageryORTO_PL = getImagery("test/data/wmts/getcapabilities-ORTO.xml");
24
25
26 @BeforeClass
27 public static void setUp() {
28 JOSMFixture.createUnitTestFixture().init();
29 }
30
31 private static ImageryInfo getImagery(String path) {
32 try {
33 return new ImageryInfo(
34 "test",
35 new File(path).toURI().toURL().toString()
36 );
37 } catch (MalformedURLException e) {
38 e.printStackTrace();
39 return null;
40 }
41 }
42
43 @Test
44 public void testPseudoMercator() throws MalformedURLException, IOException {
45 Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
46 WMTSTileSource testSource = new WMTSTileSource(testImageryPSEUDO_MERCATOR);
47
48 verifyMercatorTile(testSource, 0, 0, 1);
49 verifyMercatorTile(testSource, 0, 0, 2);
50 verifyMercatorTile(testSource, 1, 1, 2);
51 for(int x = 0; x < 4; x++) {
52 for(int y = 0; y < 4; y++) {
53 verifyMercatorTile(testSource, x, y, 3);
54 }
55 }
56 for(int x = 0; x < 8; x++) {
57 for(int y = 0; y < 4; y++) {
58 verifyMercatorTile(testSource, x, y, 4);
59 }
60 }
61
62 verifyMercatorTile(testSource, 2<<9 - 1, 2<<8 - 1, 10);
63
64 assertEquals("TileXMax", 1, testSource.getTileXMax(1));
65 assertEquals("TileYMax", 1, testSource.getTileYMax(1));
66 assertEquals("TileXMax", 2, testSource.getTileXMax(2));
67 assertEquals("TileYMax", 2, testSource.getTileYMax(2));
68 assertEquals("TileXMax", 4, testSource.getTileXMax(3));
69 assertEquals("TileYMax", 4, testSource.getTileYMax(3));
70
71 }
72
73 @Test
74 public void testGeoportalTOPOPL() throws IOException {
75 Main.setProjection(Projections.getProjectionByCode("EPSG:4326"));
76 WMTSTileSource testSource = new WMTSTileSource(testImageryTOPO_PL);
77 verifyTile(new LatLon(56,12), testSource, 0, 0, 1);
78 verifyTile(new LatLon(56,12), testSource, 0, 0, 2);
79 verifyTile(new LatLon(51.1323176, 16.8676823), testSource, 1, 1, 2);
80
81 assertEquals("TileXMax", 37, testSource.getTileXMax(1));
82 assertEquals("TileYMax", 19, testSource.getTileYMax(1));
83 assertEquals("TileXMax", 74, testSource.getTileXMax(2));
84 assertEquals("TileYMax", 37, testSource.getTileYMax(2));
85 assertEquals("TileXMax", 148, testSource.getTileXMax(3));
86 assertEquals("TileYMax", 74, testSource.getTileYMax(3));
87 assertEquals(
88 "http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/TOPO?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=MAPA "
89 + "TOPOGRAFICZNA&STYLE=&FORMAT=image/jpeg&TileMatrixSet=EPSG:4326&TileMatrix=EPSG:4326:0&TileRow=1&TileCol=1",
90 testSource.getTileUrl(1, 1, 1));
91 }
92
93 @Test
94 public void testGeoportalORTOPL4326() throws IOException {
95 Main.setProjection(Projections.getProjectionByCode("EPSG:4326"));
96 WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
97 verifyTile(new LatLon(53.5993712684958, 19.560669777688176), testSource, 12412, 3941, 14);
98
99 verifyTile(new LatLon(49.783096954497786, 22.79034127751704), testSource, 17714, 10206, 14);
100 }
101
102 @Test
103 public void testGeoportalORTOPL2180() throws IOException {
104 Main.setProjection(Projections.getProjectionByCode("EPSG:2180"));
105 WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
106
107 verifyTile(new LatLon(53.59940948387726, 19.560544913270064), testSource, 6453, 3140, 14);
108 verifyTile(new LatLon(49.782984840526055, 22.790064966993445), testSource, 9932, 9305, 14);
109 }
110
111 private void verifyTile(LatLon expected, WMTSTileSource source, int x, int y, int z) {
112 LatLon ll = new LatLon(source.tileXYToLatLon(x, y, z));
113 assertEquals("Latitude", expected.lat(), ll.lat(), 1e-05);
114 assertEquals("Longitude", expected.lon(), ll.lon(), 1e-05);
115
116 }
117
118 private void verifyMercatorTile(WMTSTileSource testSource, int x, int y, int z) {
119 TemplatedTMSTileSource verifier = new TemplatedTMSTileSource(testImageryTMS);
120 LatLon result = new LatLon(testSource.tileXYToLatLon(x, y, z));
121 LatLon expected = new LatLon(verifier.tileXYToLatLon(x, y, z-1));
122 System.out.println(z + "/" + x + "/" + y + " - result: " + result.toDisplayString() + " osmMercator: " + expected.toDisplayString());
123 assertEquals("Longitude" , expected.lon(), result.lon(), 1e-04);
124 assertEquals("Latitude", expected.lat(), result.lat(), 1e-04);
125 //assertTrue("result: " + result.toDisplayString() + " osmMercator: " + expected.toDisplayString(), result.equalsEpsilon(expected));
126// LatLon tileCenter = new Bounds(result, new LatLon(testSource.tileXYToLatLon(x+1, y+1, z))).getCenter();
127// TileXY backwardsResult = testSource.latLonToTileXY(tileCenter.toCoordinate(), z);
128 //assertEquals(x, backwardsResult.getXIndex());
129 //assertEquals(y, backwardsResult.getYIndex());
130 }
131}
Note: See TracBrowser for help on using the repository browser.