Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Custom tiles projection in WMTS #68

Closed
daliborjanak opened this issue Feb 19, 2016 · 6 comments
Closed

Custom tiles projection in WMTS #68

daliborjanak opened this issue Feb 19, 2016 · 6 comments
Assignees
Milestone

Comments

@daliborjanak
Copy link
Collaborator

Will be done in branch customtiles. Allow tileserver to use new metadata.json from MapTiler with informations about tilematrix set and serve it trought WMTS standart

@daliborjanak daliborjanak self-assigned this Feb 19, 2016
@daliborjanak daliborjanak added this to the 1.1 milestone Feb 19, 2016
@daliborjanak
Copy link
Collaborator Author

Now we have first usable results. Here is export from QGIS:
customproj
Layers:
Retro (maps.klokantech) as baselayer (EPSG:3857)
Swiss geography - rendered with MT and added in Swiss national crs EPSG:2056
Czech republic trains - rendered with MT in EPSG:5514

All layers warped displayed in QGIS in WGS84. Works well on all zoomlevels

Sample: http://labs.klokantech.com/tileserver/wmts

@daliborjanak
Copy link
Collaborator Author

Rendered GB national EPSG:27700, displayed in WGS84
customproj2

@klokan
Copy link
Member

klokan commented Feb 19, 2016

It looks really cool @daliborjanak. Great job! Thank you. Looking forward to review and test the implementation!

@daliborjanak
Copy link
Collaborator Author

Implementation is done (see PR). Tileserver can now serve tiles in custom projections. It excepts definition of tilematrixset in metadata JSON file. It is triggered when "profile" has value "custom". If some definitions are missing, than tileserver tries to compute missing params as much as it can (method $Wmts->parseTileMatrix($layer, $tileMatrix)). Additional computations could be added in future e.g. scaleDenominator:

$crs = 'EPSG:5514';
$tile_size = [256, 256];
$extent = [-951499.37, -1276279.09, -159365.31, -983013.08];
$origin = [$extent[0], $extent[3]];
$pixel_size = [];

//constants
$StandardizedRenderingPixelSize = 0.00028; //defined in WMTS standart
$metersPerUnit = 1; //defined in proj def

/* Tile at zoom 0 */
// Coordinates always negative
$pixel_size[0] = abs(($extent[0] - $extent[2]) / $tile_size[0]);
echo 'Pixel size in M: ' . $pixel_size[0] . PHP_EOL;

// Scale denominator (derivated from WMTS equation:
// pixelSpan = scaleDenominator × 0.28 10 -3 / metersPerUnit(crs))  
$scaleDenominator = ($pixel_size[0] * $metersPerUnit) / $StandardizedRenderingPixelSize;
echo 'ScaleDenominator: ' . $scaleDenominator . PHP_EOL;

The metadata JSON schema example:

{
  "name": "swiss",
  "version": "1.1.0",
  "description": "",
  "type": "overlay",
  "format": "png",
  "minzoom": "0",
  "maxzoom": "5",
  "bounds": [5.85379955, 45.73743083, 10.66445076, 47.92094704], // in WGS84
  "scale": "1",

  "profile": "custom",
  "crs": "EPSG:2056",
  "proj4": "+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs ",
  "extent": [2476632.56374451, 1066330.29363826, 2841065.95706109, 1312791.87866593], // in projected coords
  "tile_matrix": [
  {
    "id": "0",
    "tile_size": [256, 256],
    "origin": [2476632.56374451, 1312791.87866593], //topleft corner of tilematrix
    "extent": [2476632.56374451, 1066330.29363826, 2841065.95706109, 1312791.87866593],
    "pixel_size": [1423.56794264, -1423.56794264], //size of pixel in projection units
    "scale_denominator": 5084171.22372462 // def in OGC WMTS spec
  },
  {
    "id": "1",
    "tile_size": [256, 256],
    "origin": [2476632.56374451, 1312791.87866593],
    "extent": [2476632.56374451, 1066330.29363826, 2841065.95706109, 1312791.87866593],
    "pixel_size": [711.78397132, -711.78397132],
    "scale_denominator": 2542085.61186231
  },
  {
    "id": "2",
    "tile_size": [256, 256],
    "origin": [2476632.56374451, 1312791.87866593],
    "extent": [2476632.56374451, 1066330.29363826, 2841065.95706109, 1312791.87866593],
    "pixel_size": [355.89198566, -355.89198566],
    "scale_denominator": 1271042.80593115
  }
...
]
}

@klokan
Copy link
Member

klokan commented Feb 26, 2016

Really cool! Can we get this to wmts.maptiler.com please?
It would make it directly applicable for people using MapTiler 0.6.4+.

@klokan
Copy link
Member

klokan commented Mar 1, 2016

Custom tiles branch merged to master in #71. Closing. If something is missing reopen.

Thank you @daliborjanak

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants