t-rex-tileserver / t-rex

t-rex is a vector tile server specialized on publishing MVT tiles from your own data
https://t-rex.tileserver.ch/
MIT License
556 stars 69 forks source link

Trex incorrectly generate geometry that potentially has intersection #216

Closed dmitrykinakh closed 2 years ago

dmitrykinakh commented 3 years ago

Hello there,

I want to share with you a possible issue with Trex generation using the data from PostgreSQL DB.

So, the issue. We use the latest version of Trex 0.11.0 (but tested on older as well) and see that for some shapes that letter we extrude to be buildings we have the issue when shape/building jump on the map. Below I've attached examples that work and those that do not work.

Video with the issue - https://www.screencast.com/t/GlEU6x821

The geometry that has issued and Jumps on the map once it tiles WKB format: 0106000020110F00000300000001030000000100000007000000CCDD82D83B0461C11F3C0739ACFD46411917450A3D0461C18F13051DACFD46412F119A183D0461C1A88A3262B2FD4641A23E572F3A0461C10B64BEC1B2FD464188C365233A0461C139F10273ACFD4641A39285D83B0461C11A08AF39ACFD4641CCDD82D83B0461C11F3C0739ACFD46410103000000010000000800000092B3D3D23B0461C183019BD8AAFD46418296F7CE3B0461C15DF74BE9A9FD464158C59E1E3A0461C1ABDC2D2CAAFD46413D4AAD123A0461C13CF2A305A5FD4641DD9FC5F43C0461C1421818A6A4FD46412098E1073D0461C10AFBBDDFA9FD4641B094BED33B0461C106F067FCA9FD464192B3D3D23B0461C183019BD8AAFD464101030000000100000004000000CCDD82D83B0461C11F3C0739ACFD4641B6155BD13B0461C11A08AF39ACFD464192B3D3D23B0461C183019BD8AAFD4641CCDD82D83B0461C11F3C0739ACFD4641

Fixed geometry that properly displays on the map WKB format: 0106000020110F00000300000001030000000100000007000000CADD82D83B0461C1283C0739ACFD46411917450A3D0461C18F13051DACFD46412F119A183D0461C1A88A3262B2FD4641A23E572F3A0461C10B64BEC1B2FD464188C365233A0461C139F10273ACFD4641B49D2AD23B0461C1A2891917ACFD4641CADD82D83B0461C1283C0739ACFD46410103000000010000000800000094B3D3D23B0461C17B019BD8AAFD46418296F7CE3B0461C15DF74BE9A9FD464158C59E1E3A0461C1ABDC2D2CAAFD46413D4AAD123A0461C13CF2A305A5FD4641DD9FC5F43C0461C1421818A6A4FD46412098E1073D0461C10AFBBDDFA9FD4641B094BED33B0461C106F067FCA9FD464194B3D3D23B0461C17B019BD8AAFD4641010300000001000000040000007A68E2063C0461C1075D111DACFD464140572DD03B0461C1BFC543F8ABFD46413B0BEFCE3B0461C14DDFCED7AAFD46417A68E2063C0461C1075D111DACFD4641

Any idea why such a shape (the first one with intersection) leads to the jumping issue on the map?

pka commented 3 years ago

Thanks for your detailed descritption of the problem and sorry for not looking earlier into this.

I've no explanation right after looking at your video and will try to write test cases with your geometries first.

pka commented 3 years ago

My first attempt in reproducing this problem failed:

t-rex-issue-216

Configuration:

[[tileset]]
name = "issue216"
extent = [-80.14389, 26.11595, -80.14367, 26.11618]
[[tileset.layer]]
name = "issue216"
table_name = "issue216"
geometry_field = "geometry"
geometry_type = "MULTIPOLYGON"
srid = 3857
buffer_size = 1
#make_valid = true
simplify = true
query_limit = 1000

[[tileset]]
name = "issue216makevalid"
extent = [-80.14389, 26.11595, -80.14367, 26.11618]
[[tileset.layer]]
name = "issue216"
table_name = "issue216"
geometry_field = "geometry"
geometry_type = "MULTIPOLYGON"
srid = 3857
buffer_size = 1
make_valid = true
simplify = true
query_limit = 1000

Tried with t-rex 0.11 and current master.

Can you see a difference to your setup?

dmitrykinakh commented 3 years ago

I'll re-check this one more time over the weekend. At first look, your settings look the same as mine.

arbakker commented 3 years ago

Hi, we ran into the same issue. In this particular case, small inner rings are causing the problem. The problem does not occur after running the Sieve.sql script on the data to filter out inner rings smaller that a certain size.

