jts icon indicating copy to clipboard operation
jts copied to clipboard

Buffer with mitre join is incorrect due to short input segment

Open dr-jts opened this issue 9 years ago • 7 comments

A buffer with mitre join produces a clearly invalid result. (From #178)

LINESTRING (33413163.36756757 6024167.394594596, 33413164.400000002 6024161.2, 33413170.700949676 6024160.94651352, 33413171.476863 6024161.937958999, 33413173.516562365 6024163.646896194, 33413174.886529 6024164.794706001, 33413176.36098 6024165.900544, 33413177.374664 6024166.361308999, 33413179.217727 6024165.900544, 33413181.06079 6024164.518247, 33413181.598201 6024163.711844, 33413182.627393 6024163.412409, 33413184.193996 6024163.135950001, 33413185.668447 6024163.043796, 33413187.60832 6024162.828002, 33413187.961857 6024162.651233999, 33413189.552771 6024162.12093, 33413190.259844 6024160.883552, 33413190.46907465 6024160.151244123, 33413190.469074655 6024160.151244123, 33413199.200000003 6024159.800000002, 33413191.400000002 6024170.6, 33413176.366780605 6024173.156669965)

Calculating the offset curve with distance 1 yields this result: LINESTRING (33413164.353961494 6024167.558993584, 33413165.25270968 6024162.166504483, 33413170.22921036 6024161.966300433, 33413170.689357795 6024162.5542669995, 33413170.834643163 6024162.7044795, 33413172.874342527 6024164.413416695, 33413174.24430916 6024165.561226503, 33413174.286529087 6024165.594706067, 33413175.76098009 6024166.700544066, 33413175.947177395 6024166.810910631, 33413176.960861396 6024167.2716756305, 33413177.173291765 6024167.340823789, 33413177.395772245 6024167.361086195, 33413177.617199253 6024167.331451592, 33413179.460262254 6024166.8706865925, 33413179.64749846 6024166.803481703, 33413179.817726932 6024166.700544052, 33413181.66078993 6024165.318247052, 33413181.78730004 6024165.205402851, 33413181.89293125 6024165.072810738, 33413182.22796355 6024164.570083678, 33413182.85463238 6024164.387759504, 33413184.31245074 6024164.13049777, 33413185.730825834 6024164.041848544, 33413185.77900634 6024164.0376655245, 33413187.718879342 6024163.821871525, 33413187.89160352 6024163.787038209, 33413188.05553259 6024163.722429695, 33413188.345504906 6024163.577443944, 33413189.868998405 6024163.069613418, 33413190.035900213 6024162.996479063, 33413190.18675979 6024162.894272234, 33413190.316567864 6024162.766386695, 33413190.421014182 6024162.617068864, 33413191.128087185 6024161.379690864, 33413191.221368007 6024161.158272919, 33413191.430598658 6024160.425965042, 33413191.418727994 6024160.422573425, 33413190.469074655 6024161.138898443, 33413190.46907465 6024161.151244123, 33413190.509272024 6024161.150435882, 33413197.18511783 6024160.881867374, 33413190.828913998 6024169.682764986, 33413176.19911993 6024172.170825201)

And the buffer with distance 1 and join style Mitre and Mitre limit of 10: MULTIPOLYGON (((33413165.25270968 6024162.166504483, 33413170.22921036 6024161.966300433, 33413170.785809107 6024162.669988315, 33413172.874342527 6024164.413416695, 33413174.19182188 6024165.511522947, 33413175.94062682 6024166.823126336, 33413177.258121308 6024167.421986879, 33413179.63844381 6024166.826907226, 33413181.791679207 6024165.21198096, 33413182.22796355 6024164.570083678, 33413182.85463238 6024164.387759504, 33413184.31245074 6024164.13049777, 33413185.683167506 6024164.0491648195, 33413187.906168506 6024163.801875293, 33413188.345504906 6024163.577443944, 33413190.234531503 6024162.945220505, 33413190.979850836 6024161.640911401, 33413192.9065901 6024163.48802409, 33413197.18511783 6024160.881867374, 33413194.322531383 6024164.845448607, 33413195.78052168 6024166.24318437, 33413201.214967944 6024158.718566477, 33413189.674158487 6024159.182851911, 33413189.331563648 6024160.492478205, 33413188.874085024 6024161.293065953, 33413187.74118453 6024161.674555876, 33413187.32056959 6024161.853843441, 33413185.58192732 6024162.047252272, 33413184.054690827 6024162.137484228, 33413182.483240873 6024162.414798572, 33413180.957289975 6024162.858761507, 33413180.323688317 6024163.821073243, 33413178.779280014 6024164.979379261, 33413177.47072922 6024165.306516427, 33413176.87388873 6024165.035225564, 33413175.508090034 6024164.010876775, 33413174.158782203 6024162.880375692, 33413172.19961648 6024161.238912627, 33413171.190860137 6024159.92526938, 33413163.549154405 6024160.232694321, 33413162.381173644 6024167.230195608, 33413162.36805428 6024167.425790397, 33413162.393345643 6024167.620186348, 33413162.456075814 6024167.805912935, 33413162.5538341 6024167.975832789, 33413162.682863705 6024168.123415985, 33413162.838206097 6024168.242990985, 33413163.013891555 6024168.329962585, 33413163.203168582 6024168.38098852, 33413163.39876337 6024168.394107888, 33413163.59315932 6024168.368816522, 33413163.77888591 6024168.306086353, 33413163.948805764 6024168.208328067, 33413164.09638896 6024168.07929846, 33413164.215963956 6024167.923956068, 33413164.30293556 6024167.748270611, 33413164.353961494 6024167.558993584, 33413165.25270968 6024162.166504483)), ((33413187.739681058 6024170.208144737, 33413176.19911993 6024172.170825201, 33413176.010012712 6024172.222476907, 33413175.834615882 6024172.310029128, 33413175.679669846 6024172.430117281, 33413175.551129088 6024172.578126447, 33413175.453933362 6024172.748368716, 33413175.39181784 6024172.934301772, 33413175.367169596 6024173.128780314, 33413175.38093584 6024173.324330639, 33413175.432587545 6024173.513437859, 33413175.52013977 6024173.688834689, 33413175.64022792 6024173.843780726, 33413175.788237087 6024173.972321482, 33413175.958479356 6024174.069517208, 33413176.144412413 6024174.131632727, 33413176.338890955 6024174.156280973, 33413176.53444128 6024174.142514729, 33413191.97301029 6024171.51512321, 33413192.993229035 6024170.102512645, 33413187.739681058 6024170.208144737)))

dr-jts avatar Sep 22 '17 18:09 dr-jts

BufferCurve and buffer with distance = 1 , join style = Mitre, Mitre limit = 10:

image

dr-jts avatar Sep 22 '17 18:09 dr-jts

This is caused by a VERY short line segment in the input:

LINESTRING (3.341319046907465E7 6024160.151244123, 3.3413190469074655E7 6024160.151244123 )

I think this should have been filtered out by the simplification pre-processing step.

Location of short segment:

image

dr-jts avatar Sep 22 '17 18:09 dr-jts

If the short segment is removed the output is valid: image

So a workaround is to apply DouglasPeuckerSimplification with a very small distance tolerance before buffering.

dr-jts avatar Sep 22 '17 18:09 dr-jts

A possible fix is to implement a simple RadialDistance simplification step at the start of buffer curve generation. This is particularly appropriate for LineStrings, since there is no concern about affecting topology. Even for polygons, if the radial distance tolerance is very small compared to the buffer distance the buffer algorithm should be resilient to topology changes introduced.

dr-jts avatar Sep 22 '17 18:09 dr-jts

Another thing that might be happening is that the mitre join calculation is not robust when computing with very small edges. It's possible that some heuristic checks could be added to solve this.

dr-jts avatar Sep 22 '17 19:09 dr-jts

@dr-jts In computeLineBufferCurve, computeSingleSidedBufferCurve computeRingBufferCurve and computeOffsetCurveof OffsetCurveBuilder, geometries are simplified by BufferInputLineSimplifier#simplify. BufferInputLineSimplifier can be replaced by DouglasPeuckerLineSimplifier because as long as the simplifyFactor of BufferParameters is less than 1, the buffer created from simplified geometry will cover the original geometry. Then as long as a user does not set the simplifyFactor very very small or 0, addMitreJoin will not fail. Making addMitreJoin robust would be another issue to tackle.

taromurao avatar May 17 '18 09:05 taromurao

[Update] I just noticed that this method for the mitre join would not work. Sorry, please ignore this comment.

A check to make addMitreJoin robust would be that the created meet point of segments A and B would fall into the shaded area S.

drawing

taromurao avatar May 17 '18 11:05 taromurao