View Ticket
Not logged in
Ticket Hash: d95f6beaae958ad2923bb3882d7aed5e61433f84
Title: ST_Cutter | resulting geometry bug
Status: Closed Type: Code_Defect
Severity: Important Priority: Medium
Subsystem: Resolution: Fixed
Last Modified: 2020-09-29 16:19:36
Version Found In: 5.5.0
User Comments:
anonymous added on 2018-02-23 13:47:39:

Hello,

I encountered a problem with the ST_Cutter() function while trying to cut LineStrings with MultiPolygons on a Windows 7 x64 and Spatialite v4.4.0-RC0.

The resulting cut geometry of one LineStrings should be of two parts. But 3 features where created in the resulting table (two correct and one invalid geometry - see attached picture). The additional Geometry is a LineString consisting of two Points with the same coordinates. And it has a NULL value for the "blade_gemeinden_ogc_fid" attribute.

Here you have my sample data base and some pictures to visualise the problem:
https://files.fm/u/mpk3zt7e

I used following SQL commands to create the buggy result(first) and the correct result (second):
SELECT ST_Cutter(NULL,'strecken', 'geometry', NULL, 'gemeinden', 'geometry', 'streckenClipped', 1, 1);
SELECT ST_Cutter(NULL,'strecken', 'geometry', NULL, 'gemeinden', 'geometry_fixed', 'streckenClipped_fixed', 1, 1);

To fix the bug I separated the valid MultiPolygon (ogc_fid=8) of the "gemeinden" table at its touching point (see attached picture). Then The cutting algorithm works fine. But I don't think the algorithm should fail for an relatively easy cutting case and a valid MultiPolygon.

Thanks for all your development work!

Greetings from Germany
Jonas


mj10777 added on 2018-02-23 14:44:40:

Is it possible that the given ogc_fid=8 was misstyped?
The gemeinden table contains only 1-6.


anonymous added on 2018-02-23 15:37:11:
Yes, sorry. I meant MultiPolygon 6.

mj10777 added on 2018-02-25 09:54:49:

This looks to me as a double inprecision error.

1) your LINESTRING Blade 8.4 is not dose not start and end with the same point
There is a slight difference:

    x=0.0000000001
    y=0.00000001

Correct would be Blade 8.1 and Blade 8.5
    discarding Blades 8.2, 8.3 and 8.4
    Blade.8.5 : StartPoint = Blade 8.1 EndPoint
Blade 8.1: SRID=25833;LINESTRING(111207.023527506 5563188.010062917,111196.935161804 5563200.797934085,111178.7064781897 5563220.479499675,111155.5737380812 5563239.123129508,111125.9412858496 5563271.577286462,111103.7888006881 5563296.259032903,111085.0614643037 5563314.022851127,111065.9566234982 5563331.53509967,111045.0802977606 5563349.188000618,111022.0320546188 5563371.433751669,110987.2240596648 5563406.489591768,110958.2519092155 5563430.843827637,110930.3520328416 5563455.119902874,110910.1053557546 5563474.101230818,110886.661116824 5563495.829360135,
110875.9195405733 5563501.179931681)

Blade.8.2 : EndPoint = Blade 8.4 : StartPoint
Blade.8.2 : EndPoint = Blade 8.3 : StartPoint
Blade 8.2 SRID=25833;LINESTRING(110886.661116824 5563495.829360135,110875.9195405734 5563501.17993168)

Blade 8.4 : StartPoint = Blade.8.1 : EndPoint
Blade 8.4 : EndPoint = Blade.8.3 : StartPoint
Blade 8.4 : EndPoint = Blade.8.4 : StartPoint 
Blade 8.4 : SRID=25833;LINESTRING(110875.9195405734 5563501.17993168,110875.9195405733 5563501.179931681)

Blade.8.3 : StartPoint = Blade 8.2  EndPoint
SRID=25833;LINESTRING(110875.9195405734 5563501.17993168,110868.3454954775 5563504.952699217)

Blade.8.5 : StartPoint = Blade 8.1 EndPoint
SRID=25833;LINESTRING(110875.9195405733 5563501.179931681,110868.3454954775 5563504.952699217)

>> But I don't think the algorithm should fail for an relatively easy cutting case and a valid MultiPolygon.
These double inprecision errors are difficult to resolve.

This is something Sandro must look into, but it may also be caused by GEOS.


anonymous added on 2018-02-27 10:16:30:

Thanks for looking into it.

The Geometry checks (LWGEOM and Malformed Geometry checks) in Spatialite didn't catch that.
If a Spatialite algorithm gets tripped of by that, it might be helpful to check for this kind of geometry conditions?


mj10777 added on 2018-02-27 13:34:01:

The geometries themselves are correct/valid.
What happens with double precision errors is that the same function called twice many bring an different result.

    splitting the LINESTRING at the intersection of the POLYGON
    splitting the POLYGON at the intersection of the LINESTRING
      which should be the same POINT
    could have a difference of
      x=0.0000000001 y=0.00000001

This is a common computer problem for differences that, even the ant kingdoms, are considered small.
SELECT ST_Distance(MakePoint(110875.9195405734,5563501.17993168,25833),MakePoint(110875.9195405733,5563501.179931681,25833));
0.00000000009368767 meters


mj10777 added on 2018-02-27 13:50:16:

What needs to be done (where ever it is being done)

split the LINESTRING at the intersection of the POLYGON

    save the EndPoint of the first portion of the split LINESTRING

    set the StartPoint of the second LINESTRING with the saved POINT

    split the POLYGON at the intersection of the LINESTRING
    set the EndPoint of the first LINESTRING of the split POLYGON with the saved POINT
    set the StartPoint of the second LINESTRING of the split POLYGON with the saved POINT

That is the only way to resolve this, always reoccurring, problem.


anonymous added on 2018-03-09 08:16:47:

Do you mean this should be done as a pre processing step or be implemented in the ST_Cutter() function?


mj10777 added on 2018-03-10 07:27:34:

In the ST_Cutter function.


sandro added on 2020-08-26 07:21:50:
too old to be still considered

anonymous added on 2020-08-27 09:46:14:
I'm the initial reporter of the bug.

Just tried to reproduce the bug again and it is still present in the current version 5.5.0 of Spatialite.
As a small summary: The problem is that the expected number of resulting cut geometries is not correct.

Expected Result (2 LineStrings):
PK_UID | PK_UID | input_test_id | blade_blade_id | n_geoms | res_prog | the_geom
   1       1           0               1              1         1         BLOB
   2       2           0               0              1         2         BLOB

Buggy RESULT (5 LineStrings):
PK_UID | PK_UID | input_test_id | blade_blade_id | n_geoms | res_prog | the_geom
   1       1           0               1              1         1         BLOB
   2       2           0               1              1         2         BLOB
   3       3           0               0              1         3         BLOB
   4       4           0               1              1         4         BLOB
   5       5           0              NULL            1         5         BLOB


As I still think this is serious, I'll append steps to reproduce the bug as the initial files are not available anymore:

CREATE TABLE test (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT);
SELECT AddGeometryColumn('test', 'the_geom', 25832, 'LINESTRING', 'XY', 1);
INSERT INTO test (id, the_geom) VALUES
    (0, GeomFromText('LineString (540272.11674611840862781 5549169.88123260997235775, 540261.05401800421532243 5549181.79544025007635355, 540241.33938471297733486 5549199.91570725385099649, 540216.82874327735044062 5549216.61004272755235434, 540184.74386266118381172 5549246.52380357217043638, 540160.72433822392486036 5549269.30427474156022072, 540140.66735728865023702 5549285.47647831868380308, 540120.254956673248671 5549301.36810748651623726, 540098.06876144849229604 5549317.2576183183118701, 540073.35335400921758264 5549337.54255819786339998, 540035.91051294247154146 5549369.62972439266741276, 540005.13211857154965401 5549391.53741550073027611, 539975.42684022570028901 5549413.45331175532191992, 539953.76059117878321558 5549430.71496221236884594, 539928.6927099337335676 5549450.45308572705835104, 539909.73824694287031889 5549458.0615041172131896)', 25832));

