Modify

Opened 21 months ago

Last modified 11 days ago

#18295 reopened enhancement

Splitting large multipolygons

Reported by: anonymous Owned by: Don-vip
Priority: major Milestone:
Component: Plugin utilsplugin2 Version:
Keywords: multipolygon split Cc: pangoSE, Woazboat

Description (last modified by Don-vip)

I have tasked myself with splitting this beast into many multipolygons. The main reason is lower complexity and fewer members.

Is it possible to do this easily in JOSM?

I see that there is a plugin named RelationDisolve but no plugin for splitting relations.
---
Wish list:

  • Best: ability to automatically split into x relations (JOSM determines where to split them and generates the ways needed without crossing any inners)
  • Second best: Ability to split along selected way(s) and delete inners from the former relation and add them to the newly created relation.

Attachments (8)

sample.osm (3.3 KB) - added by GerdP 21 months ago.
polygon-split-error.png (301.2 KB) - added by pangoSE 18 months ago.
After joining the outer ways I tried splitting it with PolygonCutOut but got this error.
testcase1.osm (1.4 KB) - added by pangoSE 18 months ago.
1 relation and 1 closed way that can be split if the outer way and the closed way is selected and "Split Polygon" is invoked from the Tools menu.
testcase1.2.osm (1.5 KB) - added by pangoSE 18 months ago.
1 relation and 1 closed way that can be split if the outer way and the closed way is selected and "Cut Out Overlapping Polygons" is invoked from the Tools menu.
testcase2.osm (2.2 KB) - added by pangoSE 18 months ago.
cutTest.osm.bz2 (256.5 KB) - added by GerdP 18 months ago.
split_multipolygon_utilsplugin2.patch (21.0 KB) - added by Woazboat 4 weeks ago.
Patch for utilsplugin2 split object multipolygon support
josm_mp_split_v3-2021-07-07_00.15.43.mp4 (1.6 MB) - added by Woazboat 4 weeks ago.
Multipolygon splitting in action

Change History (59)

comment:1 Changed 21 months ago by GerdP

I don't know if it helps here but there is the plugin reltoolbox which seems to support splitting multipolygons.

comment:2 Changed 21 months ago by pangoSE

This ticket was made by me for the record.

@GerdP How? I use it since a few days and I have not found a way to split. It can duplicate and "reconstruct". Dunno what the last of those does.

Last edited 21 months ago by pangoSE (previous) (diff)

Changed 21 months ago by GerdP

Attachment: sample.osm added

comment:3 Changed 21 months ago by GerdP

I've never used it before, just found a source named SplittingMultipolygons.java
The support seems rather basic. Open the attached sample.osm and select the untagged way. When you click on the "multipolygon" button in the toolbox it splits the old mp and creates a new mp, but it doesn't take care about the inners. Maybe it can do more but I don't see how.

comment:4 in reply to:  2 Changed 21 months ago by Klumbumbus

Replying to pangoSE:

It can duplicate and "reconstruct". Dunno what the last of those does.

Reconstruct means if you select a multipolygon with no inners it transforms it into a simple single closed way. That even works if the outer consists of several consecutive outer ways.

comment:5 Changed 21 months ago by Don-vip

Description: modified (diff)

comment:6 Changed 21 months ago by Don-vip

Keywords: multipolygon split added

comment:7 in reply to:  3 Changed 21 months ago by pangoSE

Replying to GerdP:

I've never used it before, just found a source named SplittingMultipolygons.java
The support seems rather basic. Open the attached sample.osm and select the untagged way. When you click on the "multipolygon" button in the toolbox it splits the old mp and creates a new mp, but it doesn't take care about the inners. Maybe it can do more but I don't see how.

Are you sure it splits the old one? I cannot reproduce (it just creates a new mp using the shortest possible outer to join with - it did not touch the existing MP at all).

I'm missing a button named split here and some kind of dialog explaining what was done e.g.:
"Multipolygon named 'x' was split along the selected way:
Existing multipolygon now contains: 5 outer, 12 inners
Newly created multipolygon contains: 3 outer, 3 inners."

comment:8 Changed 21 months ago by Zverikk

Relation Toolbox cannot split multipolygons. The action mentioned is to create a multipolygon by using parts of existing MPs. To me, the best option would be to improve "Split polygon" action from the utilsplugin2.

