# Breaking donut polygons into single polygons without an interior ring whilst maintaining the polygons shape?

I have created a new dataset working with a predefined (and enforced) methodology that creates complex geometries that may have many interior rings making them donut polygons.

Some shapes may be simple rings:

Some may be incredibly complex:

(this network is several miles long and contains 28 interior rings)

I need to calculate the approximate medial axis in order to split into 12m units along their length. polygons always make up a thin network so there is confidence that approximate medial axis will provide a sufficient central line. I have my approach for this working however it is not possible to calculate skeletons or medial axis' on rings/donuts.

Is there a straightforward way to break a donut into polygon without interior rings, but still maintaining the shapes integrity allowing for such processes as detailed above? An example desired output would be:

This "split" was created in MS Paint.

My original thought was to take the centroid and build a LineString from a projection of nMetres north and south and use as a blade to ST_Split however this would not work for complex geometries, makes me uncomfortable as an approach and hoped there was a better solution to calculate these "network central lines". I thought about breaking up/splitting the network as a grid (although approach I am unsure of), to output hundreds of smaller polygons, calculating the medial axis for each and then unionising the output LineStrings; again, the approach feels like a poor workaround for poor data. This approach would also create obvious issues where the medial axis is perverted by modifying the polygon as demonstrated in another MS paint approximation:

Donut with grid overlayed

Red line demonstrates incorrect medial axis on polygon split

Original single ring Donut (4326):

