3

I have a case where I want to create a difference between two geometries, and store it my db. I later need to check for conflict between geometries in the db, and for that I check two things: if there is an intersection, and if that intersection's dimension is at most one (Point, LineString, MultiLineString, and collections containing those).

The issue I get can be reproduced with the SQL below. I have a difference that is giving me a GeometryCollection even though it only contains LineStrings, and even weirder, its dimension is 2.

begin;

create table z (
    name text NOT NULL,
    geom geometry NOT NULL
);

insert into z values
    ('a', 'POLYGON((-0.8835662511166233 46.95026,-1.1673 46.95026,-1.1673 47.24754,-0.24445 47.24754,-0.24445 47.10458117771998,-0.255375 47.100286,-0.287925 47.101438,-0.298957 47.09925,-0.314251 47.091338,-0.33027 47.088981,-0.312555 47.092257,-0.311854 47.104175,-0.315605 47.105394,-0.314916 47.106305,-0.317185 47.108012,-0.318197 47.107497,-0.322738 47.108762,-0.322166 47.113341,-0.323874 47.116436,-0.321459 47.121283,-0.325581 47.123121,-0.327816 47.122427,-0.330002 47.123199,-0.3293 47.12564,-0.330249 47.126144,-0.332498 47.125027,-0.33722 47.12614,-0.338209 47.125162,-0.339118 47.125369,-0.339153 47.12661,-0.341232 47.128987,-0.337955 47.130561,-0.33382 47.130432,-0.332489 47.131577,-0.334297 47.132289,-0.333255 47.133742,-0.338095 47.134994,-0.342742 47.134635,-0.350545 47.13761,-0.353369 47.141311,-0.347566 47.146139,-0.348841 47.146936,-0.350786 47.146715,-0.350341 47.148346,-0.352047 47.151282,-0.351485 47.152225,-0.353323 47.152762,-0.35578 47.149185,-0.36114 47.151223,-0.366432 47.151314,-0.369563 47.153469,-0.375187 47.151642,-0.384412 47.156495,-0.396127 47.159938,-0.399628 47.159767,-0.40023 47.155858,-0.404906 47.160023,-0.410125 47.158827,-0.406628 47.163987,-0.394179 47.171043,-0.38967 47.175879,-0.394587 47.176119,-0.397269 47.174935,-0.399488 47.177426,-0.402195 47.177222,-0.407773 47.179534,-0.413784 47.180231,-0.411807 47.183143,-0.411996 47.185065,-0.412716 47.185433,-0.412285 47.187333,-0.413439 47.187417,-0.413958 47.190365,-0.417619 47.190956,-0.418248 47.193134,-0.418511 47.195844,-0.412792 47.200155,-0.412285 47.201901,-0.409833 47.204575,-0.41171 47.205248,-0.410264 47.206932,-0.407826 47.206784,-0.405048 47.210537,-0.40383 47.213639,-0.401814 47.215326,-0.401168 47.219627,-0.408793 47.219609,-0.417328 47.223194,-0.421213 47.223417,-0.423234 47.221124,-0.42749 47.218448,-0.430493 47.214774,-0.432012 47.215171,-0.436489 47.21435,-0.439494 47.215173,-0.443709 47.220465,-0.448277 47.221702,-0.454212 47.218059,-0.453324 47.216126,-0.455677 47.211151,-0.461469 47.206421,-0.46267 47.206468,-0.473101 47.197326,-0.476512 47.198431,-0.478934 47.198011,-0.480203 47.199556,-0.48129 47.199278,-0.482276 47.200104,-0.483332 47.20406,-0.480932 47.206143,-0.479899 47.208412,-0.48982 47.2108,-0.493161 47.210967,-0.495366 47.210041,-0.497523 47.211184,-0.500894 47.20962,-0.506224 47.209061,-0.518344 47.210022,-0.533786 47.207824,-0.544078 47.207204,-0.547078 47.208665,-0.550243 47.20432,-0.555934 47.200523,-0.555665 47.199108,-0.557256 47.197598,-0.558835 47.194163,-0.565194 47.192525,-0.571555 47.189365,-0.581188 47.180057,-0.589552 47.175159,-0.590948 47.173115,-0.5911419999999999 47.169356,-0.593306 47.166566,-0.596559 47.163645,-0.598875 47.159885,-0.60299 47.157147,-0.606321 47.153981,-0.6064310000000001 47.153063,-0.608714 47.151739,-0.611255 47.147944,-0.614066 47.148949,-0.634778 47.151401,-0.636791 47.151277,-0.637368 47.149049,-0.641321 47.15116,-0.6429009999999999 47.150853,-0.645837 47.148712,-0.648111 47.148068,-0.648071 47.146159,-0.6502289999999999 47.144351,-0.650943 47.144014,-0.650964 47.14514,-0.655204 47.144456,-0.655244 47.141967,-0.65679 47.140824,-0.657742 47.141094,-0.657647 47.141996,-0.6591669999999999 47.141034,-0.660958 47.141474,-0.661645 47.142495,-0.662358 47.13973,-0.660788 47.138781,-0.661117 47.137602,-0.659606 47.136733,-0.666837 47.133182,-0.6700739999999999 47.134202,-0.671374 47.132367,-0.678609 47.129982,-0.679654 47.130824,-0.685009 47.131849,-0.688837 47.129736,-0.6924630000000001 47.129899,-0.694172 47.130908,-0.696088 47.129613,-0.699315 47.1292,-0.7014899999999999 47.127601,-0.701852 47.130356,-0.703497 47.131179,-0.705908 47.131881,-0.706937 47.130723,-0.7106 47.13282,-0.715656 47.132769,-0.719769 47.130794,-0.719932 47.128783,-0.722145 47.128122,-0.726214 47.127882,-0.727239 47.1286,-0.7403110000000001 47.130005,-0.743658 47.127853,-0.747465 47.126936,-0.753305 47.128401,-0.755615 47.126224,-0.757279 47.129441,-0.764166 47.130843,-0.765193 47.13241,-0.7646810000000001 47.137155,-0.765204 47.138177,-0.76298 47.14355,-0.775934 47.142725,-0.776545 47.14425,-0.784825 47.142603,-0.785197 47.146892,-0.786251 47.146968,-0.788176 47.149197,-0.789696 47.147616,-0.790662 47.148312,-0.792366 47.147384,-0.796446 47.14782,-0.79675 47.150273,-0.798743 47.152046,-0.7999000000000001 47.151605,-0.8017 47.153203,-0.802353 47.157038,-0.805691 47.156591,-0.808284 47.157468,-0.8180539999999999 47.154176,-0.821728 47.15623,-0.825337 47.156855,-0.827803 47.152363,-0.830325 47.152719,-0.831657 47.150077,-0.836781 47.150523,-0.839548 47.149972,-0.851464 47.152844,-0.855811 47.152801,-0.860479 47.151358,-0.863144 47.151598,-0.866328 47.154278,-0.866803 47.156878,-0.874066 47.158261,-0.875957 47.159696,-0.877381 47.158906,-0.879756 47.159392,-0.885042 47.158851,-0.888682 47.160368,-0.895814 47.161263,-0.899084 47.160432,-0.902938 47.161005,-0.90419 47.160098,-0.904825 47.161118,-0.906819 47.161096,-0.908851 47.160224,-0.911125 47.164967,-0.912727 47.164685,-0.910135 47.159648,-0.911496 47.159322,-0.918746 47.159644,-0.926071 47.163675,-0.927214 47.162774,-0.92893 47.162757,-0.934443 47.160325,-0.937325 47.157219,-0.938397 47.157361,-0.940798 47.154856,-0.940044 47.153671,-0.942047 47.153084,-0.941596 47.152113,-0.944796 47.151628,-0.944708 47.149874,-0.948285 47.149339,-0.955456 47.144794,-0.955037 47.144178,-0.956323 47.139477,-0.957614 47.13712,-0.956129 47.13727,-0.956686 47.136964,-0.954873 47.135147,-0.948601 47.132549,-0.948274 47.131818,-0.950375 47.129795,-0.946984 47.127447,-0.948981 47.125865,-0.948527 47.124269,-0.951528 47.123316,-0.952133 47.120092,-0.9461889999999999 47.120618,-0.946038 47.119935,-0.949882 47.117637,-0.950936 47.115496,-0.9536829999999999 47.114413,-0.95651 47.11443,-0.961096 47.116071,-0.965263 47.115767,-0.964548 47.114124,-0.9672539999999999 47.109873,-0.96705 47.108872,-0.967849 47.107754,-0.970367 47.106898,-0.96872 47.105441,-0.966329 47.104755,-0.969109 47.101294,-0.978438 47.100071,-0.979903 47.096908,-0.984779 47.094839,-0.989408 47.091092,-0.9921 47.09038,-0.99311 47.089019,-0.997895 47.09084,-0.9984960000000001 47.088622,-0.997505 47.086696,-0.998069 47.085131,-0.996599 47.08316,-1.001639 47.082483,-1.004834 47.080101,-1.008233 47.080038,-1.012071 47.07765,-1.013411 47.075481,-1.017289 47.074766,-1.023597 47.077407,-1.026835 47.077853,-1.030644 47.072867,-1.032601 47.071583,-1.032856 47.070107,-1.038363 47.068104,-1.038371 47.067549,-1.039566 47.067823,-1.035791 47.070638,-1.039291 47.07315,-1.041014 47.073183,-1.046194 47.068615,-1.042919 47.063977,-1.04296 47.059505,-1.03872 47.061387,-1.031558 47.055852,-1.040741 47.052037,-1.042479 47.052727,-1.043862 47.052359,-1.041309 47.050274,-1.040363 47.048076,-1.040996 47.047222,-1.038031 47.045406,-1.033921 47.044428,-1.028526 47.046577,-1.028338 47.043193,-1.023855 47.042567,-1.023727 47.044304,-1.022619 47.044506,-1.020078 47.042246,-1.020713 47.0395,-1.018823 47.038146,-1.020219 47.0374,-1.017553 47.03602,-1.011849 47.034329,-1.011117 47.034892,-1.012478 47.036518,-1.012062 47.037209,-1.010507 47.036397,-1.008813 47.037094,-1.005892 47.034645,-1.003499 47.034155,-1.00369 47.029205,-1.008565 47.027608,-1.005871 47.027086,-1.003761 47.02556,-1.001848 47.027837,-1.000034 47.027594,-0.995461 47.024415,-0.9974229999999999 47.022981,-1.000446 47.022611,-0.999402 47.025138,-1.000672 47.02556,-1.002044 47.024403,-1.000567 47.022544,-1.002179 47.02152,-0.999529 47.020687,-0.995514 47.017676,-0.982174 47.010593,-0.980279 47.014309,-0.982976 47.016083,-0.981502 47.017046,-0.981873 47.018124,-0.9783539999999999 47.018918,-0.976156 47.018317,-0.9756629999999999 47.01687,-0.973361 47.016124,-0.975314 47.013218,-0.973166 47.012531,-0.974932 47.010525,-0.975229 47.008652,-0.973483 47.008101,-0.972909 47.009056,-0.970504 47.007588,-0.967816 47.007355,-0.968678 47.006687,-0.965982 47.004729,-0.967052 47.005199,-0.968005 47.004208,-0.966535 47.002838,-0.964014 47.003068,-0.963229 47.001985,-0.963101 47.00063,-0.964984 46.999584,-0.9634470000000001 46.998099,-0.964354 46.997292,-0.963159 46.996458,-0.961741 46.997277,-0.962158 46.995809,-0.959851 46.995287,-0.960803 46.994723,-0.957388 46.994887,-0.9582850000000001 46.99543,-0.9567369999999999 46.996404,-0.954756 46.995966,-0.955661 46.99757,-0.95504 46.999919,-0.953334 47.000764,-0.951958 47.002736,-0.947959 47.003694,-0.948313 47.001307,-0.947166 46.999717,-0.944993 46.998988,-0.941698 47.00358,-0.9402779999999999 47.003189,-0.939812 47.002193,-0.939634 47.002783,-0.938673 47.002401,-0.9385289999999999 47.0034,-0.937296 47.003048,-0.936462 47.005257,-0.934844 47.005633,-0.935539 47.007348,-0.933399 47.009041,-0.9329499999999999 47.007838,-0.932015 47.007985,-0.932389 47.006069,-0.929194 47.008111,-0.927473 47.006346,-0.928248 47.00382,-0.9310389999999999 47.004519,-0.931063 47.003357,-0.9327800000000001 47.00456,-0.935226 47.002345,-0.928661 47.002451,-0.928445 47.000682,-0.925042 46.999834,-0.925021 47.002535,-0.919706 47.003377,-0.919365 47.002324,-0.915853 47.001637,-0.914871 47.000633,-0.916957 46.999858,-0.9179580000000001 46.998454,-0.921435 46.998028,-0.918685 46.996536,-0.918747 46.995522,-0.916525 46.996111,-0.914227 46.994688,-0.915649 46.993302,-0.915289 46.992611,-0.912311 46.992815,-0.910853 46.994271,-0.912372 46.995659,-0.9117 46.995997,-0.908708 46.99287,-0.907873 46.994955,-0.904396 46.994915,-0.902515 46.993922,-0.90103 46.991734,-0.8974839999999999 46.989799,-0.898968 46.988701,-0.895404 46.986335,-0.89623 46.985842,-0.8957270000000001 46.985249,-0.893065 46.984496,-0.8968429999999999 46.980815,-0.8948739999999999 46.980231,-0.8950709999999999 46.979177,-0.8924840000000001 46.978577,-0.892187 46.976082,-0.89028 46.975818,-0.891964 46.97582,-0.88901 46.970996,-0.877125 46.968538,-0.883595 46.962369,-0.877139 46.955856,-0.8837970000000001 46.950389,-0.8835662511166233 46.95026))'),
    ('b', 'POLYGON((-1.003499 47.034155,-1.005892 47.034645,-1.008813 47.037094,-1.010507 47.036397,-1.012062 47.037209,-1.012478 47.036518,-1.011117 47.034892,-1.011849 47.034329,-1.017553 47.03602,-1.020219 47.0374,-1.018823 47.038146,-1.020713 47.0395,-1.020078 47.042246,-1.022619 47.044506,-1.023727 47.044304,-1.023855 47.042567,-1.028338 47.043193,-1.028526 47.046577,-1.033921 47.044428,-1.038031 47.045406,-1.040996 47.047222,-1.040363 47.048076,-1.041309 47.050274,-1.043862 47.052359,-1.042479 47.052727,-1.040741 47.052037,-1.031558 47.055852,-1.03872 47.061387,-1.04296 47.059505,-1.042919 47.063977,-1.046194 47.068615,-1.041014 47.073183,-1.039291 47.07315,-1.035791 47.070638,-1.039566 47.067823,-1.038371 47.067549,-1.038363 47.068104,-1.032856 47.070107,-1.032601 47.071583,-1.030644 47.072867,-1.026835 47.077853,-1.023597 47.077407,-1.017289 47.074766,-1.013411 47.075481,-1.012071 47.07765,-1.008233 47.080038,-1.004834 47.080101,-1.001639 47.082483,-0.996599 47.08316,-0.998069 47.085131,-0.997505 47.086696,-0.9984960000000001 47.088622,-0.997895 47.09084,-0.99311 47.089019,-0.9921 47.09038,-0.989408 47.091092,-0.984779 47.094839,-0.979903 47.096908,-0.978438 47.100071,-0.969109 47.101294,-0.966329 47.104755,-0.96872 47.105441,-0.970367 47.106898,-0.967849 47.107754,-0.96705 47.108872,-0.9672539999999999 47.109873,-0.964548 47.114124,-0.965263 47.115767,-0.961096 47.116071,-0.95651 47.11443,-0.9536829999999999 47.114413,-0.950936 47.115496,-0.949882 47.117637,-0.946038 47.119935,-0.9461889999999999 47.120618,-0.952133 47.120092,-0.951528 47.123316,-0.948527 47.124269,-0.948981 47.125865,-0.946984 47.127447,-0.950375 47.129795,-0.948274 47.131818,-0.948601 47.132549,-0.954873 47.135147,-0.956686 47.136964,-0.956129 47.13727,-0.957614 47.13712,-0.956323 47.139477,-0.955037 47.144178,-0.955456 47.144794,-0.948285 47.149339,-0.944708 47.149874,-0.944796 47.151628,-0.941596 47.152113,-0.942047 47.153084,-0.940044 47.153671,-0.940798 47.154856,-0.938397 47.157361,-0.937325 47.157219,-0.934443 47.160325,-0.92893 47.162757,-0.927214 47.162774,-0.926071 47.163675,-0.918746 47.159644,-0.911496 47.159322,-0.910135 47.159648,-0.912727 47.164685,-0.911125 47.164967,-0.908851 47.160224,-0.906819 47.161096,-0.904825 47.161118,-0.90419 47.160098,-0.902938 47.161005,-0.899084 47.160432,-0.895814 47.161263,-0.888682 47.160368,-0.885042 47.158851,-0.879756 47.159392,-0.877381 47.158906,-0.875957 47.159696,-0.874066 47.158261,-0.866803 47.156878,-0.866328 47.154278,-0.863144 47.151598,-0.860479 47.151358,-0.855811 47.152801,-0.851464 47.152844,-0.839548 47.149972,-0.836781 47.150523,-0.831657 47.150077,-0.830325 47.152719,-0.827803 47.152363,-0.825337 47.156855,-0.821728 47.15623,-0.8180539999999999 47.154176,-0.808284 47.157468,-0.805691 47.156591,-0.802353 47.157038,-0.8017 47.153203,-0.7999000000000001 47.151605,-0.798743 47.152046,-0.79675 47.150273,-0.796446 47.14782,-0.792366 47.147384,-0.790662 47.148312,-0.789696 47.147616,-0.788176 47.149197,-0.786251 47.146968,-0.785197 47.146892,-0.784825 47.142603,-0.776545 47.14425,-0.775934 47.142725,-0.76298 47.14355,-0.765204 47.138177,-0.7646810000000001 47.137155,-0.765193 47.13241,-0.764166 47.130843,-0.757279 47.129441,-0.755615 47.126224,-0.753305 47.128401,-0.747465 47.126936,-0.743658 47.127853,-0.7403110000000001 47.130005,-0.727239 47.1286,-0.726214 47.127882,-0.722145 47.128122,-0.719932 47.128783,-0.719769 47.130794,-0.715656 47.132769,-0.7106 47.13282,-0.706937 47.130723,-0.705908 47.131881,-0.703497 47.131179,-0.701852 47.130356,-0.7014899999999999 47.127601,-0.699315 47.1292,-0.696088 47.129613,-0.694172 47.130908,-0.6924630000000001 47.129899,-0.688837 47.129736,-0.685009 47.131849,-0.679654 47.130824,-0.678609 47.129982,-0.671374 47.132367,-0.6700739999999999 47.134202,-0.666837 47.133182,-0.659606 47.136733,-0.661117 47.137602,-0.660788 47.138781,-0.662358 47.13973,-0.661645 47.142495,-0.660958 47.141474,-0.6591669999999999 47.141034,-0.657647 47.141996,-0.657742 47.141094,-0.65679 47.140824,-0.655244 47.141967,-0.655204 47.144456,-0.650964 47.14514,-0.650943 47.144014,-0.6502289999999999 47.144351,-0.648071 47.146159,-0.648111 47.148068,-0.645837 47.148712,-0.6429009999999999 47.150853,-0.641321 47.15116,-0.637368 47.149049,-0.636791 47.151277,-0.634778 47.151401,-0.614066 47.148949,-0.611255 47.147944,-0.608714 47.151739,-0.6064310000000001 47.153063,-0.606321 47.153981,-0.60299 47.157147,-0.598875 47.159885,-0.596559 47.163645,-0.593306 47.166566,-0.5911419999999999 47.169356,-0.590948 47.173115,-0.589552 47.175159,-0.581188 47.180057,-0.571555 47.189365,-0.565194 47.192525,-0.558835 47.194163,-0.557256 47.197598,-0.555665 47.199108,-0.555934 47.200523,-0.550243 47.20432,-0.547078 47.208665,-0.544078 47.207204,-0.533786 47.207824,-0.518344 47.210022,-0.506224 47.209061,-0.500894 47.20962,-0.497523 47.211184,-0.495366 47.210041,-0.493161 47.210967,-0.48982 47.2108,-0.479899 47.208412,-0.480932 47.206143,-0.483332 47.20406,-0.482276 47.200104,-0.48129 47.199278,-0.480203 47.199556,-0.478934 47.198011,-0.476512 47.198431,-0.473101 47.197326,-0.46267 47.206468,-0.461469 47.206421,-0.455677 47.211151,-0.453324 47.216126,-0.454212 47.218059,-0.448277 47.221702,-0.443709 47.220465,-0.439494 47.215173,-0.436489 47.21435,-0.432012 47.215171,-0.430493 47.214774,-0.42749 47.218448,-0.423234 47.221124,-0.421213 47.223417,-0.417328 47.223194,-0.408793 47.219609,-0.401168 47.219627,-0.401814 47.215326,-0.40383 47.213639,-0.405048 47.210537,-0.407826 47.206784,-0.410264 47.206932,-0.41171 47.205248,-0.409833 47.204575,-0.412285 47.201901,-0.412792 47.200155,-0.418511 47.195844,-0.418248 47.193134,-0.417619 47.190956,-0.413958 47.190365,-0.413439 47.187417,-0.412285 47.187333,-0.412716 47.185433,-0.411996 47.185065,-0.411807 47.183143,-0.413784 47.180231,-0.407773 47.179534,-0.402195 47.177222,-0.399488 47.177426,-0.397269 47.174935,-0.394587 47.176119,-0.38967 47.175879,-0.394179 47.171043,-0.406628 47.163987,-0.410125 47.158827,-0.404906 47.160023,-0.40023 47.155858,-0.399628 47.159767,-0.396127 47.159938,-0.384412 47.156495,-0.375187 47.151642,-0.369563 47.153469,-0.366432 47.151314,-0.36114 47.151223,-0.35578 47.149185,-0.353323 47.152762,-0.351485 47.152225,-0.352047 47.151282,-0.350341 47.148346,-0.350786 47.146715,-0.348841 47.146936,-0.347566 47.146139,-0.353369 47.141311,-0.350545 47.13761,-0.342742 47.134635,-0.338095 47.134994,-0.333255 47.133742,-0.334297 47.132289,-0.332489 47.131577,-0.33382 47.130432,-0.337955 47.130561,-0.341232 47.128987,-0.339153 47.12661,-0.339118 47.125369,-0.338209 47.125162,-0.33722 47.12614,-0.332498 47.125027,-0.330249 47.126144,-0.3293 47.12564,-0.330002 47.123199,-0.327816 47.122427,-0.325581 47.123121,-0.321459 47.121283,-0.323874 47.116436,-0.322166 47.113341,-0.322738 47.108762,-0.318197 47.107497,-0.317185 47.108012,-0.314916 47.106305,-0.315605 47.105394,-0.311854 47.104175,-0.312555 47.092257,-0.335593 47.087996,-0.341764 47.087377,-0.342071 47.089257,-0.340917 47.092061,-0.349764 47.091708,-0.353789 47.095386,-0.359845 47.093259,-0.368792 47.091703,-0.370858 47.090185,-0.376532 47.088641,-0.380109 47.09001,-0.381368 47.08822,-0.384549 47.087401,-0.386349 47.087343,-0.387114 47.092276,-0.396159 47.091638,-0.396735 47.08308,-0.400268 47.074938,-0.401197 47.070748,-0.407124 47.066498,-0.409291 47.066201,-0.417558 47.070664,-0.418326 47.071955,-0.423197 47.069714,-0.424254 47.071464,-0.425664 47.07098,-0.425819 47.072494,-0.426981 47.072988,-0.438973 47.069898,-0.439206 47.068855,-0.441123 47.067722,-0.45469 47.067357,-0.458225 47.068988,-0.460605 47.06816,-0.461078 47.068813,-0.465024 47.066888,-0.471237 47.059795,-0.472096 47.057572,-0.476341 47.054362,-0.48032 47.053338,-0.485332 47.063885,-0.484992 47.065973,-0.478094 47.071911,-0.472027 47.072332,-0.469805 47.073652,-0.468249 47.073194,-0.464185 47.074359,-0.463973 47.076088,-0.458991 47.079943,-0.459531 47.082046,-0.464456 47.081975,-0.468364 47.083816,-0.473271 47.081777,-0.476073 47.083041,-0.478752 47.081727,-0.484783 47.081687,-0.487739 47.080881,-0.490791 47.082896,-0.493101 47.083353,-0.504174 47.079332,-0.507317 47.079241,-0.511785 47.077466,-0.51525 47.078035,-0.525741 47.073919,-0.535313 47.0722,-0.544635 47.068135,-0.546309 47.066274,-0.557553 47.06409,-0.559461 47.061813,-0.5567 47.060691,-0.5543709999999999 47.05726,-0.558239 47.056069,-0.558275 47.053228,-0.556006 47.044378,-0.556265 47.042695,-0.548737 47.04057,-0.542042 47.034972,-0.542997 47.033622,-0.542336 47.032532,-0.54533 47.030668,-0.54581 47.029103,-0.547006 47.028835,-0.547965 47.029652,-0.551732 47.029048,-0.555679 47.030902,-0.562342 47.030496,-0.564087 47.026005,-0.563775 47.02414,-0.564869 47.020141,-0.569053 47.018291,-0.574987 47.017828,-0.580904 47.014612,-0.587014 47.009192,-0.586932 47.006709,-0.58775 47.005337,-0.594749 47.002794,-0.597171 47.000769,-0.593961 46.998759,-0.5954930000000001 46.99791,-0.601611 46.997764,-0.618781 46.992342,-0.621938 46.993911,-0.6249400000000001 46.992792,-0.624561 46.994115,-0.6279169999999999 46.995691,-0.6267430000000001 46.996879,-0.63266 46.997508,-0.6354379999999999 46.995724,-0.640352 46.996116,-0.641046 46.994672,-0.642167 46.994818,-0.645504 46.99212,-0.646962 46.992308,-0.646391 46.99368,-0.649992 46.994917,-0.648025 46.996594,-0.650398 46.997689,-0.653462 46.997772,-0.657311 46.999199,-0.657708 46.9986,-0.660979 46.998839,-0.661627 46.997686,-0.669937 47.000802,-0.670368 47.002636,-0.671843 47.003185,-0.674719 47.001621,-0.676179 47.001885,-0.676831 47.000296,-0.674732 46.999172,-0.676007 46.997074,-0.675567 46.996648,-0.68038 46.993238,-0.678529 46.992114,-0.677686 46.989976,-0.680188 46.987659,-0.6829809999999999 46.98842,-0.686887 46.988065,-0.689599 46.990414,-0.689629 46.993058,-0.693412 46.992411,-0.696663 46.994873,-0.698748 46.99461,-0.700809 46.992531,-0.70435 46.992196,-0.703637 46.991424,-0.704682 46.990212,-0.712202 46.986674,-0.715947 46.98402,-0.7181070000000001 46.987193,-0.72926 46.995934,-0.7325430000000001 46.997508,-0.739475 46.998787,-0.743405 47.000992,-0.743626 46.994335,-0.74298 46.992012,-0.747754 46.991537,-0.753551 46.992972,-0.756819 46.991958,-0.7615150000000001 46.992264,-0.76411 46.992997,-0.765475 46.994016,-0.76528 46.994815,-0.7670979999999999 46.995785,-0.768885 46.995031,-0.768693 46.998337,-0.767998 46.99898,-0.768472 47.001449,-0.769335 47.002974,-0.771352 47.003471,-0.772268 47.004577,-0.773718 47.004606,-0.776458 47.003002,-0.7780010000000001 47.00428,-0.779699 47.004275,-0.781774 47.002141,-0.783438 47.001813,-0.784541 47.002807,-0.784486 47.004214,-0.786724 47.005452,-0.78967 47.003752,-0.789635 47.002406,-0.791189 47.0001,-0.796264 46.996051,-0.800662 46.994378,-0.804104 46.99387,-0.807032 46.994405,-0.810871 46.991732,-0.809145 46.99059,-0.808373 46.991571,-0.805102 46.989541,-0.807346 46.988608,-0.808466 46.986718,-0.809551 46.988562,-0.812299 46.989251,-0.812597 46.990568,-0.815701 46.989765,-0.811339 46.991774,-0.811747 46.994549,-0.815426 46.993264,-0.817527 46.993124,-0.81869 46.994079,-0.826568 46.992643,-0.8363429999999999 46.985762,-0.839504 46.985428,-0.842993 46.990173,-0.846592 46.986729,-0.847436 46.986872,-0.847915 46.982014,-0.849641 46.981979,-0.857129 46.978461,-0.85654 46.977397,-0.8492420000000001 46.97382,-0.8526 46.971008,-0.854617 46.971188,-0.860658 46.968886,-0.861437 46.969427,-0.861169 46.970234,-0.862803 46.970306,-0.862043 46.971125,-0.863063 46.971487,-0.863054 46.972617,-0.866704 46.973134,-0.867239 46.972541,-0.868179 46.973273,-0.869896 46.972059,-0.872356 46.973921,-0.87925 46.974666,-0.880167 46.975259,-0.879569 46.976065,-0.882064 46.977455,-0.882176 46.976556,-0.884937 46.977334,-0.8851560000000001 46.976298,-0.886918 46.976492,-0.888462 46.975566,-0.892187 46.976082,-0.8924840000000001 46.978577,-0.8950709999999999 46.979177,-0.8948739999999999 46.980231,-0.8968429999999999 46.980815,-0.893065 46.984496,-0.8957270000000001 46.985249,-0.89623 46.985842,-0.895404 46.986335,-0.898968 46.988701,-0.8974839999999999 46.989799,-0.90103 46.991734,-0.902515 46.993922,-0.904396 46.994915,-0.907873 46.994955,-0.908708 46.99287,-0.9117 46.995997,-0.912372 46.995659,-0.910853 46.994271,-0.912311 46.992815,-0.915289 46.992611,-0.915649 46.993302,-0.914227 46.994688,-0.916525 46.996111,-0.918747 46.995522,-0.918685 46.996536,-0.921435 46.998028,-0.9179580000000001 46.998454,-0.916957 46.999858,-0.914871 47.000633,-0.915853 47.001637,-0.919365 47.002324,-0.919706 47.003377,-0.925021 47.002535,-0.925042 46.999834,-0.928445 47.000682,-0.928661 47.002451,-0.935226 47.002345,-0.9327800000000001 47.00456,-0.931063 47.003357,-0.9310389999999999 47.004519,-0.928248 47.00382,-0.927473 47.006346,-0.929194 47.008111,-0.932389 47.006069,-0.932015 47.007985,-0.9329499999999999 47.007838,-0.933399 47.009041,-0.935539 47.007348,-0.934844 47.005633,-0.936462 47.005257,-0.937296 47.003048,-0.9385289999999999 47.0034,-0.938673 47.002401,-0.939634 47.002783,-0.939812 47.002193,-0.9402779999999999 47.003189,-0.941698 47.00358,-0.944993 46.998988,-0.947166 46.999717,-0.948313 47.001307,-0.947959 47.003694,-0.951958 47.002736,-0.953334 47.000764,-0.95504 46.999919,-0.955661 46.99757,-0.954756 46.995966,-0.9567369999999999 46.996404,-0.9582850000000001 46.99543,-0.957388 46.994887,-0.960803 46.994723,-0.959851 46.995287,-0.962158 46.995809,-0.961741 46.997277,-0.963159 46.996458,-0.964354 46.997292,-0.9634470000000001 46.998099,-0.964984 46.999584,-0.963101 47.00063,-0.963229 47.001985,-0.964014 47.003068,-0.966535 47.002838,-0.968005 47.004208,-0.967052 47.005199,-0.965982 47.004729,-0.968678 47.006687,-0.967816 47.007355,-0.970504 47.007588,-0.972909 47.009056,-0.973483 47.008101,-0.975229 47.008652,-0.974932 47.010525,-0.973166 47.012531,-0.975314 47.013218,-0.973361 47.016124,-0.9756629999999999 47.01687,-0.976156 47.018317,-0.9783539999999999 47.018918,-0.981873 47.018124,-0.981502 47.017046,-0.982976 47.016083,-0.980279 47.014309,-0.982174 47.010593,-0.995514 47.017676,-0.999529 47.020687,-1.002179 47.02152,-1.000567 47.022544,-1.002044 47.024403,-1.000672 47.02556,-0.999402 47.025138,-1.000446 47.022611,-0.9974229999999999 47.022981,-0.995461 47.024415,-1.000034 47.027594,-1.001848 47.027837,-1.003761 47.02556,-1.005871 47.027086,-1.008565 47.027608,-1.00369 47.029205,-1.003499 47.034155))');

