Changeset 33648 in osm for applications/editors/josm/plugins/cadastre-fr/src
- Timestamp:
- 2017-09-21T16:58:03+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFile.java
r33647 r33648 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.fr.cadastre.edigeo; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.io.BufferedReader; … … 15 13 import java.util.function.Consumer; 16 14 15 import org.openstreetmap.josm.data.coor.EastNorth; 17 16 import org.openstreetmap.josm.tools.Logging; 18 17 … … 48 47 void processRecord(EdigeoRecord r) { 49 48 if ("RID".equals(r.name)) { 50 safeGet AndLog(r, s -> identifier += s, tr("Identifier"));49 safeGet(r, s -> identifier += s); 51 50 } else if ("NEX".equals(r.name) && lastReadString != null) { 52 51 safeGet(r, lastReadString); … … 78 77 protected final double safeGetDouble(EdigeoRecord r) { 79 78 return r.length > 0 ? Double.parseDouble(r.values.get(0)) : 0; 79 } 80 81 protected final EastNorth safeGetEastNorth(EdigeoRecord r) { 82 return r.length > 0 ? new EastNorth(Double.parseDouble(r.values.get(0)), 83 Double.parseDouble(r.values.get(1))) : null; 80 84 } 81 85 -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileVEC.java
r33643 r33648 4 4 import java.io.IOException; 5 5 import java.nio.file.Path; 6 import java.util.ArrayList; 7 import java.util.HashMap; 8 import java.util.List; 9 import java.util.Map; 10 11 import org.openstreetmap.josm.data.coor.EastNorth; 6 12 7 13 /** … … 11 17 12 18 /** 19 * Node descriptor block. 20 */ 21 public static class NodeBlock extends Block { 22 23 enum NodeType { 24 INITIAL_OR_FINAL(1), 25 ISOLATED(2); 26 27 int code; 28 NodeType(int code) { 29 this.code = code; 30 } 31 32 public static NodeType of(int code) { 33 for (NodeType s : values()) { 34 if (s.code == code) { 35 return s; 36 } 37 } 38 throw new IllegalArgumentException(Integer.toString(code)); 39 } 40 } 41 42 /** SCP */ String scdRef = ""; 43 /** TYP */ NodeType nodeType; 44 /** COR */ EastNorth coordinate; 45 /** ATC */ int nAttributes; 46 /** QAC */ int nQualities; 47 48 NodeBlock(String type) { 49 super(type); 50 } 51 52 @Override 53 void processRecord(EdigeoRecord r) { 54 switch (r.name) { 55 case "SCP": safeGet(r, s -> scdRef += s); break; 56 case "TYP": nodeType = NodeType.of(safeGetInt(r)); break; 57 case "COR": coordinate = safeGetEastNorth(r); break; 58 case "ATC": nAttributes = safeGetInt(r); break; 59 case "QAC": nQualities = safeGetInt(r); break; 60 default: 61 super.processRecord(r); 62 } 63 } 64 } 65 66 /** 67 * Arc descriptor block. 68 */ 69 public static class ArcBlock extends Block { 70 enum ArcType { 71 LINE(1), 72 CIRCLE_ARC(2), 73 CURVE(3); 74 75 int code; 76 ArcType(int code) { 77 this.code = code; 78 } 79 80 public static ArcType of(int code) { 81 for (ArcType s : values()) { 82 if (s.code == code) { 83 return s; 84 } 85 } 86 throw new IllegalArgumentException(Integer.toString(code)); 87 } 88 } 89 90 /** SCP */ String scdRef = ""; 91 /** CM1 */ EastNorth minCoordinate; 92 /** CM2 */ EastNorth maxCoordinate; 93 /** TYP */ ArcType arcType; 94 /** PTC */ int nPoints; 95 /** COR */ EastNorth initialPoint; 96 /** COR */ EastNorth finalPoint; 97 /** ATC */ int nAttributes; 98 /** QAC */ int nQualities; 99 100 ArcBlock(String type) { 101 super(type); 102 } 103 104 @Override 105 void processRecord(EdigeoRecord r) { 106 switch (r.name) { 107 case "SCP": safeGet(r, s -> scdRef += s); break; 108 case "CM1": minCoordinate = safeGetEastNorth(r); break; 109 case "CM2": maxCoordinate = safeGetEastNorth(r); break; 110 case "TYP": arcType = ArcType.of(safeGetInt(r)); break; 111 case "PTC": nPoints = safeGetInt(r); break; 112 case "COR": 113 EastNorth en = safeGetEastNorth(r); 114 if (initialPoint == null) { 115 initialPoint = en; 116 } else if (finalPoint == null) { 117 finalPoint = en; 118 } 119 break; 120 case "ATC": nAttributes = safeGetInt(r); break; 121 case "QAC": nQualities = safeGetInt(r); break; 122 default: 123 super.processRecord(r); 124 } 125 } 126 } 127 128 /** 129 * Face descriptor block. 130 */ 131 public static class FaceBlock extends Block { 132 /** SCP */ String scdRef = ""; 133 /** CM1 */ EastNorth minCoordinate; 134 /** CM2 */ EastNorth maxCoordinate; 135 /** ATC */ int nAttributes; 136 /** QAC */ int nQualities; 137 138 FaceBlock(String type) { 139 super(type); 140 } 141 142 @Override 143 void processRecord(EdigeoRecord r) { 144 switch (r.name) { 145 case "SCP": safeGet(r, s -> scdRef += s); break; 146 case "CM1": minCoordinate = safeGetEastNorth(r); break; 147 case "CM2": maxCoordinate = safeGetEastNorth(r); break; 148 case "ATC": nAttributes = safeGetInt(r); break; 149 case "QAC": nQualities = safeGetInt(r); break; 150 default: 151 super.processRecord(r); 152 } 153 } 154 } 155 156 /** 157 * Object descriptor block. 158 */ 159 public static class ObjectBlock extends Block { 160 /** SCP */ String scdRef = ""; 161 /** CM1 */ EastNorth minCoordinate; 162 /** CM2 */ EastNorth maxCoordinate; 163 /** REF */ String pointRef = ""; 164 /** ATC */ int nAttributes; 165 /** ATP */ final List<String> attributeDefs = new ArrayList<>(); 166 /** TEX */ EdigeoCharset charset; 167 /** ATV */ final List<String> attributeValues = new ArrayList<>(); 168 /** QAC */ int nQualities; 169 /** QAP */ final List<String> qualityIndics = new ArrayList<>(); 170 171 ObjectBlock(String type) { 172 super(type); 173 } 174 175 @Override 176 void processRecord(EdigeoRecord r) { 177 switch (r.name) { 178 case "SCP": safeGet(r, s -> scdRef += s); break; 179 case "CM1": minCoordinate = safeGetEastNorth(r); break; 180 case "CM2": maxCoordinate = safeGetEastNorth(r); break; 181 case "REF": safeGet(r, s -> pointRef += s); break; 182 case "ATC": nAttributes = safeGetInt(r); break; 183 case "ATP": safeGet(r, attributeDefs); break; 184 case "TEX": safeGet(r, s -> charset = EdigeoCharset.of(s)); break; 185 case "ATV": safeGet(r, attributeValues); break; 186 case "QAC": nQualities = safeGetInt(r); break; 187 case "QAP": safeGet(r, qualityIndics); break; 188 default: 189 super.processRecord(r); 190 } 191 } 192 } 193 194 /** 195 * Relation descriptor block. 196 */ 197 public static class RelationBlock extends Block { 198 199 enum Composition { 200 PLUS("P"), 201 MINUS("M"); 202 203 String code; 204 Composition(String code) { 205 this.code = code; 206 } 207 208 public static Composition of(String code) { 209 for (Composition s : values()) { 210 if (s.code.equals(code)) { 211 return s; 212 } 213 } 214 throw new IllegalArgumentException(code); 215 } 216 } 217 218 /** SCP */ String scdRef = ""; 219 /** FTC */ int nElements; 220 /** FTP */ final List<String> elements = new ArrayList<>(); 221 /** SNS */ final Map<String, Composition> compositions = new HashMap<>(); 222 /** ATC */ int nAttributes; 223 /** QAC */ int nQualities; 224 225 RelationBlock(String type) { 226 super(type); 227 } 228 229 @Override 230 void processRecord(EdigeoRecord r) { 231 switch (r.name) { 232 case "SCP": safeGet(r, s -> scdRef += s); break; 233 case "FTC": nElements = safeGetInt(r); break; 234 case "FTP": safeGet(r, elements); break; 235 case "SNS": safeGet(r, s -> compositions.put(elements.get(elements.size()-1), Composition.of(s))); break; 236 case "ATC": nAttributes = safeGetInt(r); break; 237 case "QAC": nQualities = safeGetInt(r); break; 238 default: 239 super.processRecord(r); 240 } 241 } 242 } 243 244 /** 13 245 * Constructs a new {@code EdigeoFileVEC}. 14 246 * @param path path to VEC file … … 21 253 @Override 22 254 protected Block createBlock(String type) { 23 // TODO Auto-generated method stub 24 return null; 25 } 26 255 switch (type) { 256 case "PNO": 257 return new NodeBlock(type); 258 case "PAR": 259 return new ArcBlock(type); 260 case "PFE": 261 return new FaceBlock(type); 262 case "FEA": 263 return new ObjectBlock(type); 264 case "LNK": 265 return new RelationBlock(type); 266 default: 267 throw new IllegalArgumentException(type); 268 } 269 } 27 270 }
Note:
See TracChangeset
for help on using the changeset viewer.