Changeset 33645 in osm for applications/editors
- Timestamp:
- 2017-09-21T01:49:47+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFile.java
r33643 r33645 11 11 import java.time.LocalDate; 12 12 import java.time.format.DateTimeFormatter; 13 import java.util.List; 13 14 import java.util.Objects; 15 import java.util.function.Consumer; 14 16 15 17 import org.openstreetmap.josm.tools.Logging; … … 27 29 static class Block { 28 30 /** RTY */ final String type; 29 /** RID */ String identifier; 31 /** RID */ String identifier = ""; 32 33 // Remembers the last string read, to handle multiline text (more than 80 chars) with "NEXT" keyword 34 Consumer<String> lastReadString; 30 35 31 36 Block(String type) { … … 33 38 } 34 39 35 public final String get Type() {40 public final String getBlockType() { 36 41 return type; 37 42 } 38 43 39 public final String get Identifier() {44 public final String getBlockIdentifier() { 40 45 return identifier; 41 46 } … … 43 48 void processRecord(EdigeoRecord r) { 44 49 if ("RID".equals(r.name)) { 45 identifier = safeGetAndLog(r, tr("Identifier")); 50 safeGetAndLog(r, s -> identifier += s, tr("Identifier")); 51 } else if ("NEX".equals(r.name) && lastReadString != null) { 52 safeGet(r, lastReadString); 46 53 } else { 47 54 throw new IllegalArgumentException(r.toString()); 48 55 } 56 } 57 58 protected void safeGet(EdigeoRecord r, List<String> list) { 59 safeGet(r, s -> { 60 int idx = list.size() - 1; 61 list.set(idx, list.get(idx) + s); 62 }); 63 } 64 65 protected void safeGet(EdigeoRecord r, Consumer<String> callback) { 66 (lastReadString = callback).accept(r.length > 0 ? r.values.get(0) : null); 67 } 68 69 protected int safeGetInt(EdigeoRecord r) { 70 return r.length > 0 ? Integer.parseInt(r.values.get(0)) : 0; 71 } 72 73 protected LocalDate safeGetDate(EdigeoRecord r) { 74 return r.length > 0 ? LocalDate.parse(r.values.get(0), dateFormatter) : null; 75 } 76 77 protected void safeGetAndLog(EdigeoRecord r, Consumer<String> callback, String msg) { 78 if (r.length > 0) { 79 String v = r.values.get(0); 80 Logging.info(msg + ": " + v); 81 (lastReadString = callback).accept(v); 82 } 83 } 84 85 protected LocalDate safeGetDateAndLog(EdigeoRecord r, String msg) { 86 if (r.length > 0) { 87 LocalDate v = LocalDate.parse(r.values.get(0), dateFormatter); 88 Logging.info(msg + ": " + v); 89 return v; 90 } 91 return null; 49 92 } 50 93 } … … 116 159 currentBlock.processRecord(r); 117 160 } 118 119 protected static String safeGet(EdigeoRecord r) {120 return r.length > 0 ? r.values.get(0) : null;121 }122 123 protected static int safeGetInt(EdigeoRecord r) {124 return r.length > 0 ? Integer.parseInt(r.values.get(0)) : 0;125 }126 127 protected static LocalDate safeGetDate(EdigeoRecord r) {128 return r.length > 0 ? LocalDate.parse(r.values.get(0), dateFormatter) : null;129 }130 131 protected static String safeGetAndLog(EdigeoRecord r, String msg) {132 if (r.length > 0) {133 String v = r.values.get(0);134 Logging.info(msg + ": " + v);135 return v;136 }137 return null;138 }139 140 protected static LocalDate safeGetDateAndLog(EdigeoRecord r, String msg) {141 if (r.length > 0) {142 LocalDate v = LocalDate.parse(r.values.get(0), dateFormatter);143 Logging.info(msg + ": " + v);144 return v;145 }146 return null;147 }148 161 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileDIC.java
r33643 r33645 4 4 import java.io.IOException; 5 5 import java.nio.file.Path; 6 import java.util.ArrayList; 7 import java.util.Collections; 8 import java.util.List; 6 9 7 10 /** … … 11 14 12 15 /** 16 * Abstract definition. 17 */ 18 abstract static class Def extends Block { 19 20 /** LAB */ String code = ""; 21 /** TEX */ EdigeoCharset charset; 22 /** DEF */ String definition = ""; 23 /** ORI */ String origin = ""; 24 /** CAT */ String category = ""; 25 26 Def(String type) { 27 super(type); 28 } 29 30 @Override 31 void processRecord(EdigeoRecord r) { 32 switch (r.name) { 33 case "LAB": safeGet(r, s -> code += s); break; 34 case "TEX": safeGet(r, s -> charset = EdigeoCharset.of(s)); break; 35 case "DEF": safeGet(r, s -> definition += s); break; 36 case "ORI": safeGet(r, s -> origin += s); break; 37 case "CAT": safeGet(r, s -> category += s); break; 38 default: 39 super.processRecord(r); 40 } 41 } 42 43 /** 44 * Returns code. 45 * @return code 46 */ 47 public final String getCode() { 48 return code; 49 } 50 51 /** 52 * Returns definition. 53 * @return definition 54 */ 55 public final String getDefinition() { 56 return definition; 57 } 58 59 /** 60 * Returns definition source. 61 * @return definition source 62 */ 63 public final String getOrigin() { 64 return origin; 65 } 66 67 /** 68 * Returns category. 69 * @return category 70 */ 71 public final String getCategory() { 72 return category; 73 } 74 } 75 76 /** 77 * Object definition. 78 */ 79 public static class ObjectDef extends Def { 80 ObjectDef(String type) { 81 super(type); 82 } 83 } 84 85 /** 86 * Attribute definition. 87 */ 88 public static class AttributeDef extends Def { 89 90 /** TYP */ String type = ""; 91 /** UNI */ String unit = ""; 92 /** AVC */ int nValues; 93 /** AVL */ final List<String> values = new ArrayList<>(); 94 /** AVD */ final List<String> descrs = new ArrayList<>(); 95 96 AttributeDef(String type) { 97 super(type); 98 } 99 100 @Override 101 void processRecord(EdigeoRecord r) { 102 switch (r.name) { 103 case "TYP": safeGet(r, s -> type += s); break; 104 case "UNI": safeGet(r, s -> unit += s); break; 105 case "AVC": nValues = safeGetInt(r); break; 106 case "AVL": values.add(""); safeGet(r, values); break; 107 case "AVD": descrs.add(""); safeGet(r, descrs); break; 108 default: 109 super.processRecord(r); 110 } 111 } 112 113 /** 114 * Returns attribute type. 115 * @return attribute type 116 */ 117 public final String getType() { 118 return type; 119 } 120 121 /** 122 * Returns default unit. 123 * @return default unit 124 */ 125 public final String getUnit() { 126 return unit; 127 } 128 129 /** 130 * Returns number of values. 131 * @return number of values 132 */ 133 public final int getNumberOfValues() { 134 return nValues; 135 } 136 137 /** 138 * Returns pre-coded values. 139 * @return pre-coded values 140 */ 141 public final List<String> getValues() { 142 return Collections.unmodifiableList(values); 143 } 144 145 /** 146 * Returns descriptions of pre-coded values. 147 * @return descriptions of pre-coded values 148 */ 149 public final List<String> getDescriptions() { 150 return Collections.unmodifiableList(descrs); 151 } 152 } 153 154 /** 155 * Relation definition. 156 */ 157 public static class RelationDef extends Def { 158 RelationDef(String type) { 159 super(type); 160 } 161 } 162 163 /** DID */ List<ObjectDef> objects; 164 /** DIA */ List<AttributeDef> attributes; 165 /** DIR */ List<RelationDef> relations; 166 167 /** 13 168 * Constructs a new {@code EdigeoFileDIC}. 14 169 * @param path path to DIC file … … 20 175 21 176 @Override 177 protected void init() { 178 objects = new ArrayList<>(); 179 attributes = new ArrayList<>(); 180 relations = new ArrayList<>(); 181 } 182 183 @Override 22 184 protected Block createBlock(String type) { 23 // TODO Auto-generated method stub 24 return null; 25 } 26 185 switch (type) { 186 case "DID": 187 ObjectDef objDef = new ObjectDef(type); 188 objects.add(objDef); 189 return objDef; 190 case "DIA": 191 AttributeDef attDef = new AttributeDef(type); 192 attributes.add(attDef); 193 return attDef; 194 case "DIR": 195 RelationDef relDef = new RelationDef(type); 196 relations.add(relDef); 197 return relDef; 198 default: 199 throw new IllegalArgumentException(type); 200 } 201 } 202 203 /** 204 * Returns list of object definitions. 205 * @return list of object definitions 206 */ 207 public final List<ObjectDef> getObjects() { 208 return Collections.unmodifiableList(objects); 209 } 210 211 /** 212 * Returns list of attribute definitions. 213 * @return list of attribute definitions 214 */ 215 public final List<AttributeDef> getAttributes() { 216 return Collections.unmodifiableList(attributes); 217 } 218 219 /** 220 * Returns list of relation definitions. 221 * @return list of relation definitions 222 */ 223 public final List<RelationDef> getRelations() { 224 return Collections.unmodifiableList(relations); 225 } 27 226 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileGEN.java
r33644 r33645 16 16 */ 17 17 public static class GeoBounds extends Block { 18 String cm1;19 String cm2;18 /** CM1 */ String min = ""; 19 /** CM2 */ String max = ""; 20 20 21 21 GeoBounds(String type) { … … 26 26 void processRecord(EdigeoRecord r) { 27 27 switch (r.name) { 28 case "CM1": cm1 = safeGet(r); break;29 case "CM2": cm2 = safeGet(r); break;28 case "CM1": safeGet(r, s -> min += s); break; 29 case "CM2": safeGet(r, s -> max += s); break; 30 30 default: 31 31 super.processRecord(r); … … 37 37 * @return the minimal coordinates 38 38 */ 39 public final String get Cm1() {40 return cm1;39 public final String getMinCm1() { 40 return min; 41 41 } 42 42 … … 45 45 * @return the maximal coordinates 46 46 */ 47 public final String get Cm2() {48 return cm2;47 public final String getMaxCm2() { 48 return max; 49 49 } 50 50 } … … 80 80 } 81 81 82 String information;83 Structure structure;84 String offsetId;82 /** INF */ String information = ""; 83 /** STR */ Structure structure; 84 /** REG */ String offsetId = ""; 85 85 86 86 GeoData(String type) { … … 91 91 void processRecord(EdigeoRecord r) { 92 92 switch (r.name) { 93 case "INF": information = safeGetAndLog(r, tr("Information")); break;93 case "INF": safeGetAndLog(r, s -> information += s, tr("Information")); break; 94 94 case "STR": structure = Structure.of(safeGetInt(r)); break; 95 case "REG": offsetId = safeGet(r); break;95 case "REG": safeGet(r, s -> offsetId += s); break; 96 96 default: 97 97 super.processRecord(r); … … 124 124 } 125 125 126 GeoBounds bounds;127 GeoData geodata;126 /** DEG */ GeoBounds bounds; 127 /** GSE */ GeoData geodata; 128 128 129 129 /** -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileGEO.java
r33644 r33645 56 56 } 57 57 58 ReferenceType type;59 String name;60 String code;61 int nDim;62 AltitudeSystem altitudeSystem;63 String unit;58 /** RET */ ReferenceType type; 59 /** REN */ String name = ""; 60 /** REL */ String code = ""; 61 /** DIM */ int nDim; 62 /** ALS */ AltitudeSystem altitudeSystem; 63 /** UNH */ String unit = ""; 64 64 65 65 CoorReference(String type) { … … 70 70 void processRecord(EdigeoRecord r) { 71 71 switch (r.name) { 72 case "RET": type = ReferenceType.of(safeGet(r)); break;73 case "REN": name = safeGetAndLog(r, tr("Projection")); break;74 case "REL": code = safeGetAndLog(r, tr("Projection")); break;72 case "RET": safeGet(r, s -> type = ReferenceType.of(s)); break; 73 case "REN": safeGetAndLog(r, s -> name += s, tr("Projection")); break; 74 case "REL": safeGetAndLog(r, s -> code += s, tr("Projection")); break; 75 75 case "DIM": nDim = safeGetInt(r); break; 76 76 case "ALS": altitudeSystem = AltitudeSystem.of(safeGetInt(r)); break; 77 case "UNH": unit = safeGet(r); break;77 case "UNH": safeGet(r, s -> unit += s); break; 78 78 default: 79 79 super.processRecord(r); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileTHF.java
r33643 r33645 45 45 } 46 46 47 /** AUT */ String author ;48 /** ADR */ String recipient ;47 /** AUT */ String author = ""; 48 /** ADR */ String recipient = ""; 49 49 /** LOC */ int nLots; 50 50 /** VOC */ int nVolumes; 51 51 /** SEC */ SecurityClassification security; 52 /** RDI */ String diffusionRestriction ;53 /** VER */ String edigeoVersion ;52 /** RDI */ String diffusionRestriction = ""; 53 /** VER */ String edigeoVersion = ""; 54 54 /** VDA */ LocalDate edigeoDate; 55 /** TRL */ String transmissionName ;55 /** TRL */ String transmissionName = ""; 56 56 /** EDN */ int transmissionEdition; 57 57 /** TDA */ LocalDate transmissionDate; 58 /** INF */ String transmissionInformation ;58 /** INF */ String transmissionInformation = ""; 59 59 60 60 Support(String type) { … … 65 65 void processRecord(EdigeoRecord r) { 66 66 switch (r.name) { 67 case "AUT": author = safeGetAndLog(r, tr("Author")); break;68 case "ADR": recipient = safeGetAndLog(r, tr("Recipient")); break;67 case "AUT": safeGetAndLog(r, s -> author += s, tr("Author")); break; 68 case "ADR": safeGetAndLog(r, s -> recipient += s, tr("Recipient")); break; 69 69 case "LOC": nLots = safeGetInt(r); break; 70 70 case "VOC": nVolumes = safeGetInt(r); break; 71 71 case "SEC": security = SecurityClassification.of(safeGetInt(r)); break; 72 case "RDI": diffusionRestriction = safeGetAndLog(r, tr("Diffusion restriction")); break;73 case "VER": edigeoVersion = safeGet(r); break;72 case "RDI": safeGetAndLog(r, s -> diffusionRestriction += s, tr("Diffusion restriction")); break; 73 case "VER": safeGet(r, s -> edigeoVersion += s); break; 74 74 case "VDA": edigeoDate = safeGetDate(r); break; 75 case "TRL": transmissionName = safeGet(r); break;75 case "TRL": safeGet(r, s -> transmissionName += s); break; 76 76 case "EDN": transmissionEdition = safeGetInt(r); break; 77 77 case "TDA": transmissionDate = safeGetDateAndLog(r, tr("Date")); break; 78 case "INF": transmissionInformation = safeGetAndLog(r, tr("Information")); break;78 case "INF": safeGetAndLog(r, s -> transmissionInformation += s, tr("Information")); break; 79 79 default: 80 80 super.processRecord(r); … … 184 184 public static class Lot extends Block { 185 185 186 /** LON */ String name ;187 /** INF */ String information ;188 /** GNN */ String genDataName ;189 /** GNI */ String genDataId ;190 /** GON */ String coorRefName ;191 /** GOI */ String coorRefId ;192 /** QAN */ String qualityName ;193 /** QAI */ String qualityId ;194 /** DIN */ String dictName ;195 /** DII */ String dictId ;196 /** SCN */ String scdName ;197 /** SCI */ String scdId ;186 /** LON */ String name = ""; 187 /** INF */ String information = ""; 188 /** GNN */ String genDataName = ""; 189 /** GNI */ String genDataId = ""; 190 /** GON */ String coorRefName = ""; 191 /** GOI */ String coorRefId = ""; 192 /** QAN */ String qualityName = ""; 193 /** QAI */ String qualityId = ""; 194 /** DIN */ String dictName = ""; 195 /** DII */ String dictId = ""; 196 /** SCN */ String scdName = ""; 197 /** SCI */ String scdId = ""; 198 198 /** GDC */ int nGeoData; 199 199 /** GDN */ final List<String> geoDataName = new ArrayList<>(); … … 207 207 void processRecord(EdigeoRecord r) { 208 208 switch (r.name) { 209 case "LON": name = safeGetAndLog(r, tr("Name")); break;210 case "INF": information = safeGetAndLog(r, tr("Information")); break;211 case "GNN": genDataName = safeGet(r); break;212 case "GNI": genDataId = safeGet(r); break;213 case "GON": coorRefName = safeGet(r); break;214 case "GOI": coorRefId = safeGet(r); break;215 case "QAN": qualityName = safeGet(r); break;216 case "QAI": qualityId = safeGet(r); break;217 case "DIN": dictName = safeGet(r); break;218 case "DII": dictId = safeGet(r); break;219 case "SCN": s cdName = safeGet(r); break;220 case "SCI": s cdId = safeGet(r); break;209 case "LON": safeGetAndLog(r, s -> name += s, tr("Name")); break; 210 case "INF": safeGetAndLog(r, s -> information += s, tr("Information")); break; 211 case "GNN": safeGet(r, s -> genDataName += s); break; 212 case "GNI": safeGet(r, s -> genDataId += s); break; 213 case "GON": safeGet(r, s -> coorRefName += s); break; 214 case "GOI": safeGet(r, s -> coorRefId += s); break; 215 case "QAN": safeGet(r, s -> qualityName += s); break; 216 case "QAI": safeGet(r, s -> qualityId += s); break; 217 case "DIN": safeGet(r, s -> dictName += s); break; 218 case "DII": safeGet(r, s -> dictId += s); break; 219 case "SCN": safeGet(r, s -> scdName += s); break; 220 case "SCI": safeGet(r, s -> scdId += s); break; 221 221 case "GDC": nGeoData = safeGetInt(r); break; 222 case "GDN": geoDataName.add( safeGet(r)); break;223 case "GDI": geoDataId.add( safeGet(r)); break;222 case "GDN": geoDataName.add(""); safeGet(r, geoDataName); break; 223 case "GDI": geoDataId.add(""); safeGet(r, geoDataId); break; 224 224 default: 225 225 super.processRecord(r); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoRecord.java
r33642 r33645 76 76 assert line.length() <= 80; 77 77 values = Arrays.asList(line.substring(8).split(";")); 78 assert (nature == Nature.SIMPLE && values.size() == 1) || (nature == Nature.COMPOSED && values.size() > 1) : line; 78 assert nature == Nature.RESERVED 79 || (nature == Nature.SIMPLE && values.size() == 1) 80 || (nature == Nature.COMPOSED && values.size() > 1) : line; 79 81 } else { 80 82 values = Collections.emptyList(); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/pci/EdigeoPciReader.java
r33643 r33645 59 59 } 60 60 DataSet ds = new DataSet(); 61 ds.setName(thf.getSupport().get Identifier());61 ds.setName(thf.getSupport().getBlockIdentifier()); 62 62 ds.setUploadPolicy(UploadPolicy.DISCOURAGED); 63 63 return ds;
Note:
See TracChangeset
for help on using the changeset viewer.