select
    st_intersection(st_difference(a.geom, b.geom), b.geom), -- a GEOMETRYCOLLECTION of 203 LINESTRINGs
    st_dimension(st_intersection(st_difference(a.geom, b.geom), b.geom)) -- 2
from z a, z b
where a.name = 'a' and b.name = 'b';

rollback;

However, as stated in PostGIS documentation:

[ST_Dimension] returns 0 for POINT, 1 for LINESTRING, 2 for POLYGON, and the largest dimension of the components of a GEOMETRYCOLLECTION

Hence my question is: is that a bug I should report somewhere, or is there something I overlooked?

$ select postgis_full_version();
POSTGIS="2.5.5" [EXTENSION] PGSQL="120" GEOS="3.8.1-CAPI-1.13.3" PROJ="Rel. 7.0.1, May 1st, 2020" GDAL="GDAL 3.1.4, released 2020/10/20" LIBXML="2.9.10" LIBJSON="0.14" LIBPROTOBUF="1.3.3" TOPOLOGY RASTER

NOTE: There is a bit more context here if ever needed.

3

It seems to me this is not an issue with wrongly constructed collections as per your GitHub issue.

The GEOMETRYCOLLECTION has 459 members (or 461 if the geometries are passed in in different order) and indeed contains a single Polygon (sliver), which is most likely due to floating point imprecision:

