orb icon indicating copy to clipboard operation
orb copied to clipboard

When i use a large polygon and clip it,it looks bad

Open liujiusheng opened this issue 1 year ago • 3 comments
trafficstars

problem image

When i use a large polygon to generate Mapbox Vector Tile,it looks bad. But it has no problem in mapbox studio,with the same data. My data is a China province boundary.

data in mapbox studio

I have try to remove the Clip function,and then it looks right,but the result mvt binary is too big.

tile := maptile.New(x, y, maptile.Zoom(z))
layer := mvt.Layer{
Name:    path,
Version: 2,
Extent:  4096,
//Features: geoFeatures,
}
layer.Features = Tile(layer, geoFeatures, tile, fields)
layer.Clip(mvt.MapboxGLDefaultExtentBound)

layer.Simplify(simplify.DouglasPeucker(0.0))
layer.RemoveEmpty(1.0, 1.0)
layers := mvt.Layers{&layer}
return mvt.Marshal(layers)

liujiusheng avatar Jan 15 '24 13:01 liujiusheng

Can you provide the data and tile number for the province, so I can debug? Possible issues are polygon not closed (endpoints not the same), or the wrong winding order. But hard to know without the actual data.

paulmach avatar Jan 16 '24 15:01 paulmach

thanks.

shpdata.zip

it may happen when zoom>9

z: 10,x: 817,y: 422

z: 10,x: 816,y: 421

z: 10,x: 816,y: 420

the ring function in orb lead to the problem when the clip bound is in the polygon and whitout intersect with the polygon outline.

liujiusheng avatar Jan 17 '24 05:01 liujiusheng

Screenshot 2024-01-27 at 8 40 35 PM

I am not able to duplicate.

One thing to consider is that Clip modifies the input data. If you need to reuse it then you need to Clone() it before passing it in.

paulmach avatar Jan 28 '24 04:01 paulmach

thanks. Maybe it recurrence only when we render the whole map. mapbox mapbox/tippecanoe project use Vatti algorithm called "wagyu",your clip algorithm is Sutherland-Hodgeman clip algorithm. Sutherland-Hodgeman clip algorithm can not deal with polyon with hole and Concave polygon.

liujiusheng avatar Feb 21 '24 01:02 liujiusheng

Sutherland-Hodgeman clip algorithm can not deal with polyon with hole and Concave polygon.

Is that true? the wikipedia page has an example of a concave polygon. From the Vatti clipping algorithm wikipedia page it says it support "Even complex (self-intersecting) polygons" which I bet Sutherland-Hodgeman doesn't support.

You could try https://github.com/paulmach/orb/tree/master/clip/smartclip I don't remember how it handles all the edge cases, but it is smarter.

paulmach avatar Feb 23 '24 23:02 paulmach