Changeset 29152 in osm for applications/editors/josm/plugins/smed2/src/seamap
- Timestamp:
- 2013-01-01T16:08:15+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/seamap/Map.java
r29151 r29152 14 14 import java.util.HashMap; 15 15 16 import s57.S57att.Att; 17 import s57.S57obj.Obj; 18 import s57.S57val.Conv; 16 import s57.S57att; 17 import s57.S57att.*; 18 import s57.S57obj; 19 import s57.S57obj.*; 20 import s57.S57val; 21 import s57.S57val.*; 19 22 20 23 public class Map { 21 24 22 public enum Fflag { NODE, WAY, AREA } 25 public enum Fflag { 26 UNKN, NODE, WAY, AREA 27 } 23 28 24 29 public class AttItem { 25 30 Conv conv; 26 31 Object val; 27 }28 32 29 public class ObjItem { 30 int idx; 31 ArrayList<EnumMap<Att, AttItem>> atts; 33 AttItem(Conv iconv, Object ival) { 34 conv = iconv; 35 val = ival; 36 } 32 37 } 33 38 … … 38 43 public Obj type; 39 44 public EnumMap<Att, AttItem> atts; 40 public EnumMap<Obj, ArrayList<ObjItem>> objs; 45 public EnumMap<Obj, HashMap<Integer, EnumMap<Att, AttItem>>> objs; 46 47 Feature() { 48 clean(); 49 } 50 51 void clean() { 52 id = 0; 53 flag = Fflag.UNKN; 54 refs = new ArrayList<Long>(); 55 type = Obj.UNKOBJ; 56 atts = new EnumMap<Att, AttItem>(Att.class); 57 objs = new EnumMap<Obj, HashMap<Integer, EnumMap<Att, AttItem>>>(Obj.class); 58 } 41 59 } 42 60 43 61 public class Coord { 44 62 double lat; 45 63 double lon; 46 Coord (double ilat, double ilon) { 64 65 Coord(double ilat, double ilon) { 47 66 lat = ilat; 48 67 lon = ilon; 49 68 } 50 69 } 51 70 52 71 public HashMap<Long, Coord> nodes; 53 72 public HashMap<Long, ArrayList<Long>> ways; 54 73 public HashMap<Long, ArrayList<Long>> mpolys; 55 74 public ArrayList<Feature> features; 56 57 public Map () { 75 76 private Feature feature; 77 78 public Map() { 58 79 nodes = new HashMap<Long, Coord>(); 59 80 ways = new HashMap<Long, ArrayList<Long>>(); 60 81 mpolys = new HashMap<Long, ArrayList<Long>>(); 82 feature = new Feature(); 61 83 features = new ArrayList<Feature>(); 84 features.add(feature); 62 85 } 63 86 64 87 public void addNode(long id, double lat, double lon) { 65 88 nodes.put(id, new Coord(lat, lon)); 89 if (feature.type == Obj.UNKOBJ) { 90 feature.clean(); 91 } else { 92 feature = new Feature(); 93 features.add(feature); 94 } 66 95 } 67 96 68 97 public void addWay(long id) { 69 98 ways.put(id, new ArrayList<Long>()); 99 if (feature.type == Obj.UNKOBJ) { 100 feature.clean(); 101 } else { 102 feature = new Feature(); 103 features.add(feature); 104 } 70 105 } 71 106 72 107 public void addToWay(long way, long node) { 73 108 ways.get(way).add(node); 74 109 } 75 public void addRelation(long id) { 110 111 public void addMpoly(long id) { 76 112 mpolys.put(id, new ArrayList<Long>()); 77 113 } 78 79 public void addToRelation(long rel, long way) { 80 mpolys.get(rel).add(way); 114 115 public void addToMpoly(long id, long way) { 116 mpolys.get(id).add(way); 117 } 118 119 public void addTag(String key, String val) { 120 String subkeys[] = key.split(":"); 121 if ((subkeys.length > 1) && subkeys[0].equals("seamark")) { 122 Obj obj = S57obj.enumType(subkeys[1]); 123 if ((subkeys.length > 2) && (obj != Obj.UNKOBJ)) { 124 int idx = 0; 125 Att att = Att.UNKATT; 126 try { 127 idx = Integer.parseInt(subkeys[2]); 128 if (subkeys.length == 4) { 129 att = s57.S57att.enumAttribute(subkeys[3], obj); 130 } 131 } catch (Exception e) { 132 att = S57att.enumAttribute(subkeys[2], obj); 133 } 134 HashMap<Integer, EnumMap<Att, AttItem>> items = feature.objs.get(obj); 135 if (items == null) { 136 items = new HashMap<Integer, EnumMap<Att, AttItem>>(); 137 feature.objs.put(obj, items); 138 } 139 EnumMap<Att, AttItem> atts = items.get(idx); 140 if (atts == null) { 141 atts = new EnumMap<Att, AttItem>(Att.class); 142 } 143 AttVal attval = S57val.convertValue(val, att); 144 atts.put(att, new AttItem(attval.conv, attval.val)); 145 } else { 146 if (subkeys[1].equals("type")) { 147 feature.type = S57obj.enumType(val); 148 } else { 149 Att att = S57att.enumAttribute(subkeys[1], Obj.UNKOBJ); 150 if (att != Att.UNKATT) { 151 AttVal attval = S57val.convertValue(val, att); 152 feature.atts.put(att, new AttItem(attval.conv, attval.val)); 153 } 154 } 155 } 156 } 81 157 } 82 158 }
Note:
See TracChangeset
for help on using the changeset viewer.