geom_moved moved geom

geom_ok ok geom

Here are the steps to reproduce (both the correct and incorrect result):

mkdir tiles-ok tiles-problem
export PGPASSWORD=postgres
export PGCONN="PG:dbname='postgres' host='localhost' port='5433' user='postgres'"
ogr2ogr -f PostgreSQL "$PGCONN" netherlands.gpkg country

# following will result in moved geometries, see geom_moved.png
# running postgres on host, 172.17.0.1 is ip address of hostmachine on docker0 interface
docker run --rm --add-host=dockerhost:"172.17.0.1" -p 6767:6767 -u $(id -u ${USER}):$(id -g ${USER}) -v `pwd`/config:/config -v `pwd`/tiles-problem:/var/data/out sourcepole/t-rex:0.11.0 t_rex serve --loglevel info --config /config/config-problem.toml

# Sieve.sql from https://github.com/mapbox/postgis-vt-util/blob/master/src/Sieve.sql
psql -U postgres -h localhost -p 5433 -d postgres -f Sieve.sql
psql -U postgres -h localhost -p 5433 -d postgres -c "drop table if exists country_sieve; create table country_sieve as select cdr.fid, cdr.name, Sieve(cdr.geom, (3440.640*3440.640)) as geom from country cdr where st_area(cdr.geom) > (3440.640*3440.640);"

# following will result in correct output, see geom_ok.png
docker run --rm --add-host=dockerhost:"172.17.0.1" -p 6767:6767 -u $(id -u ${USER}):$(id -g ${USER}) -v `pwd`/config:/config -v `pwd`/tiles-ok:/var/cache/mvtcache sourcepole/t-rex:0.11.0 serve --loglevel info --config /config/config-ok.toml

See the attached zip file for the config and data.

t-rex-issue.zip

dmitrykinakh commented 3 years ago

