tegola: Using ST_AsMVTGeom with SRID 4326 causes rendered polygons to shift North East at low zoom levels

Hey folks,

I’m encountering a strange issue that I don’t understand.

Actual Behavior

As depicted in this video my polygons make a break for the North Sea as I decrease the level of zoom!

Expected Behavior

I’d expect the rendered polygons to stay broadly in place.

Data used (where to get the data.)

The data I’m trying to render (the U.K. Green Belt) has an SRID of 4326. I’m not really sure how best to share the dataset. Here are a few rows from a rather large table:

1	Dacorum	E07000096	10641.8521	London area	MULTIPOLYGON (((-0.6823910543879775 51.79442049154736, -0.6820207666365838 51.793914403976984, -0.6819713848363225 51.79383883693092, -0.68181718413316 51.79354116129086, -0.681757008310655 51.793420770858305, -0.6817289000878424 51.793262729024335, -0.6816416907559254 51.792610939463515, -0.682077201068385 51.792543964867356, -0.6836648487770477 51.792397475541435, -0.6835427325127756 51.791829909612915, -0.6834380147509416 51.79091404101849, -0.6822741496507773 51.79063184039543, -0.6819715604338256 51.79053697046843, -0.6801900953184341 51.790129634344986, -0.6792041975193462 51.789911856466006, -0.678539862509953 51.78978285767217, -0.6779668889459732 51.78968447162917, -0.6773787715355224 51.789656799683485, -0.6773438694016111 51.78965738718103, -0.6773016788002109 51.789659304360626, -0.6772699159312111 51.78966062849171, -0.6772449735700208 51.78966175060037, -0.6768733469474261 51.789680048477756, -0.6764042007104336 51.78970174330193, -0.6757583943192862 51.78972201334949, -0.675731184432956 51.789722830861855, -0.6752319103844732 51.78973701541884, -0.6751607226829526 51.78973888387708, -0.674657200470108 51.789758494002605, -0.6740790459092716 51.789789632851196, -0.6736651397913052 51.789812784839214, -0.6733805802603757 51.78982853802452, -0.6728781303029318 51.78985798942243, -0.6724945743427929 51.789881479829646, -0.6724655071260714 51.78988382217019, -0.6720649129747007 51.789900932610315, -0.6719773693260692 51.78990429585588, -0.6718045986865776 51.789785741636045, -0.6718204167682593 51.789771443860104, -0.672037027871634 51.78952381647077, -0.6720965849678283 51.78945536177922, -0.6723361898636423 51.78918002968447, -0.6724074573291118 51.78909837253961, -0.6724463787811322 51.78905371019328, -0.6724792300381808 51.78901530038562, -0.6724942476807851 51.788997630630696, -0.6725134743126341 51.78897536873464, -0.6726969261308722 51.78876108420843, -0.6726938880602696 51.78875641025826, -0.6726912993062227 51.7887517413799, -0.6726517270812589 51.788679784626055, -0.6726482848196629 51.78867356855132, -0.6726121507590964 51.78860797167656, -0.6725635614674956 51.78851918875484, -0.6725493476946693 51.788494166566366, -0.6724948596073567 51.78840531702065, -0.6724737042193774 51.7883698131915, -0.6724455862982182 51.78833985049032, -0.6724142446384994 51.78831154180263, -0.6723833916271904 51.7882823934146, -0.6723635905555609 51.788262496261346, -0.6723323767202445 51.788229837067774, -0.6723143668464049 51.788210661473954, -0.6722711061375689 51.788156223496635, -0.6722654607171678 51.78814801337568, -0.6722419971039467 51.788113607386364, -0.6722213161638712 51.788077263657215, -0.672206486499918 51.788042118937376, -0.6722022531398697 51.78803223434054, -0.672195534044267 51.78801417529882, -0.6722147067000929 51.788009050799, -0.6720905253938415 51.78788710728692, -0.6719283094359495 51.78773326351341, -0.6718463011722531 51.787655908766034, -0.6718357115006041 51.787646231097604, -0.6715200855228332 51.787995450399634, -0.671437671388897 51.788086395267136, -0.6713767733168188 51.788154133141, -0.6713552606182245 51.78817721423278, -0.671271001067565 51.78826926207954, -0.6711848713255002 51.78836326687989, -0.6711057618152616 51.788449762059315, -0.6710228946158494 51.78854027891163, -0.670934436726988 51.788636505111654, -0.6708473741865363 51.78873161407814, -0.6708075631560819 51.78877542063819, -0.6707602922918098 51.78882687561842, -0.6706868064080563 51.78890696913891, -0.6706015937307952 51.78900027354478, -0.6705182730267139 51.78909135138448, -0.670429328543992 51.789188273046875, -0.6704087383452862 51.7892105191877, -0.6703464728483941 51.78927879854472, -0.670255171634439 51.78937892140446, -0.6701629383270535 51.789480157599925, -0.6701573171488997 51.789486415110886, -0.6701226953658251 51.78952381517812, -0.6700464243793672 51.789605845956835, -0.6697483858841133 51.78992602779007, -0.6696351243453291 51.79004852455572, -0.6696192147762021 51.790065905118276, -0.6695482691759355 51.790074795346094, -0.6690512773394568 51.79011862474669, -0.6690121901922139 51.790122956850965, -0.6689335372934418 51.79013162459448, -0.6689158293037788 51.79013324943348, -0.6686494891724232 51.790176172173005, -0.6686348374826228 51.790181347283195, -0.6686097663015265 51.790186827021095, -0.668541348976491 51.79020192248736, -0.6684638248360191 51.79021902781277, -0.6684405384932544 51.79022495033033, -0.668415910570235 51.79023014731582, -0.6684067977700983 51.79023186941177, -0.6683749659286942 51.79023600472657, -0.6683603928023071 51.79023851019191, -0.6683138947102006 51.79024782039966, -0.668213319879375 51.790262839215785, -0.6681318901977727 51.79027371387916, -0.66803267773717 51.79028874797217, -0.6680035563001416 51.79029291388865, -0.6679917349162041 51.79029404779221, -0.6677026630879016 51.79032449132701, -0.6676079975716337 51.79033873137158, -0.6674728133089548 51.7903443658039, -0.6673001337485263 51.790346059416976, -0.6664914155062979 51.79020496632472)) ...etc.... ((-0.4721991445046227 51.82786563968654, -0.472333634100177 51.827885091277295, -0.4721986948388686 51.827865633845484, -0.4721991445046227 51.82786563968654)))	20