comment:9 Changed 21 months ago by GerdP

Owner: changed from team to GerdP
Status: newassigned

Their are probably many obstacles, but I'll try to implement something for the easy cases where the selected cutting way doesn't touch (or cross) any inner of the existing mp first. Might take a while...

comment:10 in reply to:  9 Changed 21 months ago by pangoSE

Replying to GerdP:

Their are probably many obstacles, but I'll try to implement something for the easy cases where the selected cutting way doesn't touch (or cross) any inner of the existing mp first. Might take a while...

Wonderful! Thanks in advance. The case you mention is the only I think we should support. If the cutting way crosses an inner we just throw an error "Error: The selected way crosses an inner of the multipolygon."

comment:11 Changed 21 months ago by stoecker

But usually you want cutting through inners. Splitting should be naturally, e.g. along already existing features like roads or waterways. And then you'll cut through and obsolete some inners that now become normal outers. In this case the border of the new splitted MP should flow around the inner and the inner become independent.

comment:12 Changed 21 months ago by GerdP

Yes, sure, I have that in mind. I've done a few splits of huge MP some years ago and also missed support for it.
In fact it was one reason why I started to look at the code in JOSM.

comment:13 Changed 21 months ago by GerdP

Hmm, I think Dirk (stoecker) is right, the only reasonable way to split a big wood/forest MP is this:

  • Find one or more major roads or a river or a railway which connects the outer ring with one or more inners. An example might be the river Ätran described by relation 8928582 which cuts the given MP into two halves, or - probably better - some highways like O 1661 and O 1659 which "cut" a rather small triangle.
  • My next step would be to draw parallel ways (Shift+P)
  • Next would be to connect the inners next to those news ways and
  • finally remove the new distinct area from the MP. The validator helps to find the inners which are wrong.

I see no easy way to automate any of this besides the drawing of the parallel ways.

comment:14 Changed 21 months ago by Klumbumbus

Please don't encourage the users to "glue" area featues to linear feature, like landuse on streets. That's considered as bad tagging style by the majority of users.

comment:15 in reply to:  14 Changed 21 months ago by stoecker

Replying to Klumbumbus:

Please don't encourage the users to "glue" area featues to linear feature, like landuse on streets. That's considered as bad tagging style by the majority of users.

I'm still not convinced that's true. It's considered bad by the loudest yelling users. I know a lot of people (including myself) who simply don't argue anymore, but who find that mapping style with empty zones around roads extremly ugly and also strange from a geodetic viewpoint.

comment:16 Changed 21 months ago by GerdP

I don't see where I encouraged the glueing?

comment:17 in reply to:  16 Changed 21 months ago by Klumbumbus

Replying to GerdP:

I don't see where I encouraged the glueing?

Splitting the forrest at the Ätran or O 1661/1659 ways sounded like glueing to me, but I missunderstood.

Last edited 21 months ago by Klumbumbus (previous) (diff)

comment:18 Changed 20 months ago by GerdP

@anonym: I just noticed that there is a plugin PolygonCutOut which is described as "Plugin for splitting and cutting out (multi)polygons" It seems to do what you want as long as the outer ring is a single (closed) way.
Edit: It cannot handle multipolygons with any unclosed ways. You "beast" has a few of them. So, first step to use this plugin would be to combine the ways that build closed rings (inner and outer).

Last edited 20 months ago by GerdP (previous) (diff)

comment:19 Changed 20 months ago by GerdP

Resolution: othersoftware
Status: assignedclosed

comment:20 in reply to:  18 ; Changed 19 months ago by pangoSE

Replying to GerdP:

@anonym: I just noticed that there is a plugin PolygonCutOut which is described as "Plugin for splitting and cutting out (multi)polygons" It seems to do what you want as long as the outer ring is a single (closed) way.
Edit: It cannot handle multipolygons with any unclosed ways. You "beast" has a few of them. So, first step to use this plugin would be to combine the ways that build closed rings (inner and outer).

Perfect. Thanks! Please change the reporter to my username so that I get notified if anything changes.

comment:21 Changed 19 months ago by GerdP

Cc: pangoSE added

Changed 18 months ago by pangoSE

Attachment: polygon-split-error.png added