WITH
    z (name, geom) AS (
        VALUES
            ('a', 'POLYGON((-0.8835662511166233 46.95026,-1.1673 46.95026,-1.1673 47.24754,-0.24445 47.24754,-0.24445 47.10458117771998,-0.255375 47.100286,-0.287925 47.101438,-0.298957 47.09925,-0.314251 47.091338,-0.33027 47.088981,-0.312555 47.092257,-0.311854 47.104175,-0.315605 47.105394,-0.314916 47.106305,-0.317185 47.108012,-0.318197 47.107497,-0.322738 47.108762,-0.322166 47.113341,-0.323874 47.116436,-0.321459 47.121283,-0.325581 47.123121,-0.327816 47.122427,-0.330002 47.123199,-0.3293 47.12564,-0.330249 47.126144,-0.332498 47.125027,-0.33722 47.12614,-0.338209 47.125162,-0.339118 47.125369,-0.339153 47.12661,-0.341232 47.128987,-0.337955 47.130561,-0.33382 47.130432,-0.332489 47.131577,-0.334297 47.132289,-0.333255 47.133742,-0.338095 47.134994,-0.342742 47.134635,-0.350545 47.13761,-0.353369 47.141311,-0.347566 47.146139,-0.348841 47.146936,-0.350786 47.146715,-0.350341 47.148346,-0.352047 47.151282,-0.351485 47.152225,-0.353323 47.152762,-0.35578 47.149185,-0.36114 47.151223,-0.366432 47.151314,-0.369563 47.153469,-0.375187 47.151642,-0.384412 47.156495,-0.396127 47.159938,-0.399628 47.159767,-0.40023 47.155858,-0.404906 47.160023,-0.410125 47.158827,-0.406628 47.163987,-0.394179 47.171043,-0.38967 47.175879,-0.394587 47.176119,-0.397269 47.174935,-0.399488 47.177426,-0.402195 47.177222,-0.407773 47.179534,-0.413784 47.180231,-0.411807 47.183143,-0.411996 47.185065,-0.412716 47.185433,-0.412285 47.187333,-0.413439 47.187417,-0.413958 47.190365,-0.417619 47.190956,-0.418248 47.193134,-0.418511 47.195844,-0.412792 47.200155,-0.412285 47.201901,-0.409833 47.204575,-0.41171 47.205248,-0.410264 47.206932,-0.407826 47.206784,-0.405048 47.210537,-0.40383 47.213639,-0.401814 47.215326,-0.401168 47.219627,-0.408793 47.219609,-0.417328 47.223194,-0.421213 47.223417,-0.423234 47.221124,-0.42749 47.218448,-0.430493 47.214774,-0.432012 47.215171,-0.436489 47.21435,-0.439494 47.215173,-0.443709 47.220465,-0.448277 47.221702,-0.454212 47.218059,-0.453324 47.216126,-0.455677 47.211151,-0.461469 47.206421,-0.46267 47.206468,-0.473101 47.197326,-0.476512 47.198431,-0.478934 47.198011,-0.480203 47.199556,-0.48129 47.199278,-0.482276 47.200104,-0.483332 47.20406,-0.480932 47.206143,-0.479899 47.208412,-0.48982 47.2108,-0.493161 47.210967,-0.495366 47.210041,-0.497523 47.211184,-0.500894 47.20962,-0.506224 47.209061,-0.518344 47.210022,-0.533786 47.207824,-0.544078 47.207204,-0.547078 47.208665,-0.550243 47.20432,-0.555934 47.200523,-0.555665 47.199108,-0.557256 47.197598,-0.558835 47.194163,-0.565194 47.192525,-0.571555 47.189365,-0.581188 47.180057,-0.589552 47.175159,-0.590948 47.173115,-0.5911419999999999 47.169356,-0.593306 47.166566,-0.596559 47.163645,-0.598875 47.159885,-0.60299 47.157147,-0.606321 47.153981,-0.6064310000000001 47.153063,-0.608714 47.151739,-0.611255 47.147944,-0.614066 47.148949,-0.634778 47.151401,-0.636791 47.151277,-0.637368 47.149049,-0.641321 47.15116,-0.6429009999999999 47.150853,-0.645837 47.148712,-0.648111 47.148068,-0.648071 47.146159,-0.6502289999999999 47.144351,-0.650943 47.144014,-0.650964 47.14514,-0.655204 47.144456,-0.655244 47.141967,-0.65679 47.140824,-0.657742 47.141094,-0.657647 47.141996,-0.6591669999999999 47.141034,-0.660958 47.141474,-0.661645 47.142495,-0.662358 47.13973,-0.660788 47.138781,-0.661117 47.137602,-0.659606 47.136733,-0.666837 47.133182,-0.6700739999999999 47.134202,-0.671374 47.132367,-0.678609 47.129982,-0.679654 47.130824,-0.685009 47.131849,-0.688837 47.129736,-0.6924630000000001 47.129899,-0.694172 47.130908,-0.696088 47.129613,-0.699315 47.1292,-0.7014899999999999 47.127601,-0.701852 47.130356,-0.703497 47.131179,-0.705908 47.131881,-0.706937 47.130723,-0.7106 47.13282,-0.715656 47.132769,-0.719769 47.130794,-0.719932 47.128783,-0.722145 47.128122,-0.726214 47.127882,-0.727239 47.1286,-0.7403110000000001 47.130005,-0.743658 47.127853,-0.747465 47.126936,-0.753305 47.128401,-0.755615 47.126224,-0.757279 47.129441,-0.764166 47.130843,-0.765193 47.13241,-0.7646810000000001 47.137155,-0.765204 47.138177,-0.76298 47.14355,-0.775934 47.142725,-0.776545 47.14425,-0.784825 47.142603,-0.785197 47.146892,-0.786251 47.146968,-0.788176 47.149197,-0.789696 47.147616,-0.790662 47.148312,-0.792366 47.147384,-0.796446 47.14782,-0.79675 47.150273,-0.798743 47.152046,-0.7999000000000001 47.151605,-0.8017 47.153203,-0.802353 47.157038,-0.805691 47.156591,-0.808284 47.157468,-0.8180539999999999 47.154176,-0.821728 47.15623,-0.825337 47.156855,-0.827803 47.152363,-0.830325 47.152719,-0.831657 47.150077,-0.836781 47.150523,-0.839548 47.149972,-0.851464 47.152844,-0.855811 47.152801,-0.860479 47.151358,-0.863144 47.151598,-0.866328 47.154278,-0.866803 47.156878,-0.874066 47.158261,-0.875957 47.159696,-0.877381 47.158906,-0.879756 47.159392,-0.885042 47.158851,-0.888682 47.160368,-0.895814 47.161263,-0.899084 47.160432,-0.902938 47.161005,-0.90419 47.160098,-0.904825 47.161118,-0.906819 47.161096,-0.908851 47.160224,-0.911125 47.164967,-0.912727 47.164685,-0.910135 47.159648,-0.911496 47.159322,-0.918746 47.159644,-0.926071 47.163675,-0.927214 47.162774,-0.92893 47.162757,-0.934443 47.160325,-0.937325 47.157219,-0.938397 47.157361,-0.940798 47.154856,-0.940044 47.153671,-0.942047 47.153084,-0.941596 47.152113,-0.944796 47.151628,-0.944708 47.149874,-0.948285 47.149339,-0.955456 47.144794,-0.955037 47.144178,-0.956323 47.139477,-0.957614 47.13712,-0.956129 47.13727,-0.956686 47.136964,-0.954873 47.135147,-0.948601 47.132549,-0.948274 47.131818,-0.950375 47.129795,-0.946984 47.127447,-0.948981 47.125865,-0.948527 47.124269,-0.951528 47.123316,-0.952133 47.120092,-0.9461889999999999 47.120618,-0.946038 47.119935,-0.949882 47.117637,-0.950936 47.115496,-0.9536829999999999 47.114413,-0.95651 47.11443,-0.961096 47.116071,-0.965263 47.115767,-0.964548 47.114124,-0.9672539999999999 47.109873,-0.96705 47.108872,-0.967849 47.107754,-0.970367 47.106898,-0.96872 47.105441,-0.966329 47.104755,-0.969109 47.101294,-0.978438 47.100071,-0.979903 47.096908,-0.984779 47.094839,-0.989408 47.091092,-0.9921 47.09038,-0.99311 47.089019,-0.997895 47.09084,-0.9984960000000001 47.088622,-0.997505 47.086696,-0.998069 47.085131,-0.996599 47.08316,-1.001639 47.082483,-1.004834 47.080101,-1.008233 47.080038,-1.012071 47.07765,-1.013411 47.075481,-1.017289 47.074766,-1.023597 47.077407,-1.026835 47.077853,-1.030644 47.072867,-1.032601 47.071583,-1.032856 47.070107,-1.038363 47.068104,-1.038371 47.067549,-1.039566 47.067823,-1.035791 47.070638,-1.039291 47.07315,-1.041014 47.073183,-1.046194 47.068615,-1.042919 47.063977,-1.04296 47.059505,-1.03872 47.061387,-1.031558 47.055852,-1.040741 47.052037,-1.042479 47.052727,-1.043862 47.052359,-1.041309 47.050274,-1.040363 47.048076,-1.040996 47.047222,-1.038031 47.045406,-1.033921 47.044428,-1.028526 47.046577,-1.028338 47.043193,-1.023855 47.042567,-1.023727 47.044304,-1.022619 47.044506,-1.020078 47.042246,-1.020713 47.0395,-1.018823 47.038146,-1.020219 47.0374,-1.017553 47.03602,-1.011849 47.034329,-1.011117 47.034892,-1.012478 47.036518,-1.012062 47.037209,-1.010507 47.036397,-1.008813 47.037094,-1.005892 47.034645,-1.003499 47.034155,-1.00369 47.029205,-1.008565 47.027608,-1.005871 47.027086,-1.003761 47.02556,-1.001848 47.027837,-1.000034 47.027594,-0.995461 47.024415,-0.9974229999999999 47.022981,-1.000446 47.022611,-0.999402 47.025138,-1.000672 47.02556,-1.002044 47.024403,-1.000567 47.022544,-1.002179 47.02152,-0.999529 47.020687,-0.995514 47.017676,-0.982174 47.010593,-0.980279 47.014309,-0.982976 47.016083,-0.981502 47.017046,-0.981873 47.018124,-0.9783539999999999 47.018918,-0.976156 47.018317,-0.9756629999999999 47.01687,-0.973361 47.016124,-0.975314 47.013218,-0.973166 47.012531,-0.974932 47.010525,-0.975229 47.008652,-0.973483 47.008101,-0.972909 47.009056,-0.970504 47.007588,-0.967816 47.007355,-0.968678 47.006687,-0.965982 47.004729,-0.967052 47.005199,-0.968005 47.004208,-0.966535 47.002838,-0.964014 47.003068,-0.963229 47.001985,-0.963101 47.00063,-0.964984 46.999584,-0.9634470000000001 46.998099,-0.964354 46.997292,-0.963159 46.996458,-0.961741 46.997277,-0.962158 46.995809,-0.959851 46.995287,-0.960803 46.994723,-0.957388 46.994887,-0.9582850000000001 46.99543,-0.9567369999999999 46.996404,-0.954756 46.995966,-0.955661 46.99757,-0.95504 46.999919,-0.953334 47.000764,-0.951958 47.002736,-0.947959 47.003694,-0.948313 47.001307,-0.947166 46.999717,-0.944993 46.998988,-0.941698 47.00358,-0.9402779999999999 47.003189,-0.939812 47.002193,-0.939634 47.002783,-0.938673 47.002401,-0.9385289999999999 47.0034,-0.937296 47.003048,-0.936462 47.005257,-0.934844 47.005633,-0.935539 47.007348,-0.933399 47.009041,-0.9329499999999999 47.007838,-0.932015 47.007985,-0.932389 47.006069,-0.929194 47.008111,-0.927473 47.006346,-0.928248 47.00382,-0.9310389999999999 47.004519,-0.931063 47.003357,-0.9327800000000001 47.00456,-0.935226 47.002345,-0.928661 47.002451,-0.928445 47.000682,-0.925042 46.999834,-0.925021 47.002535,-0.919706 47.003377,-0.919365 47.002324,-0.915853 47.001637,-0.914871 47.000633,-0.916957 46.999858,-0.9179580000000001 46.998454,-0.921435 46.998028,-0.918685 46.996536,-0.918747 46.995522,-0.916525 46.996111,-0.914227 46.994688,-0.915649 46.993302,-0.915289 46.992611,-0.912311 46.992815,-0.910853 46.994271,-0.912372 46.995659,-0.9117 46.995997,-0.908708 46.99287,-0.907873 46.994955,-0.904396 46.994915,-0.902515 46.993922,-0.90103 46.991734,-0.8974839999999999 46.989799,-0.898968 46.988701,-0.895404 46.986335,-0.89623 46.985842,-0.8957270000000001 46.985249,-0.893065 46.984496,-0.8968429999999999 46.980815,-0.8948739999999999 46.980231,-0.8950709999999999 46.979177,-0.8924840000000001 46.978577,-0.892187 46.976082,-0.89028 46.975818,-0.891964 46.97582,-0.88901 46.970996,-0.877125 46.968538,-0.883595 46.962369,-0.877139 46.955856,-0.8837970000000001 46.950389,-0.8835662511166233 46.95026))'::GEOMETRY),
            ('b', 'POLYGON((-1.003499 47.034155,-1.005892 47.034645,-1.008813 47.037094,-1.010507 47.036397,-1.012062 47.037209,-1.012478 47.036518,-1.011117 47.034892,-1.011849 47.034329,-1.017553 47.03602,-1.020219 47.0374,-1.018823 47.038146,-1.020713 47.0395,-1.020078 47.042246,-1.022619 47.044506,-1.023727 47.044304,-1.023855 47.042567,-1.028338 47.043193,-1.028526 47.046577,-1.033921 47.044428,-1.038031 47.045406,-1.040996 47.047222,-1.040363 47.048076,-1.041309 47.050274,-1.043862 47.052359,-1.042479 47.052727,-1.040741 47.052037,-1.031558 47.055852,-1.03872 47.061387,-1.04296 47.059505,-1.042919 47.063977,-1.046194 47.068615,-1.041014 47.073183,-1.039291 47.07315,-1.035791 47.070638,-1.039566 47.067823,-1.038371 47.067549,-1.038363 47.068104,-1.032856 47.070107,-1.032601 47.071583,-1.030644 47.072867,-1.026835 47.077853,-1.023597 47.077407,-1.017289 47.074766,-1.013411 47.075481,-1.012071 47.07765,-1.008233 47.080038,-1.004834 47.080101,-1.001639 47.082483,-0.996599 47.08316,-0.998069 47.085131,-0.997505 47.086696,-0.9984960000000001 47.088622,-0.997895 47.09084,-0.99311 47.089019,-0.9921 47.09038,-0.989408 47.091092,-0.984779 47.094839,-0.979903 47.096908,-0.978438 47.100071,-0.969109 47.101294,-0.966329 47.104755,-0.96872 47.105441,-0.970367 47.106898,-0.967849 47.107754,-0.96705 47.108872,-0.9672539999999999 47.109873,-0.964548 47.114124,-0.965263 47.115767,-0.961096 47.116071,-0.95651 47.11443,-0.9536829999999999 47.114413,-0.950936 47.115496,-0.949882 47.117637,-0.946038 47.119935,-0.9461889999999999 47.120618,-0.952133 47.120092,-0.951528 47.123316,-0.948527 47.124269,-0.948981 47.125865,-0.946984 47.127447,-0.950375 47.129795,-0.948274 47.131818,-0.948601 47.132549,-0.954873 47.135147,-0.956686 47.136964,-0.956129 47.13727,-0.957614 47.13712,-0.956323 47.139477,-0.955037 47.144178,-0.955456 47.144794,-0.948285 47.149339,-0.944708 47.149874,-0.944796 47.151628,-0.941596 47.152113,-0.942047 47.153084,-0.940044 47.153671,-0.940798 47.154856,-0.938397 47.157361,-0.937325 47.157219,-0.934443 47.160325,-0.92893 47.162757,-0.927214 47.162774,-0.926071 47.163675,-0.918746 47.159644,-0.911496 47.159322,-0.910135 47.159648,-0.912727 47.164685,-0.911125 47.164967,-0.908851 47.160224,-0.906819 47.161096,-0.904825 47.161118,-0.90419 47.160098,-0.902938 47.161005,-0.899084 47.160432,-0.895814 47.161263,-0.888682 47.160368,-0.885042 47.158851,-0.879756 47.159392,-0.877381 47.158906,-0.875957 47.159696,-0.874066 47.158261,-0.866803 47.156878,-0.866328 47.154278,-0.863144 47.151598,-0.860479 47.151358,-0.855811 47.152801,-0.851464 47.152844,-0.839548 47.149972,-0.836781 47.150523,-0.831657 47.150077,-0.830325 47.152719,-0.827803 47.152363,-0.825337 47.156855,-0.821728 47.15623,-0.8180539999999999 47.154176,-0.808284 47.157468,-0.805691 47.156591,-0.802353 47.157038,-0.8017 47.153203,-0.7999000000000001 47.151605,-0.798743 47.152046,-0.79675 47.150273,-0.796446 47.14782,-0.792366 47.147384,-0.790662 47.148312,-0.789696 47.147616,-0.788176 47.149197,-0.786251 47.146968,-0.785197 47.146892,-0.784825 47.142603,-0.776545 47.14425,-0.775934 47.142725,-0.76298 47.14355,-0.765204 47.138177,-0.7646810000000001 47.137155,-0.765193 47.13241,-0.764166 47.130843,-0.757279 47.129441,-0.755615 47.126224,-0.753305 47.128401,-0.747465 47.126936,-0.743658 47.127853,-0.7403110000000001 47.130005,-0.727239 47.1286,-0.726214 47.127882,-0.722145 47.128122,-0.719932 47.128783,-0.719769 47.130794,-0.715656 47.132769,-0.7106 47.13282,-0.706937 47.130723,-0.705908 47.131881,-0.703497 47.131179,-0.701852 47.130356,-0.7014899999999999 47.127601,-0.699315 47.1292,-0.696088 47.129613,-0.694172 47.130908,-0.6924630000000001 47.129899,-0.688837 47.129736,-0.685009 47.131849,-0.679654 47.130824,-0.678609 47.129982,-0.671374 47.132367,-0.6700739999999999 47.134202,-0.666837 47.133182,-0.659606 47.136733,-0.661117 47.137602,-0.660788 47.138781,-0.662358 47.13973,-0.661645 47.142495,-0.660958 47.141474,-0.6591669999999999 47.141034,-0.657647 47.141996,-0.657742 47.141094,-0.65679 47.140824,-0.655244 47.141967,-0.655204 47.144456,-0.650964 47.14514,-0.650943 47.144014,-0.6502289999999999 47.144351,-0.648071 47.146159,-0.648111 47.148068,-0.645837 47.148712,-0.6429009999999999 47.150853,-0.641321 47.15116,-0.637368 47.149049,-0.636791 47.151277,-0.634778 47.151401,-0.614066 47.148949,-0.611255 47.147944,-0.608714 47.151739,-0.6064310000000001 47.153063,-0.606321 47.153981,-0.60299 47.157147,-0.598875 47.159885,-0.596559 47.163645,-0.593306 47.166566,-0.5911419999999999 47.169356,-0.590948 47.173115,-0.589552 47.175159,-0.581188 47.180057,-0.571555 47.189365,-0.565194 47.192525,-0.558835 47.194163,-0.557256 47.197598,-0.555665 47.199108,-0.555934 47.200523,-0.550243 47.20432,-0.547078 47.208665,-0.544078 47.207204,-0.533786 47.207824,-0.518344 47.210022,-0.506224 47.209061,-0.500894 47.20962,-0.497523 47.211184,-0.495366 47.210041,-0.493161 47.210967,-0.48982 47.2108,-0.479899 47.208412,-0.480932 47.206143,-0.483332 47.20406,-0.482276 47.200104,-0.48129 47.199278,-0.480203 47.199556,-0.478934 47.198011,-0.476512 47.198431,-0.473101 47.197326,-0.46267 47.206468,-0.461469 47.206421,-0.455677 47.211151,-0.453324 47.216126,-0.454212 47.218059,-0.448277 47.221702,-0.443709 47.220465,-0.439494 47.215173,-0.436489 47.21435,-0.432012 47.215171,-0.430493 47.214774,-0.42749 47.218448,-0.423234 47.221124,-0.421213 47.223417,-0.417328 47.223194,-0.408793 47.219609,-0.401168 47.219627,-0.401814 47.215326,-0.40383 47.213639,-0.405048 47.210537,-0.407826 47.206784,-0.410264 47.206932,-0.41171 47.205248,-0.409833 47.204575,-0.412285 47.201901,-0.412792 47.200155,-0.418511 47.195844,-0.418248 47.193134,-0.417619 47.190956,-0.413958 47.190365,-0.413439 47.187417,-0.412285 47.187333,-0.412716 47.185433,-0.411996 47.185065,-0.411807 47.183143,-0.413784 47.180231,-0.407773 47.179534,-0.402195 47.177222,-0.399488 47.177426,-0.397269 47.174935,-0.394587 47.176119,-0.38967 47.175879,-0.394179 47.171043,-0.406628 47.163987,-0.410125 47.158827,-0.404906 47.160023,-0.40023 47.155858,-0.399628 47.159767,-0.396127 47.159938,-0.384412 47.156495,-0.375187 47.151642,-0.369563 47.153469,-0.366432 47.151314,-0.36114 47.151223,-0.35578 47.149185,-0.353323 47.152762,-0.351485 47.152225,-0.352047 47.151282,-0.350341 47.148346,-0.350786 47.146715,-0.348841 47.146936,-0.347566 47.146139,-0.353369 47.141311,-0.350545 47.13761,-0.342742 47.134635,-0.338095 47.134994,-0.333255 47.133742,-0.334297 47.132289,-0.332489 47.131577,-0.33382 47.130432,-0.337955 47.130561,-0.341232 47.128987,-0.339153 47.12661,-0.339118 47.125369,-0.338209 47.125162,-0.33722 47.12614,-0.332498 47.125027,-0.330249 47.126144,-0.3293 47.12564,-0.330002 47.123199,-0.327816 47.122427,-0.325581 47.123121,-0.321459 47.121283,-0.323874 47.116436,-0.322166 47.113341,-0.322738 47.108762,-0.318197 47.107497,-0.317185 47.108012,-0.314916 47.106305,-0.315605 47.105394,-0.311854 47.104175,-0.312555 47.092257,-0.335593 47.087996,-0.341764 47.087377,-0.342071 47.089257,-0.340917 47.092061,-0.349764 47.091708,-0.353789 47.095386,-0.359845 47.093259,-0.368792 47.091703,-0.370858 47.090185,-0.376532 47.088641,-0.380109 47.09001,-0.381368 47.08822,-0.384549 47.087401,-0.386349 47.087343,-0.387114 47.092276,-0.396159 47.091638,-0.396735 47.08308,-0.400268 47.074938,-0.401197 47.070748,-0.407124 47.066498,-0.409291 47.066201,-0.417558 47.070664,-0.418326 47.071955,-0.423197 47.069714,-0.424254 47.071464,-0.425664 47.07098,-0.425819 47.072494,-0.426981 47.072988,-0.438973 47.069898,-0.439206 47.068855,-0.441123 47.067722,-0.45469 47.067357,-0.458225 47.068988,-0.460605 47.06816,-0.461078 47.068813,-0.465024 47.066888,-0.471237 47.059795,-0.472096 47.057572,-0.476341 47.054362,-0.48032 47.053338,-0.485332 47.063885,-0.484992 47.065973,-0.478094 47.071911,-0.472027 47.072332,-0.469805 47.073652,-0.468249 47.073194,-0.464185 47.074359,-0.463973 47.076088,-0.458991 47.079943,-0.459531 47.082046,-0.464456 47.081975,-0.468364 47.083816,-0.473271 47.081777,-0.476073 47.083041,-0.478752 47.081727,-0.484783 47.081687,-0.487739 47.080881,-0.490791 47.082896,-0.493101 47.083353,-0.504174 47.079332,-0.507317 47.079241,-0.511785 47.077466,-0.51525 47.078035,-0.525741 47.073919,-0.535313 47.0722,-0.544635 47.068135,-0.546309 47.066274,-0.557553 47.06409,-0.559461 47.061813,-0.5567 47.060691,-0.5543709999999999 47.05726,-0.558239 47.056069,-0.558275 47.053228,-0.556006 47.044378,-0.556265 47.042695,-0.548737 47.04057,-0.542042 47.034972,-0.542997 47.033622,-0.542336 47.032532,-0.54533 47.030668,-0.54581 47.029103,-0.547006 47.028835,-0.547965 47.029652,-0.551732 47.029048,-0.555679 47.030902,-0.562342 47.030496,-0.564087 47.026005,-0.563775 47.02414,-0.564869 47.020141,-0.569053 47.018291,-0.574987 47.017828,-0.580904 47.014612,-0.587014 47.009192,-0.586932 47.006709,-0.58775 47.005337,-0.594749 47.002794,-0.597171 47.000769,-0.593961 46.998759,-0.5954930000000001 46.99791,-0.601611 46.997764,-0.618781 46.992342,-0.621938 46.993911,-0.6249400000000001 46.992792,-0.624561 46.994115,-0.6279169999999999 46.995691,-0.6267430000000001 46.996879,-0.63266 46.997508,-0.6354379999999999 46.995724,-0.640352 46.996116,-0.641046 46.994672,-0.642167 46.994818,-0.645504 46.99212,-0.646962 46.992308,-0.646391 46.99368,-0.649992 46.994917,-0.648025 46.996594,-0.650398 46.997689,-0.653462 46.997772,-0.657311 46.999199,-0.657708 46.9986,-0.660979 46.998839,-0.661627 46.997686,-0.669937 47.000802,-0.670368 47.002636,-0.671843 47.003185,-0.674719 47.001621,-0.676179 47.001885,-0.676831 47.000296,-0.674732 46.999172,-0.676007 46.997074,-0.675567 46.996648,-0.68038 46.993238,-0.678529 46.992114,-0.677686 46.989976,-0.680188 46.987659,-0.6829809999999999 46.98842,-0.686887 46.988065,-0.689599 46.990414,-0.689629 46.993058,-0.693412 46.992411,-0.696663 46.994873,-0.698748 46.99461,-0.700809 46.992531,-0.70435 46.992196,-0.703637 46.991424,-0.704682 46.990212,-0.712202 46.986674,-0.715947 46.98402,-0.7181070000000001 46.987193,-0.72926 46.995934,-0.7325430000000001 46.997508,-0.739475 46.998787,-0.743405 47.000992,-0.743626 46.994335,-0.74298 46.992012,-0.747754 46.991537,-0.753551 46.992972,-0.756819 46.991958,-0.7615150000000001 46.992264,-0.76411 46.992997,-0.765475 46.994016,-0.76528 46.994815,-0.7670979999999999 46.995785,-0.768885 46.995031,-0.768693 46.998337,-0.767998 46.99898,-0.768472 47.001449,-0.769335 47.002974,-0.771352 47.003471,-0.772268 47.004577,-0.773718 47.004606,-0.776458 47.003002,-0.7780010000000001 47.00428,-0.779699 47.004275,-0.781774 47.002141,-0.783438 47.001813,-0.784541 47.002807,-0.784486 47.004214,-0.786724 47.005452,-0.78967 47.003752,-0.789635 47.002406,-0.791189 47.0001,-0.796264 46.996051,-0.800662 46.994378,-0.804104 46.99387,-0.807032 46.994405,-0.810871 46.991732,-0.809145 46.99059,-0.808373 46.991571,-0.805102 46.989541,-0.807346 46.988608,-0.808466 46.986718,-0.809551 46.988562,-0.812299 46.989251,-0.812597 46.990568,-0.815701 46.989765,-0.811339 46.991774,-0.811747 46.994549,-0.815426 46.993264,-0.817527 46.993124,-0.81869 46.994079,-0.826568 46.992643,-0.8363429999999999 46.985762,-0.839504 46.985428,-0.842993 46.990173,-0.846592 46.986729,-0.847436 46.986872,-0.847915 46.982014,-0.849641 46.981979,-0.857129 46.978461,-0.85654 46.977397,-0.8492420000000001 46.97382,-0.8526 46.971008,-0.854617 46.971188,-0.860658 46.968886,-0.861437 46.969427,-0.861169 46.970234,-0.862803 46.970306,-0.862043 46.971125,-0.863063 46.971487,-0.863054 46.972617,-0.866704 46.973134,-0.867239 46.972541,-0.868179 46.973273,-0.869896 46.972059,-0.872356 46.973921,-0.87925 46.974666,-0.880167 46.975259,-0.879569 46.976065,-0.882064 46.977455,-0.882176 46.976556,-0.884937 46.977334,-0.8851560000000001 46.976298,-0.886918 46.976492,-0.888462 46.975566,-0.892187 46.976082,-0.8924840000000001 46.978577,-0.8950709999999999 46.979177,-0.8948739999999999 46.980231,-0.8968429999999999 46.980815,-0.893065 46.984496,-0.8957270000000001 46.985249,-0.89623 46.985842,-0.895404 46.986335,-0.898968 46.988701,-0.8974839999999999 46.989799,-0.90103 46.991734,-0.902515 46.993922,-0.904396 46.994915,-0.907873 46.994955,-0.908708 46.99287,-0.9117 46.995997,-0.912372 46.995659,-0.910853 46.994271,-0.912311 46.992815,-0.915289 46.992611,-0.915649 46.993302,-0.914227 46.994688,-0.916525 46.996111,-0.918747 46.995522,-0.918685 46.996536,-0.921435 46.998028,-0.9179580000000001 46.998454,-0.916957 46.999858,-0.914871 47.000633,-0.915853 47.001637,-0.919365 47.002324,-0.919706 47.003377,-0.925021 47.002535,-0.925042 46.999834,-0.928445 47.000682,-0.928661 47.002451,-0.935226 47.002345,-0.9327800000000001 47.00456,-0.931063 47.003357,-0.9310389999999999 47.004519,-0.928248 47.00382,-0.927473 47.006346,-0.929194 47.008111,-0.932389 47.006069,-0.932015 47.007985,-0.9329499999999999 47.007838,-0.933399 47.009041,-0.935539 47.007348,-0.934844 47.005633,-0.936462 47.005257,-0.937296 47.003048,-0.9385289999999999 47.0034,-0.938673 47.002401,-0.939634 47.002783,-0.939812 47.002193,-0.9402779999999999 47.003189,-0.941698 47.00358,-0.944993 46.998988,-0.947166 46.999717,-0.948313 47.001307,-0.947959 47.003694,-0.951958 47.002736,-0.953334 47.000764,-0.95504 46.999919,-0.955661 46.99757,-0.954756 46.995966,-0.9567369999999999 46.996404,-0.9582850000000001 46.99543,-0.957388 46.994887,-0.960803 46.994723,-0.959851 46.995287,-0.962158 46.995809,-0.961741 46.997277,-0.963159 46.996458,-0.964354 46.997292,-0.9634470000000001 46.998099,-0.964984 46.999584,-0.963101 47.00063,-0.963229 47.001985,-0.964014 47.003068,-0.966535 47.002838,-0.968005 47.004208,-0.967052 47.005199,-0.965982 47.004729,-0.968678 47.006687,-0.967816 47.007355,-0.970504 47.007588,-0.972909 47.009056,-0.973483 47.008101,-0.975229 47.008652,-0.974932 47.010525,-0.973166 47.012531,-0.975314 47.013218,-0.973361 47.016124,-0.9756629999999999 47.01687,-0.976156 47.018317,-0.9783539999999999 47.018918,-0.981873 47.018124,-0.981502 47.017046,-0.982976 47.016083,-0.980279 47.014309,-0.982174 47.010593,-0.995514 47.017676,-0.999529 47.020687,-1.002179 47.02152,-1.000567 47.022544,-1.002044 47.024403,-1.000672 47.02556,-0.999402 47.025138,-1.000446 47.022611,-0.9974229999999999 47.022981,-0.995461 47.024415,-1.000034 47.027594,-1.001848 47.027837,-1.003761 47.02556,-1.005871 47.027086,-1.008565 47.027608,-1.00369 47.029205,-1.003499 47.034155))'::GEOMETRY)
    )
