1

I have some layers in Geoserver(latest stable) that came from PostGIS data (they belong to a store with PostGIS type and gets data from a PostGIS database)

In those layers there are only WMS settings, not WMTS

I went to Caching Defaults in Geoserver, the WMTS Service is already enabled.

So I went to my Openlayers and try this, so I can get a PostGIS-based layer, from Geoserver to the map.

var projection = ol.proj.get('EPSG:3857');
var textent = ol.proj.transformExtent([2297128.5, 4618333, 2459120.25, 4763120], 'EPSG:900913', 'EPSG:3857');
var projectionExtent = projection.getExtent();
var size = ol.extent.getWidth(projectionExtent) / 256;
var resolutions = new Array(14);
var matrixIds = new Array(14);
for (var z = 0; z < 14; ++z) {
  // generate resolutions and matrixIds arrays for this WMTS
  resolutions[z] = size / Math.pow(2, z);
  matrixIds[z] = z;
}

 var ait  =  new ol.layer.Tile({
      opacity: 0.7,
      extent: textent,
      source: new ol.source.WMTS({
        url: 'http://localhost:8080/geoserver/mymap/wmts?',
        layer: 'mymap:planet_osm_polygon, mymap:planet_osm_line, mymap:planet_osm_roads, mymap:planet_osm_point',
        matrixSet: 'EPSG:3857',
        format: 'image/png',
        projection: projection,
        tileGrid: new ol.tilegrid.WMTS({
          origin: ol.extent.getTopLeft(projectionExtent),
          resolutions: resolutions,
          matrixIds: matrixIds
        }),
        style: 'default'
      })
    })

planet_osm_polygon, planet_osm_line, planet_osm_roads and planet_osm_point are composing the final layer. In simple WMS settings would be params: {'LAYERS': 'mymap:planet_osm_polygon, mymap:planet_osm_line, mymap:planet_osm_roads, mymap:planet_osm_point'.... but, in the WMTS case I dont know how I should set them, so that why I set them in layer

This does not work, I get

GET http://localhost:8080/geoserver/mymap/wmts?layer=mymap%3Aplanet_osm_polygon%2C%20mymap%3Aplanet_osm_line%2C%20mymap%3Aplanet_osm_roads%2C%20mymap%3Aplanet_osm_point&style=default&tilematrixset=EPSG%3A3857&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fpng&TileMatrix=9&TileCol=286&TileRow=196 404 (Not Found)

Am I using the wrong settings or Geoserver does not support WMTS for PostGIS-based layers?

  • 2
    I can't say directly what you are missing but you must make your layer to appear in the wmts GetCapabilities before you have any chance to success. GeoServer certainly supports wmts from PostGIS source but publishing new layers through wmts may not happen automatically. Does your layer work through wms? – user30184 Oct 10 '15 at 20:07
4

The default geoserver (geo web cache) WMTS is available at http://myserver.com:8080/geoserver/gwc/service/wmts?request=getcapabilities . I suspect you need to use a url similar to this to get the capabilities document and then check that your code matches the parameters advertised there.

|improve this answer|||||
0

for starters...

try TileMatrix=EPSG%3A38579%3A9 in the URL //ESPG:3857:9

change matrixIds[z] = z to matrixIds[z] = 'ESPG:3857:' + z (same issue - this fix worked for me)

check the WMTS Get Capabilities to ensure you are referencing the correct tilematrix set (in my case I'm using ESPG:900913) and column and row indices conform to the limits defined for each tilematrix (zoom level)

make sure your SLD style is in fact 'default' or the request will also fail

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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