Opened 5 years ago
Last modified 3 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 )
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)
Change History (66)
comment:1 by , 5 years ago
follow-up: 4 comment:2 by , 5 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.
by , 5 years ago
Attachment: | sample.osm added |
---|
follow-up: 7 comment:3 by , 5 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.
comment:4 by , 5 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 , 5 years ago
Description: | modified (diff) |
---|
comment:6 by , 5 years ago
Keywords: | multipolygon split added |
---|
comment:7 by , 5 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 , 5 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.
follow-up: 10 comment:9 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
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 by , 5 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 , 5 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 , 5 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 , 5 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.
follow-up: 15 comment:14 by , 5 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.
comment:15 by , 5 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:17 by , 5 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.
follow-up: 20 comment:18 by , 5 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).
comment:19 by , 5 years ago
Resolution: | → othersoftware |
---|---|
Status: | assigned → closed |
follow-up: 27 comment:20 by , 5 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 , 5 years ago
Cc: | added |
---|
by , 5 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 , 5 years ago
Yep, got the same. You have to close all rings, not just the outer ones.
comment:23 by , 5 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.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!
by , 5 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 , 5 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 , 5 years ago
Attachment: | testcase2.osm added |
---|
follow-up: 25 comment:24 by , 5 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.
comment:25 by , 5 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 , 5 years ago
Attachment: | cutTest.osm.bz2 added |
---|
comment:26 by , 5 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.
comment:27 by , 5 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.
follow-up: 29 comment:28 by , 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
comment:29 by , 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 , 4 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 , 4 years ago
Attachment: | split_multipolygon_utilsplugin2.patch added |
---|
Patch for utilsplugin2 split object multipolygon support
comment:31 by , 4 years ago
Component: | Core → Plugin utilsplugin2 |
---|---|
Resolution: | othersoftware |
Status: | closed → reopened |
Summary: | Splitting large multipolygons → [Patch] Splitting large multipolygons |
comment:32 by , 4 years ago
Cc: | added |
---|---|
Owner: | changed from | to
Status: | reopened → new |
comment:33 by , 4 years ago
Cc: | removed |
---|---|
Component: | Plugin utilsplugin2 → Core |
Summary: | [Patch] Splitting large multipolygons → Splitting 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
comment:34 by , 4 years ago
Cc: | added |
---|
comment:35 by , 4 years ago
Component: | Core → Plugin utilsplugin2 |
---|---|
Summary: | Splitting large multipolygons → [Patch] Splitting large multipolygons |
by , 4 years ago
Attachment: | josm_mp_split_v3-2021-07-07_00.15.43.mp4 added |
---|
Multipolygon splitting in action
comment:36 by , 4 years ago
Fantastic work @woazboat! I'm looking forward to try this in action and split the huge ones in Sweden 😃
comment:37 by , 4 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 , 4 years ago
Owner: | changed from | to
---|---|
Priority: | normal → major |
Status: | new → assigned |
follow-up: 52 comment:42 by , 4 years ago
Something seems to be wrong with the command stack. I've got to undo multiple steps. Is that intended?
comment:43 by , 4 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:45 by , 4 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Summary: | [Patch] Splitting large multipolygons → Splitting 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.
follow-up: 49 comment:46 by , 4 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 , 4 years ago
I've started to document this action by creating the wiki page. Hope I got everything right (diff).
follow-up: 50 comment:48 by , 4 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.
comment:49 by , 4 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.
comment:50 by , 4 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 , 4 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 , 4 years ago
Attachment: | split_multipolygon_utilsplugin2_fix_2021-08-02.patch added |
---|
Fix: prevent mp split with multiple split ways selected + combine into one undo/redo action
follow-ups: 53 56 comment:52 by , 4 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
comment:53 by , 4 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 , 3 years ago
AFAIK, this is also a problem with splitting closed ways, New ticket?
See #21491
by , 3 years ago
Attachment: | utilsplugin2_mp_split_selection_enable_fix_2022-03-06.patch added |
---|
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
comment:56 by , 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?
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]
I don't know if it helps here but there is the plugin reltoolbox which seems to support splitting multipolygons.