@turf/union problem
Before the merger
After the merger
Why are the gaps in the middle filled up after the merger?
Hi @AllKai. Can you please attach the geojson and function calls you used to generate the result? Thank you!
This is our merge code:
const mergePolygons = (polygons) => { if (!polygons || polygons.length === 1) return polygons; // 将所有多边形的路径转换为 GeoJSON 格式 let geoPolygons = []; polygons.forEach((item) => { if (item.length && item.length >= 3) { geoPolygons.push(turf.polygon([item])); } }); // 合并至少需要两个多边形 if (geoPolygons.length < 2) return []; let featureCollection = turf.featureCollection(geoPolygons) const unionPolygon = turf.union(featureCollection); return unionPolygon?.geometry?.coordinates || [] };
and the 'polygons' parameter format is: [[x,y],[x,y]...]
out data: polygons.json
Hi @AllKai. Can you please attach the geojson and function calls you used to generate the result? Thank you!
https://github.com/Turfjs/turf/issues/2917#issuecomment-3064528299
Hi @AllKai. Have reproduced this locally using your code and the result looks ok.
https://geojson.io
https://geojsonlint.com
I'm not sure which mapping library you are using. Could it be a rendering or shading issue? Perhaps post your actual output geojson and what mapping library you're using if you'd like further help.
Hi @AllKai. Have reproduced this locally using your code and the result looks ok.
https://geojson.io
https://geojsonlint.com
I'm not sure which mapping library you are using. Could it be a rendering or shading issue? Perhaps post your actual output geojson and what mapping library you're using if you'd like further help.
It looks like you don't have this problem there, we are using the Amap map component, could it be a rendering problem with the map component?
Maybe. Does it normally display ok for polygons with holes in them?
Maybe. Does it normally display ok for polygons with holes in them?
I don't know, this problem is also a problem that our testers inadvertently draw, and this kind of aspect almost never appears in actual business, but we have to deal with what to do once this kind of business problem occurs. I have raised this issue with the Amap team and await their response
Are you passing the entire geojson text straight to amap? Or just the geometry coordinates?
return unionPolygon?.geometry?.coordinates || []
If the latter, perhaps check which direction amap expects the rings to be wound. If it's different from what geojson uses it could be turning the rings "inside out" leading to weird rendering issues.
Hi @AllKai. Will close this for now as it seems Turf is working properly. If you hear back from Amap or new info comes to light that suggests Turf has a fault please feel free to reopen.
https://geojsonlint.com
I'm not sure which mapping library you are using. Could it be a rendering or shading issue? Perhaps post your actual output geojson and what mapping library you're using if you'd like further help.