After joining the outer ways I tried splitting it with PolygonCutOut but got this error.

comment:22 Changed 18 months ago by GerdP

Yep, got the same. You have to close all rings, not just the outer ones.

comment:23 Changed 18 months ago by pangoSE

All inner rings you mean? I joined them and I still get the same error. I'm not sure this plugin is capable of splitting with an unclosed way ending in both ends on the outer way of the polygon to be split.

The errors are really cryptic. "Please select at least one way" (I had 1 way and 1 relation selected). The documentation is non-existant.

I got this working:

  • testcase1.2.osm (1 closed way inside 1 relation which borders on 2 sides with the outer of the relation) -> 3 ways - Nice!
  • testcase2.osm (1 closed way inside 1 relation which borders on 2 sides with the outer of the relation, the relation has an inner) -> 2 ways + 1 relation with an inner - Really nice!
Last edited 18 months ago by pangoSE (previous) (diff)

Changed 18 months ago by pangoSE

Attachment: testcase1.osm added

1 relation and 1 closed way that can be split if the outer way and the closed way is selected and "Split Polygon" is invoked from the Tools menu.

Changed 18 months ago by pangoSE

Attachment: testcase1.2.osm added

1 relation and 1 closed way that can be split if the outer way and the closed way is selected and "Cut Out Overlapping Polygons" is invoked from the Tools menu.

Changed 18 months ago by pangoSE

Attachment: testcase2.osm added

comment:24 Changed 18 months ago by GerdP

It still works for me, but I don't try to cut out a polygon. I just draw a way which connects two nodes of the outer ring and select that way.

comment:25 in reply to:  24 Changed 18 months ago by pangoSE

Replying to GerdP:

It still works for me, but I don't try to cut out a polygon. I just draw a way which connects two nodes of the outer ring and select that way.

Nice that it works for you. I just decided splitting the beast manually was probably easier for me than wrestling yet another tool (without clear documentation).

If you care to give a working example of this succesful split, I would be happy if you could do that in the JOSM wiki or here: https://wiki.openstreetmap.org/wiki/PolygonCutOut.

My way of splitting manually was this:

  • download the polygon and all the members in a new layer
  • decide where to split and add a way that ends in 2 places on the outer ring
  • cut the 2 places with the Knife tool from auto_tools
  • select the polygon to be cut in the reltoolbox
  • (using reltoolbox) add the new way as outer, remove the outers that are no longer applicable
  • run the validator
  • the validator returns a perfect list of inners to create the new polygon from :)
  • select the offending inners
  • (in reltoolbox) create polygon
  • (in reltoolbox) add the outers to the new relation
  • select the offending inners again
  • open the relation editor of the original polyton and remove them from the relation
  • run validator and fix any errors
  • upload

Changed 18 months ago by GerdP

Attachment: cutTest.osm.bz2 added

comment:26 Changed 18 months ago by GerdP

Attached sample uses your "beast". I used this search clause to find the unclosed rings:

(role:inner or role:outer)  -closed

After closing all the rings I create the "cut way" in the upper part. Next I select that way and use "Split Polygon"
Result are two multipolygons, each with the correct inners.

Last edited 18 months ago by GerdP (previous) (diff)

comment:27 in reply to:  20 Changed 18 months ago by skyper

Replying to pangoSE:

Perfect. Thanks! Please change the reporter to my username so that I get notified if anything changes.

Note: You can add username to cc: under modify ticket. Commenting on a ticket should do the trick, too.

comment:28 Changed 10 months ago by pch14@…

Perhaps easier? Rundown below

  • Menu Download Object: paste number of MP-Relation, select: new layer; incl. members etc
  • combine outer ring (C) (110 km long)
  • draw path to split outer ring
  • select outer ring and splitting path
  • remove relation from the new object (alt-shift-G)
  • validate
  • remove relation from the erroneous members reported (alt-shift-G)
  • shift select new object
  • Menu make relation (crtl-B)
  • Add properties same as other relation
  • validate
  • no errors

Should I trust that no hidden spoilers came out of this? The large MP truly sucks ;) Defers tile rendering for weeks! Simple edits appear to touch a very large area, …

Hmm: one "outer" member of the new MP is actually inside of an inner member of the old MP, so it does not get moved to the right MP! But it does not get reported as an error… Can correct individually

