3

I'm trying to connect to OSM, via the URL "https://tile.openstreetmap.org/{z}/{x}/{y}.png", with GeoTools WMTS (gt-wmts-28.0.jar). I can connect to a WebMapServer, but now I'd like to add WebMapTile functionallity. As I understand, according to ( https://wiki.openstreetmap.org/wiki/Raster_tile_providers ), it should be free to use. What can be wrong?

This is the code i use:

try {
        URL url = new URL("https://tile.openstreetmap.org/{z}/{x}/{y}.png");
        wmts = new WebMapTileServer(url);
        
    } catch (IOException | ServiceException e) {
        e.printStackTrace();
    }

This is the stack trace;

    apr. 15, 2024 8:07:30 FM org.geotools.data.ows.AbstractOpenWebService internalIssueRequest
ALLVARLIG: Failed to execute request https://tile.openstreetmap.org/{z}/{x}/{y}.png?REQUEST=GetCapabilities&VERSION=1.0.0&SERVICE=WMTS
java.io.IOException: Server returned HTTP response code: 400 for URL: https://tile.openstreetmap.org/{z}/{x}/{y}.png?REQUEST=GetCapabilities&VERSION=1.0.0&SERVICE=WMTS
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1924)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
    at org.geotools.http.SimpleHttpClient$SimpleHTTPResponse.<init>(SimpleHttpClient.java:209)
    at org.geotools.http.SimpleHttpClient.get(SimpleHttpClient.java:136)
    at org.geotools.http.SimpleHttpClient.get(SimpleHttpClient.java:105)
    at org.geotools.data.ows.AbstractOpenWebService.internalIssueRequest(AbstractOpenWebService.java:455)
    at org.geotools.data.ows.AbstractOpenWebService.issueRequest(AbstractOpenWebService.java:489)
    at org.geotools.data.ows.AbstractOpenWebService.negotiateVersion(AbstractOpenWebService.java:287)
    at org.geotools.data.ows.AbstractOpenWebService.<init>(AbstractOpenWebService.java:124)
    at org.geotools.data.ows.AbstractOpenWebService.<init>(AbstractOpenWebService.java:97)
    at org.geotools.data.ows.AbstractOpenWebService.<init>(AbstractOpenWebService.java:88)
    at org.geotools.data.ows.AbstractOpenWebService.<init>(AbstractOpenWebService.java:77)
    at org.geotools.ows.wmts.WebMapTileServer.<init>(WebMapTileServer.java:151)
    at org.geotools.jdbcconnection.mapview.WMTSHandler.<init>(WMTSHandler.java:37)
    at org.geotools.jdbcconnection.mapview.MapView.addargs(MapView.java:2688)
    at org.geotools.jdbcconnection.mapview.MapView.<init>(MapView.java:356)
    at org.geotools.jdbcconnection.MainDialog$169.actionPerformed(MainDialog.java:3683)
    at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
    at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
    at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
    at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
    at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
    at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:297)
    at java.desktop/java.awt.Component.processMouseEvent(Component.java:6635)
    at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
    at java.desktop/java.awt.Component.processEvent(Component.java:6400)
    at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at org.geotools.jdbcconnection.mapview.WMTSHandler.<init>(WMTSHandler.java:43)
    at org.geotools.jdbcconnection.mapview.MapView.addargs(MapView.java:2688)
    at org.geotools.jdbcconnection.mapview.MapView.<init>(MapView.java:356)
    at org.geotools.jdbcconnection.MainDialog$169.actionPerformed(MainDialog.java:3683)
    at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
    at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
    at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
    at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
    at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
    at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:297)
    at java.desktop/java.awt.Component.processMouseEvent(Component.java:6635)
    at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
    at java.desktop/java.awt.Component.processEvent(Component.java:6400)
    at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
2

1 Answer 1

3

You need to provide a getCapabilies endpoint rather than the zxy template, GeoTools expects to read the template URL from the capabilities response.

BUT since OSM is not actually a WMTS service it won't provide you with a getCapabilities endpoint. So you will need to use the OSMService which allows you to do something like:

final TileService service = new OSMService("OSM", "http://tile.openstreetmap.org/");
final Tile tile = new OSMTile(2166, 1189, new WebMercatorZoomLevel(12), service);
final BufferedImage image = tile.getBufferedImage();

See the test cases in the gt-tile-client module.

1
  • Ok, I will then open a Tile OSM thread.
    – Paul Malm
    Apr 15 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.