go-spatial / tegola

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

Allow using mvt_postgis provider for PostGIS version lower than 3.0 #772

Closed blinkzz closed 2 years ago

blinkzz commented 3 years ago

It seems like the only thing that stops using it for lower versions of PostGIS extension, that ST_AsMVT fifth argument (feature_id_name) was added in 3.0, but there is literally nothing bad in opting it out and use ST_AsMVT without it. I tried editing postgis.go in my local fork and it was successfull and was working perfectly fine at this AWS RDS instance with this configuration:

Here is what my edit looks like:

sqls = append(sqls, fmt.Sprintf(
    `(SELECT ST_AsMVT(q,'%s',%d,'%s') AS data FROM (%s) AS q)`,
    layers[i].MVTName,
    tegola.DefaultExtent,
    l.GeomFieldName(),
    sql,
))

My experience in Go rather low by now, so i am asking for maintainers to look upon this and maybe consider making feature_id_name optional, this way Tegola will support older versions of PostGIS with much faster MVT generation approach

ARolek commented 3 years ago

@blinkzz you are correct, the feature_id parameter is the key detail forcing PostGIS 3.0. I'm trying to remember why we ended up making this decision. I recall a technical limitation, but I would need to do some digging. @gdey can you recall why we require feature_id for the MVT Provider?

gdey commented 3 years ago

I don't recall. I tried to look to see what may have been the reason. I think it had to be with part of the rendering engine requiring the FeatureID, and if you don't specify it in AS_MVT, it will not add that and an empty field. I could be mistaken on this.

blinkzz commented 3 years ago

Well, looks like Mapbox GL JS is doing fine job handling it right now, also promoteId can be used in source specification too to force using field other than gid

blinkzz commented 2 years ago

Seems like this issue was resolved in #744