-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc95cdc
commit 6881207
Showing
7 changed files
with
204 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/test/java/org/opentripplanner/graph_builder/module/osm/naming/SidewalkNamerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package org.opentripplanner.graph_builder.module.osm.naming; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner.framework.geometry.GeometryUtils; | ||
import org.opentripplanner.framework.geometry.WgsCoordinate; | ||
import org.opentripplanner.framework.i18n.I18NString; | ||
import org.opentripplanner.graph_builder.services.osm.EdgeNamer; | ||
import org.opentripplanner.openstreetmap.model.OSMWay; | ||
import org.opentripplanner.openstreetmap.wayproperty.specifier.WayTestData; | ||
import org.opentripplanner.street.model.StreetTraversalPermission; | ||
import org.opentripplanner.street.model._data.StreetModelForTest; | ||
import org.opentripplanner.street.model.edge.StreetEdge; | ||
import org.opentripplanner.street.model.edge.StreetEdgeBuilder; | ||
import org.opentripplanner.test.support.GeoJsonIo; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
class SidewalkNamerTest { | ||
|
||
private static final I18NString SIDEWALK = I18NString.of("sidewalk"); | ||
private static final Logger LOG = LoggerFactory.getLogger(SidewalkNamerTest.class); | ||
|
||
@Test | ||
void postprocess() { | ||
var builder = new ModelBuilder(); | ||
var sidewalk = builder.addUnamedSidewalk( | ||
new WgsCoordinate(33.75029, -84.39198), | ||
new WgsCoordinate(33.74932, -84.39275) | ||
); | ||
|
||
LOG.info( | ||
"Geometry of {}: {}", | ||
sidewalk.edge.getName(), | ||
GeoJsonIo.toUrl(sidewalk.edge.getGeometry()) | ||
); | ||
|
||
var pryorStreet = builder.addStreetEdge( | ||
"Pryor Street", | ||
new WgsCoordinate(33.75032, -84.39190), | ||
new WgsCoordinate(33.74924, -84.39275) | ||
); | ||
|
||
LOG.info( | ||
"Geometry of {}: {}", | ||
pryorStreet.edge.getName(), | ||
GeoJsonIo.toUrl(pryorStreet.edge.getGeometry()) | ||
); | ||
|
||
assertNotEquals(sidewalk.edge.getName(), pryorStreet.edge.getName()); | ||
builder.postProcess(new SidewalkNamer()); | ||
assertEquals(sidewalk.edge.getName(), pryorStreet.edge.getName()); | ||
} | ||
|
||
private static class ModelBuilder { | ||
|
||
private final List<EdgePair> pairs = new ArrayList<>(); | ||
|
||
EdgePair addUnamedSidewalk(WgsCoordinate... coordinates) { | ||
var edge = edgeBuilder(coordinates) | ||
.withName(SIDEWALK) | ||
.withPermission(StreetTraversalPermission.PEDESTRIAN) | ||
.withBogusName(true) | ||
.buildAndConnect(); | ||
|
||
var way = WayTestData.footwaySidewalk(); | ||
assertTrue(way.isSidewalk()); | ||
var p = new EdgePair(way, edge); | ||
pairs.add(p); | ||
return p; | ||
} | ||
|
||
EdgePair addStreetEdge(String name, WgsCoordinate... coordinates) { | ||
var edge = edgeBuilder(coordinates) | ||
.withName(I18NString.of(name)) | ||
.withPermission(StreetTraversalPermission.ALL) | ||
.buildAndConnect(); | ||
var way = WayTestData.highwayTertiary(); | ||
way.addTag("name", name); | ||
assertFalse(way.isSidewalk()); | ||
assertTrue(way.isNamed()); | ||
var p = new EdgePair(way, edge); | ||
pairs.add(p); | ||
return p; | ||
} | ||
|
||
void postProcess(EdgeNamer namer) { | ||
pairs.forEach(p -> namer.recordEdge(p.way, p.edge)); | ||
namer.postprocess(); | ||
} | ||
|
||
private static StreetEdgeBuilder<?> edgeBuilder(WgsCoordinate... c) { | ||
var coordinates = Arrays.stream(c).toList(); | ||
var ls = GeometryUtils.makeLineString(c); | ||
return new StreetEdgeBuilder<>() | ||
.withFromVertex( | ||
StreetModelForTest.intersectionVertex(coordinates.getFirst().asJtsCoordinate()) | ||
) | ||
.withToVertex( | ||
StreetModelForTest.intersectionVertex(coordinates.getLast().asJtsCoordinate()) | ||
) | ||
.withGeometry(ls); | ||
} | ||
} | ||
|
||
private record EdgePair(OSMWay way, StreetEdge edge) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/java/org/opentripplanner/test/support/GeoJsonIo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.opentripplanner.test.support; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.opentripplanner.framework.json.ObjectMappers; | ||
|
||
/** | ||
* Helper class for generating URLs to geojson.io. | ||
*/ | ||
public class GeoJsonIo { | ||
|
||
private static final ObjectMapper MAPPER = ObjectMappers.geoJson(); | ||
|
||
public static String toUrl(Geometry geometry) { | ||
try { | ||
var geoJson = MAPPER.writeValueAsString(geometry); | ||
var encoded = URLEncoder.encode(geoJson, StandardCharsets.UTF_8); | ||
return "http://geojson.io/#data=data:application/json,%s".formatted(encoded); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |