Skip to content

Commit

Permalink
Fix for non-mercator tiles (CrunchyData#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
jomue authored Nov 11, 2020
1 parent 390d563 commit e21624c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion layer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ func (lyr *LayerTable) requestSql(tile *Tile, qp *queryParameters) (string, erro
type sqlParameters struct {
TileSql string
QuerySql string
TileSrid int
Resolution int
Buffer int
Properties string
Expand All @@ -350,6 +351,10 @@ func (lyr *LayerTable) requestSql(tile *Tile, qp *queryParameters) (string, erro
tileSql := tileBounds.SQL()
tileQuerySql := queryBounds.SQL()

// SRID of the tile we are going to generate, which might be different
// from the layer SRID in the database
tileSrid := tile.Bounds.SRID

// preserve case and special characters in column names
// of SQL query by double quoting names
attrNames := make([]string, 0, len(qp.Properties))
Expand All @@ -371,6 +376,7 @@ func (lyr *LayerTable) requestSql(tile *Tile, qp *queryParameters) (string, erro
sp := sqlParameters{
TileSql: tileSql,
QuerySql: tileQuerySql,
TileSrid: tileSrid,
Resolution: qp.Resolution,
Buffer: qp.Buffer,
Properties: strings.Join(attrNames, ", "),
Expand All @@ -390,7 +396,7 @@ func (lyr *LayerTable) requestSql(tile *Tile, qp *queryParameters) (string, erro
tmplSql := `
SELECT ST_AsMVT(mvtgeom, {{ .MvtParams }}) FROM (
SELECT ST_AsMVTGeom(
ST_Transform(ST_Force2D(t."{{ .GeometryColumn }}"), 3857),
ST_Transform(ST_Force2D(t."{{ .GeometryColumn }}"), {{ .TileSrid }}),
bounds.geom_clip,
{{ .Resolution }},
{{ .Buffer }}
Expand Down

0 comments on commit e21624c

Please sign in to comment.