comment:29 in reply to:  28 Changed 10 months ago by anonymous

Replying to pch14@…:

Perhaps easier? Rundown below

  • Menu Download Object: paste number of MP-Relation, select: new layer; incl. members etc
  • combine outer ring (C) (110 km long)

There may be problems with this - ways in the outer ring may belong to other adjacent features/multipolygons - better not combine, rather partition (P) the outer ring where the split shall happen and stitch the gap manually

comment:30 Changed 8 months ago by anonymous

Just want to chime in and say that this would be a very welcome feature. When you start to work with complex nature, possibly partly imported, you often get large multipolygons. I recently got one with over 4000 inners inside a national park. As water and wetlands etc are nowadays expected to be inners of surrounding forests any mapping attempt aiming for complete land cover will have a challenge of managing multipolygons.

I've tried the existing tools, but as outlined above they only work for limited types of multipolygons. To avoid lots of duplicated ways many multipolygons are often designed such that they share ways with neighboring multipolygons, and thus get their outers split in multiple segments. It seems like the current cutting tools don't manage that type of polygon.

Changed 4 weeks ago by Woazboat

Patch for utilsplugin2 split object multipolygon support

comment:31 Changed 4 weeks ago by skyper

Component: CorePlugin utilsplugin2
Resolution: othersoftware
Status: closedreopened
Summary: Splitting large multipolygons[Patch] Splitting large multipolygons

comment:32 Changed 4 weeks ago by skyper

Cc: Woazboat added
Owner: changed from GerdP to team
Status: reopenednew

comment:33 Changed 4 weeks ago by Woazboat

Cc: Woazboat removed
Component: Plugin utilsplugin2Core
Summary: [Patch] Splitting large multipolygonsSplitting large multipolygons

I've added support for splitting multipolygons to the utilsplugin2 split object action (see the attached patch).

What this enhancement adds:

  • Multipolygons can be split along a selected way that bisects the multipolygon and connects to the outer ring
  • Inners are automatically assigned to the appropriate multipolygon
  • Also works when the outer ring consists of multiple ways
  • Warns user and doesn't perform split by default if the resulting multipolygons would be invalid (can be allowed via a preference flag, user is still prompted to fix occurring errors)

Limitations:

  • Cannot split multipolygons with multiple outer rings (this is supported by the code on a technical level, but has been disabled intentionally to prevent fragmentation since the assignment of multipolygon parts is essentially unpredictable and could lead to small disconnected slices floating around)
  • Split way must not connect to or intersect inners (this would require conversion of inners to outers which is not implemented)
  • Split way relation member is not added in-order to be contiguous with the rest of the outer ring but simply appended
  • It is undetermined wich multipolygon part retains the old history/id and which one is created as a new relation (this could/should be improved so that e.g. the larger multipolygon retains the history)

Thanks for updating the ticket @skyper

Last edited 4 weeks ago by Woazboat (previous) (diff)

comment:34 Changed 4 weeks ago by Woazboat

Cc: Woazboat added

comment:35 Changed 4 weeks ago by Woazboat

Component: CorePlugin utilsplugin2
Summary: Splitting large multipolygons[Patch] Splitting large multipolygons

Changed 4 weeks ago by Woazboat

Multipolygon splitting in action

comment:36 Changed 3 weeks ago by pangoSE

Fantastic work @woazboat! I'm looking forward to try this in action and split the huge ones in Sweden 😃

comment:37 Changed 2 weeks ago by bagage

That's indeed a really nice improvement :). Thrilled to try it as well - if a .jar is available somewhere to try it early it'd be very nice!

comment:38 Changed 2 weeks ago by Don-vip

Owner: changed from team to Don-vip
Priority: normalmajor
Status: newassigned

comment:39 Changed 2 weeks ago by Don-vip

Resolution: fixed
Status: assignedclosed

In 35792/osm:

fix #18295 - add support for splitting multipolygons to the utilsplugin2 split object action (patch by Woazboat)

What this enhancement adds:

  • Multipolygons can be split along a selected way that bisects the multipolygon and connects to the outer ring
  • Inners are automatically assigned to the appropriate multipolygon
  • Also works when the outer ring consists of multiple ways
  • Warns user and doesn't perform split by default if the resulting multipolygons would be invalid (can be allowed via a preference flag, user is still prompted to fix occurring errors)