``````POLYGON((-0.553825519541172 51.3195197680391,-0.553828332004988 51.3195216012381,-0.553829766502607 51.31952161895,-0.553832578966705 51.3195234521489,-0.553833985198839 51.3195243687484,-0.553835334899984 51.3195270831231,-0.55383530663446 51.3195279820107,-0.553836684601286 51.3195297974977,-0.553836656335785 51.3195306963854,-0.553838006037268 51.31953341076,-0.553837977771789 51.3195343096477,-0.553837892975346 51.3195370063105,-0.553837864709861 51.3195379051982,-0.5538363736807 51.3195396852617,-0.553834882651423 51.3195414653251,-0.553833391622029 51.3195432453886,-0.553833363356451 51.3195441442762,-0.553830437828531 51.3195459066278,-0.553828975064486 51.3195467878035,-0.55382604953623 51.319548550155,-0.553798398338031 51.319560798052,-0.553744558664546 51.3195844126515,-0.553727118528775 51.3195913911958,-0.553674741552389 51.319614124588,-0.553673307051983 51.3196141068742,-0.55367040978234 51.3196149703342,-0.553668947013045 51.3196158515079,-0.553664615242729 51.3196166972538,-0.55366318074225 51.3196166795399,-0.553660311741293 51.319616644112,-0.553657442740343 51.319616608684,-0.553654573739398 51.319616573256,-0.55365170473846 51.3196165378279,-0.553648864006785 51.3196156035122,-0.553647429506348 51.3196155857981,-0.553644588774822 51.3196146514823,-0.55364174804341 51.3196137171664,-0.55364037008188 51.3196119016771,-0.553638963851011 51.3196109850754,-0.553636123119942 51.3196100507594,-0.553634745158742 51.31960823527,-0.553633367197649 51.3196064197807,-0.553631960967087 51.3196055031788,-0.55363201750624 51.3196037054037,-0.553632045775813 51.3196028065162,-0.553630611275787 51.3196027888019,-0.553627770545394 51.3196018544857,-0.553626364315083 51.3196009378838,-0.553624986354537 51.3195991223943,-0.553623580124365 51.3195982057924,-0.553622202164007 51.3195963903029,-0.553620824203759 51.3195945748134,-0.553619446243617 51.3195927593239,-0.553619474513426 51.3195918604364,-0.553619559322842 51.3195891637738,-0.553619587592645 51.3195882648862,-0.553619672402044 51.3195855682236,-0.55361970067184 51.3195846693361,-0.553621191710829 51.3195828892755,-0.553621248250356 51.3195810915004,-0.553622739289165 51.3195793114397,-0.553624202058157 51.3195784302666,-0.553627127595971 51.3195766679202,-0.553628590364795 51.3195757867471,-0.553630053133563 51.3195749055739,-0.553631515902274 51.3195740244006,-0.553685327352015 51.319551308741,-0.55370133298043 51.3195443124894,-0.553753709863687 51.3195215790843,-0.55378136104978 51.3195093311976,-0.553782795546986 51.31950934891,-0.553785721074355 51.3195075865597,-0.55378715557151 51.319507604272,-0.553791487329345 51.3195067585215,-0.553792921826478 51.3195067762338,-0.553795819087023 51.3195059127708,-0.553798688081244 51.3195059481953,-0.553801557075469 51.3195059836197,-0.553804397803593 51.3195069179317,-0.553807266797888 51.319506953356,-0.553808673029012 51.3195078699558,-0.55381294825461 51.3195088219796,-0.553814382751821 51.3195088396917,-0.553817195214528 51.319510672891,-0.553818601445965 51.3195115894906,-0.55381997941165 51.3195134049779,-0.553821385643225 51.3195143215775,-0.553822763609099 51.3195161370647,-0.553824169840814 51.3195170536642,-0.553825547806879 51.3195188691514,-0.553825519541172 51.3195197680391),(-0.553690895735613 51.3195567729209,-0.553637084282122 51.3195794885829,-0.553634187014011 51.319580352042,-0.553632695975607 51.3195821321028,-0.553631176667517 51.3195848110511,-0.553629685628849 51.3195865911119,-0.55362962908964 51.319588388887,-0.553629544280816 51.3195910855496,-0.553630922241311 51.319592901039,-0.553632300201912 51.3195947165284,-0.553635112662454 51.319596549732,-0.553636490623328 51.3195983652214,-0.55364076585361 51.3195993172515,-0.553640681045406 51.3196020139142,-0.553642059006661 51.3196038294034,-0.553643436968024 51.3196056448927,-0.553646249429675 51.3196074780961,-0.553649090160797 51.3196084124118,-0.553651902622843 51.3196102456151,-0.553654771623389 51.3196102810432,-0.55365907512422 51.3196103341852,-0.55366194412478 51.3196103696131,-0.553666275894546 51.3196095238673,-0.553669173163918 51.3196086604074,-0.553721550136729 51.3195859270177,-0.553738990271239 51.3195789484742,-0.553791395442429 51.3195553161649,-0.553820481137417 51.3195430859815,-0.55382337839976 51.3195422225178,-0.553824869429505 51.3195404424545,-0.553826360459134 51.3195386623911,-0.553827879754325 51.3195359834401,-0.553827936285678 51.3195341856649,-0.553828021082697 51.319531489002,-0.553826643116166 51.3195296735149,-0.553823830651931 51.3195278403158,-0.553822452685673 51.3195260248286,-0.553819611956 51.319525090517,-0.553816771226443 51.3195241562054,-0.553815336728752 51.3195241384934,-0.553815364994663 51.3195232396057,-0.55381542152648 51.3195214418305,-0.553814071826674 51.3195187274556,-0.553812693861069 51.3195169119683,-0.553809853132158 51.3195159776565,-0.553807040669427 51.319514144457,-0.553804199940804 51.319513210145,-0.553801359212298 51.319512275833,-0.553797055720372 51.3195122226964,-0.553794158459449 51.3195130861594,-0.55379128946479 51.3195130507348,-0.553788363937281 51.3195148130853,-0.553759278251948 51.3195270432609,-0.553706901365115 51.3195497766685,-0.553690895735613 51.3195567729209))
``````

I know that this is computationally possible as using tools such as FME I am able to use CentralLineReplacer that works very quickly and accurately however I do not want to use FME.