SELECT  GeometryType(dmp.geom) AS gt, COUNT(*)
FROM    z AS a, z AS b,
        LATERAL ST_Dump(ST_Intersection(ST_Difference(a.geom, b.geom), b.geom)) AS dmp
GROUP BY
        1
;

     gt     | count 
------------+-------
 POLYGON    |     1
 LINESTRING |   458
(2 rows)

This is also true for the exact geometries of the linked GitHub issue.

For reference, this is produced on POSTGIS 3.0.0 | GEOS 3.8.0


To clarify the relationship assumptions on the PostGIS level:

The ST_Difference for non-overlapping (but potentially touching) A & B geometries is (spatially equal to) A, since

[...] ST_Difference(A, B) always returns a portion of A.

SELECT ST_AsText(ST_Difference('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::GEOMETRY, 'POLYGON((1 0, 2 0, 2 1, 1 1, 1 0))'::GEOMETRY));

           st_astext            
--------------------------------
 POLYGON((1 0,0 0,0 1,1 1,1 0))
(1 row)

and an ST_Intersection between the above with B is the common boundary (as per the DE-9IM definition) as in an ST_Intersection of A & B; i.e. with ST_Difference:

SELECT ST_AsText(ST_Intersection(ST_Difference('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::GEOMETRY, 'POLYGON((1 0, 2 0, 2 1, 1 1, 1 0))'::GEOMETRY), 'POLYGON((1 0, 2 0, 2 1, 1 1, 1 0))'::GEOMETRY));

      st_astext      
---------------------
 LINESTRING(1 1,1 0)
(1 row)

and with only ST_Intersects:

SELECT ST_AsText(ST_Intersection('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::GEOMETRY, 'POLYGON((1 0, 2 0, 2 1, 1 1, 1 0))'::GEOMETRY));

      st_astext      
---------------------
 LINESTRING(1 0,1 1)
(1 row)

EXCEPT, unfortunately, for cases with floating point imprecision (between geometries with non-matching vertices).

Note here that, with PostGIS 3.1 most spatial relationship construction functions (e.g. ST_Difference & ST_Intersection) come with an additional parameter gridSize, which, when set, snaps the inputs

[...] to a grid of the given size, and the result vertices are computed on that same grid.

which helps getting exact matches for when non-matching vertices are in snapping distance from each other.


Update:

One possible solution to correct the topology; derive the ST_Intersection and ST_Difference of an ST_Union of A & B with either A or B, to be used as base geometries A' & B':

SELECT  GeometryType(dmp.geom) AS gt, COUNT(*)
FROM    (
    SELECT  ST_Intersection(ST_Union(a.geom, b.geom), a.geom) AS geom_with_name_a,
            ST_Difference(ST_Union(a.geom, b.geom), ST_Intersection(ST_Union(a.geom, b.geom), a.geom)) AS geom_with_name_b
    FROM    z a, z b
    WHERE   a.name = 'a' and b.name = 'b'
) q, LATERAL ST_Dump(ST_Intersection(ST_Difference(geom_with_name_a, geom_with_name_b), geom_with_name_b)) AS dmp
GROUP BY
        1
;

     gt       | count 
--------------+-------
 LINESTRING   |   461
(1 row)

Result type is MULTILINESTRING and represents the complete common boundary of both geometries.

7
  • Updated with a solution applicable for (topologically incorrect) adjacent polygons with shared borders.
    – geozelot
    Jun 15 at 11:39
  • Thank you that very complete answer! It will for sure help me. However I do not understand why I didn't see the POLYGON in the result. The way I searched for it was by copying the result and grep -i poly..
    – Ulysse BN
    Jun 15 at 12:03
  • Copied from IDE/client? Probably didn't get the full string length there...
    – geozelot
    Jun 15 at 12:06
  • Yeah that is what I though but I get a valid GEOMETRYCOLLECTION when I copy.. (pastebin.com/CZ0HirLL)
    – Ulysse BN
    Jun 15 at 12:43
  • 1
    Yeah, that's just because of the cross product of your implicit CROSS JOIN; your query runs the operations on a b and b a - forgot the WHERE? Better use the explicit JOIN syntax to identify these kinds of errors. -> Divide that number by 2 and you get 459.
    – geozelot
    Jun 15 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.