CREATE TABLE blade (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT);
SELECT AddGeometryColumn('blade', 'the_geom', 25832, 'MULTIPOLYGON', 'XY', 1);
INSERT INTO blade (id, the_geom) VALUES
    (0, GeomFromText('MultiPolygon (((539964.4946268746862188 5546053.65955317951738834, 540015.79367753060068935 5546089.72045324742794037, 540107.0198927508899942 5546408.58560395985841751, 540063.36108553875237703 5546577.1331277946010232, 539947.75465238548349589 5546681.68797979131340981, 539788.09790068340953439 5546709.46793080028146505, 539789.33351307036355138 5546796.54405487421900034, 539734.91830111260060221 5546815.45209563057869673, 539675.34182198520284146 5546694.17327957972884178, 539559.20589866442605853 5546746.84992728754878044, 539450.42215238988865167 5546831.6944403238594532, 539281.72926714445929974 5546910.32076702360063791, 539262.04219382326118648 5546992.97015011124312878, 539267.10999075474683195 5547039.09996236208826303, 539289.44452463183552027 5547072.57239410281181335, 539355.67114238766953349 5547161.96748204436153173, 539366.94894647167529911 5547247.24621962569653988, 539350.30295326339546591 5547327.95620326790958643, 539273.85514653078280389 5547440.54239168018102646, 539222.24358793685678393 5547524.47563907876610756, 539356.42748220602516085 5547667.28003904689103365, 539245.26951073308009654 5547869.14544376358389854, 539470.32557834428735077 5548168.8849339485168457, 539364.49518821970559657 5548206.76177111826837063, 539478.16628876444883645 5548522.25276778638362885, 539499.51876019465271384 5548702.79252081271260977, 539519.18817939155269414 5548862.66250377427786589, 539542.46715348889119923 5549051.87015043757855892, 539664.41798344091512263 5549304.49251998122781515, 539549.2263224592898041 5549409.21938239224255085, 539350.81155836395919323 5549818.44005781132727861, 539347.41490444028750062 5549873.66237355675548315, 539632.63841007906012237 5549908.04074665810912848, 539786.39436021307483315 5550098.438127133063972, 539895.07259481179062277 5549476.27077059168368578, 540591.891640993533656 5548815.00356010347604752, 541160.66481658443808556 5548793.5195504454895854, 541482.12926832213997841 5548780.02702464256435633, 541598.00223782798275352 5548740.35190085042268038, 541543.93916078528854996 5548643.19847309030592442, 541599.35619357950054109 5548476.22249399311840534, 542414.18723867344669998 5548557.78417878597974777, 543128.56974443257786334 5548313.11461480334401131, 543216.60825959639623761 5547721.5473078116774559, 543095.56744759017601609 5547275.83099356293678284, 543040.70653603004757315 5547168.65608721319586039, 542867.41178097727242857 5547178.15044896490871906, 542731.73919656604994088 5547059.33127322141081095, 542577.6847508690552786 5547008.17956411559134722, 542482.30272222496569157 5547024.2563373064622283, 542317.36730711394920945 5547114.96771952603012323, 542045.58224895165767521 5547096.44934896286576986, 541961.65479807555675507 5547139.77414816897362471, 541805.02690716204233468 5546919.47027875762432814, 541850.95585308223962784 5546628.22961740288883448, 541630.97327528463210911 5546275.56456170510500669, 541109.61928368743974715 5546129.91360948327928782, 540817.92067424103152007 5546007.93040838371962309, 540834.3379721085075289 5545741.10708731692284346, 540475.71077231538947672 5545465.67789591383188963, 540442.39944978919811547 5545628.09752197936177254, 540375.99494333495385945 5545744.81978411599993706, 539993.10182794625870883 5545975.19354826305061579, 539964.4946268746862188 5546053.65955317951738834)),((539843.99932064954191446 5546173.28706541657447815, 539964.4946268746862188 5546053.65955317951738834, 539780.21928648045286536 5546061.92911943886429071, 539758.59024655818939209 5545968.54632697533816099, 539768.9047431277576834 5545877.68543888814747334, 539811.31820216146297753 5545770.53241232503205538, 539885.14370199595578015 5545680.95967545825988054, 539962.4733741139061749 5545627.46250290609896183, 540054.3216295869788155 5545589.08501000050455332, 540139.47539618471637368 5545567.51510356552898884, 540190.5418557389639318 5545555.84324601944535971, 540210.41088722506538033 5545516.00602818839251995, 540211.91358155524358153 5545441.90978207252919674, 540244.17103175632655621 5545313.3717779703438282, 540301.48932924226392061 5545202.2852080799639225, 540484.36136894789524376 5544644.37521131616085768, 540636.08413043420296162 5544514.37463312037289143, 540755.95720540534239262 5544326.69508207775652409, 540746.02488161262590438 5544076.34868989419192076, 540221.21169378643389791 5544298.84147854801267385, 540162.48571410577278584 5544283.64244549069553614, 540092.79845809505786747 5544266.21995593514293432, 539519.76766633847728372 5544448.71106508746743202, 539334.87064006074797362 5544537.01435780990868807, 539099.63252617255784571 5544739.36317759472876787, 538672.81370896217413247 5545458.1280251145362854, 537741.96374291751999408 5545966.55112528335303068, 537352.10302598564885557 5546490.95156060624867678, 536911.04945949371904135 5547023.31850838847458363, 536777.91512344742659479 5547469.87999335024505854, 536744.63653262099251151 5547581.27038968447595835, 536968.30393043311778456 5547899.99360952340066433, 536954.99294206325430423 5548408.0225661713629961, 536925.42176174186170101 5548632.55518470052629709, 536646.61418166221119463 5548960.093790203332901, 536759.65325690084137022 5549306.59128561802208424, 536917.67679629905615002 5549803.09049900434911251, 536980.09608466643840075 5549981.46236639562994242, 537085.74302978336345404 5550297.7931158933788538, 537126.08277689944952726 5550528.7487581567838788, 537307.88739782245829701 5550494.41564301308244467, 537275.54553056322038174 5550411.71044919732958078, 537486.19641297624912113 5550237.87924236431717873, 537603.07669541379436851 5549902.04996111337095499, 537729.81324350414797664 5549721.51294769998639822, 537752.55675160372629762 5549586.89427991770207882, 537790.08542912639677525 5549512.61127294600009918, 537923.76782638521399349 5549384.24610703717917204, 537881.95166087918914855 5549275.3335745083168149, 537896.12533918826375157 5549168.55775126349180937, 537998.43086961423978209 5549008.53762111067771912, 537990.79766944248694927 5548842.28448635060340166, 537805.38183112011756748 5548709.44604553654789925, 538002.62755427951924503 5548505.37252454366534948, 538058.98670840950217098 5548440.42982813250273466, 538196.61071146733593196 5547821.8559299036860466, 538119.82888683024793863 5547710.2333876583725214, 538306.25845342152751982 5547447.85931098647415638, 538403.23495345818810165 5547451.8279244638979435, 538818.51578245055861771 5547154.07288298849016428, 538744.74029087217058986 5547091.54044246580451727, 538647.36642591585405171 5547008.5175430104136467, 538687.12398145906627178 5546972.30237500369548798, 538800.21294370421674103 5546872.53668675757944584, 538944.50789897085633129 5546911.48492701537907124, 539056.03011194441933185 5547184.90631713531911373, 539167.72521342802792788 5547203.18148465175181627, 539127.57011970190797001 5547160.34225109312683344, 539082.43444575858302414 5547116.40140138473361731, 539050.62568980432115495 5547056.72150066308677197, 539042.6994200439658016 5547003.52959711104631424, 539047.14045185560826212 5546932.57801339030265808, 539068.90907098643947393 5546845.96855085715651512, 539088.70881028450094163 5546730.11375529505312443, 539110.85408225131686777 5546578.07335911318659782, 539262.66696794226299971 5546507.02590230386704206, 539495.42297288519330323 5546489.36897860653698444, 539745.78994127153418958 5546427.4450488006696105, 539816.8508564974181354 5546327.82717660814523697, 539850.85060659656301141 5546279.48807357531040907, 539861.86662976536899805 5546229.68222862668335438, 539843.99932064954191446 5546173.28706541657447815)))', 25832)),
    (1, GeomFromText('MultiPolygon (((541736.59728119079954922 5550639.29482255876064301, 541718.46901623765006661 5550299.72382411360740662, 541511.52849088190123439 5549945.3173858504742384, 541570.69078085222281516 5549692.36540611553937197, 541506.2887278909329325 5549512.9530262490734458, 541504.06044846563600004 5549326.79688384849578142, 541629.00383704097475857 5549185.24489175993949175, 541738.70227167347911745 5548907.30274824053049088, 541713.80039251025300473 5548753.7067320579662919, 541598.00223782798275352 5548740.35190085042268038, 541482.12926832213997841 5548780.02702464256435633, 541160.66481658443808556 5548793.5195504454895854, 540591.891640993533656 5548815.00356010347604752, 539895.07259481179062277 5549476.27077059168368578, 539786.39436021307483315 5550098.438127133063972, 540260.0865206690505147 5550374.20614118408411741, 540807.73675942840054631 5550851.59405752085149288, 541202.16217473603319377 5550891.61347595509141684, 541736.59728119079954922 5550639.29482255876064301)))', 25832));

SELECT ST_Cutter(NULL, 'test', 'the_geom', NULL, 'blade', 'the_geom', 'cut', 1);

sandro added on 2020-09-29 16:18:43:
fixed by commit de42913e92

sandro added on 2020-09-29 16:19:36:
fixed by commit de42913e92