• It may be hard to reach a result as in your "split" example with PostGIS because that seems to be invalid as a polygon geometry because of ring self-intersection. But with a little gap between the ends it would be OK. The donut in your example could probably be handled by taking either outer or inner ring and using offset line but i fear that it is not good as a general solution. Feb 15 at 11:45
• @user30184 Yes, I fear the answer is that I need to push back on the initial dataset. Offsetting lines wont do it looking at the complex polygon and the fact that the polygon networks are rarely of a consistence width often tapering down. Feb 15 at 11:48
• What are the polygons (in real life), and why do you want to split/break them? Might help to understand your problem
– BERA
Feb 15 at 13:03
• @BERA They are buffered road networks that have been unionised, buffered and the the difference found so that we have a polygon representing 4 metres away and a 1 metre width. They need to be broken up so that we can perform an ST_ApproximateMedialAxis to understand a central line. This central is required to segment and split the network into 12m chunkcs Feb 15 at 13:57
• What about doing a 4.5m buffer from the original road network then? That would (almost) be the central line (except at the ends)
– JGH
Feb 15 at 14:02

So, in order to get the central axis of a polygon-donut, proceed as follows.

1. Create a custom function ST_MergingTwoIsolinesOneAverage() https://gis.stackexchange.com/a/375525/120129.

2. Run Spatial-SQL, while adjusting the required number of points (888 in my example):

