Start modification restrictions.
This commit is contained in:
parent
92af449178
commit
3ee2984e52
3 changed files with 92 additions and 101 deletions
51
src/main/org/insa/graph/AccessRestrictions.java
Normal file
51
src/main/org/insa/graph/AccessRestrictions.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package org.insa.graph;
|
||||||
|
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
public class AccessRestrictions {
|
||||||
|
|
||||||
|
public enum AccessMode {
|
||||||
|
|
||||||
|
// Specific modes
|
||||||
|
FOOT, BICYCLE, SMALL_MOTORCYCLE, AGRICULTURAL, MOTORCYCLE, MOTORCAR, HEAVY_GOODS, PUBLIC_TRANSPORT;
|
||||||
|
|
||||||
|
// All available modes
|
||||||
|
public static final EnumSet<AccessMode> ALL = EnumSet.allOf(AccessMode.class);
|
||||||
|
|
||||||
|
// Vehicle
|
||||||
|
public static final EnumSet<AccessMode> VEHICLE = EnumSet.range(AccessMode.BICYCLE,
|
||||||
|
AccessMode.PUBLIC_TRANSPORT);
|
||||||
|
|
||||||
|
// Motor vehicle
|
||||||
|
public static final EnumSet<AccessMode> MOTOR_VEHICLE = EnumSet.range(AccessMode.SMALL_MOTORCYCLE,
|
||||||
|
AccessMode.PUBLIC_TRANSPORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum AccessRestriction {
|
||||||
|
ALLOWED, FORBIDDEN, PRIVATE, DESTINATION, FORESTRY, UNKNOWN
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map mode -> restriction
|
||||||
|
private final EnumMap<AccessMode, AccessRestriction> restrictions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new access restrictions with unknown restrictions.
|
||||||
|
*/
|
||||||
|
public AccessRestrictions() {
|
||||||
|
this.restrictions = new EnumMap<>(AccessMode.class);
|
||||||
|
for (AccessMode mode: AccessMode.values()) {
|
||||||
|
this.restrictions.put(mode, AccessRestriction.UNKNOWN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of access restrictions with the given restrictions.
|
||||||
|
*
|
||||||
|
* @param restrictions
|
||||||
|
*/
|
||||||
|
public AccessRestrictions(EnumMap<AccessMode, AccessRestriction> restrictions) {
|
||||||
|
this.restrictions = restrictions;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,83 +1,11 @@
|
||||||
package org.insa.graph;
|
package org.insa.graph;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class containing information for road that may be shared by multiple arcs.
|
* Class containing information for road that may be shared by multiple arcs.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RoadInformation {
|
public class RoadInformation {
|
||||||
|
|
||||||
/**
|
|
||||||
* Access mode.
|
|
||||||
*/
|
|
||||||
public enum AccessMode {
|
|
||||||
FOOT, BICYCLE, SMALL_MOTORCYCLE, MOTORCYCLE, MOTORCAR, BUS
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class containing access restriction information.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static class AccessRestriction {
|
|
||||||
|
|
||||||
// Private road
|
|
||||||
private boolean is_private = false;
|
|
||||||
|
|
||||||
// Public transport restricted.
|
|
||||||
private boolean is_publicTransport = false;
|
|
||||||
|
|
||||||
// Map Enum -> Allowed.
|
|
||||||
private Map<AccessMode, Boolean> allowedModes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a new AccessInformation with unknown information: Not private, not
|
|
||||||
* public transport and all modes are allowed.
|
|
||||||
*/
|
|
||||||
public AccessRestriction() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param isPrivate
|
|
||||||
* @param isPublicTransport
|
|
||||||
* @param allowedModes
|
|
||||||
*/
|
|
||||||
public AccessRestriction(boolean isPrivate, boolean isPublicTransport,
|
|
||||||
Map<AccessMode, Boolean> allowedModes) {
|
|
||||||
this.is_private = isPrivate;
|
|
||||||
this.is_publicTransport = isPublicTransport;
|
|
||||||
this.allowedModes = allowedModes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if this is a private road.
|
|
||||||
*/
|
|
||||||
public boolean isPrivate() {
|
|
||||||
return is_private;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if this road is reserved for public transport.
|
|
||||||
*/
|
|
||||||
public boolean isPublicTransport() {
|
|
||||||
return is_publicTransport;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mode
|
|
||||||
*
|
|
||||||
* @return true if this road is allowed for the specified mode.
|
|
||||||
*/
|
|
||||||
public boolean isAllowedFor(AccessMode mode) {
|
|
||||||
if (this.allowedModes == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return this.allowedModes.getOrDefault(mode, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Road type.
|
* Road type.
|
||||||
*/
|
*/
|
||||||
|
@ -104,7 +32,7 @@ public class RoadInformation {
|
||||||
private final RoadType type;
|
private final RoadType type;
|
||||||
|
|
||||||
// Access information
|
// Access information
|
||||||
private final AccessRestriction access;
|
private final AccessRestrictions access;
|
||||||
|
|
||||||
// One way road?
|
// One way road?
|
||||||
private final boolean oneway;
|
private final boolean oneway;
|
||||||
|
@ -115,8 +43,7 @@ public class RoadInformation {
|
||||||
// Name of the road.
|
// Name of the road.
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public RoadInformation(RoadType roadType, AccessRestriction access, boolean isOneWay,
|
public RoadInformation(RoadType roadType, AccessRestrictions access, boolean isOneWay, int maxSpeed, String name) {
|
||||||
int maxSpeed, String name) {
|
|
||||||
this.type = roadType;
|
this.type = roadType;
|
||||||
this.access = access;
|
this.access = access;
|
||||||
this.oneway = isOneWay;
|
this.oneway = isOneWay;
|
||||||
|
@ -129,7 +56,7 @@ public class RoadInformation {
|
||||||
/**
|
/**
|
||||||
* @return true if this is a private road.
|
* @return true if this is a private road.
|
||||||
*/
|
*/
|
||||||
public AccessRestriction getAccessRestrictions() {
|
public AccessRestrictions getAccessRestrictions() {
|
||||||
return this.access;
|
return this.access;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +90,7 @@ public class RoadInformation {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -174,8 +102,7 @@ public class RoadInformation {
|
||||||
if (getType() == RoadType.MOTORWAY) {
|
if (getType() == RoadType.MOTORWAY) {
|
||||||
typeAsString = "highway";
|
typeAsString = "highway";
|
||||||
}
|
}
|
||||||
return typeAsString + " : " + getName() + " " + (isOneWay() ? " (oneway) " : "") + maxSpeed
|
return typeAsString + " : " + getName() + " " + (isOneWay() ? " (oneway) " : "") + maxSpeed + " km/h (max.)";
|
||||||
+ " km/h (max.)";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,14 @@ import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.insa.graph.AccessRestrictions;
|
||||||
|
import org.insa.graph.AccessRestrictions.AccessRestriction;
|
||||||
import org.insa.graph.Arc;
|
import org.insa.graph.Arc;
|
||||||
import org.insa.graph.Graph;
|
import org.insa.graph.Graph;
|
||||||
import org.insa.graph.GraphInformation;
|
import org.insa.graph.GraphInformation;
|
||||||
import org.insa.graph.Node;
|
import org.insa.graph.Node;
|
||||||
import org.insa.graph.Point;
|
import org.insa.graph.Point;
|
||||||
import org.insa.graph.RoadInformation;
|
import org.insa.graph.RoadInformation;
|
||||||
import org.insa.graph.RoadInformation.AccessMode;
|
|
||||||
import org.insa.graph.RoadInformation.AccessRestriction;
|
|
||||||
import org.insa.graph.RoadInformation.RoadType;
|
import org.insa.graph.RoadInformation.RoadType;
|
||||||
|
|
||||||
public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphReader {
|
public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphReader {
|
||||||
|
@ -26,29 +26,39 @@ public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphRead
|
||||||
// Length of the map id field (in bytes)
|
// Length of the map id field (in bytes)
|
||||||
protected static final int MAP_ID_FIELD_LENGTH = 32;
|
protected static final int MAP_ID_FIELD_LENGTH = 32;
|
||||||
|
|
||||||
// Some masks...
|
|
||||||
private static final int MASK_UNKNOWN = 0x01;
|
|
||||||
private static final int MASK_PRIVATE = 0x02;
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static final int MASK_AGRICULTURAL = 0x04;
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static final int MASK_SERVICE = 0x08;
|
|
||||||
private static final int MASK_PUBLIC_TRANSPORT = 0x10;
|
|
||||||
|
|
||||||
private static final int MASK_FOOT = 0x01 << 8;
|
|
||||||
private static final int MASK_BICYCLE = 0x02 << 8;
|
|
||||||
private static final int MASK_MOTORCYCLE = 0x0C << 8;
|
|
||||||
private static final int MASK_SMALL_MOTORCYCLE = 0x08 << 8;
|
|
||||||
private static final int MASK_MOTORCAR = 0x10 << 8;
|
|
||||||
private static final int MASK_BUS = 0x20 << 8;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new access information by parsing the given value.
|
* Create a new access information by parsing the given value (V6 version).
|
||||||
*
|
*
|
||||||
* @param access
|
* @param access
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected static AccessRestriction toAccessInformation(int access) {
|
protected static AccessRestrictions toAccessInformationV7(long access) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new access information by parsing the given value (V6 version).
|
||||||
|
*
|
||||||
|
* @param access
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected static AccessRestrictions toAccessInformationV6(int access) {
|
||||||
|
|
||||||
|
// Some masks...
|
||||||
|
final int MASK_UNKNOWN = 0x01;
|
||||||
|
final int MASK_PRIVATE = 0x02;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
final int MASK_AGRICULTURAL = 0x04;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
final int MASK_SERVICE = 0x08;
|
||||||
|
final int MASK_PUBLIC_TRANSPORT = 0x10;
|
||||||
|
|
||||||
|
final int MASK_FOOT = 0x01 << 8;
|
||||||
|
final int MASK_BICYCLE = 0x02 << 8;
|
||||||
|
final int MASK_MOTORCYCLE = 0x0C << 8;
|
||||||
|
final int MASK_SMALL_MOTORCYCLE = 0x08 << 8;
|
||||||
|
final int MASK_MOTORCAR = 0x10 << 8;
|
||||||
|
final int MASK_BUS = 0x20 << 8;
|
||||||
|
|
||||||
// Unknown -> Return default access information.
|
// Unknown -> Return default access information.
|
||||||
if ((access & MASK_UNKNOWN) != 0) {
|
if ((access & MASK_UNKNOWN) != 0) {
|
||||||
|
@ -259,9 +269,12 @@ public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphRead
|
||||||
private RoadInformation readRoadInformation() throws IOException {
|
private RoadInformation readRoadInformation() throws IOException {
|
||||||
char type = (char) dis.readUnsignedByte();
|
char type = (char) dis.readUnsignedByte();
|
||||||
int x = dis.readUnsignedByte();
|
int x = dis.readUnsignedByte();
|
||||||
AccessRestriction access = new AccessRestriction();
|
AccessRestrictions access = new AccessRestrictions();
|
||||||
if (getCurrentVersion() >= 6) {
|
if (getCurrentVersion() >= 7) {
|
||||||
access = toAccessInformation(dis.readUnsignedShort());
|
access = toAccessInformationV7(dis.readLong());
|
||||||
|
}
|
||||||
|
else if (getCurrentVersion() >= 6) {
|
||||||
|
access = toAccessInformationV6(dis.readUnsignedShort());
|
||||||
}
|
}
|
||||||
return new RoadInformation(toRoadType(type), access, (x & 0x80) > 0, (x & 0x7F) * 5, dis.readUTF());
|
return new RoadInformation(toRoadType(type), access, (x & 0x80) > 0, (x & 0x7F) * 5, dis.readUTF());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue