| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package relcontext.actions;
|
|---|
| 3 |
|
|---|
| 4 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 5 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
|---|
| 6 | import org.openstreetmap.josm.data.osm.RelationMember;
|
|---|
| 7 |
|
|---|
| 8 | /**
|
|---|
| 9 | * @author freeExec
|
|---|
| 10 | * @see <a href="https://wiki.openstreetmap.org/wiki/Key:public_transport">osmwiki:Key:public_transport</a>
|
|---|
| 11 | */
|
|---|
| 12 | public final class PublicTransportHelper {
|
|---|
| 13 |
|
|---|
| 14 | public static final String PUBLIC_TRANSPORT = "public_transport";
|
|---|
| 15 | public static final String STOP_POSITION = "stop_position";
|
|---|
| 16 | public static final String STOP = "stop";
|
|---|
| 17 | public static final String STOP_AREA = "stop_area";
|
|---|
| 18 | public static final String PLATFORM = "platform";
|
|---|
| 19 | public static final String HIGHWAY = "highway";
|
|---|
| 20 | public static final String RAILWAY = "railway";
|
|---|
| 21 | public static final String BUS_STOP = "bus_stop";
|
|---|
| 22 | public static final String RAILWAY_HALT = "halt";
|
|---|
| 23 | public static final String RAILWAY_STATION = "station";
|
|---|
| 24 |
|
|---|
| 25 | private PublicTransportHelper() {
|
|---|
| 26 | // Hide default constructor for utils classes
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | public static String getRoleByMember(RelationMember m) {
|
|---|
| 30 | if (isMemberStop(m)) return STOP;
|
|---|
| 31 | else if (isMemberPlatform(m)) return PLATFORM;
|
|---|
| 32 | return null;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | public static boolean isMemberStop(RelationMember m) {
|
|---|
| 36 | return isNodeStop(m); // stop is only node
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | public static boolean isMemberPlatform(RelationMember m) {
|
|---|
| 40 | return isNodePlatform(m) || isWayPlatform(m);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | public static boolean isNodeStop(RelationMember m) {
|
|---|
| 44 | return isNodeStop(m.getMember());
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | public static boolean isNodeStop(OsmPrimitive p) {
|
|---|
| 48 | if (p.getType() == OsmPrimitiveType.NODE && !p.isIncomplete()) {
|
|---|
| 49 | if (p.hasKey(PUBLIC_TRANSPORT)) {
|
|---|
| 50 | String pt = p.get(PUBLIC_TRANSPORT);
|
|---|
| 51 | return STOP_POSITION.equals(pt);
|
|---|
| 52 | } else if (p.hasKey(RAILWAY)) {
|
|---|
| 53 | String rw = p.get(RAILWAY);
|
|---|
| 54 | return RAILWAY_HALT.equals(rw) || RAILWAY_STATION.equals(rw);
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 | return false;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | public static boolean isNodePlatform(RelationMember m) {
|
|---|
| 61 | return isNodePlatform(m.getMember());
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | public static boolean isNodePlatform(OsmPrimitive p) {
|
|---|
| 65 | if (p.getType() == OsmPrimitiveType.NODE && !p.isIncomplete()) {
|
|---|
| 66 | if (p.hasKey(PUBLIC_TRANSPORT)) {
|
|---|
| 67 | String pt = p.get(PUBLIC_TRANSPORT);
|
|---|
| 68 | return PLATFORM.equals(pt);
|
|---|
| 69 | } else if (p.hasKey(HIGHWAY)) {
|
|---|
| 70 | String hw = p.get(HIGHWAY);
|
|---|
| 71 | if (BUS_STOP.equals(hw)) return true;
|
|---|
| 72 | else return PLATFORM.equals(hw);
|
|---|
| 73 | } else if (p.hasKey(RAILWAY)) {
|
|---|
| 74 | String rw = p.get(RAILWAY);
|
|---|
| 75 | return PLATFORM.equals(rw);
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 | return false;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | public static boolean isWayPlatform(RelationMember m) {
|
|---|
| 82 | return isWayPlatform(m.getMember());
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | public static boolean isWayPlatform(OsmPrimitive p) {
|
|---|
| 86 | if (p.getType() == OsmPrimitiveType.WAY && !p.isIncomplete()) {
|
|---|
| 87 | if (p.hasKey(PUBLIC_TRANSPORT)) {
|
|---|
| 88 | String pt = p.get(PUBLIC_TRANSPORT);
|
|---|
| 89 | return PLATFORM.equals(pt);
|
|---|
| 90 | } else if (p.hasKey(HIGHWAY)) {
|
|---|
| 91 | String hw = p.get(HIGHWAY);
|
|---|
| 92 | return PLATFORM.equals(hw);
|
|---|
| 93 | } else if (p.hasKey(RAILWAY)) {
|
|---|
| 94 | String rw = p.get(RAILWAY);
|
|---|
| 95 | return PLATFORM.equals(rw);
|
|---|
| 96 | }
|
|---|
| 97 | }
|
|---|
| 98 | return false;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | public static boolean isMemberRouteway(RelationMember m) {
|
|---|
| 102 | return isWayRouteway(m.getMember());
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | public static boolean isWayRouteway(OsmPrimitive p) {
|
|---|
| 106 | if (p.getType() == OsmPrimitiveType.WAY && !p.isIncomplete())
|
|---|
| 107 | return p.hasKey(HIGHWAY) || p.hasKey(RAILWAY);
|
|---|
| 108 | return false;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | public static String getNameViaStoparea(RelationMember m) {
|
|---|
| 112 | return getNameViaStoparea(m.getMember());
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | public static String getNameViaStoparea(OsmPrimitive prim) {
|
|---|
| 116 | String result = prim.getName();
|
|---|
| 117 | if (result != null) return result;
|
|---|
| 118 | // try to get name by stop_area
|
|---|
| 119 | for (OsmPrimitive refOp : prim.getReferrers()) {
|
|---|
| 120 | if (refOp.getType() == OsmPrimitiveType.RELATION
|
|---|
| 121 | && refOp.hasTag(PUBLIC_TRANSPORT, STOP_AREA)) {
|
|---|
| 122 | result = refOp.getName();
|
|---|
| 123 | if (result != null) return result;
|
|---|
| 124 | }
|
|---|
| 125 | }
|
|---|
| 126 | return null;
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|