go-spatial / tegola

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

Unable to use !ZOOM! in sql query #887

Closed KCC-IT-Admin closed 1 year ago

KCC-IT-Admin commented 2 years ago

I'm using a Tegola Lambda function, but when attempting to use the !ZOOM! function in my custom query it throws an exception:

2022-09-21 21:16:41 [FATAL] main.go:71: error fetching geometry type for layer (us_pos1): ERROR: syntax error at or near "ANY" (SQLSTATE 42601)

As I understand, !ZOOM! replaces with the requested Zoom level of the tile you request. Not sure why it's substituting ANY for it. if I substitute my !ZOOM! and !BBOX! variables with numbers, it works as expected in PGAdmin

the relevant toml sql:

sql = "SELECT gid, adm0code, pos1code, CASE When !ZOOM! < 5 THEN ST_AsBinary(ST_SimplifyPreserveTopology(geom,1)) When !ZOOM! < 10 THEN ST_AsBinary(ST_SimplifyPreserveTopology(geom,0.01)) When !ZOOM! >= 10 THEN ST_AsBinary(ST_SimplifyPreserveTopology(geom,0.005)) ELSE ST_AsBinary(geom) END AS geom FROM public.us_pos1 WHERE geom && !BBOX!"

The below query line works, but doesn't have the extra simplification I'm looking to get with my CASE commands. (Is simplification not supported in the Lambda version?)

sql = "SELECT gid, adm0code, pos1code, ST_AsBinary(ST_SimplifyPreserveTopology(geom,0.005)) AS geom FROM public.us_pos1 WHERE geom && !BBOX!"

ARolek commented 2 years ago

@KCC-IT-Admin can you post your tegola config? I bet if you were to define the geometry_type on the config this error would go away. What's happening is tegola is trying to infer your geometry_type during startup and is hitting an error. If you set the geometry_type in the config this step is bypassed during init.

pnorman commented 1 year ago

Duplicate of #343

KCC-IT-Admin commented 1 year ago

@KCC-IT-Admin can you post your tegola config? I bet if you were to define the geometry_type on the config this error would go away. What's happening is tegola is trying to infer your geometry_type during startup and is hitting an error. If you set the geometry_type in the config this step is bypassed during init.

That was it exactly. Working now as intended, thank you!