If I set the provider type to postgis and use ST_AsBinary, everything works, but is kinda slow, so I’d like to use the mvt_postgis provider type, which is much faster but leads to this weird issue.

Config file (sanitized version of the config file used.)

When using the postgis provider, my config looks like this:

[[providers]]
name = "${SCHEMA}"      # provider name is referenced from map layers
type = "postgis"    # the type of data provider. currently only supports postgis / mvt_postgis
host = "${DBHOST}"      # postgis database host
port = "${DBPORT}"      # postgis database port
database = "${DBNAME}"  # postgis database name
user = "${DBUSER}"      # postgis database user
password = "${DBPASS}"  # postgis database password
srid = 4326             # The default srid for this provider. If not provided it will be WebMercator (3857)

  [[providers.layers]]
  name = "greenbelt"
  geometry_fieldname="geom"
  id_fieldname="gid"
  geometry_type = "MultiPolygon"
  srid="4326"
  dont_simplify = true
  sql = "SELECT ST_AsBinary(geom) AS geom, gid FROM ${SCHEMA}.greenbelt WHERE geom && !BBOX! and zlevel=!ZOOM!"

(I’ve pre-simplified the geoms for each zoom level, hence passing in the !ZOOM! and enabling dont_simplify).

Again, this works perfectly and the rendered polygons behave exactly as expected at all levels of zoom, but is kinda slow.

When I switch it to the mvt_postgis provider, I update my config to look like this:

[[providers]]
name = "${SCHEMA}"      # provider name is referenced from map layers
type = "mvt_postgis"    # the type of data provider. currently only supports postgis / mvt_postgis
host = "${DBHOST}"      # postgis database host
port = "${DBPORT}"      # postgis database port
database = "${DBNAME}"  # postgis database name
user = "${DBUSER}"      # postgis database user
password = "${DBPASS}"  # postgis database password
srid = 4326             # The default srid for this provider. If not provided it will be WebMercator (3857)

  [[providers.layers]]
  name = "greenbelt"
  geometry_fieldname="geom"
  id_fieldname="gid"
  geometry_type = "MultiPolygon"
  srid="4326"
  dont_simplify = true
  sql = "SELECT ST_AsMVTGeom(geom, !BBOX!) AS geom, gid FROM ${SCHEMA}.greenbelt WHERE geom && !BBOX! and zlevel=!ZOOM!"

It’s in this last configuration that the issue of the escaping polygons arises, and I have no idea why.

While trying to figure things out, I found this StackOverflow answer that seemed to suggest that it might be a problem with the bounding box not scaling properly? However I’m not sophisticated enough to understand if this is indeed even related to the issue I’m seeing, nor how one would implement the solution described in the Tegola config, given that Tegola handles the bounding box stuff through the !BBOX! token.

If there is any further information I can provide please let me know. I’ve been super impressed with Tegola since I’ve discovered it, thanks for a great tool!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@renzeroni excellent! thank you for the follow-up. I have documented this in the README as well. Onward!