go-spatial / tegola

Tegola is a Mapbox Vector Tile server written in Go
http://tegola.io/
MIT License
1.3k stars 198 forks source link

Issue when reprojecting the geometry #961

Closed trideset3 closed 12 months ago

trideset3 commented 12 months ago

Hello,

the data in my PostGIS db is in EPSG:3765 (geometry field is "geom"). I'm using tegola to serve vector tiles but I want to reproject the data to 4326 (or 3857). This is my tegola config:

[webserver]
port = ":${TEGOLA_PORT}"
hostname = "${TEGOLA_HOSTNAME}"

[webserver.headers]
Access-Control-Allow-Origin = "*"
Cache-Control = "s-maxage=3600"

[cache]
type = "redis"
address = "${TEGOLA_REDIS_HOST}:${TEGOLA_REDIS_PORT}"
password = ""
ttl = 10
max_zoom = 18
ssl = "false"
db = 1

[[providers]]
name = "test"
type = "mvt_postgis"
uri = "postgres://${TEGOLA_DB_USER}:${TEGOLA_DB_PASSWORD}@${TEGOLA_DB_HOST}:${TEGOLA_DB_PORT}/${TEGOLA_DB_NAME}?sslmode=disable" # PostGIS connection string (required)
srid = 4326  # Should it be 4326 or 3765? I tried both but it doesn't make a difference.

[[providers.layers]]
  name = "test_layer"
  geometry_fieldname = "geom"
  geometry_type="polygon"
  id_fieldname = "id"
  sql = "SELECT ST_AsMVTGeom(ST_TRANSFORM(geom, 4326), !BBOX!) AS geom, id, naziv FROM test_table WHERE geom && !BBOX!"

[[maps]]
name = "test_map"
center = [16.5166646, 43.7333304, 12.0]
  [[maps.layers]]
  provider_layer = "test.test_layer"
  min_zoom = 1
  max_zoom = 20

With this configuration, the tiles are empty. I tried different solutions (reprojecting to 3857, different geometry alias in query, transforming the bbox and so on) but nothing works. What is the proper way and best practice to do the reprojection and make tegola aware of it? I'm running tegola v0.16.0.

trideset3 commented 12 months ago

Ok, I was missing the transform of the geom or bbox in the conditional clause. There is no issue, my mistake.

  [[providers.layers]]
  name = "test_layer"
  geometry_fieldname = "geom"
  geometry_type="polygon"
  id_fieldname = "id"
  sql = "SELECT ST_AsMVTGeom(ST_Transform(geom, 4326),!BBOX!) AS geom, id  FROM test_table WHERE geom && ST_Transform(!BBOX!,3765)"
ARolek commented 12 months ago

Glad you figured that out!