Replies: 7 comments 3 replies
-
Hi @mofada. Have you taken a look at turf-unkink-polygon? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
The error message suggests there are duplicated points in your polygon. A quick scan of the geojson you provided shows at least one:
Perhaps try removing any duplicates (except for the first and last vertex as the error suggests) and see if you can get any further. |
Beta Was this translation helpful? Give feedback.
-
Can someone help me take a look? Please |
Beta Was this translation helpful? Give feedback.
-
@twelch @smallsaucepan Thank you for your help, I have solved my problem. I try to generate random points within the split polygon, and then determine whether these points are within the original polygon. If one is within the initial polygon, then it is the outer ring, otherwise it is the inner ring and should be cut off. Then determine whether there is an intersection between the outer ring and the inner ring. If there is an intersection, use mask to process it. In the end, all outer rings are the final result. This may not be the optimal solution, but it is the closest to the result I can think of. Now it's just that the particularly complex polygons are not very accurate. I'll try to optimize them again. |
Beta Was this translation helpful? Give feedback.
-
I adjusted my thinking and no longer differentiate between inner and outer rings, because it is easy to misjudge the inner and outer rings when the graph resembles a nested ring. The current idea is to first disassemble the polygon and obtain multiple split polygons. Loop through the polygon array, compare it with the current polygon, and find the intersection part, and then mask the intersection part. Finally, you will get a complete incomplete Nested tiled polygon array, then generate random points on the polygon array, determine whether the random points are in the original shape, and obtain the final result |
Beta Was this translation helpful? Give feedback.
-
The first picture is the original graph, the second picture is the final result. {"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[120.200834,30.259003],[120.202271,30.25919],[120.2022801981249,30.259193326646464],[120.201157,30.26022],[120.201014,30.260594],[120.20103047332846,30.261019481205235],[120.20087,30.260344],[120.200834,30.259003]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[120.20103047332846,30.261019481205235],[120.201049,30.261498],[120.201409,30.262216],[120.20193550158776,30.262437993334874],[120.201085,30.261249],[120.20103047332846,30.261019481205235]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[120.20193550158776,30.262437993334874],[120.202666,30.262746],[120.205505,30.262746],[120.2065371160128,30.262666996456364],[120.20645871050601,30.26160510369275],[120.20687,30.262278],[120.2073516013376,30.262604651488807],[120.207948,30.262559],[120.209026,30.262403],[120.20952427612372,30.26218684227659],[120.209709,30.262497],[120.20984086930105,30.263196640059746],[120.211434,30.262434],[120.21305319079248,30.261057922439477],[120.215207,30.261031],[120.215746,30.260625],[120.21593581563629,30.260074092808356],[120.216428,30.260344],[120.216932,30.260937],[120.217003,30.261498],[120.216105,30.262684],[120.214704,30.263464],[120.213662,30.263744],[120.210607,30.264056],[120.2097498266098,30.264358378279304],[120.209673,30.264462],[120.208919,30.264743],[120.20862119558302,30.264756516497133],[120.208308,30.264867],[120.206511,30.265117],[120.204104,30.264399],[120.202379,30.263058],[120.20193550158776,30.262437993334874]],[[120.2065371160128,30.262666996456364],[120.2073516013376,30.262604651488807],[120.20802,30.263058],[120.209673,30.263277],[120.20984086930105,30.263196640059746],[120.209997,30.264025],[120.2097498266098,30.264358378279304],[120.20862119558302,30.264756516497133],[120.207553,30.264805],[120.20687,30.264618],[120.206619,30.263776],[120.2065371160128,30.262666996456364]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[120.21593581563629,30.260074092808356],[120.215961,30.260001],[120.215889,30.259221],[120.214488,30.256788],[120.213662,30.255852],[120.212656,30.255104],[120.211218,30.254573],[120.210212,30.254667],[120.209314,30.25501],[120.20898227052328,30.255359865825582],[120.208236,30.254948],[120.207481,30.25476],[120.206691,30.25476],[120.206331,30.254948],[120.205541,30.256164],[120.20548724933472,30.25645275984346],[120.203708,30.256383],[120.203062,30.257006],[120.20300010654738,30.258535285354064],[120.2022801981249,30.259193326646464],[120.203565,30.259658],[120.204391,30.259689],[120.20493,30.26022],[120.203403,30.260251],[120.203439,30.2605],[120.205074,30.260687],[120.20624357417667,30.26121064572661],[120.20626,30.26128],[120.20645871050601,30.26160510369275],[120.20643277557475,30.261253851377028],[120.207913,30.261561],[120.208955,30.261561],[120.20911114834743,30.26149318617732],[120.20952427612372,30.26218684227659],[120.211398,30.261374],[120.212727,30.261062],[120.21305319079248,30.261057922439477],[120.213159,30.260968],[120.213626,30.260251],[120.21381931015424,30.259465173255794],[120.214021,30.259471],[120.215746,30.25997],[120.21593581563629,30.260074092808356]],[[120.20299,30.258785],[120.20300010654738,30.258535285354064],[120.203205,30.258348],[120.204176,30.257724],[120.20538713802442,30.257383909572393],[120.205361,30.257131],[120.20548724933472,30.25645275984346],[120.20608,30.256476],[120.20613160093001,30.25717486268199],[120.206619,30.257038],[120.20830555480387,30.25629554564168],[120.208308,30.256071],[120.20898227052328,30.255359865825582],[120.209026,30.255384],[120.20948540441361,30.255825788325474],[120.210715,30.255478],[120.211721,30.255509],[120.212368,30.255727],[120.213051,30.256258],[120.213662,30.257256],[120.213877,30.258223],[120.213841,30.259377],[120.21381931015424,30.259465173255794],[120.21175199181693,30.259405449508442],[120.211721,30.260157],[120.210859,30.260531],[120.21043755050144,30.260531000098123],[120.210104,30.261062],[120.20911114834743,30.26149318617732],[120.208631,30.260687],[120.2085699783078,30.260464330595386],[120.207517,30.260282],[120.207158,30.260032],[120.207194,30.259471],[120.20731516865227,30.25927727200382],[120.206475,30.259253],[120.2062835544387,30.259232860109364],[120.20643277557475,30.261253851377028],[120.20626,30.261218],[120.20624357417667,30.26121064572661],[120.205972,30.260064],[120.205577,30.259221],[120.20557047295803,30.25915784480987],[120.203205,30.258909],[120.20299,30.258785]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[120.21175199181693,30.259405449508442],[120.211757,30.259284],[120.211578,30.258722],[120.210356,30.256663],[120.20948540441361,30.255825788325474],[120.20917,30.255915],[120.20830555480387,30.25629554564168],[120.20828572324451,30.25811674384086],[120.207877,30.258379],[120.20731516865227,30.25927727200382],[120.20827278466169,30.259304937030322],[120.208272,30.259377],[120.2085699783078,30.260464330595386],[120.208955,30.260531],[120.21043755050144,30.260531000098123],[120.210751,30.260032],[120.210715,30.259377],[120.21071352776303,30.259375448824134],[120.21175199181693,30.259405449508442]],[[120.20827278466169,30.259304937030322],[120.20828572324451,30.25811674384086],[120.208703,30.257849],[120.209026,30.257849],[120.209709,30.258317],[120.21071352776303,30.259375448824134],[120.20827278466169,30.259304937030322]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[120.2062835544387,30.259232860109364],[120.20613160093001,30.25717486268199],[120.20538713802442,30.257383909572393],[120.20557047295803,30.25915784480987],[120.2062835544387,30.259232860109364]]]}}]} |
Beta Was this translation helpful? Give feedback.
-
Please provide the following when reporting an issue:
"@turf/turf": "^6.5.0"
.geojson
).how can i deconstruct polygon
I want to disassemble the polygon and disassemble the complete polygon below into polygons with multiple shaded parts. Is there any good way?
This means removing the parts where they overlap
example one
the code show with svg
geojson
example two
the code show with svg
the code of geojson
Beta Was this translation helpful? Give feedback.
All reactions