Modify

Opened 4 years ago

Last modified 2 years ago

#18295 reopened enhancement

[Patch] 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 (10)

sample.osm (3.3 KB ) - added by GerdP 4 years ago.
polygon-split-error.png (301.2 KB ) - added by pangoSE 4 years ago.
After joining the outer ways I tried splitting it with PolygonCutOut but got this error.
testcase1.osm (1.4 KB ) - added by pangoSE 4 years 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 4 years 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 4 years ago.
cutTest.osm.bz2 (256.5 KB ) - added by GerdP 4 years ago.
split_multipolygon_utilsplugin2.patch (21.0 KB ) - added by Woazboat 3 years 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 3 years ago.
Multipolygon splitting in action
split_multipolygon_utilsplugin2_fix_2021-08-02.patch (6.1 KB ) - added by Woazboat 3 years ago.
Fix: prevent mp split with multiple split ways selected + combine into one undo/redo action
utilsplugin2_mp_split_selection_enable_fix_2022-03-06.patch (1.0 KB ) - added by Woazboat 2 years ago.
Extract fix 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. into separate patch

Change History (66)

comment:1 by GerdP, 4 years ago

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

comment:2 by pangoSE, 4 years ago

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 4 years ago by pangoSE (previous) (diff)

by GerdP, 4 years ago

Attachment: sample.osm added

comment:3 by GerdP, 4 years ago

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.

in reply to:  2 comment:4 by Klumbumbus, 4 years ago

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 by Don-vip, 4 years ago

Description: modified (diff)

comment:6 by Don-vip, 4 years ago

Keywords: multipolygon split added

in reply to:  3 comment:7 by pangoSE, 4 years ago

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 by Zverikk, 4 years ago

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 by GerdP, 4 years ago

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...

in reply to:  9 comment:10 by pangoSE, 4 years ago

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 by stoecker, 4 years ago

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 by GerdP, 4 years ago

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 by GerdP, 4 years ago

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 by Klumbumbus, 4 years ago

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.

in reply to:  14 comment:15 by stoecker, 4 years ago

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 by GerdP, 4 years ago

I don't see where I encouraged the glueing?

in reply to:  16 comment:17 by Klumbumbus, 4 years ago

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 4 years ago by Klumbumbus (previous) (diff)

comment:18 by GerdP, 4 years ago

@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 4 years ago by GerdP (previous) (diff)

comment:19 by GerdP, 4 years ago

Resolution: othersoftware
Status: assignedclosed

in reply to:  18 ; comment:20 by pangoSE, 4 years ago

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 by GerdP, 4 years ago

Cc: pangoSE added

by pangoSE, 4 years ago

Attachment: polygon-split-error.png added

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

comment:22 by GerdP, 4 years ago

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

comment:23 by pangoSE, 4 years ago

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.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!
Version 2, edited 4 years ago by pangoSE (previous) (next) (diff)

by pangoSE, 4 years ago

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.

by pangoSE, 4 years ago

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.

by pangoSE, 4 years ago

Attachment: testcase2.osm added

comment:24 by GerdP, 4 years ago

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.

in reply to:  24 comment:25 by pangoSE, 4 years ago

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

by GerdP, 4 years ago

Attachment: cutTest.osm.bz2 added

comment:26 by GerdP, 4 years ago

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 4 years ago by GerdP (previous) (diff)

in reply to:  20 comment:27 by skyper, 4 years ago

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 by pch14@…, 4 years ago

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

in reply to:  28 comment:29 by anonymous, 4 years ago

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 by anonymous, 3 years ago

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.

by Woazboat, 3 years ago

Patch for utilsplugin2 split object multipolygon support

comment:31 by skyper, 3 years ago

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

comment:32 by skyper, 3 years ago

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

comment:33 by Woazboat, 3 years ago

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 3 years ago by Woazboat (previous) (diff)

comment:34 by Woazboat, 3 years ago

Cc: Woazboat added

comment:35 by Woazboat, 3 years ago

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

by Woazboat, 3 years ago

Multipolygon splitting in action

comment:36 by pangoSE, 3 years ago

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

comment:37 by bagage, 3 years ago

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 by Don-vip, 3 years ago

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

comment:39 by Don-vip, 3 years ago

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 by Don-vip, 3 years ago

In 35793/osm:

see #18295 - dist

comment:41 by Don-vip, 3 years ago

Thanks for the patch!

comment:42 by GerdP, 3 years ago

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

comment:43 by Woazboat, 3 years ago

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 by GerdP, 3 years ago

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

comment:45 by skyper, 3 years ago

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 by skyper, 3 years ago

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 by skyper, 3 years ago

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

comment:48 by mdk, 3 years ago

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.

in reply to:  46 comment:49 by skyper, 3 years ago

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.

in reply to:  48 comment:50 by skyper, 3 years ago

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 by skyper, 3 years ago

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

by Woazboat, 3 years ago

Fix: prevent mp split with multiple split ways selected + combine into one undo/redo action

in reply to:  42 ; comment:52 by Woazboat, 3 years ago

Summary: Splitting large multipolygons[Patch] Splitting large multipolygons

Replying to GerdP:

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

Replying to skyper:

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.

These issues have been fixed in the new patch I attached

in reply to:  52 comment:53 by skyper, 3 years ago

Replying to Woazboat:

Replying to GerdP:

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

AFAIK, this is also a problem with splitting closed ways, New ticket?

These issues have been fixed in the new patch I attached

Thanks. Everything else can be handled in new tickets, I guess.

comment:54 by GerdP, 2 years ago

AFAIK, this is also a problem with splitting closed ways, New ticket?

See #21491

comment:55 by skyper, 2 years ago

Ping

by Woazboat, 2 years ago

Extract fix 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. into separate patch

in reply to:  52 comment:56 by Woazboat, 2 years ago

Replying to Woazboat:

Replying to GerdP:

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

Replying to skyper:

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.

These issues have been fixed in the new patch I attached

I separated the second part of this fix into a separate patch since the first part has already been fixed in [35842/osm]

Modify Ticket

Change Properties
Set your email in Preferences
Action
as reopened The owner will remain Don-vip.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from Don-vip to the specified user. Next status will be 'new'.
Next status will be 'needinfo'. The owner will be changed from Don-vip to anonymous.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. 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.