Changeset 17185 in josm


Ignore:
Timestamp:
2020-10-13T11:57:39+02:00 (2 weeks ago)
Author:
GerdP
Message:

fix #19822: Inconsistent behavior with GeoJSON multipolygons
Handle care when one polygon is part of two(or more) multipolygons. e.g. serves as inner in relation A, but as a outer for relation B

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/GeoJSONReader.java

    r17131 r17185  
    433433        for (TestError e : test.getErrors()) {
    434434            if (e.getPrimitives().size() == 2 && !e.isFixable()) {
    435                 Way mpWay = null;
    436                 Way tagged = null;
     435                List<Way> mpWays = new ArrayList<>();
     436                Way replacement = null;
    437437                for (OsmPrimitive p : e.getPrimitives()) {
    438438                    if (p.isTagged() && p.referrers(Relation.class).count() == 0)
    439                         tagged = (Way) p;
     439                        replacement = (Way) p;
    440440                    else if (p.referrers(Relation.class).anyMatch(Relation::isMultipolygon))
    441                         mpWay = (Way) p;
    442                 }
    443                 if (mpWay != null && tagged != null) {
     441                        mpWays.add((Way) p);
     442                }
     443                if (replacement == null && mpWays.size() == 2) {
     444                    replacement = mpWays.remove(1);
     445                }
     446                if (replacement != null && mpWays.size() == 1) {
     447                    Way mpWay = mpWays.get(0);
    444448                    for (Relation r : mpWay.referrers(Relation.class).filter(Relation::isMultipolygon)
    445449                            .collect(Collectors.toList())) {
    446450                        for (int i = 0; i < r.getMembersCount(); i++) {
    447451                            if (r.getMember(i).getMember().equals(mpWay)) {
    448                                 r.setMember(i, new RelationMember(r.getRole(i), tagged));
     452                                r.setMember(i, new RelationMember(r.getRole(i), replacement));
    449453                            }
    450454                        }
  • trunk/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java

    r17131 r17185  
    198198                    new GeoJSONReader().doParseDataSet(in, null).getPrimitives(it -> true));
    199199            assertTrue(primitives.stream().anyMatch(p -> p instanceof Relation && p.isMultipolygon()));
     200            assertEquals(3, primitives.stream().filter(Way.class::isInstance).count());
     201        }
     202    }
     203
     204    /**
     205     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/19822">Bug #19822</a>.
     206     * @throws Exception in case of error
     207     */
     208    @Test
     209    public void testTicket19822Nested() throws Exception {
     210        try (InputStream in = TestUtils.getRegressionDataStream(19822, "problem3.geojson")) {
     211            final List<OsmPrimitive> primitives = new ArrayList<>(
     212                    new GeoJSONReader().doParseDataSet(in, null).getPrimitives(it -> true));
     213            assertTrue(primitives.stream().anyMatch(p -> p instanceof Relation && p.isMultipolygon()));
     214            assertEquals(3, primitives.stream().filter(Way.class::isInstance).count());
    200215        }
    201216    }
Note: See TracChangeset for help on using the changeset viewer.