Today I've faced exactly the same issue that @arbakker is describing. The problematic geometry for me is: 0106000020110F00000C000000010300000001000000070000005311BB7C570561C1E029BDD9DAC54641FA6BBF02560561C188CD4442F4C546419A1745F5490561C1559EBFCBF6C5464116EF61EF490561C1D405EC02F5C54641F2B050414B0561C1198E75C1F4C546411816F60E4B0561C1AA9E0F4BDDC546415311BB7C570561C1E029BDD9DAC546410103000000010000001E000000925909BF1D0561C12256012EB6C646411C0E48F60A0561C1E2F123CDB8C64641F6255FD30A0561C16686BAE0B9C64641EEEBC01FFD0461C1B8A67987BBC646411FA7482DFC0461C1335D2FAAB9C6464155CD3239040561C1D1491CBB8DC646414ED465C9060561C182D2FE3281C64641ED5B7CE40D0561C11A94704B61C64641A69F25E2140561C101CBC5B546C64641C9E3072D240561C1F5F6701316C646418E5AB6BC250561C1D82DC8E312C64641E10F784E320561C1BEBF7C86F4C5464151139B49330561C1BB908C20F3C54641541A731D360561C1B417DF4A0BC646410AC9D579370561C1E69D1E6A18C64641655C358F370561C1A6F770B71DC64641DA83DD36370561C19B4928B722C64641EA82996D360561C10A601B6726C64641CDAB9DF2300561C142CBE03732C646416B2BF61B310561C1BB7493A035C64641EBE23686310561C13FBD52BE66C646415CDE8A70310561C12971B6206CC64641FC428349380561C19CA386D26AC64641D85BA75E390561C1A8F2B7336CC64641A66117AE390561C13E9A3D886DC646415A5517013A0561C18817364186C64641DE938735230561C13AA4DFF689C6464132310E77230561C1F11109C8A6C646414C34399F1D0561C17F402BCBA7C64641925909BF1D0561C12256012EB6C646410103000000010000000D0000006A410AB71B0661C1A4020D9E3FC64641F4E23830530661C19B3D505836C646417C50291B8B0661C16FB8A8432EC64641C5E8AB4DC10661C13298D0541FC64641CC245D69C60661C130A9D1F341C64641079752A8B40661C14A45691C93C64641A690577F9A0661C1BE7D72B097C64641AF2280388C0661C152FBC6C59BC64641F5742D6B700661C1120E1167A1C646417DBC7559540661C1FB25D4A1A4C6464193C92A49380661C17046E481A9C64641904297A61C0661C105AC3138ADC646416A410AB71B0661C1A4020D9E3FC6464101030000000100000010000000565BC717AF0561C15AE1E8A9E0C74641FFF0AA12AE0561C1BDE5CAB46FC74641A7B5509BAE0561C1F59C718268C746414C261F1CB00561C16EC2DC325AC7464148E17A06B10561C1C520B0125BC746411A51DA21BA0561C1CA98BB9659C74641DF0A79B4B90561C1DD256AED32C74641995D7F37C90561C129E9A81230C746414E8EBA29CA0561C152262DEF9FC746413FB97F1E020661C1BEADB94696C74641C32B59C7020661C1E9F91162CFC74641415C3CC4E60561C122911A4AD4C746411237300FE70561C1F343E755F0C746415DFE439CD40561C192C2F568F3C7464110FE6043D40561C1535CA41BD8C74641565BC717AF0561C15AE1E8A9E0C746410103000000010000000A00000041BA4F5CF80561C1FC19D32A44C64641517EEA63F90561C1391F1D30AAC64641213A351A000661C1540C1F8FA9C646415D20419B000661C1102DB21DE4C6464138B740D7F90561C1FE8569EFE4C646413BAFE309FA0561C1B17925BAFEC646412CD00FEBE40561C1B895E50A02C7464195824556E40561C1422AF674AEC6464169AC3A52E30561C14565772048C6464141BA4F5CF80561C1FC19D32A44C6464101030000000100000005000000431CEBC44F0661C12085EB49C2C64641B318F50A500661C14D20A92DDFC64641419898B7380661C1C02ACBFBE2C6464172315680380661C1B7664F4BC6C64641431CEBC44F0661C12085EB49C2C646410103000000020000000C00000048E17A0CDE0461C1AC2E6E6B90C946415E4BC863750461C1463789619FC94641DE67567C700461C120AC164792C946418D85716A870461C1163582C280C94641639CF5039C0461C17B6EBFA179C946417C306C22EE0461C1EB5D96F16DC9464182D93C4F0F0561C14F7AB6316AC946416CC0E2DF130561C1384E16DF66C94641BA56A02E170561C1C53EB88C66C94641D8ED49EB170561C192B6FF4F6CC94641925CFE29180561C1AB59F51988C9464148E17A0CDE0461C1AC2E6E6B90C94641050000009862A976EE0461C1EA569BB588C94641F276E373EE0461C1586A8AC687C94641B11E256CED0461C1BCF57AC487C94641814C7B6DED0461C19734013788C946419862A976EE0461C1EA569BB588C9464101030000000100000008000000494535BB890561C1A520C3FEAFC94641FD7522B2850561C10B29878AB0C9464138EDF8817C0561C17390B6A3B8C9464186AC47D67B0561C1A8553A8476C94641C02B7E49970561C1B5A722DF71C9464115A726A2970561C18528D182A9C94641F42D66548D0561C15DE37CB2ACC94641494535BB890561C1A520C3FEAFC9464101030000000100000007000000C3531802CF0561C18C71D49667C94641E36A430BEB0561C134891A4E62C9464155532854EC0561C13DBFE151D3C946414B59867CDE0561C1A24E4073D5C94641D0F8517BDE0561C130E4FEC0D3C94641ABBB1E44D00561C1C2267358D6C94641C3531802CF0561C18C71D49667C946410103000000010000003B0000007B7AAAE2A50661C165F5839502CB4641DEE00B77A40661C18BDB684077CA4641083D9BE19D0661C16AF7E48978CA4641423EE8199D0661C1DB9AE60D2ACA464133BCF86E9D0661C179BE5F1E1FCA464118A6B9C19C0661C1FFBA9669EAC9464158D58A009D0661C17443BD5CEAC94641855F203A9C0661C13800802FB2C946413657D1B89B0661C1AEBE1B1B79C94641068B5EE59A0661C1FF3D3D5379C9464169DB9C269A0661C18D8519C241C94641230149C39A0661C1496C649A41C94641B61409BB9A0661C1B438C1C83BC9464197900F88990661C112022B37D5C846414D8EB839990661C1315173B5CBC84641931804D6980661C1C154C1A8AEC84641EBB310D3980661C1FFB425CCAAC846411B1FCA749A0661C1256BD15FAAC84641218E75399A0661C1DAE9954A96C846418FE4F2FB980661C1DE9C118596C8464191A9FCF2980661C19A84E80C85C84641D3E32D40960661C17B284FB385C84641A301BC1D960661C162006F8973C84641E02D909A980661C1F731E61673C84641C93E9D59980661C178B518F25EC846412AF60456C80661C1E5BA70DE53C84641B747C6B4C80661C1A954D94C7BC84641047E1901AD0661C1EE77143880C84641AF92319EAD0661C1C4B79367A5C846410401FFCEAD0661C13E1B65A4CBC84641C1C71FA89F0661C15D71DBE9CDC846416757B843A10661C1EA818AF43FC946416EDF8FE5AE0661C1835AF67F3CC94641C49C737DCA0661C1CE75EC5637C94641F625A8F0C90661C16FC07702FDC846412AA568A5D80661C10AB24B82FAC8464195EBA7D8D90661C167B559CD6FC94641452D2215CD0661C16EEFD0B572C94641C69315ADCD0661C19155DA8BA6C946419C33A23ECD0661C111AE47A1A6C946415BB1BF2ECC0661C1311AC0EBA8C9464138BCBC24B00661C1B58E9383ADC946413A12FE63B10661C1C3D0F90422CA4641A5E51654C70661C188808A901DCA464110E9B76DC70661C16C3D0ACF13CA46418126C21EC70661C1C8E53FD4FBC946418E06F00EC30661C1420AD7A3FCC9464180B740B8C20661C12C992A58E0C9464160B2CFE3CB0661C1CD4DCA85E2C94641A79A4AE4CC0661C1FEA0EDB019CA464125E891A8CD0661C1E72791EE4FCA46419BE562FDCD0661C1D0AED8E057CA46412C651988CE0661C143575BC985CA46412743EF2BCD0661C117E2712E86CA4641BFAD28E5CD0661C1E3CC50A6C3CA4641FB594B43CF0661C16FB7527EC3CA4641F6B2E0C8CF0661C124CDC87AF3CA46414D6ADA52CF0661C131DA4257FBCA46417B7AAAE2A50661C165F5839502CB4641010300000001000000050000001748502ED70561C15B6DC50E6DCA464187490FC5D10561C147E108786DCA4641B792A4A2D10561C1CFA175AD47CA46412CFE8CADD60561C15C363AD446CA46411748502ED70561C15B6DC50E6DCA464101030000000100000011000000E4141D0F5A0561C12E6EA3513ACB4641B6045EC5590561C11A1661881ECB4641EF6DCE495A0561C1DCBC50731ACB4641C8162F0B5A0561C153F587E002CB46411F4C815F540561C1E52774C302CB4641B203C16D540561C1DA44B439FDCA464195732907540561C13B119840D5CA4641743C2726540561C146BCD5F6D0CA464111CADF5A540561C1C577FC6DCFCA4641F0CA5AB5540561C1B34E69CCCECA4641941B5BFF590561C1D0920CDACDCA46417C3DB7125B0561C189BEC68CCBCA46414D9E91E36D0561C1FB151B8AC8CA46411702AF706E0561C1E469214D01CB4641FF7533B37F0561C13BE39F41FDCA4641EB0B3B69800561C1C018391535CB4641E4141D0F5A0561C12E6EA3513ACB4641 It's moving on the map when you zoom from z12 to z13 level.

I found that the problem is in this whole inside the polygon. image

There is no issue with the "moving" shape on the map if I remove that whole. Does anyone know why small wholes cause this issue? Is there some workaround for small zoom levels (10>=13) to have such things not rendered or might there is some article that can explain how to properly shows data on different zoom levels so on z10 we show just big shapes and on z15-18 we show all those small details?

dmitrykinakh commented 3 years ago

@pka - do I need to provide extra information about this issue or it's clear for you? Let me know if I can do anything that can help to investigate this issue.

WouterVisscher commented 3 years ago

Does anyone know why small wholes cause this issue?

@dmitrykinakh, @arbakker and I think this propably has something to do with features/holes that would be "smaller" then the size of a pixel. In the example/image that Anton posted of the Netherlands the geometries causing this behaviour where smaller then 1720.32x1720.32 (the 'size' in meters of a pixel at that zoomlevel z1). So basically a feature that is to small to render.

Is there some workaround..

The work around we implemented was by preprocessing the data with that logic. Filtering out all object per zoom level that are to small for visualisation (these were whole features as well as 'donuts' in larger features). We made a small tool (https://github.com/PDOK/sieve) for this for GPKG and for PostGIS we used the Mapbox Sieve script Anton refered to.

dmitrykinakh commented 2 years ago

That was the issue. @WouterVisscher - thanks for the recommendation! @pka - my issue was resolved. Feel free to close the issue.