t-rex-tileserver / t-rex

t-rex is a vector tile server specialized on publishing MVT tiles from your own data
https://t-rex.tileserver.ch/
MIT License
556 stars 69 forks source link

Non-Mercator grids have a different tile scheme after seeding #175

Closed arashgh-gh closed 4 years ago

arashgh-gh commented 4 years ago

Hello,

I use OpenLayers to visualize my vector tiles in "EPSG:25832" just the way as the provided example.

...
var extent=[-46133.17, 5048875.26857567, 1206211.10142433, 6301219.54]
var res=[4891.96981025128,2445.98490512564,1222.99245256282,611.496226281410,305.748113140705,152.874056570353,76.4370282851763,38.2185141425881,19.1092570712941,9.55462853564703,4.77731426782352,2.38865713391176,1.19432856695588,0.597164283477939,0.298582141738970,0.14929107086948457,0.0746455354347426,0.0373227677173713]

projection.setExtent(extent);

var matrixIds = [];
for (var i = 0; i < res.length; i++) {
  matrixIds.push(i);
}

var tileGrid = new TileGrid({
  origin: [extent[0], extent[3]],
  resolutions: res,
  matrixIds: matrixIds
});

var vectorTile= new VectorTileLayer({
  source: new VectorTileSource({
      format: new MVT(),
      tileGrid: tileGrid,
      tilePixelRatio: 16,
      projection:'EPSG:25832',
      url:'url'
  })
})

const map = new Map({
  target:'map',
  layers:[
  /*new TileLayer({
      source: new OSM()
    }),*/
    vectorTile
  ],
  view:  new View({
    center: [362299,5702281],
    projection:projection,
    extent:extent,
    resolution:500,
    //zoom: 6,
    minZoom:6,
    maxZoom:20
  })
});
...

Here is my user grid in config.toml:

[grid.user]
width = 256
height = 256
srid = 25832
units = "m"
extent = {minx = -46133.17, miny = 5048875.26857567, maxx = 1206211.10142433, maxy = 6301219.54}
resolutions = [4891.96981025128,2445.98490512564,1222.99245256282,611.496226281410,305.748113140705,152.874056570353,76.4370282851763,38.2185141425881,19.1092570712941,9.55462853564703,4.77731426782352,2.38865713391176,1.19432856695588,0.597164283477939,0.298582141738970,0.14929107086948457,0.0746455354347426,0.0373227677173713]
origin = "TopLeft"

The generated cache files on the fly, which are produced by moving around in the map, works fine. But if I use t_rex generate --config config.toml, the tiles will be shown messy and in wrong positions in OpenLayers. I figured out if I change the origin from TopLeft to BottomLeft, the generated tiles by t_rex generate command would be visualized perfectly by OpenLayers. Afterwards I removed the cache files and tried with origin="BottomLeft" to produce the cache files on the fly, this time the tiles are in wrong positions. It means, I have to change between origin="TopLeft" for live caching via OpenLayers and origin="BottomLeft" for t_rex generate.

Any idea or explanation for this problem? Many thanks.

stvno commented 4 years ago

I have the same problem and I'm trying to understand what is going on. While reading the source code I noticed this line which confuses me:

https://github.com/t-rex-tileserver/t-rex/blob/master/t-rex-service/src/mvt_service.rs#L293

Doesn't this mean that the Y always gets flipped, regardless of the origin?

arashgh-gh commented 4 years ago

@stvno

Thanks for your reply. I don't know, if I understood the code correctly but I think something misses at the function pub fn generate() because prior to this in the function pub fn tile_cached() which fetches or creates the tile, the srid of the grid is controlled: https://github.com/t-rex-tileserver/t-rex/blob/c2e9202212115d9cb71331f02df2edda3cb6cbbf/t-rex-service/src/mvt_service.rs#L134

and then it puts the path like this in line 139 by using: let path = format!("{}/{}/{}/{}.pbf", tileset, zoom, xtile, ytile);

but in generate the path is defined like this:

let y = self.grid.ytile_from_xyz(ytile, zoom);
let path = format!("{}/{}/{}/{}.pbf", &tileset.name, zoom, xtile, y);

I think you are right and it reverses the Y always by generating caches!

pka commented 4 years ago

This is a bug, indeed. Live tiles have an XYZ scheme for Mercator grids and a TMS scheme for other grids. But tiles are always cached in XYZ scheme.

arashgh-gh commented 4 years ago

@pka

Thanks for your feedback. Another thing that I noticed is that if I open the seeded .pbf data in QGIS, they are in "EPSG:3857" but if I download the same .pbf from browser then it is in "EPSG:25832". Is it also related to this bug? Is the final transformation of user grid done in the map application?

pka commented 4 years ago

Fixed in e18c8b6

@arashgh-gh: I don't see any relation with your last observation. Could you please open a new issue and describe how you open a .pbf with QGIS?