Changeset 33649 in osm for applications/editors/josm/plugins/cadastre-fr
- Timestamp:
- 2017-09-22T00:19:23+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo
- Files:
-
- 4 added
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFile.java
r33648 r33649 14 14 15 15 import org.openstreetmap.josm.data.coor.EastNorth; 16 import org.openstreetmap.josm.data.osm.DataSet; 16 17 import org.openstreetmap.josm.tools.Logging; 17 18 … … 102 103 } 103 104 105 protected final Path path; 104 106 private boolean bomFound; 105 107 private boolean eomFound; … … 107 109 private Block currentBlock; 108 110 109 EdigeoFile(Path path) throws IOException { 110 init(); 111 EdigeoFile(Path path) { 112 this.path = path; 113 } 114 115 public EdigeoFile read(DataSet ds) throws IOException, ReflectiveOperationException { 111 116 try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.ISO_8859_1)) { 112 117 String line; … … 148 153 } 149 154 } 155 return this; 150 156 } 151 157 152 protected void init() { 153 // To be overidden if needed 158 protected abstract Block createBlock(String type) throws ReflectiveOperationException; 159 160 protected static <T extends Block> T addBlock(List<T> blocks, T block) { 161 blocks.add(block); 162 return block; 154 163 } 155 164 156 protected abstract Block createBlock(String type); 157 158 private void processRecord(EdigeoRecord r) { 165 private void processRecord(EdigeoRecord r) throws ReflectiveOperationException { 159 166 if ("RTY".equals(r.name)) { 160 currentBlock = createBlock(r.values.get(0));167 currentBlock = Objects.requireNonNull(createBlock(r.values.get(0)), r.toString()); 161 168 return; 162 169 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileDIC.java
r33646 r33649 8 8 import java.util.List; 9 9 10 import org.openstreetmap.josm.data.osm.DataSet; 11 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileDIC.DicBlock; 12 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock; 13 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot; 14 10 15 /** 11 16 * Edigeo DIC file. 12 17 */ 13 public class EdigeoFileDIC extends Edigeo File{18 public class EdigeoFileDIC extends EdigeoLotFile<DicBlock> { 14 19 15 20 /** 16 21 * Abstract definition. 17 22 */ 18 abstract static class D ef extendsBlock {23 abstract static class DicBlock extends ChildBlock { 19 24 20 25 /** LAB */ String code = ""; … … 24 29 /** CAT */ String category = ""; 25 30 26 D ef(String type) {27 super( type);31 DicBlock(Lot lot, String type) { 32 super(lot, type); 28 33 } 29 34 … … 77 82 * Object definition. 78 83 */ 79 public static class ObjectDef extends D ef{80 ObjectDef( String type) {81 super( type);84 public static class ObjectDef extends DicBlock { 85 ObjectDef(Lot lot, String type) { 86 super(lot, type); 82 87 } 83 88 } … … 86 91 * Attribute definition. 87 92 */ 88 public static class AttributeDef extends D ef{93 public static class AttributeDef extends DicBlock { 89 94 90 95 /** TYP */ String type = ""; … … 94 99 /** AVD */ final List<String> descrs = new ArrayList<>(); 95 100 96 AttributeDef( String type) {97 super( type);101 AttributeDef(Lot lot, String type) { 102 super(lot, type); 98 103 } 99 104 … … 155 160 * Relation definition. 156 161 */ 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; 162 public static class RelationDef extends DicBlock { 163 RelationDef(Lot lot, String type) { 164 super(lot, type); 165 } 166 } 166 167 167 168 /** 168 169 * Constructs a new {@code EdigeoFileDIC}. 170 * @param lot parent lot 171 * @param seId subset id 169 172 * @param path path to DIC file 170 173 * @throws IOException if any I/O error occurs 171 174 */ 172 public EdigeoFileDIC(Path path) throws IOException { 173 super(path); 175 public EdigeoFileDIC(Lot lot, String seId, Path path) throws IOException { 176 super(lot, seId, path); 177 register("DID", ObjectDef.class); 178 register("DIA", AttributeDef.class); 179 register("DIR", RelationDef.class); 180 lot.dic = this; 174 181 } 175 182 176 183 @Override 177 protected void init() { 178 objects = new ArrayList<>(); 179 attributes = new ArrayList<>(); 180 relations = new ArrayList<>(); 181 } 182 183 @Override 184 protected Block createBlock(String type) { 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 } 184 public EdigeoFileDIC read(DataSet ds) throws IOException, ReflectiveOperationException { 185 super.read(ds); 186 return this; 201 187 } 202 188 … … 206 192 */ 207 193 public final List<ObjectDef> getObjects() { 208 return Collections.unmodifiableList( objects);194 return Collections.unmodifiableList(blocks.getInstances(ObjectDef.class)); 209 195 } 210 196 … … 214 200 */ 215 201 public final List<AttributeDef> getAttributes() { 216 return Collections.unmodifiableList( attributes);202 return Collections.unmodifiableList(blocks.getInstances(AttributeDef.class)); 217 203 } 218 204 … … 222 208 */ 223 209 public final List<RelationDef> getRelations() { 224 return Collections.unmodifiableList( relations);210 return Collections.unmodifiableList(blocks.getInstances(RelationDef.class)); 225 211 } 226 212 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileGEN.java
r33645 r33649 7 7 import java.nio.file.Path; 8 8 9 import org.openstreetmap.josm.data.osm.DataSet; 10 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileGEN.GenBlock; 11 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock; 12 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot; 13 9 14 /** 10 15 * Edigeo GEN file. 11 16 */ 12 public class EdigeoFileGEN extends EdigeoFile { 17 public class EdigeoFileGEN extends EdigeoLotFile<GenBlock> { 18 19 abstract static class GenBlock extends ChildBlock { 20 GenBlock(Lot lot, String type) { 21 super(lot, type); 22 } 23 } 13 24 14 25 /** 15 26 * Geographic bounds. 16 27 */ 17 public static class GeoBounds extends Block {28 public static class GeoBounds extends GenBlock { 18 29 /** CM1 */ String min = ""; 19 30 /** CM2 */ String max = ""; 20 31 21 GeoBounds( String type) {22 super( type);32 GeoBounds(Lot lot, String type) { 33 super(lot, type); 23 34 } 24 35 … … 53 64 * Geographic data. 54 65 */ 55 public static class GeoData extends Block {66 public static class GeoData extends GenBlock { 56 67 57 68 /** … … 84 95 /** REG */ String offsetId = ""; 85 96 86 GeoData( String type) {87 super( type);97 GeoData(Lot lot, String type) { 98 super(lot, type); 88 99 } 89 100 … … 124 135 } 125 136 126 /** DEG */ GeoBounds bounds;127 /** GSE */ GeoData geodata;128 129 137 /** 130 138 * Constructs a new {@code EdigeoFileGEN}. 139 * @param lot parent lot 140 * @param seId subset id 131 141 * @param path path to GEN file 132 142 * @throws IOException if any I/O error occurs 133 143 */ 134 public EdigeoFileGEN(Path path) throws IOException { 135 super(path); 144 public EdigeoFileGEN(Lot lot, String seId, Path path) throws IOException { 145 super(lot, seId, path); 146 register("DEG", GeoBounds.class); 147 register("GSE", GeoData.class); 148 lot.gen = this; 136 149 } 137 150 138 151 @Override 139 protected Block createBlock(String type) { 140 switch (type) { 141 case "DEG": 142 bounds = new GeoBounds(type); 143 return bounds; 144 case "GSE": 145 geodata = new GeoData(type); 146 return geodata; 147 default: 148 throw new IllegalArgumentException(type); 149 } 152 public EdigeoFileGEN read(DataSet ds) throws IOException, ReflectiveOperationException { 153 super.read(ds); 154 return this; 150 155 } 151 156 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileGEO.java
r33645 r33649 7 7 import java.nio.file.Path; 8 8 9 import org.openstreetmap.josm.data.osm.DataSet; 10 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileGEO.GeoBlock; 11 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock; 12 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot; 13 9 14 /** 10 15 * Edigeo GEO file. 11 16 */ 12 public class EdigeoFileGEO extends EdigeoFile { 17 public class EdigeoFileGEO extends EdigeoLotFile<GeoBlock> { 18 19 abstract static class GeoBlock extends ChildBlock { 20 GeoBlock(Lot lot, String type) { 21 super(lot, type); 22 } 23 } 13 24 14 25 /** 15 26 * Coordinates reference. 16 27 */ 17 public static class CoorReference extends Block {28 public static class CoorReference extends GeoBlock { 18 29 19 30 enum ReferenceType { … … 63 74 /** UNH */ String unit = ""; 64 75 65 CoorReference( String type) {66 super( type);76 CoorReference(Lot lot, String type) { 77 super(lot, type); 67 78 } 68 79 … … 132 143 /** 133 144 * Constructs a new {@code EdigeoFileGEO}. 145 * @param lot parent lot 146 * @param seId subset id 134 147 * @param path path to GEO file 135 148 * @throws IOException if any I/O error occurs 136 149 */ 137 public EdigeoFileGEO(Path path) throws IOException { 138 super(path); 150 public EdigeoFileGEO(Lot lot, String seId, Path path) throws IOException { 151 super(lot, seId, path); 152 register("GEO", CoorReference.class); 153 lot.geo = this; 139 154 } 140 155 141 156 @Override 142 protected Block createBlock(String type) { 143 if ("GEO".equals(type)) { 144 return new CoorReference(type); 145 } 146 throw new IllegalArgumentException(type); 157 public EdigeoFileGEO read(DataSet ds) throws IOException, ReflectiveOperationException { 158 super.read(ds); 159 return this; 147 160 } 148 161 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileQAL.java
r33647 r33649 8 8 import java.util.List; 9 9 10 import org.openstreetmap.josm.data.osm.DataSet; 11 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileQAL.QalBlock; 12 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock; 13 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot; 14 10 15 /** 11 16 * Edigeo QAL file. 12 17 */ 13 public class EdigeoFileQAL extends EdigeoFile { 18 public class EdigeoFileQAL extends EdigeoLotFile<QalBlock> { 19 20 abstract static class QalBlock extends ChildBlock { 21 QalBlock(Lot lot, String type) { 22 super(lot, type); 23 } 24 } 14 25 15 26 /** 16 27 * Update descriptor. 17 28 */ 18 public static class Update extends Block {29 public static class Update extends QalBlock { 19 30 20 31 enum UpdateType { … … 67 78 /** COP */ final List<String> mcdRef = new ArrayList<>(); 68 79 69 Update( String type) {70 super( type);80 Update(Lot lot, String type) { 81 super(lot, type); 71 82 } 72 83 … … 90 101 /** 91 102 * Constructs a new {@code EdigeoFileQAL}. 103 * @param lot parent lot 104 * @param seId subset id 92 105 * @param path path to QAL file 93 106 * @throws IOException if any I/O error occurs 94 107 */ 95 public EdigeoFileQAL(Path path) throws IOException { 96 super(path); 108 public EdigeoFileQAL(Lot lot, String seId, Path path) throws IOException { 109 super(lot, seId, path); 110 register("QUP", Update.class); 111 lot.qal = this; 97 112 } 98 113 99 114 @Override 100 protected Block createBlock(String type) { 101 if ("QUP".equals(type)) { 102 return new Update(type); 103 } 104 throw new IllegalArgumentException(type); 115 public EdigeoFileQAL read(DataSet ds) throws IOException, ReflectiveOperationException { 116 super.read(ds); 117 return this; 105 118 } 106 119 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileSCD.java
r33647 r33649 7 7 import java.util.List; 8 8 9 import org.openstreetmap.josm.data.osm.DataSet; 10 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.ScdBlock; 11 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock; 12 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot; 13 9 14 /** 10 15 * Edigeo SCD file. 11 16 */ 12 public class EdigeoFileSCD extends EdigeoFile { 17 public class EdigeoFileSCD extends EdigeoLotFile<ScdBlock> { 18 19 /** 20 * MCD definition. 21 */ 22 abstract static class ScdBlock extends ChildBlock { 23 ScdBlock(Lot lot, String type) { 24 super(lot, type); 25 } 26 } 13 27 14 28 /** 15 29 * MCD Object definition. 16 30 */ 17 public static class McdObj Def extendsBlock {31 public static class McdObjectDef extends ScdBlock { 18 32 19 33 /** DIP */ String dictRef = ""; … … 23 37 /** QAC */ int nQualities; 24 38 25 McdObj Def(String type) {26 super( type);39 McdObjectDef(Lot lot, String type) { 40 super(lot, type); 27 41 } 28 42 … … 44 58 * MCD Attribute definition. 45 59 */ 46 public static class McdAttr Def extendsBlock {60 public static class McdAttributeDef extends ScdBlock { 47 61 48 62 /** DIP */ String dictRef = ""; … … 54 68 /** AV2 */ String max = ""; 55 69 56 McdAttr Def(String type) {57 super( type);70 McdAttributeDef(Lot lot, String type) { 71 super(lot, type); 58 72 } 59 73 … … 77 91 * MCD Primitive definition. 78 92 */ 79 public static class McdPrim Def extendsBlock {93 public static class McdPrimitiveDef extends ScdBlock { 80 94 81 95 enum PrimitiveKind { … … 103 117 /** QAC */ int nQualities; 104 118 105 McdPrim Def(String type) {106 super( type);119 McdPrimitiveDef(Lot lot, String type) { 120 super(lot, type); 107 121 } 108 122 … … 122 136 * MCD Relation definition. 123 137 */ 124 abstract static class McdRel Def extendsBlock {138 abstract static class McdRelationDef extends ScdBlock { 125 139 126 140 /** CA1 */ int minCardinal; 127 141 /** CA2 */ int maxCardinal; 128 142 /** SCC */ int nTypes; 129 /** SCP */ final List<S tring> scdRef = new ArrayList<>();143 /** SCP */ final List<ScdBlock> scdRef = new ArrayList<>(); 130 144 /** OCC */ final List<Integer> nOccurences = new ArrayList<>(); 131 145 /** AAC */ int nAttributes; 132 146 /** QAC */ int nQualities; 133 147 134 McdRel Def(String type) {135 super( type);148 McdRelationDef(Lot lot, String type) { 149 super(lot, type); 136 150 } 137 151 … … 142 156 case "CA2": maxCardinal = safeGetInt(r); break; 143 157 case "SCC": nTypes = safeGetInt(r); break; 144 case "SCP": s afeGet(r, scdRef); break;158 case "SCP": scdRef.add(lot.scd.find(r.values)); break; 145 159 case "OCC": nOccurences.add(safeGetInt(r)); break; 146 160 case "AAC": nAttributes = safeGetInt(r); break; … … 155 169 * MCD Semantic Relation definition. 156 170 */ 157 public static class McdSem RelDef extends McdRelDef {171 public static class McdSemanticRelationDef extends McdRelationDef { 158 172 159 173 /** DIP */ String dictRef = ""; 160 174 161 McdSem RelDef(String type) {162 super( type);175 McdSemanticRelationDef(Lot lot, String type) { 176 super(lot, type); 163 177 } 164 178 … … 176 190 * MCD Construction Relation definition. 177 191 */ 178 public static class Mcd BuildRelDef extends McdRelDef {192 public static class McdConstructionRelationDef extends McdRelationDef { 179 193 180 194 enum RelationKind { … … 206 220 /** KND */ RelationKind kind; 207 221 208 Mcd BuildRelDef(String type) {209 super( type);222 McdConstructionRelationDef(Lot lot, String type) { 223 super(lot, type); 210 224 } 211 225 … … 222 236 /** 223 237 * Constructs a new {@code EdigeoFileSCD}. 238 * @param lot parent lot 239 * @param seId subset id 224 240 * @param path path to SCD file 225 241 * @throws IOException if any I/O error occurs 226 242 */ 227 public EdigeoFileSCD(Path path) throws IOException { 228 super(path); 243 public EdigeoFileSCD(Lot lot, String seId, Path path) throws IOException { 244 super(lot, seId, path); 245 register("OBJ", McdObjectDef.class); 246 register("ATT", McdAttributeDef.class); 247 register("PGE", McdPrimitiveDef.class); 248 register("ASS", McdSemanticRelationDef.class); 249 register("REL", McdConstructionRelationDef.class); 250 lot.scd = this; 229 251 } 230 252 231 253 @Override 232 protected Block createBlock(String type) { 233 switch (type) { 234 case "OBJ": 235 return new McdObjDef(type); 236 case "ATT": 237 return new McdAttrDef(type); 238 case "PGE": 239 return new McdPrimDef(type); 240 case "ASS": 241 return new McdSemRelDef(type); 242 case "REL": 243 return new McdBuildRelDef(type); 244 default: 245 throw new IllegalArgumentException(type); 246 } 254 public EdigeoFileSCD read(DataSet ds) throws IOException, ReflectiveOperationException { 255 super.read(ds); 256 return this; 247 257 } 248 258 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileTHF.java
r33646 r33649 10 10 import java.util.Collections; 11 11 import java.util.List; 12 import java.util.Objects; 13 14 import org.openstreetmap.josm.data.osm.DataSet; 12 15 13 16 /** … … 186 189 /** LON */ String name = ""; 187 190 /** INF */ String information = ""; 188 /** GNN */ String gen DataName = "";189 /** GNI */ String gen DataId = "";190 /** GON */ String coorRefName = "";191 /** GOI */ String coorRefId = "";192 /** QAN */ String q ualityName = "";193 /** QAI */ String q ualityId = "";194 /** DIN */ String dic tName = "";195 /** DII */ String dic tId = "";191 /** GNN */ String genName = ""; 192 /** GNI */ String genId = ""; 193 /** GON */ String geoName = ""; 194 /** GOI */ String geoId = ""; 195 /** QAN */ String qalName = ""; 196 /** QAI */ String qalId = ""; 197 /** DIN */ String dicName = ""; 198 /** DII */ String dicId = ""; 196 199 /** SCN */ String scdName = ""; 197 200 /** SCI */ String scdId = ""; 198 /** GDC */ int nGeoData; 199 /** GDN */ final List<String> geoDataName = new ArrayList<>(); 200 /** GDI */ final List<String> geoDataId = new ArrayList<>(); 201 /** GDC */ int nVec; 202 /** GDN */ final List<String> vecName = new ArrayList<>(); 203 /** GDI */ final List<String> vecId = new ArrayList<>(); 204 205 EdigeoFileGEN gen; 206 EdigeoFileGEO geo; 207 EdigeoFileDIC dic; 208 EdigeoFileSCD scd; 209 EdigeoFileQAL qal; 210 final List<EdigeoFileVEC> vec = new ArrayList<>(); 201 211 202 212 Lot(String type) { … … 209 219 case "LON": safeGetAndLog(r, s -> name += s, tr("Name")); break; 210 220 case "INF": safeGetAndLog(r, s -> information += s, tr("Information")); break; 211 case "GNN": safeGet(r, s -> gen DataName += s); break;212 case "GNI": safeGet(r, s -> gen DataId += 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 -> q ualityName += s); break;216 case "QAI": safeGet(r, s -> q ualityId += s); break;217 case "DIN": safeGet(r, s -> dic tName += s); break;218 case "DII": safeGet(r, s -> dic tId += s); break;221 case "GNN": safeGet(r, s -> genName += s); break; 222 case "GNI": safeGet(r, s -> genId += s); break; 223 case "GON": safeGet(r, s -> geoName += s); break; 224 case "GOI": safeGet(r, s -> geoId += s); break; 225 case "QAN": safeGet(r, s -> qalName += s); break; 226 case "QAI": safeGet(r, s -> qalId += s); break; 227 case "DIN": safeGet(r, s -> dicName += s); break; 228 case "DII": safeGet(r, s -> dicId += s); break; 219 229 case "SCN": safeGet(r, s -> scdName += s); break; 220 230 case "SCI": safeGet(r, s -> scdId += s); break; 221 case "GDC": n GeoData= safeGetInt(r); break;222 case "GDN": safeGet(r, geoDataName); break;223 case "GDI": safeGet(r, geoDataId); break;231 case "GDC": nVec = safeGetInt(r); break; 232 case "GDN": safeGet(r, vecName); break; 233 case "GDI": safeGet(r, vecId); break; 224 234 default: 225 235 super.processRecord(r); … … 227 237 } 228 238 239 void readFiles(Path path, DataSet ds) throws IOException, ReflectiveOperationException { 240 Path dir = path.getParent(); 241 new EdigeoFileGEN(this, genId, dir.resolve(name + genName + ".GEN")).read(ds); 242 new EdigeoFileGEO(this, geoId, dir.resolve(name + geoName + ".GEO")).read(ds); 243 new EdigeoFileDIC(this, dicId, dir.resolve(name + dicName + ".DIC")).read(ds); 244 new EdigeoFileSCD(this, scdId, dir.resolve(name + scdName + ".SCD")).read(ds); 245 new EdigeoFileQAL(this, qalId, dir.resolve(name + qalName + ".QAL")).read(ds); 246 for (int i = 0; i < getNumberOfGeoData(); i++) { 247 new EdigeoFileVEC(this, vecId.get(i), dir.resolve(name + vecName.get(i) + ".VEC")).read(ds); 248 } 249 } 250 229 251 /** 230 252 * Returns name. … … 248 270 */ 249 271 public final String getGenDataName() { 250 return gen DataName;272 return genName; 251 273 } 252 274 … … 256 278 */ 257 279 public final String getGenDataId() { 258 return gen DataId;280 return genId; 259 281 } 260 282 … … 264 286 */ 265 287 public final String getCoorRefName() { 266 return coorRefName;288 return geoName; 267 289 } 268 290 … … 272 294 */ 273 295 public final String getCoorRefId() { 274 return coorRefId;296 return geoId; 275 297 } 276 298 … … 280 302 */ 281 303 public final String getQualityName() { 282 return q ualityName;304 return qalName; 283 305 } 284 306 … … 288 310 */ 289 311 public final String getQualityId() { 290 return q ualityId;312 return qalId; 291 313 } 292 314 … … 296 318 */ 297 319 public final String getDictName() { 298 return dic tName;320 return dicName; 299 321 } 300 322 … … 304 326 */ 305 327 public final String getDictId() { 306 return dic tId;328 return dicId; 307 329 } 308 330 … … 328 350 */ 329 351 public final int getNumberOfGeoData() { 330 return n GeoData;352 return nVec; 331 353 } 332 354 … … 337 359 */ 338 360 public final String getGeoDataName(int i) { 339 return geoDataName.get(i);361 return vecName.get(i); 340 362 } 341 363 … … 345 367 */ 346 368 public final List<String> getGeoDataNames() { 347 return Collections.unmodifiableList( geoDataName);369 return Collections.unmodifiableList(vecName); 348 370 } 349 371 … … 353 375 */ 354 376 public final List<String> getGeoDataIds() { 355 return Collections.unmodifiableList( geoDataId);377 return Collections.unmodifiableList(vecId); 356 378 } 357 379 … … 362 384 */ 363 385 public final String getGeoDataId(int i) { 364 return geoDataId.get(i); 365 } 366 } 367 368 Support support; 369 List<Lot> lots; 386 return vecId.get(i); 387 } 388 } 389 390 /** 391 * Block inside {@link EdigeoLotFile}. 392 */ 393 public static class ChildBlock extends Block { 394 395 protected final Lot lot; 396 397 ChildBlock(Lot lot, String type) { 398 super(type); 399 this.lot = Objects.requireNonNull(lot, "lot"); 400 } 401 } 402 403 /** GTS */ Support support; 404 /** GTL */ final List<Lot> lots = new ArrayList<>(); 370 405 371 406 /** … … 378 413 } 379 414 380 @Override381 protected void init() {382 lots = new ArrayList<>();383 }384 385 415 /** 386 416 * Returns the support descriptor. … … 402 432 protected Block createBlock(String type) { 403 433 switch (type) { 404 case "GTS": 405 support = new Support(type); 406 return support; 407 case "GTL": 408 Lot lot = new Lot(type); 409 lots.add(lot); 410 return lot; 434 case "GTS": return support = new Support(type); 435 case "GTL": return addBlock(lots, new Lot(type)); 411 436 default: 412 437 throw new IllegalArgumentException(type); 413 438 } 414 439 } 440 441 @Override 442 public EdigeoFileTHF read(DataSet ds) throws IOException, ReflectiveOperationException { 443 super.read(ds); 444 for (Lot lot : getLots()) { 445 lot.readFiles(path, ds); 446 } 447 return this; 448 } 415 449 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileVEC.java
r33648 r33649 5 5 import java.nio.file.Path; 6 6 import java.util.ArrayList; 7 import java.util.Collections; 7 8 import java.util.HashMap; 8 9 import java.util.List; … … 10 11 11 12 import org.openstreetmap.josm.data.coor.EastNorth; 13 import org.openstreetmap.josm.data.osm.DataSet; 14 import org.openstreetmap.josm.data.osm.Node; 15 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.McdObjectDef; 16 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.McdPrimitiveDef; 17 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.McdRelationDef; 18 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.ScdBlock; 19 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock; 20 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot; 21 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileVEC.VecBlock; 12 22 13 23 /** 14 24 * Edigeo VEC file. 15 25 */ 16 public class EdigeoFileVEC extends EdigeoFile { 26 public class EdigeoFileVEC extends EdigeoLotFile<VecBlock<?>> { 27 28 abstract static class VecBlock<T extends ScdBlock> extends ChildBlock { 29 final Class<T> klass; 30 31 /** SCP */ T scdRef; 32 33 VecBlock(Lot lot, String type, Class<T> klass) { 34 super(lot, type); 35 this.klass = klass; 36 } 37 38 @Override 39 void processRecord(EdigeoRecord r) { 40 switch (r.name) { 41 case "SCP": scdRef = lot.scd.find(r.values, klass); break; 42 default: 43 super.processRecord(r); 44 } 45 } 46 } 17 47 18 48 /** 19 49 * Node descriptor block. 20 50 */ 21 public static class NodeBlock extends Block{51 public static class NodeBlock extends VecBlock<McdPrimitiveDef> { 22 52 23 53 enum NodeType { … … 40 70 } 41 71 42 /** SCP */ String scdRef = "";43 72 /** TYP */ NodeType nodeType; 44 73 /** COR */ EastNorth coordinate; … … 46 75 /** QAC */ int nQualities; 47 76 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; 77 NodeBlock(Lot lot, String type) { 78 super(lot, type, McdPrimitiveDef.class); 79 } 80 81 @Override 82 void processRecord(EdigeoRecord r) { 83 switch (r.name) { 56 84 case "TYP": nodeType = NodeType.of(safeGetInt(r)); break; 57 85 case "COR": coordinate = safeGetEastNorth(r); break; … … 62 90 } 63 91 } 92 93 /** 94 * Returns the reference to SCD. 95 * @return the reference to SCD 96 */ 97 public final McdPrimitiveDef getScdRef() { 98 return scdRef; 99 } 100 101 /** 102 * Returns the node type. 103 * @return the node type 104 */ 105 public final NodeType getNodeType() { 106 return nodeType; 107 } 108 109 /** 110 * Returns the node coordinates. 111 * @return the node coordinates 112 */ 113 public final EastNorth getCoordinate() { 114 return coordinate; 115 } 116 117 /** 118 * Returns the number of attributes. 119 * @return the number of attributes 120 */ 121 public final int getNumberOfAttributes() { 122 return nAttributes; 123 } 124 125 /** 126 * Returns the number of quality indicators. 127 * @return the number of quality indicators 128 */ 129 public final int getNumberOfQualityIndicators() { 130 return nQualities; 131 } 64 132 } 65 133 … … 67 135 * Arc descriptor block. 68 136 */ 69 public static class ArcBlock extends Block{137 public static class ArcBlock extends VecBlock<McdPrimitiveDef> { 70 138 enum ArcType { 71 139 LINE(1), … … 88 156 } 89 157 90 /** SCP */ String scdRef = "";91 158 /** CM1 */ EastNorth minCoordinate; 92 159 /** CM2 */ EastNorth maxCoordinate; … … 98 165 /** QAC */ int nQualities; 99 166 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; 167 ArcBlock(Lot lot, String type) { 168 super(lot, type, McdPrimitiveDef.class); 169 } 170 171 @Override 172 void processRecord(EdigeoRecord r) { 173 switch (r.name) { 108 174 case "CM1": minCoordinate = safeGetEastNorth(r); break; 109 175 case "CM2": maxCoordinate = safeGetEastNorth(r); break; … … 129 195 * Face descriptor block. 130 196 */ 131 public static class FaceBlock extends Block { 132 /** SCP */ String scdRef = ""; 197 public static class FaceBlock extends VecBlock<McdPrimitiveDef> { 133 198 /** CM1 */ EastNorth minCoordinate; 134 199 /** CM2 */ EastNorth maxCoordinate; … … 136 201 /** QAC */ int nQualities; 137 202 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; 203 FaceBlock(Lot lot, String type) { 204 super(lot, type, McdPrimitiveDef.class); 205 } 206 207 @Override 208 void processRecord(EdigeoRecord r) { 209 switch (r.name) { 146 210 case "CM1": minCoordinate = safeGetEastNorth(r); break; 147 211 case "CM2": maxCoordinate = safeGetEastNorth(r); break; … … 157 221 * Object descriptor block. 158 222 */ 159 public static class ObjectBlock extends Block { 160 /** SCP */ String scdRef = ""; 223 public static class ObjectBlock extends VecBlock<McdObjectDef> { 161 224 /** CM1 */ EastNorth minCoordinate; 162 225 /** CM2 */ EastNorth maxCoordinate; … … 169 232 /** QAP */ final List<String> qualityIndics = new ArrayList<>(); 170 233 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; 234 ObjectBlock(Lot lot, String type) { 235 super(lot, type, McdObjectDef.class); 236 } 237 238 @Override 239 void processRecord(EdigeoRecord r) { 240 switch (r.name) { 179 241 case "CM1": minCoordinate = safeGetEastNorth(r); break; 180 242 case "CM2": maxCoordinate = safeGetEastNorth(r); break; … … 195 257 * Relation descriptor block. 196 258 */ 197 public static class RelationBlock extends Block{259 public static class RelationBlock extends VecBlock<McdRelationDef> { 198 260 199 261 enum Composition { … … 216 278 } 217 279 218 /** SCP */ String scdRef = "";219 280 /** FTC */ int nElements; 220 281 /** FTP */ final List<String> elements = new ArrayList<>(); … … 223 284 /** QAC */ int nQualities; 224 285 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; 286 RelationBlock(Lot lot, String type) { 287 super(lot, type, McdRelationDef.class); 288 } 289 290 @Override 291 void processRecord(EdigeoRecord r) { 292 switch (r.name) { 233 293 case "FTC": nElements = safeGetInt(r); break; 234 294 case "FTP": safeGet(r, elements); break; … … 244 304 /** 245 305 * Constructs a new {@code EdigeoFileVEC}. 306 * @param lot parent lot 307 * @param seId subset id 246 308 * @param path path to VEC file 247 309 * @throws IOException if any I/O error occurs 248 310 */ 249 public EdigeoFileVEC(Path path) throws IOException { 250 super(path); 311 public EdigeoFileVEC(Lot lot, String seId, Path path) throws IOException { 312 super(lot, seId, path); 313 register("PNO", NodeBlock.class); 314 register("PAR", ArcBlock.class); 315 register("PFE", FaceBlock.class); 316 register("FEA", ObjectBlock.class); 317 register("LNK", RelationBlock.class); 318 lot.vec.add(this); 251 319 } 252 320 253 321 @Override 254 protected Block createBlock(String type) { 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 } 322 public EdigeoFileVEC read(DataSet ds) throws IOException, ReflectiveOperationException { 323 super.read(ds); 324 for (NodeBlock nb : getNodes()) { 325 assert nb.getNumberOfAttributes() == 0; 326 assert nb.getNumberOfQualityIndicators() == 0; 327 Node n = new Node(nb.getCoordinate()); 328 ds.addPrimitive(n); 329 } 330 return this; 331 } 332 333 /** 334 * Returns the list of node descriptors. 335 * @return the list of node descriptors 336 */ 337 public final List<NodeBlock> getNodes() { 338 return Collections.unmodifiableList(blocks.getInstances(NodeBlock.class)); 339 } 340 341 /** 342 * Returns the list of arc descriptors. 343 * @return the list of arc descriptors 344 */ 345 public final List<ArcBlock> getArcs() { 346 return Collections.unmodifiableList(blocks.getInstances(ArcBlock.class)); 347 } 348 349 /** 350 * Returns the list of face descriptors. 351 * @return the list of face descriptors 352 */ 353 public final List<FaceBlock> getFaces() { 354 return Collections.unmodifiableList(blocks.getInstances(FaceBlock.class)); 355 } 356 357 /** 358 * Returns the list of object descriptors. 359 * @return the list of object descriptors 360 */ 361 public final List<ObjectBlock> getObjects() { 362 return Collections.unmodifiableList(blocks.getInstances(ObjectBlock.class)); 363 } 364 365 /** 366 * Returns the list of relation descriptors. 367 * @return the list of relation descriptors 368 */ 369 public final List<RelationBlock> getRelations() { 370 return Collections.unmodifiableList(blocks.getInstances(RelationBlock.class)); 269 371 } 270 372 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/pci/EdigeoPciReader.java
r33645 r33649 12 12 import org.openstreetmap.josm.io.AbstractReader; 13 13 import org.openstreetmap.josm.io.IllegalDataException; 14 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileDIC;15 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileGEN;16 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileGEO;17 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileQAL;18 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD;19 14 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF; 20 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot;21 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileVEC;22 15 23 16 /** … … 40 33 } catch (IOException e) { 41 34 throw e; 42 } catch ( Throwable t) {43 throw new IOException( t);35 } catch (Exception | AssertionError e) { 36 throw new IOException(e); 44 37 } 45 38 } 46 39 47 DataSet parse(Path path, ProgressMonitor instance) throws IOException { 48 Path dir = path.getParent(); 49 EdigeoFileTHF thf = new EdigeoFileTHF(path); 50 for (Lot lot : thf.getLots()) { 51 EdigeoFileGEN gen = new EdigeoFileGEN(dir.resolve(lot.getName()+lot.getGenDataName()+".GEN")); 52 EdigeoFileGEO geo = new EdigeoFileGEO(dir.resolve(lot.getName()+lot.getCoorRefName()+".GEO")); 53 EdigeoFileDIC dic = new EdigeoFileDIC(dir.resolve(lot.getName()+lot.getDictName()+".DIC")); 54 EdigeoFileSCD scd = new EdigeoFileSCD(dir.resolve(lot.getName()+lot.getScdName()+".SCD")); 55 EdigeoFileQAL qal = new EdigeoFileQAL(dir.resolve(lot.getName()+lot.getQualityName()+".QAL")); 56 for (int i = 0; i < lot.getNumberOfGeoData(); i++) { 57 EdigeoFileVEC vec = new EdigeoFileVEC(dir.resolve(lot.getName()+lot.getGeoDataName(i)+".VEC")); 58 } 59 } 60 DataSet ds = new DataSet(); 61 ds.setName(thf.getSupport().getBlockIdentifier()); 62 ds.setUploadPolicy(UploadPolicy.DISCOURAGED); 63 return ds; 40 DataSet parse(Path path, ProgressMonitor instance) throws IOException, ReflectiveOperationException { 41 DataSet data = new DataSet(); 42 data.setUploadPolicy(UploadPolicy.DISCOURAGED); 43 EdigeoFileTHF thf = new EdigeoFileTHF(path).read(data); 44 data.setName(thf.getSupport().getBlockIdentifier()); 45 return data; 64 46 } 65 47
Note:
See TracChangeset
for help on using the changeset viewer.