Ticket #5179: osm-join-areas-6.6.1.patch

File osm-join-areas-6.6.1.patch, 4.0 KB (added by extropy, 16 years ago)

Separate multipolygon relations for each resulting multipolygon.

  • src/org/openstreetmap/josm/actions/JoinAreasAction.java

     
    500500        //find polygons
    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));
     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);
    507521        }
    508522
     523        commitCommands(marktr("Assemble new polygons"));
     524
    509525        // Delete the discarded inner ways
    510526        if (discardedWays.size() > 0) {
    511527            cmds.add(DeleteCommand.delete(Main.map.mapView.getEditLayer(), discardedWays, true));
     528            commitCommands(marktr("Delete Ways that are not part of an inner multipolygon"));
    512529        }
    513         commitCommands(marktr("Delete Ways that are not part of an inner multipolygon"));
    514530
    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         }
    520531
    521         commitCommands(marktr("Fix relations"));
    522 
    523         for (Multipolygon pol : polygons) {
    524             stripTags(pol.innerWays);
    525         }
    526 
    527532        makeCommitsOneAction(marktr("Joined overlapping areas"));
    528533
    529534        if (warnAboutRelations) {
     
    16291634     * @param Way The outer way
    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();
    16361641        newRel.put("type", "multipolygon");
     
    16401645        cmds.add(new AddCommand(newRel));
    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
    16491652
     
    16901693     * @param ArrayList<RelationRole> List of relations with roles the (original) ways were part of
    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 &&
    16971705                    r.rel.get("type").equalsIgnoreCase("multipolygon") &&