Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pedestrian area polygons #63

Merged
merged 2 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,9 @@ public void process(Tables.OsmShipwayLinestring element, FeatureCollector featur
public void process(Tables.OsmHighwayPolygon element, FeatureCollector features) {
String manMade = element.manMade();
if (isBridgeOrPier(manMade) ||
// ignore underground pedestrian areas
(element.isArea() && element.layer() >= 0)) {
// only allow closed ways where area=yes, and multipolygons
// and ignore underground pedestrian areas
(!element.source().canBeLine() && element.layer() >= 0)) {
String highwayClass = highwayClass(element.highway(), element.publicTransport(), null, element.manMade());
if (highwayClass != null) {
features.polygon(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ SourceFeature lineFeature(Map<String, Object> props) {
);
}

SourceFeature closedWayFeature(Map<String, Object> props) {
return SimpleFeature.createFakeOsmFeature(
newLineString(0, 0, 1, 0, 1, 1, 0, 1, 0, 0),
new HashMap<>(props),
OSM_SOURCE,
null,
0,
null
);
}

SourceFeature polygonFeatureWithArea(double area, Map<String, Object> props) {
return SimpleFeature.create(
GeoUtils.worldToLatLonCoords(rectangle(0, Math.sqrt(area))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,21 +990,44 @@ public void testPiers() {

@Test
public void testPedestrianArea() {
assertFeatures(10, List.of(Map.of(
Map<String, Object> pedestrianArea = Map.of(
"_layer", "transportation",
"class", "path",
"subclass", "pedestrian",

"_minzoom", 13,
"_maxzoom", 14,
"_type", "polygon"
)), process(polygonFeature(Map.of(
);
Map<String, Object> circularPath = Map.of(
"_layer", "transportation",
"class", "path",
"subclass", "pedestrian",

"_minzoom", 14,
"_maxzoom", 14,
"_type", "line"
);
assertFeatures(14, List.of(pedestrianArea), process(closedWayFeature(Map.of(
"highway", "pedestrian",
"area", "yes",
"foot", "yes"
))));
assertFeatures(14, List.of(pedestrianArea), process(polygonFeature(Map.of(
"highway", "pedestrian",
"foot", "yes"
))));
assertFeatures(14, List.of(circularPath), process(closedWayFeature(Map.of(
"highway", "pedestrian",
"foot", "yes"
))));
assertFeatures(14, List.of(circularPath), process(closedWayFeature(Map.of(
"highway", "pedestrian",
"foot", "yes",
"area", "no"
))));
// ignore underground pedestrian areas
assertFeatures(10, List.of(),
assertFeatures(14, List.of(),
process(polygonFeature(Map.of(
"highway", "pedestrian",
"area", "yes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Lineal;
import org.locationtech.jts.geom.MultiLineString;
import org.locationtech.jts.geom.Polygonal;
import org.locationtech.jts.geom.Puntal;

Expand Down Expand Up @@ -77,7 +79,26 @@ public static SimpleFeature create(Geometry latLonGeometry, Map<String, Object>
/** Returns a new feature with OSM relation info. Useful for setting up inputs for OSM unit tests. */
public static SimpleFeature createFakeOsmFeature(Geometry latLonGeometry, Map<String, Object> tags, String source,
String sourceLayer, long id, List<OsmReader.RelationMember<OsmRelationInfo>> relations) {
return new SimpleFeature(latLonGeometry, null, tags, source, sourceLayer, id, relations);
String area = (String) tags.get("area");
return new SimpleFeature(latLonGeometry, null, tags, source, sourceLayer, id, relations) {
@Override
public boolean canBePolygon() {
return latLonGeometry instanceof Polygonal || (latLonGeometry instanceof LineString line
&& OsmReader.canBePolygon(line.isClosed(), area, latLonGeometry.getNumPoints()));
}

@Override
public boolean canBeLine() {
return latLonGeometry instanceof MultiLineString || (latLonGeometry instanceof LineString line
&& OsmReader.canBeLine(line.isClosed(), area, latLonGeometry.getNumPoints()));
}

@Override
protected Geometry computePolygon() {
var geom = worldGeometry();
return geom instanceof LineString line ? GeoUtils.JTS_FACTORY.createPolygon(line.getCoordinates()) : geom;
}
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,16 @@ public String toString() {
}
}

/** Returns {@code true} if a way can be interpreted as a line. */
public static boolean canBeLine(boolean closed, String area, int points) {
return (!closed || !"yes".equals(area)) && points >= 2;
}

/** Returns {@code true} if a way can be interpreted as a polygon. */
public static boolean canBePolygon(boolean closed, String area, int points) {
return (closed && !"no".equals(area)) && points >= 4;
}

/**
* A {@link LineString} or {@link Polygon} created from an OSM way.
* <p>
Expand All @@ -529,8 +539,8 @@ private class WaySourceFeature extends OsmFeature {
public WaySourceFeature(ReaderWay way, boolean closed, String area, NodeLocationProvider nodeLocations,
List<RelationMember<OsmRelationInfo>> relationInfo) {
super(way, false,
(!closed || !"yes".equals(area)) && way.getNodes().size() >= 2, // line
(closed && !"no".equals(area)) && way.getNodes().size() >= 4, // polygon
OsmReader.canBeLine(closed, area, way.getNodes().size()),
OsmReader.canBePolygon(closed, area, way.getNodes().size()),
relationInfo
);
this.nodeIds = way.getNodes();
Expand Down