Skip to content

Commit

Permalink
Overlapping allowed in AtlasEntityPolygonsFilter (#182)
Browse files Browse the repository at this point in the history
* Overlapping allowed

* Removing extra function

* remove test
  • Loading branch information
jklamer authored and matthieun committed Jul 27, 2018
1 parent 3740c67 commit 16916b4
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.openstreetmap.atlas.geography.Polygon;
import org.openstreetmap.atlas.geography.atlas.items.AtlasEntity;
import org.openstreetmap.atlas.geography.converters.PolygonStringFormat;
import org.openstreetmap.atlas.geography.index.QuadTree;
import org.openstreetmap.atlas.geography.index.RTree;
import org.openstreetmap.atlas.utilities.configuration.Configuration;
import org.slf4j.Logger;
Expand Down Expand Up @@ -145,43 +144,6 @@ private static List<Polygon> getPolygonsFromFormatMap(
.collect(Collectors.toList());
}

private static Predicate<GeometricSurface> notOverlappingSurfaces(final Type polygonType)
{
final QuadTree<GeometricSurface> vettedSurfaces = new QuadTree<>();
return geometricSurface ->
{
if (vettedSurfaces.get(geometricSurface.bounds()).stream()
.noneMatch(surfaceOverlappingPredicate(geometricSurface)))
{
vettedSurfaces.add(geometricSurface.bounds(), geometricSurface);
return true;
}
else
{
logger.warn("Dropping {} GeometricSurface {}", polygonType, geometricSurface);
return false;
}
};
}

private static Predicate<GeometricSurface> surfaceOverlappingPredicate(
final GeometricSurface geometricSurface)
{
if (geometricSurface instanceof MultiPolygon)
{
return surface -> surface.overlaps((MultiPolygon) geometricSurface);
}
else if (geometricSurface instanceof Polygon)
{
return surface -> surface.overlaps((Polygon) geometricSurface);
}
else
{
logger.warn("Unrecognized GeometricSurface {}", geometricSurface);
return surface -> false;
}
}

private AtlasEntityPolygonsFilter(final Type filterType,
final Collection<? extends GeometricSurface> geometricSurfaces)
{
Expand All @@ -196,9 +158,7 @@ private AtlasEntityPolygonsFilter(final Type filterType,
this.filterType = filterType;
this.intersectionPolicy = intersectionPolicy;
this.geometricSurfaces = (RTree<GeometricSurface>) RTree
.forLocated(geometricSurfaces == null ? Collections.EMPTY_SET
: geometricSurfaces.stream().filter(notOverlappingSurfaces(this.filterType))
.collect(Collectors.toSet()));
.forLocated(geometricSurfaces == null ? Collections.EMPTY_SET : geometricSurfaces);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,40 +430,6 @@ public void testMultiPolygonForms()
3, 1, -1, -1);
}

@Test
public void testOverlappingPolygons()
{
final Atlas testOverlappingPolygonsAtlas = this.setup.getOverlappingPolygons();
final Polygon polygon1 = this.getPolygonWithName(testOverlappingPolygonsAtlas, "polygon1");
final Polygon polygon2 = this.getPolygonWithName(testOverlappingPolygonsAtlas, "polygon2");
final Polygon polygon3 = this.getPolygonWithName(testOverlappingPolygonsAtlas, "polygon3");
final Polygon polygon4 = this.getPolygonWithName(testOverlappingPolygonsAtlas, "polygon4");
final Polygon polygon5 = this.getPolygonWithName(testOverlappingPolygonsAtlas, "polygon5");
final MultiMap<Polygon, Polygon> multiPolygonMap1 = new MultiMap<>();
final MultiMap<Polygon, Polygon> multiPolygonMap2 = new MultiMap<>();
multiPolygonMap1.add(polygon3, polygon4);
multiPolygonMap2.add(polygon5, polygon2);

final MultiPolygon multiPolygon1 = new MultiPolygon(multiPolygonMap1);
final MultiPolygon multiPolygon2 = new MultiPolygon(multiPolygonMap2);

// Test overlapping polygons
this.assertCounts(testOverlappingPolygonsAtlas, AtlasEntityPolygonsFilter.Type.INCLUDE
.polygons(Arrays.asList(polygon1, polygon2, polygon3)), 2, 4, -1, -1);
this.assertCounts(testOverlappingPolygonsAtlas, AtlasEntityPolygonsFilter.Type.INCLUDE
.polygons(Arrays.asList(polygon2, polygon1, polygon3)), 4, 5, -1, -1);
this.assertCounts(testOverlappingPolygonsAtlas,
AtlasEntityPolygonsFilter.Type.INCLUDE.polygonsAndMultiPolygons(
Arrays.asList(polygon1, polygon2), Collections.singleton(multiPolygon1)),
2, 4, -1, -1);

// Test overlapping multipolygons
this.assertCounts(testOverlappingPolygonsAtlas, AtlasEntityPolygonsFilter.Type.INCLUDE
.multiPolygons(Arrays.asList(multiPolygon1, multiPolygon2)), 0, 3, -1, -1);
this.assertCounts(testOverlappingPolygonsAtlas, AtlasEntityPolygonsFilter.Type.INCLUDE
.multiPolygons(Arrays.asList(multiPolygon2, multiPolygon1)), 1, 6, -1, -1);
}

private void assertCounts(final Atlas atlas, final Predicate<AtlasEntity> filter,
final long expectedPointCount, final long expectedLineCount,
final long expectedAreaCount, final long expectedRelationCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public class AtlasEntityPolygonsFilterTestRule extends CoreTestRule
private Atlas includeExcludeArrangements;
@TestAtlas(loadFromJosmOsmResource = "multiPolygons.osm")
private Atlas multiPolygons;
@TestAtlas(loadFromJosmOsmResource = "overlappingPolygons.osm")
private Atlas overlappingPolygons;
@TestAtlas(loadFromJosmOsmResource = "testCounts.osm")
private Atlas testCounts;
@TestAtlas(loadFromJosmOsmResource = "testForms.osm")
Expand All @@ -32,11 +30,6 @@ public Atlas getMultiPolygons()
return this.multiPolygons;
}

public Atlas getOverlappingPolygons()
{
return this.overlappingPolygons;
}

public Atlas getTestCounts()
{
return this.testCounts;
Expand Down

This file was deleted.

0 comments on commit 16916b4

Please sign in to comment.