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
545 stars 68 forks source link

Unable to serve correct tiles with reprojection #282

Open yarray opened 2 years ago

yarray commented 2 years ago

I tried multiple sources including Natural Earth, UIA, etc., with both shapefile and postgis as datasources. However, although I could see some lines/polygons sometimes, it seemed that the tiles were always incorrect. To illustrate the problem, I created two datasets of polygons.

The first one contained several large polygons, like:

截屏2022-02-16 下午1 14 50

I then generated config with

./t_rex genconfig --datasource <path>/large_polygon.shp > config.test.toml

and then served the tileset with

RUST_LOG=debug ./t_rex serve -c config.dresden.toml

In the Xray tab:

截屏2022-02-16 下午1 28 10

The log printed "1 features" for some tiles. It also occasionally printed "ERROR 1: latitude or longitude exceeded limits". I'm not sure whether it's related to the final output.

截屏2022-02-16 下午2 39 10

The corresponding config was:

# t-rex configuration

[service.mvt]
viewer = true

[[datasource]]
path = "/Users/yarray/data/test/large_polygon.shp"
name = "datasource"
default = true

[grid]
predefined = "web_mercator"

[[tileset]]
name = "large_polygon"
extent = [65.11901, 15.94669, 129.20218, 60.21640]
[[tileset.layer]]
name = "large_polygon"
table_name = "large_polygon"
geometry_field = ""
geometry_type = "POLYGON"
srid = 4326
buffer_size = 1
#make_valid = true
simplify = true
query_limit = 1000
#[[tileset.layer.query]]

#[cache.file]
#base = "/tmp/mvtcache"
#baseurl = "http://example.com/tiles"

[webserver]
# Bind address. Use 0.0.0.0 to listen on all adresses.
bind = "127.0.0.1"
port = 6767

#[[webserver.static]]
#path = "/static"
#dir = "./public/"

The input shapefile was large_polygon.zip.

pka commented 2 years ago

Had a quick look at the data and seems to be a reprojection problem. When I reproject manually from EPSG:4326 (WGS 84) to EPSG:3857 (Web Mercator), the tiles look fine.

ogr2ogr -t_srs EPSG:3857 poly3857.shp ./large_polygon.shp
yarray commented 2 years ago

@pka Thanks for your help! I can confirm that supplying data with EPSG:3857 works. But is my config correct for 4326 data? It is still a bug I guess?

pka commented 2 years ago

Your configuration looks correct and automatic reprojection should give the same result. Will look into it.