Changeset 3595 in josm


Ignore:
Timestamp:
2010-10-09T07:49:39+02:00 (14 years ago)
Author:
bastiK
Message:

applied #5179 (patch by bilbo) - Join overlapping areas / Separate multipolygon relations for each resulting multipolygon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r3554 r3595  
    501501        List<AssembledMultipolygon> preparedPolygons = findPolygons(bounadries);
    502502
    503         //assemble final ways
     503        //assemble final polygons
    504504        List<Multipolygon> polygons = new ArrayList<Multipolygon>();
    505505        for (AssembledMultipolygon pol : preparedPolygons) {
    506             polygons.add(joinPolygon(pol));
    507         }
     506
     507            //create the new ways
     508            Multipolygon resultPol = joinPolygon(pol);
     509
     510            //create multipolygon relation, if necessary.
     511            RelationRole ownMultipolygonRelation = addOwnMultigonRelation(resultPol.innerWays, resultPol.outerWay);
     512
     513            //add back the original relations, merged with our new multipolygon relation
     514            fixRelations(relations, resultPol.outerWay, ownMultipolygonRelation);
     515
     516            //strip tags from inner ways
     517            //TODO: preserve tags on existing inner ways
     518            stripTags(resultPol.innerWays);
     519
     520            polygons.add(resultPol);
     521        }
     522
     523        commitCommands(marktr("Assemble new polygons"));
    508524
    509525        // Delete the discarded inner ways
    510526        if (discardedWays.size() > 0) {
    511527            cmds.add(DeleteCommand.delete(Main.map.mapView.getEditLayer(), discardedWays, true));
    512         }
    513         commitCommands(marktr("Delete Ways that are not part of an inner multipolygon"));
    514 
    515         // We can attach our new multipolygon relation and pretend it has always been there
    516         for (Multipolygon pol : polygons) {
    517             addOwnMultigonRelation(pol.innerWays, pol.outerWay, relations);
    518             fixRelations(relations, pol.outerWay);
    519         }
    520 
    521         commitCommands(marktr("Fix relations"));
    522 
    523         for (Multipolygon pol : polygons) {
    524             stripTags(pol.innerWays);
    525         }
     528            commitCommands(marktr("Delete Ways that are not part of an inner multipolygon"));
     529        }
     530
    526531
    527532        makeCommitsOneAction(marktr("Joined overlapping areas"));
     
    16301635     * @param ArrayList<RelationRole> The list of relation with roles to add own relation to
    16311636     */
    1632     private void addOwnMultigonRelation(Collection<Way> inner, Way outer, ArrayList<RelationRole> rels) {
    1633         if (inner.size() == 0) return;
     1637    private RelationRole addOwnMultigonRelation(Collection<Way> inner, Way outer) {
     1638        if (inner.size() == 0) return null;
    16341639        // Create new multipolygon relation and add all inner ways to it
    16351640        Relation newRel = new Relation();
     
    16411646
    16421647        // We don't add outer to the relation because it will be handed to fixRelations()
    1643         // which will then do the remaining work. Collections are passed by reference, so no
    1644         // need to return it
    1645         rels.add(new RelationRole(newRel, "outer"));
    1646         //return rels;
     1648        // which will then do the remaining work.
     1649        return new RelationRole(newRel, "outer");
    16471650    }
    16481651
     
    16911694     * @param Way The newly created outer area/way
    16921695     */
    1693     private void fixRelations(ArrayList<RelationRole> rels, Way outer) {
     1696    private void fixRelations(ArrayList<RelationRole> rels, Way outer, RelationRole ownMultipol) {
    16941697        ArrayList<RelationRole> multiouters = new ArrayList<RelationRole>();
     1698
     1699        if (ownMultipol != null){
     1700            multiouters.add(ownMultipol);
     1701        }
     1702
    16951703        for (RelationRole r : rels) {
    16961704            if (r.rel.get("type") != null &&
Note: See TracChangeset for help on using the changeset viewer.