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: way surface type storage #1794

Merged
merged 15 commits into from
May 24, 2024
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
48 changes: 27 additions & 21 deletions docs/api-reference/endpoints/directions/extra-info/surface.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@ $.routes[*].extras.surface.values
```

This extra provides info about the [surface](https://wiki.openstreetmap.org/wiki/Key:surface) of the corresponding parts of the route.
The strike-through values have been recently removed.

| Value | Name |
|:-----:|:----------------:|
| 0 | Unknown |
| 1 | Paved |
| 2 | Unpaved |
| 3 | Asphalt |
| 4 | Concrete |
| 5 | Cobblestone |
| 6 | Metal |
| 7 | Wood |
| 8 | Compacted Gravel |
| 9 | Fine Gravel |
| 10 | Gravel |
| 11 | Dirt |
| 12 | Ground |
| 13 | Ice |
| 14 | Paving Stones |
| 15 | Sand |
| 16 | Woodchips |
| 17 | Grass |
| 18 | Grass Paver |
| Value | Name | Corresponding value* of [`surface`](https://wiki.openstreetmap.org/wiki/Key:surface)-tag(s) |
|:------:|:----------------:|:-----------------------------------------------------------------------------------------------:|
| 0 | Unknown | |
| 1 | Paved | `paved` |
| 2 | Unpaved | `unpaved`, `woodchips`, `rock`, `rocks`, `stone`, `shells`, `salt` |
| 3 | Asphalt | `asphalt`, `chipseal`, `bitmac`, `tarmac` |
| 4 | Concrete | `concrete`, `cement` |
| ~~5~~ | ~~Cobblestone~~ | |
| 6 | Metal | `metal` |
| 7 | Wood | `wood` |
| 8 | Compacted Gravel | `compacted`, `pebblestone` |
| ~~9~~ | ~~Fine Gravel~~ | |
| 10 | Gravel | `gravel`, `fine_gravel` |
| 11 | Dirt | `dirt`, `earth`, `soil` |
| 12 | Ground | `ground`, `mud` |
| 13 | Ice | `ice`, `snow` |
| 14 | Paving Stones | `paving_stones`, `paved_stones`, `sett`, `cobblestone`, `unhewn_cobblestone`, `bricks`, `brick` |
| 15 | Sand | `sand` |
| ~~16~~ | ~~Woodchips~~ | |
| 17 | Grass | `grass` |
| 18 | Grass Paver | `grass_paver` |

*) For tags listing multiple values separated by a semicolon `;` only the first value is considered, and for a
given `value` all values of the form `value[:*]` are matched, where the part `[:*]` is optional. For example, all the
three ways tagged with `surface=concrete`, `surface=concrete:plates;asphalt` and `surface=cement`, respectively, would
be categorized as "Concrete".

[//]: # (keep in sync with org.heigit.ors.routing.graphhopper.extensions.SurfaceType)
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,8 @@ void testExtrasDetails() {
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.body("routes[0].containsKey('extras')", is(true))
.body("routes[0].extras.surface.values.size()", is(38))
.body("routes[0].extras.surface.values[18][1]", is(181))
.body("routes[0].extras.surface.values.size()", is(32))
.body("routes[0].extras.surface.values[18][1]", is(237))
.body("routes[0].extras.suitability.values[18][0]", is(359))
.body("routes[0].extras.containsKey('steepness')", is(true))
.statusCode(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class CellStorage implements Storable<CellStorage> {
*/
public CellStorage(int nodeCount, Directory dir, IsochroneNodeStorage isochroneNodeStorage) {
this.isochroneNodeStorage = isochroneNodeStorage;
cells = dir.find("cells");
cells = dir.create("cells");
byteCount = 4;
this.nodeCount = nodeCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class IsochroneNodeStorage implements Storable<IsochroneNodeStorage> {
private final IntSet cellIdsSet = new IntHashSet();

public IsochroneNodeStorage(int nodeCount, Directory dir) {
isochroneNodes = dir.find("isochronenodes");
isochroneNodes = dir.create("isochronenodes");
this.nodeCount = nodeCount;
// 5 bytes per node for its cell id.
// 1 byte for isBordernode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class BorderNodeDistanceStorage implements Storable<BorderNodeDistanceSto
public BorderNodeDistanceStorage(Directory dir, Weighting weighting, IsochroneNodeStorage isochroneNodeStorage, int nodeCount) {
final String name = FileUtility.weightingToFileName(weighting);
this.isochroneNodeStorage = isochroneNodeStorage;
borderNodes = dir.find("bordernodes_" + name);
borderNodes = dir.create("bordernodes_" + name);
this.weighting = weighting;
byteCount = 12; //adj bordernode id (int 4B) and distance (double 8B)
this.nodeCount = nodeCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public EccentricityStorage(Directory dir, Weighting weighting, IsochroneNodeStor
//A map of nodeId to pointer is stored in the first block.
//The second block stores 2 values for each pointer, full reachability and eccentricity
final String name = FileUtility.weightingToFileName(weighting);
eccentricities = dir.find("eccentricities_" + name);
eccentricities = dir.create("eccentricities_" + name);
this.weighting = weighting;
this.isochroneNodeStorage = isochroneNodeStorage;
this.nodeCount = nodeCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,81 +13,67 @@
*/
package org.heigit.ors.routing.graphhopper.extensions;

public class SurfaceType {
public enum SurfaceType {

//Keep in sync with documentation: surface.md

public static final int UNKNOWN = 0;
public static final int PAVED = 1;
public static final int UNPAVED = 2;
public static final int ASPHALT = 3;
public static final int CONCRETE = 4;
public static final int COBBLESTONE = 5;
public static final int METAL = 6;
public static final int WOOD = 7;
public static final int COMPACTED_GRAVEL = 8;
public static final int FINE_GRAVEL = 9;
public static final int GRAVEL = 10;
public static final int DIRT = 11;
public static final int GROUND = 12;
public static final int ICE = 13;
public static final int PAVING_STONE = 14;
public static final int SAND = 15;
public static final int WOODCHIPS = 16;
public static final int GRASS = 17;
public static final int GRASS_PAVER = 18;
UNKNOWN(0),
PAVED(1),
UNPAVED(2),
ASPHALT(3),
CONCRETE(4),
METAL(6),
WOOD(7),
COMPACTED_GRAVEL(8),
GRAVEL(10),
DIRT(11),
GROUND(12),
ICE(13),
PAVING_STONE(14),
SAND(15),
GRASS(17),
GRASS_PAVER(18);

private SurfaceType() {
private final byte value;

private static final SurfaceType[] values = values();

private SurfaceType(int value) {
this.value = (byte) value;
}

public static int getFromString(String surface) {
public byte value() {
return value;
}

public static SurfaceType getFromId(int id) {
return values[id];
}

public static SurfaceType getFromString(String surface) {

if (surface.contains(";"))
surface = surface.split(";")[0];
if (surface.contains(":"))
surface = surface.split(":")[0];

if ("paved".equalsIgnoreCase(surface)) {
return SurfaceType.PAVED;
} else if ("unpaved".equalsIgnoreCase(surface)) {
return SurfaceType.UNPAVED;
} else if ("asphalt".equalsIgnoreCase(surface)) {
return SurfaceType.ASPHALT;
} else if ("concrete".equalsIgnoreCase(surface) || "concrete:lanes".equalsIgnoreCase(surface)
|| "concrete:plates".equalsIgnoreCase(surface)) {
return SurfaceType.CONCRETE;
} else if ("paving_stones".equalsIgnoreCase(surface) || "paving_stones:20".equalsIgnoreCase(surface) || "paving_stones:30".equalsIgnoreCase(surface) || "paving_stones:50".equalsIgnoreCase(surface) || "paved_stones".equalsIgnoreCase(surface)) {
return SurfaceType.PAVING_STONE;
} else if ("cobblestone:flattened".equalsIgnoreCase(surface)
|| "sett".equalsIgnoreCase(surface)) {
return SurfaceType.PAVING_STONE;
} else if ("cobblestone".equalsIgnoreCase(surface)) {
return SurfaceType.COBBLESTONE;
} else if ("metal".equalsIgnoreCase(surface)) {
return SurfaceType.METAL;
} else if ("wood".equalsIgnoreCase(surface)) {
return SurfaceType.WOOD;
} else if ("compacted".equalsIgnoreCase(surface) || "pebblestone".equalsIgnoreCase(surface)) {
return SurfaceType.COMPACTED_GRAVEL;
} else if ("fine_gravel".equalsIgnoreCase(surface)) {
return SurfaceType.FINE_GRAVEL;
} else if ("gravel".equalsIgnoreCase(surface)) {
return SurfaceType.GRAVEL;
} else if ("dirt".equalsIgnoreCase(surface)) {
return SurfaceType.DIRT;
} else if ("ground".equalsIgnoreCase(surface) || "earth".equalsIgnoreCase(surface)
|| "mud".equalsIgnoreCase(surface)) {
return SurfaceType.GROUND;
} else if ("ice".equalsIgnoreCase(surface) || "snow".equalsIgnoreCase(surface)) {
return SurfaceType.ICE;
} else if ("sand".equalsIgnoreCase(surface)) {
return SurfaceType.SAND;
} else if ("woodchips".equalsIgnoreCase(surface)) {
return SurfaceType.WOODCHIPS;
} else if ("grass".equalsIgnoreCase(surface)) {
return SurfaceType.GRASS;
} else if ("grass_paver".equalsIgnoreCase(surface)) {
return SurfaceType.GRASS_PAVER;
}

return SurfaceType.UNKNOWN;
return switch (surface.toLowerCase()) {
case "paved" -> SurfaceType.PAVED;
case "unpaved", "woodchips", "rock", "rocks", "stone", "shells", "salt" -> SurfaceType.UNPAVED;
case "asphalt", "chipseal", "bitmac", "tarmac" -> SurfaceType.ASPHALT;
case "concrete", "cement" -> SurfaceType.CONCRETE;
case "paving_stones", "paved_stones", "sett", "cobblestone", "unhewn_cobblestone", "bricks", "brick" -> SurfaceType.PAVING_STONE;
case "metal" -> SurfaceType.METAL;
case "wood" -> SurfaceType.WOOD;
case "compacted", "pebblestone" -> SurfaceType.COMPACTED_GRAVEL;
case "gravel", "fine_gravel" -> SurfaceType.GRAVEL;
case "dirt", "earth", "soil" -> SurfaceType.DIRT;
case "ground", "mud" -> SurfaceType.GROUND;
case "ice", "snow" -> SurfaceType.ICE;
case "sand" -> SurfaceType.SAND;
case "grass" -> SurfaceType.GRASS;
case "grass_paver" -> SurfaceType.GRASS_PAVER;
default -> SurfaceType.UNKNOWN;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");

this.orsEdges = dir.find("ext_borders");
this.orsEdges = dir.create("ext_borders");
}

/**
Expand All @@ -117,7 +117,7 @@ public void init() {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");
Directory d = new RAMDirectory();
this.orsEdges = d.find("");
this.orsEdges = d.create("");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");

this.orsEdges = dir.find("ext_csv");
this.orsEdges = dir.create("ext_csv");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");

this.orsEdges = dir.find("ext_greenindex");
this.orsEdges = dir.create("ext_greenindex");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ext_hgv storage must be initialized only once.");

this.orsEdges = dir.find("ext_hgv");
this.orsEdges = dir.create("ext_hgv");
}

private int nextBlockEntryIndex(int size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");

this.orsEdges = dir.find("ext_hillindex");
this.orsEdges = dir.create("ext_hillindex");
}

public HillIndexGraphStorage create(long initBytes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");

this.orsEdges = dir.find("ext_noiselevel");
this.orsEdges = dir.create("ext_noiselevel");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");

this.orsEdges = dir.find("ext_osmids");
this.orsEdges = dir.create("ext_osmids");
}

/**
Expand All @@ -36,7 +36,7 @@ public void init() {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");
Directory d = new RAMDirectory();
this.orsEdges = d.find("");
this.orsEdges = d.create("");
}

public OsmIdGraphStorage create(long initBytes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public void init() {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");
Directory d = new RAMDirectory();
this.edges = d.find("");
this.edges = d.create("");
}

public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ext_road_access_restrictions storage must be initialized only once.");

this.edges = dir.find("ext_road_access_restrictions");
this.edges = dir.create("ext_road_access_restrictions");
}

public void setEdgeValue(int edgeId, int restriction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");

this.orsEdges = dir.find("ext_shadowindex");
this.orsEdges = dir.create("ext_shadowindex");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public SpeedStorage(FlagEncoder flagEncoder) {

@Override
public void init(Graph graph, Directory directory) {
this.speedData = directory.find("ext_speeds_" + this.flagEncoder.toString());
this.speedData = directory.create("ext_speeds_" + this.flagEncoder.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ext_tolls storage must be initialized only once.");

this.edges = dir.find("ext_tolls");
this.edges = dir.create("ext_tolls");
}

protected final int nextBlockEntryIndex(int size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");

this.orsEdgesProperties = dir.find("ext_traffic_edge_properties");
this.orsEdgesTrafficLinkLookup = dir.find("ext_traffic_edges_traffic_lookup");
this.orsSpeedPatternLookup = dir.find("ext_traffic_pattern_lookup");
this.orsEdgesProperties = dir.create("ext_traffic_edge_properties");
this.orsEdgesTrafficLinkLookup = dir.create("ext_traffic_edges_traffic_lookup");
this.orsSpeedPatternLookup = dir.create("ext_traffic_pattern_lookup");
}

/**
Expand All @@ -454,9 +454,9 @@ public void init() {
if (edgesCount > 0)
throw new AssertionError("The ORS storage must be initialized only once.");
Directory d = new RAMDirectory();
this.orsEdgesProperties = d.find("");
this.orsEdgesTrafficLinkLookup = d.find("");
this.orsSpeedPatternLookup = d.find("");
this.orsEdgesProperties = d.create("");
this.orsEdgesTrafficLinkLookup = d.create("");
this.orsSpeedPatternLookup = d.create("");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void init(Graph graph, Directory dir) {
if (edgesCount > 0)
throw new AssertionError("The ext_traildifficulty storage must be initialized only once.");

this.edges = dir.find("ext_traildifficulty");
this.edges = dir.create("ext_traildifficulty");
}

protected final int nextBlockEntryIndex(int size) {
Expand Down
Loading
Loading