Limitations:

  • Cannot split multipolygons with multiple outer rings (this is supported by the code on a technical level, but has been disabled intentionally to prevent fragmentation since the assignment of multipolygon parts is essentially unpredictable and could lead to small disconnected slices floating around)
  • Split way must not connect to or intersect inners (this would require conversion of inners to outers which is not implemented)
  • Split way relation member is not added in-order to be contiguous with the rest of the outer ring but simply appended
  • It is undetermined wich multipolygon part retains the old history/id and which one is created as a new relation (this could/should be improved so that e.g. the larger multipolygon retains the history)

comment:40 Changed 2 weeks ago by Don-vip

In 35793/osm:

see #18295 - dist

comment:41 Changed 2 weeks ago by Don-vip

Thanks for the patch!

comment:42 Changed 2 weeks ago by GerdP

Something seems to be wrong with the command stack. I've got to undo multiple steps. Is that intended?

comment:43 Changed 2 weeks ago by Woazboat

Not intended as such but rather a consequence of:

1) The split way command that is used to split the outer ways needs to be applied immediately before any further splits can be made, otherwise it would mess up the relation members.
2) The already applied SplitWayCommands cannot be added to the SequenceCommand since there is no way to prevent them from being applied again.

This could be solved by either modifying SequenceCommand so that commands can be applied selectively/marked as already executed (similar to how already executed commands can be added to the UndoRedoHandler), or implementing a new command type for this special case.

comment:44 Changed 2 weeks ago by GerdP

Yes, see e.g. usage of JoinAreaCommand in JoinAreasAction

comment:45 Changed 12 days ago by skyper

Resolution: fixed
Status: closedreopened
Summary: [Patch] Splitting large multipolygonsSplitting large multipolygons

Thanks a lot for this new feature.
There is another minor issue.
Similar to closed ways, the relation part can only split at one way. But unlike the action with a closed way, which does nothing, the action with relation is executed using only one of the selected "split" ways. Can we, please, get the same behavior in all cases. Best would be a notification about the incorrect selection in both situations.

comment:46 Changed 12 days ago by skyper

Oh no, playing around with this action including redo/undo and Undo Selection I get warnings on the console:

- 00590.784 E: java.lang.IllegalStateException: JOSM expected to find primitive [relation -99761] in dataset but it is not there. Please report this at https://josm.openstreetmap.de. This is not a critical error, it should be safe to continue in your work.

comment:47 Changed 12 days ago by skyper

I've started to document this action by creating the wiki page. Hope I got everything right (diff).

comment:48 Changed 12 days ago by mdk

For closed ways it works also when you select a way and two nodes of that way.
And it also works if you select only two nodes of a closed way.
And it also works if the selected nodes belongs to more than one way, as long as there is only one way which contains both nodes.

comment:49 in reply to:  46 Changed 11 days ago by skyper

Replying to skyper:

Oh no, playing around with this action including redo/undo and Undo Selection I get warnings on the console:

- 00590.784 E: java.lang.IllegalStateException: JOSM expected to find primitive [relation -99761] in dataset but it is not there. Please report this at https://josm.openstreetmap.de. This is not a critical error, it should be safe to continue in your work.

Grr, sorry, this is a problem of Undo Selection, see #21152.

comment:50 in reply to:  48 Changed 11 days ago by skyper

Replying to mdk:

For closed ways it works also when you select a way and two nodes of that way.
And it also works if you select only two nodes of a closed way.
And it also works if the selected nodes belongs to more than one way, as long as there is only one way which contains both nodes.

Thanks, played around a little more and tried my best: diff
Found some bugs meanwhile, where the multipolygon parts suffers from #21153 but not from #21154.

comment:51 Changed 11 days ago by skyper

Mmh, splitting "outer" ways completely out of download area or without any download area can become dangerous. Hope users download all parents in advance.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as reopened The owner will remain Don-vip.
as The resolution will be set.
to The owner will be changed from Don-vip to the specified user.
The owner will change to anonymous
as duplicate The resolution will be set to duplicate.The specified ticket will be cross-referenced with this ticket

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.