``````WITH
tbla(geom) AS (SELECT ST_SETSrid(ST_Boundary('POLYGON((-0.553825519541172 51.3195197680391,-0.553828332004988 51.3195216012381,-0.553829766502607 51.31952161895,-0.553832578966705 51.3195234521489,-0.553833985198839 51.3195243687484,-0.553835334899984 51.3195270831231,-0.55383530663446 51.3195279820107,-0.553836684601286 51.3195297974977,-0.553836656335785 51.3195306963854,-0.553838006037268 51.31953341076,-0.553837977771789 51.3195343096477,-0.553837892975346 51.3195370063105,-0.553837864709861 51.3195379051982,-0.5538363736807 51.3195396852617,-0.553834882651423 51.3195414653251,-0.553833391622029 51.3195432453886,-0.553833363356451 51.3195441442762,-0.553830437828531 51.3195459066278,-0.553828975064486 51.3195467878035,-0.55382604953623 51.319548550155,-0.553798398338031 51.319560798052,-0.553744558664546 51.3195844126515,-0.553727118528775 51.3195913911958,-0.553674741552389 51.319614124588,-0.553673307051983 51.3196141068742,-0.55367040978234 51.3196149703342,-0.553668947013045 51.3196158515079,-0.553664615242729 51.3196166972538,-0.55366318074225 51.3196166795399,-0.553660311741293 51.319616644112,-0.553657442740343 51.319616608684,-0.553654573739398 51.319616573256,-0.55365170473846 51.3196165378279,-0.553648864006785 51.3196156035122,-0.553647429506348 51.3196155857981,-0.553644588774822 51.3196146514823,-0.55364174804341 51.3196137171664,-0.55364037008188 51.3196119016771,-0.553638963851011 51.3196109850754,-0.553636123119942 51.3196100507594,-0.553634745158742 51.31960823527,-0.553633367197649 51.3196064197807,-0.553631960967087 51.3196055031788,-0.55363201750624 51.3196037054037,-0.553632045775813 51.3196028065162,-0.553630611275787 51.3196027888019,-0.553627770545394 51.3196018544857,-0.553626364315083 51.3196009378838,-0.553624986354537 51.3195991223943,-0.553623580124365 51.3195982057924,-0.553622202164007 51.3195963903029,-0.553620824203759 51.3195945748134,-0.553619446243617 51.3195927593239,-0.553619474513426 51.3195918604364,-0.553619559322842 51.3195891637738,-0.553619587592645 51.3195882648862,-0.553619672402044 51.3195855682236,-0.55361970067184 51.3195846693361,-0.553621191710829 51.3195828892755,-0.553621248250356 51.3195810915004,-0.553622739289165 51.3195793114397,-0.553624202058157 51.3195784302666,-0.553627127595971 51.3195766679202,-0.553628590364795 51.3195757867471,-0.553630053133563 51.3195749055739,-0.553631515902274 51.3195740244006,-0.553685327352015 51.319551308741,-0.55370133298043 51.3195443124894,-0.553753709863687 51.3195215790843,-0.55378136104978 51.3195093311976,-0.553782795546986 51.31950934891,-0.553785721074355 51.3195075865597,-0.55378715557151 51.319507604272,-0.553791487329345 51.3195067585215,-0.553792921826478 51.3195067762338,-0.553795819087023 51.3195059127708,-0.553798688081244 51.3195059481953,-0.553801557075469 51.3195059836197,-0.553804397803593 51.3195069179317,-0.553807266797888 51.319506953356,-0.553808673029012 51.3195078699558,-0.55381294825461 51.3195088219796,-0.553814382751821 51.3195088396917,-0.553817195214528 51.319510672891,-0.553818601445965 51.3195115894906,-0.55381997941165 51.3195134049779,-0.553821385643225 51.3195143215775,-0.553822763609099 51.3195161370647,-0.553824169840814 51.3195170536642,-0.553825547806879 51.3195188691514,-0.553825519541172 51.3195197680391),(-0.553690895735613 51.3195567729209,-0.553637084282122 51.3195794885829,-0.553634187014011 51.319580352042,-0.553632695975607 51.3195821321028,-0.553631176667517 51.3195848110511,-0.553629685628849 51.3195865911119,-0.55362962908964 51.319588388887,-0.553629544280816 51.3195910855496,-0.553630922241311 51.319592901039,-0.553632300201912 51.3195947165284,-0.553635112662454 51.319596549732,-0.553636490623328 51.3195983652214,-0.55364076585361 51.3195993172515,-0.553640681045406 51.3196020139142,-0.553642059006661 51.3196038294034,-0.553643436968024 51.3196056448927,-0.553646249429675 51.3196074780961,-0.553649090160797 51.3196084124118,-0.553651902622843 51.3196102456151,-0.553654771623389 51.3196102810432,-0.55365907512422 51.3196103341852,-0.55366194412478 51.3196103696131,-0.553666275894546 51.3196095238673,-0.553669173163918 51.3196086604074,-0.553721550136729 51.3195859270177,-0.553738990271239 51.3195789484742,-0.553791395442429 51.3195553161649,-0.553820481137417 51.3195430859815,-0.55382337839976 51.3195422225178,-0.553824869429505 51.3195404424545,-0.553826360459134 51.3195386623911,-0.553827879754325 51.3195359834401,-0.553827936285678 51.3195341856649,-0.553828021082697 51.319531489002,-0.553826643116166 51.3195296735149,-0.553823830651931 51.3195278403158,-0.553822452685673 51.3195260248286,-0.553819611956 51.319525090517,-0.553816771226443 51.3195241562054,-0.553815336728752 51.3195241384934,-0.553815364994663 51.3195232396057,-0.55381542152648 51.3195214418305,-0.553814071826674 51.3195187274556,-0.553812693861069 51.3195169119683,-0.553809853132158 51.3195159776565,-0.553807040669427 51.319514144457,-0.553804199940804 51.319513210145,-0.553801359212298 51.319512275833,-0.553797055720372 51.3195122226964,-0.553794158459449 51.3195130861594,-0.55379128946479 51.3195130507348,-0.553788363937281 51.3195148130853,-0.553759278251948 51.3195270432609,-0.553706901365115 51.3195497766685,-0.553690895735613 51.3195567729209))'),4326))
SELECT ST_MergingTwoIsolinesOneAverage(ST_Union(geom), 888) geom FROM tbla
``````

Check the result, and if necessary, adjust the number of points, the more there are, the more accurate and smoother the result.

Remember, this geo-tool is not simple, and it can work with the boundaries of closed shapes like polygons-doughnuts among other things :-)...

Original spatial solutions...

Translated with www.DeepL.com/Translator (free version)

• Thank you, The function takes a little time to digest. I will read through and work and get back to you this evening. Feb 16 at 8:58
• Vector functions are indeed "heavy," but they are more reliable in their behavior... Feb 16 at 17:35
• Yes I agree. I avoid using alternative software like the plague and try to do everything using Vector Functions. I was not trained and not from a mathematical background so find it much better to learn. I am looking through now thank you. Feb 16 at 18:45
• 1) In this case there is no need to rush, 2) I think there are strengths and weaknesses in the application of both vector geometry and raster algebra, you just have to know how to use them correctly... Feb 16 at 19:23