~ubuntu-branches/ubuntu/vivid/mkgmap/vivid

« back to all changes in this revision

Viewing changes to src/uk/me/parabola/imgfmt/app/net/AccessTagsAndBits.java

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2014-08-13 22:13:41 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140813221341-i9dzzjuto2o7hfh6
Tags: 0.0.0+svn3333-1
* New upstream version
  Closes: #745097
* add debian/classpath (thanks for the patch to Manfred Stock
  <manfred.stock+debian@gmail.com>)
  Closes: #741596
* d/copyright: DEP5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 or
 
6
 * version 2 as published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * General Public License for more details.
 
12
 */
 
13
package uk.me.parabola.imgfmt.app.net;
 
14
 
 
15
import java.util.LinkedHashMap;
 
16
import java.util.Map;
 
17
import uk.me.parabola.mkgmap.reader.osm.Element;
 
18
import uk.me.parabola.mkgmap.reader.osm.TagDict;
 
19
 
 
20
/**
 
21
 * mkgmap internal representation of (vehicle) access.
 
22
 * @author GerdP
 
23
 *
 
24
 */
 
25
public final class AccessTagsAndBits {
 
26
        // constants for vehicle class
 
27
        public static final byte FOOT      = 0x01;
 
28
        public static final byte BIKE      = 0x02;
 
29
        public static final byte CAR       = 0x04;
 
30
        public static final byte DELIVERY  = 0x08;
 
31
 
 
32
        public static final byte TRUCK     = 0x10;
 
33
        public static final byte BUS       = 0x20;
 
34
        public static final byte TAXI      = 0x40;
 
35
        public static final byte EMERGENCY = (byte) 0x80;
 
36
 
 
37
        // other routing attributes
 
38
        public static final byte R_THROUGHROUTE = 0x001; // note: 1 means throughroute is allowed
 
39
        public static final byte R_CARPOOL      = 0x002;        
 
40
        public static final byte R_ONEWAY       = 0x004;
 
41
        public static final byte R_TOLL             = 0x008;
 
42
        public static final byte R_UNPAVED      = 0x010;
 
43
        public static final byte R_FERRY        = 0x020;
 
44
        public static final byte R_ROUNDABOUT   = 0x040;
 
45
 
 
46
        public final static Map<String, Byte> ACCESS_TAGS = new LinkedHashMap<String, Byte>(){{
 
47
                put("mkgmap:foot", FOOT);
 
48
                put("mkgmap:bicycle", BIKE);
 
49
                put("mkgmap:car", CAR);
 
50
                put("mkgmap:delivery", DELIVERY);
 
51
                put("mkgmap:truck", TRUCK);
 
52
                put("mkgmap:bus", BUS);
 
53
                put("mkgmap:taxi", TAXI);
 
54
                put("mkgmap:emergency", EMERGENCY);
 
55
        }};
 
56
 
 
57
        public final static Map<Short, Byte> ACCESS_TAGS_COMPILED = new LinkedHashMap<Short, Byte>(){{
 
58
                for (Map.Entry<String, Byte> entry : ACCESS_TAGS.entrySet())
 
59
                        put(TagDict.getInstance().xlate(entry.getKey()),entry.getValue());
 
60
        }};
 
61
 
 
62
        public final static Map<String, Byte> ROUTE_TAGS = new LinkedHashMap<String, Byte>(){{
 
63
                put("mkgmap:throughroute", R_THROUGHROUTE);
 
64
                put("mkgmap:carpool", R_CARPOOL); 
 
65
                put("oneway", R_ONEWAY);
 
66
                put("mkgmap:toll", R_TOLL);
 
67
                put("mkgmap:unpaved", R_UNPAVED);
 
68
                put("mkgmap:ferry", R_FERRY);
 
69
                put("junction", R_ROUNDABOUT);
 
70
        }};
 
71
 
 
72
        public static byte evalAccessTags(Element el){
 
73
                byte noAccess = 0;
 
74
                for (Map.Entry<Short,Byte> entry : ACCESS_TAGS_COMPILED.entrySet()){
 
75
                        if (el.tagIsLikeNo(entry.getKey()))
 
76
                                noAccess |= entry.getValue();
 
77
                }
 
78
                return  (byte) ~noAccess;
 
79
        }
 
80
 
 
81
 
 
82
        private static final short carpoolTagKey = TagDict.getInstance().xlate("mkgmap:carpool"); 
 
83
        private static final short tollTagKey = TagDict.getInstance().xlate("mkgmap:toll"); 
 
84
        private static final short unpavedTagKey = TagDict.getInstance().xlate("mkgmap:unpaved"); 
 
85
        private static final short ferryTagKey = TagDict.getInstance().xlate("mkgmap:ferry"); 
 
86
        private static final short throughrouteTagKey = TagDict.getInstance().xlate("mkgmap:throughroute"); 
 
87
        private static final short junctionTagKey = TagDict.getInstance().xlate("junction"); 
 
88
        private static final short onewayTagKey = TagDict.getInstance().xlate("oneway"); 
 
89
        public static byte evalRouteTags(Element el){
 
90
                byte routeFlags = 0;
 
91
 
 
92
                // Style has to set "yes"
 
93
                if (el.tagIsLikeYes(carpoolTagKey))
 
94
                        routeFlags |= R_CARPOOL;
 
95
                if (el.tagIsLikeYes(tollTagKey))
 
96
                        routeFlags |= R_TOLL;
 
97
                if (el.tagIsLikeYes(unpavedTagKey))
 
98
                        routeFlags |= R_UNPAVED;
 
99
                if (el.tagIsLikeYes(ferryTagKey))
 
100
                        routeFlags |= R_FERRY;
 
101
 
 
102
                // Style has to set "no" 
 
103
                if (el.tagIsLikeNo(throughrouteTagKey))
 
104
                        routeFlags &= ~R_THROUGHROUTE;
 
105
                else 
 
106
                        routeFlags |= R_THROUGHROUTE;
 
107
 
 
108
                // tags without the mkgmap: prefix
 
109
                if ("roundabout".equals(el.getTag(junctionTagKey))) 
 
110
                        routeFlags |= R_ROUNDABOUT;
 
111
                if (el.tagIsLikeYes(onewayTagKey))
 
112
                        routeFlags |= R_ONEWAY;
 
113
 
 
114
                return routeFlags;
 
115
        }
 
116
 
 
117
}