The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Geo::OGC::Service::WMTS - Perl extension to create geospatial web map tile services

SYNOPSIS

The process_request method of this module is called by the Geo::OGC::Service framework.

In a psgi script write something like

 use Geo::OGC::Service::WMTS;

 my $ogc = Geo::OGC::Service->new({
 config => '/var/www/etc/OGC-services.conf',
 services => {
        'WFS' => 'Geo::OGC::Service::WFS',
        'WMTS' => 'Geo::OGC::Service::WMTS',
        'WMS' => 'Geo::OGC::Service::WMTS',
        'TMS' => 'Geo::OGC::Service::WMTS',
 }});

 builder {
    mount "/WFS" => $ogc->to_app;
    mount "/WMTS" => $ogc->to_app;
    mount "/TMS" => $ogc->to_app;
    mount "/" => $default;
 };

DESCRIPTION

This module aims to provide the operations defined by the Open Geospatial Consortium's Web Map Tile Service standard. Additionally, this module aims to support WMS used as WMTS and TMS.

This module is designed to be a part of the Geo::OGC::Service framework.

A Geo::OGC::Service::WMTS object is a content providing service object created by a Geo::OGC::Service object. As described in the documentation of Geo::OGC::Service a service object is created as a result of a service request. A Geo::OGC::Service::WMTS object is a hash reference, which contains keys env, request, plugin, config, service, and optionally posted, filter, and parameters.

env

The PSGI $env.

request

A Plack::Request object constructed from the $env;

plugin

The plugin object given as an argument to Geo::OGC::Service in its constructor as a top level attribute or as a service specific attribute.

config

The configuration for this service as constructed by the Geo::OGC::Service object.

service

The name of the requested service (WMTS, WMS, or TMS).

posted

A XML::LibXML documentElement of the POSTed XML.

filter

A XML::LibXML documentElement contructed from a filter GET parameter.

parameters

A hash made from Plack::Request->parameters (thus removing its multi value nature). The keys are all converted to lower case and the values are decoded to Perl's internal format assuming they are UTF-8.

CONFIGURATION

The configuration is defined similarly as to other services under Geo::OGC::Service, either as a file or as a variable in the call to Geo::OGC::Service->new.

The file must be JSON and either have top level key WMTS, WMS, or TMS if more than one service is defined. The value of the key must be a hash, or the name of a key, which has a hash value.

Known top level keys in the hash are 'resource', 'blank', 'debug', and 'TileSets'. TileSets is an array of hashes. The keys of a TileSet hash are Layers, Format, Resolutions, SRS, BoundingBox, path, and ext.

PLUGIN

The plugin object can be used to modify the config object in response time.

A Geo::OGC::Service::WMTS object calls the plugin object's config method with arguments ($config, $self) before the config is used to create a response to a GetCapabilities request, and in RESTful service if layer name is not defined. The config method is not called for each tile request and thus the configuration should probably have parameter serve_arbitrary_layers set to true.

A Geo::OGC::Service::WMTS object calls the plugin object's process method when making the tile if the plugin object exists. The method is given as argument a hash reference with the following keys:

dataset

The GDAL dataset of the layer, if the layer has a configuration parameter 'file'.

tile

A Geo::OGC::Service::WMTS::Tile object made from the request. The extent is from projection, which is deduced from the tilematrixset parameter.

service

The Geo::OGC::Service::WMTS object.

headers

Currently ['Content-Type' => "image/png"]

EXPORT

None by default. Package globals include

$radius_of_earth_at_equator

6378137

$standard_pixel_size

0.28/1000

$tile_width

256

$tile_height

256

$originShift3857

Math::Trig::pi * $radius_of_earth_at_equator

%projections

Hash of 'EPSG:nnnn' => {identifier => x, crs => x, extent => {SRS => x, minx => x, maxx => x, miny => x, maxy => x}}. Currently contains EPSG:3857 and EPSG:3067.

METHODS

process_request

The entry method into this service. Calls RESTful if there is no request parameter, otherwise dispatches the call to WMSGetCapabilities, GetCapabilities, GetTile, GetMap, or FeatureInfo depending on service and request. If request is not recognized, returns an error XML with exceptionCode => 'InvalidParameterValue'.

GetCapabilities

Sends a capabilities document according to WMTS standard.

WMSGetCapabilities

Sends a capabilities document according to WMS standard.

GetMap

Serves the tile request if WMS is used.

Sends the requested tile based on parameters BBOX, LAYERS, and SRS.

The tiles should be in a tile map resource type of directory structure (z/y/x.png). The value of the 'path' key in the TileSet config element should point to the directory.

GetTile

Serves the tile request if WMTS is used.

Sends the requested tile based on parameters Layer, Tilerow, Tilecol, Tilematrix, Tilematrixset, and Format.

The tile is served from a tile map directory or it is made on the fly from a GDAL data source (the value of the 'file' key in the TileSet). In addition, processing may be applied to the data source (the 'processing' key). The processing may be one of those implemented in GDAL.

Using the 'file' keyword requires GDAL 2.1.

Keyword RESTful (0/1) controls the ResourceURL element in the capabilities XML. Default is false.

RESTful

RESTful service. The URL should have the form <service>/layer/<TileMatrixSet>/<TileMatrix>/<TileCol>/<TileRow>.<ext>. TileMatrixSet is optional. Compare this to the template in capabilities.

Sends TileMapService response if the layer is not in the URL, TileMap response if the layer is in the URL but zoom, row, and col are not, or the requested tile based on layer, zoom, row, and column in the URL.

FeatureInfo

Not yet implemented.

Geo::OGC::Service::WMTS::Tile

A class for the dimensions of the tile to be sent to the client. Methods are

Geo::OGC::Service::WMTS::Tile->new($extent, $parameters)

$extent should be a reference to a hash of minx, maxx, miny, and maxy. $parameters should be a reference to a has of tilematrix, tilecol, and tilerow.

size

The width and height of the tile in pixels. These come originally from the Geo::OGC::Service::WMTS globals.

projwin

An array (minx maxy maxx miny).

extent

A Geo::GDAL::Extent object of the tile extent.

expand($pixels)

Expand (or shrink) the tile $pixels pixels. Useful for some processing tasks.

LIMITATIONS

Currently only EPSG 3067 (ETRS-TM35FIN) and 3857 (Google Mercator) are supported. To support other tile matrix sets add them to %Geo::OGC::Service::WMTS::projections.

SEE ALSO

Discuss this module on the Geo-perl email list.

https://list.hut.fi/mailman/listinfo/geo-perl

For the WMTS standard see

http://www.opengeospatial.org/standards/wmts

REPOSITORY

https://github.com/ajolma/Geo-OGC-Service-WMTS

AUTHOR

Ari Jolma, <ari.jolma at gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2015- by Ari Jolma

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.22.0 or, at your option, any later version of Perl 5 you may have available.