Ignore:
Timestamp:
2017-09-22T00:19:23+02:00 (7 years ago)
Author:
donvip
Message:

Edigeo: improve parsing of SCD & SCP references, code refactoring

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  
    1414
    1515import org.openstreetmap.josm.data.coor.EastNorth;
     16import org.openstreetmap.josm.data.osm.DataSet;
    1617import org.openstreetmap.josm.tools.Logging;
    1718
     
    102103    }
    103104
     105    protected final Path path;
    104106    private boolean bomFound;
    105107    private boolean eomFound;
     
    107109    private Block currentBlock;
    108110
    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 {
    111116        try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.ISO_8859_1)) {
    112117            String line;
     
    148153            }
    149154        }
     155        return this;
    150156    }
    151157
    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;
    154163    }
    155164
    156     protected abstract Block createBlock(String type);
    157 
    158     private void processRecord(EdigeoRecord r) {
     165    private void processRecord(EdigeoRecord r) throws ReflectiveOperationException {
    159166        if ("RTY".equals(r.name)) {
    160             currentBlock = createBlock(r.values.get(0));
     167            currentBlock = Objects.requireNonNull(createBlock(r.values.get(0)), r.toString());
    161168            return;
    162169        }
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileDIC.java

    r33646 r33649  
    88import java.util.List;
    99
     10import org.openstreetmap.josm.data.osm.DataSet;
     11import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileDIC.DicBlock;
     12import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock;
     13import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot;
     14
    1015/**
    1116 * Edigeo DIC file.
    1217 */
    13 public class EdigeoFileDIC extends EdigeoFile {
     18public class EdigeoFileDIC extends EdigeoLotFile<DicBlock> {
    1419
    1520    /**
    1621     * Abstract definition.
    1722     */
    18     abstract static class Def extends Block {
     23    abstract static class DicBlock extends ChildBlock {
    1924
    2025        /** LAB */ String code = "";
     
    2429        /** CAT */ String category = "";
    2530
    26         Def(String type) {
    27             super(type);
     31        DicBlock(Lot lot, String type) {
     32            super(lot, type);
    2833        }
    2934
     
    7782     * Object definition.
    7883     */
    79     public static class ObjectDef extends Def {
    80         ObjectDef(String type) {
    81             super(type);
     84    public static class ObjectDef extends DicBlock {
     85        ObjectDef(Lot lot, String type) {
     86            super(lot, type);
    8287        }
    8388    }
     
    8691     * Attribute definition.
    8792     */
    88     public static class AttributeDef extends Def {
     93    public static class AttributeDef extends DicBlock {
    8994
    9095        /** TYP */ String type = "";
     
    9499        /** AVD */ final List<String> descrs = new ArrayList<>();
    95100
    96         AttributeDef(String type) {
    97             super(type);
     101        AttributeDef(Lot lot, String type) {
     102            super(lot, type);
    98103        }
    99104
     
    155160     * Relation definition.
    156161     */
    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    }
    166167
    167168    /**
    168169     * Constructs a new {@code EdigeoFileDIC}.
     170     * @param lot parent lot
     171     * @param seId subset id
    169172     * @param path path to DIC file
    170173     * @throws IOException if any I/O error occurs
    171174     */
    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;
    174181    }
    175182
    176183    @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;
    201187    }
    202188
     
    206192     */
    207193    public final List<ObjectDef> getObjects() {
    208         return Collections.unmodifiableList(objects);
     194        return Collections.unmodifiableList(blocks.getInstances(ObjectDef.class));
    209195    }
    210196
     
    214200     */
    215201    public final List<AttributeDef> getAttributes() {
    216         return Collections.unmodifiableList(attributes);
     202        return Collections.unmodifiableList(blocks.getInstances(AttributeDef.class));
    217203    }
    218204
     
    222208     */
    223209    public final List<RelationDef> getRelations() {
    224         return Collections.unmodifiableList(relations);
     210        return Collections.unmodifiableList(blocks.getInstances(RelationDef.class));
    225211    }
    226212}
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileGEN.java

    r33645 r33649  
    77import java.nio.file.Path;
    88
     9import org.openstreetmap.josm.data.osm.DataSet;
     10import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileGEN.GenBlock;
     11import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock;
     12import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot;
     13
    914/**
    1015 * Edigeo GEN file.
    1116 */
    12 public class EdigeoFileGEN extends EdigeoFile {
     17public 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    }
    1324
    1425    /**
    1526     * Geographic bounds.
    1627     */
    17     public static class GeoBounds extends Block {
     28    public static class GeoBounds extends GenBlock {
    1829        /** CM1 */ String min = "";
    1930        /** CM2 */ String max = "";
    2031
    21         GeoBounds(String type) {
    22             super(type);
     32        GeoBounds(Lot lot, String type) {
     33            super(lot, type);
    2334        }
    2435
     
    5364     * Geographic data.
    5465     */
    55     public static class GeoData extends Block {
     66    public static class GeoData extends GenBlock {
    5667
    5768        /**
     
    8495        /** REG */ String offsetId = "";
    8596
    86         GeoData(String type) {
    87             super(type);
     97        GeoData(Lot lot, String type) {
     98            super(lot, type);
    8899        }
    89100
     
    124135    }
    125136
    126     /** DEG */ GeoBounds bounds;
    127     /** GSE */ GeoData geodata;
    128 
    129137    /**
    130138     * Constructs a new {@code EdigeoFileGEN}.
     139     * @param lot parent lot
     140     * @param seId subset id
    131141     * @param path path to GEN file
    132142     * @throws IOException if any I/O error occurs
    133143     */
    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;
    136149    }
    137150
    138151    @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;
    150155    }
    151156}
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileGEO.java

    r33645 r33649  
    77import java.nio.file.Path;
    88
     9import org.openstreetmap.josm.data.osm.DataSet;
     10import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileGEO.GeoBlock;
     11import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock;
     12import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot;
     13
    914/**
    1015 * Edigeo GEO file.
    1116 */
    12 public class EdigeoFileGEO extends EdigeoFile {
     17public 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    }
    1324
    1425    /**
    1526     * Coordinates reference.
    1627     */
    17     public static class CoorReference extends Block {
     28    public static class CoorReference extends GeoBlock {
    1829
    1930        enum ReferenceType {
     
    6374        /** UNH */ String unit = "";
    6475
    65         CoorReference(String type) {
    66             super(type);
     76        CoorReference(Lot lot, String type) {
     77            super(lot, type);
    6778        }
    6879
     
    132143    /**
    133144     * Constructs a new {@code EdigeoFileGEO}.
     145     * @param lot parent lot
     146     * @param seId subset id
    134147     * @param path path to GEO file
    135148     * @throws IOException if any I/O error occurs
    136149     */
    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;
    139154    }
    140155
    141156    @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;
    147160    }
    148161}
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileQAL.java

    r33647 r33649  
    88import java.util.List;
    99
     10import org.openstreetmap.josm.data.osm.DataSet;
     11import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileQAL.QalBlock;
     12import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock;
     13import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot;
     14
    1015/**
    1116 * Edigeo QAL file.
    1217 */
    13 public class EdigeoFileQAL extends EdigeoFile {
     18public 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    }
    1425
    1526    /**
    1627     * Update descriptor.
    1728     */
    18     public static class Update extends Block {
     29    public static class Update extends QalBlock {
    1930
    2031        enum UpdateType {
     
    6778        /** COP */ final List<String> mcdRef = new ArrayList<>();
    6879
    69         Update(String type) {
    70             super(type);
     80        Update(Lot lot, String type) {
     81            super(lot, type);
    7182        }
    7283
     
    90101    /**
    91102     * Constructs a new {@code EdigeoFileQAL}.
     103     * @param lot parent lot
     104     * @param seId subset id
    92105     * @param path path to QAL file
    93106     * @throws IOException if any I/O error occurs
    94107     */
    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;
    97112    }
    98113
    99114    @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;
    105118    }
    106119}
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileSCD.java

    r33647 r33649  
    77import java.util.List;
    88
     9import org.openstreetmap.josm.data.osm.DataSet;
     10import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.ScdBlock;
     11import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock;
     12import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot;
     13
    914/**
    1015 * Edigeo SCD file.
    1116 */
    12 public class EdigeoFileSCD extends EdigeoFile {
     17public 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    }
    1327
    1428    /**
    1529     * MCD Object definition.
    1630     */
    17     public static class McdObjDef extends Block {
     31    public static class McdObjectDef extends ScdBlock {
    1832
    1933        /** DIP */ String dictRef = "";
     
    2337        /** QAC */ int nQualities;
    2438
    25         McdObjDef(String type) {
    26             super(type);
     39        McdObjectDef(Lot lot, String type) {
     40            super(lot, type);
    2741        }
    2842
     
    4458     * MCD Attribute definition.
    4559     */
    46     public static class McdAttrDef extends Block {
     60    public static class McdAttributeDef extends ScdBlock {
    4761
    4862        /** DIP */ String dictRef = "";
     
    5468        /** AV2 */ String max = "";
    5569
    56         McdAttrDef(String type) {
    57             super(type);
     70        McdAttributeDef(Lot lot, String type) {
     71            super(lot, type);
    5872        }
    5973
     
    7791     * MCD Primitive definition.
    7892     */
    79     public static class McdPrimDef extends Block {
     93    public static class McdPrimitiveDef extends ScdBlock {
    8094
    8195        enum PrimitiveKind {
     
    103117        /** QAC */ int nQualities;
    104118
    105         McdPrimDef(String type) {
    106             super(type);
     119        McdPrimitiveDef(Lot lot, String type) {
     120            super(lot, type);
    107121        }
    108122
     
    122136     * MCD Relation definition.
    123137     */
    124     abstract static class McdRelDef extends Block {
     138    abstract static class McdRelationDef extends ScdBlock {
    125139
    126140        /** CA1 */ int minCardinal;
    127141        /** CA2 */ int maxCardinal;
    128142        /** SCC */ int nTypes;
    129         /** SCP */ final List<String> scdRef = new ArrayList<>();
     143        /** SCP */ final List<ScdBlock> scdRef = new ArrayList<>();
    130144        /** OCC */ final List<Integer> nOccurences = new ArrayList<>();
    131145        /** AAC */ int nAttributes;
    132146        /** QAC */ int nQualities;
    133147
    134         McdRelDef(String type) {
    135             super(type);
     148        McdRelationDef(Lot lot, String type) {
     149            super(lot, type);
    136150        }
    137151
     
    142156            case "CA2": maxCardinal = safeGetInt(r); break;
    143157            case "SCC": nTypes = safeGetInt(r); break;
    144             case "SCP": safeGet(r, scdRef); break;
     158            case "SCP": scdRef.add(lot.scd.find(r.values)); break;
    145159            case "OCC": nOccurences.add(safeGetInt(r)); break;
    146160            case "AAC": nAttributes = safeGetInt(r); break;
     
    155169     * MCD Semantic Relation definition.
    156170     */
    157     public static class McdSemRelDef extends McdRelDef {
     171    public static class McdSemanticRelationDef extends McdRelationDef {
    158172
    159173        /** DIP */ String dictRef = "";
    160174
    161         McdSemRelDef(String type) {
    162             super(type);
     175        McdSemanticRelationDef(Lot lot, String type) {
     176            super(lot, type);
    163177        }
    164178
     
    176190     * MCD Construction Relation definition.
    177191     */
    178     public static class McdBuildRelDef extends McdRelDef {
     192    public static class McdConstructionRelationDef extends McdRelationDef {
    179193
    180194        enum RelationKind {
     
    206220        /** KND */ RelationKind kind;
    207221
    208         McdBuildRelDef(String type) {
    209             super(type);
     222        McdConstructionRelationDef(Lot lot, String type) {
     223            super(lot, type);
    210224        }
    211225
     
    222236    /**
    223237     * Constructs a new {@code EdigeoFileSCD}.
     238     * @param lot parent lot
     239     * @param seId subset id
    224240     * @param path path to SCD file
    225241     * @throws IOException if any I/O error occurs
    226242     */
    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;
    229251    }
    230252
    231253    @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;
    247257    }
    248258}
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileTHF.java

    r33646 r33649  
    1010import java.util.Collections;
    1111import java.util.List;
     12import java.util.Objects;
     13
     14import org.openstreetmap.josm.data.osm.DataSet;
    1215
    1316/**
     
    186189        /** LON */ String name = "";
    187190        /** 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 = "";
     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 = "";
    196199        /** SCN */ String scdName = "";
    197200        /** 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<>();
    201211
    202212        Lot(String type) {
     
    209219            case "LON": safeGetAndLog(r, s -> name += s, tr("Name")); break;
    210220            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;
     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;
    219229            case "SCN": safeGet(r, s -> scdName += s); break;
    220230            case "SCI": safeGet(r, s -> scdId += s); break;
    221             case "GDC": nGeoData = 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;
    224234            default:
    225235                super.processRecord(r);
     
    227237        }
    228238
     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
    229251        /**
    230252         * Returns name.
     
    248270         */
    249271        public final String getGenDataName() {
    250             return genDataName;
     272            return genName;
    251273        }
    252274
     
    256278         */
    257279        public final String getGenDataId() {
    258             return genDataId;
     280            return genId;
    259281        }
    260282
     
    264286         */
    265287        public final String getCoorRefName() {
    266             return coorRefName;
     288            return geoName;
    267289        }
    268290
     
    272294         */
    273295        public final String getCoorRefId() {
    274             return coorRefId;
     296            return geoId;
    275297        }
    276298
     
    280302         */
    281303        public final String getQualityName() {
    282             return qualityName;
     304            return qalName;
    283305        }
    284306
     
    288310         */
    289311        public final String getQualityId() {
    290             return qualityId;
     312            return qalId;
    291313        }
    292314
     
    296318         */
    297319        public final String getDictName() {
    298             return dictName;
     320            return dicName;
    299321        }
    300322
     
    304326         */
    305327        public final String getDictId() {
    306             return dictId;
     328            return dicId;
    307329        }
    308330
     
    328350         */
    329351        public final int getNumberOfGeoData() {
    330             return nGeoData;
     352            return nVec;
    331353        }
    332354
     
    337359         */
    338360        public final String getGeoDataName(int i) {
    339             return geoDataName.get(i);
     361            return vecName.get(i);
    340362        }
    341363
     
    345367         */
    346368        public final List<String> getGeoDataNames() {
    347             return Collections.unmodifiableList(geoDataName);
     369            return Collections.unmodifiableList(vecName);
    348370        }
    349371
     
    353375         */
    354376        public final List<String> getGeoDataIds() {
    355             return Collections.unmodifiableList(geoDataId);
     377            return Collections.unmodifiableList(vecId);
    356378        }
    357379
     
    362384         */
    363385        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<>();
    370405
    371406    /**
     
    378413    }
    379414
    380     @Override
    381     protected void init() {
    382         lots = new ArrayList<>();
    383     }
    384 
    385415    /**
    386416     * Returns the support descriptor.
     
    402432    protected Block createBlock(String type) {
    403433        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));
    411436            default:
    412437                throw new IllegalArgumentException(type);
    413438        }
    414439    }
     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    }
    415449}
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileVEC.java

    r33648 r33649  
    55import java.nio.file.Path;
    66import java.util.ArrayList;
     7import java.util.Collections;
    78import java.util.HashMap;
    89import java.util.List;
     
    1011
    1112import org.openstreetmap.josm.data.coor.EastNorth;
     13import org.openstreetmap.josm.data.osm.DataSet;
     14import org.openstreetmap.josm.data.osm.Node;
     15import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.McdObjectDef;
     16import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.McdPrimitiveDef;
     17import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.McdRelationDef;
     18import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.ScdBlock;
     19import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock;
     20import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.Lot;
     21import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileVEC.VecBlock;
    1222
    1323/**
    1424 * Edigeo VEC file.
    1525 */
    16 public class EdigeoFileVEC extends EdigeoFile {
     26public 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    }
    1747
    1848    /**
    1949     * Node descriptor block.
    2050     */
    21     public static class NodeBlock extends Block {
     51    public static class NodeBlock extends VecBlock<McdPrimitiveDef> {
    2252
    2353        enum NodeType {
     
    4070        }
    4171
    42         /** SCP */ String scdRef = "";
    4372        /** TYP */ NodeType nodeType;
    4473        /** COR */ EastNorth coordinate;
     
    4675        /** QAC */ int nQualities;
    4776
    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) {
    5684            case "TYP": nodeType = NodeType.of(safeGetInt(r)); break;
    5785            case "COR": coordinate = safeGetEastNorth(r); break;
     
    6290            }
    6391        }
     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        }
    64132    }
    65133
     
    67135     * Arc descriptor block.
    68136     */
    69     public static class ArcBlock extends Block {
     137    public static class ArcBlock extends VecBlock<McdPrimitiveDef> {
    70138        enum ArcType {
    71139            LINE(1),
     
    88156        }
    89157
    90         /** SCP */ String scdRef = "";
    91158        /** CM1 */ EastNorth minCoordinate;
    92159        /** CM2 */ EastNorth maxCoordinate;
     
    98165        /** QAC */ int nQualities;
    99166
    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) {
    108174            case "CM1": minCoordinate = safeGetEastNorth(r); break;
    109175            case "CM2": maxCoordinate = safeGetEastNorth(r); break;
     
    129195     * Face descriptor block.
    130196     */
    131     public static class FaceBlock extends Block {
    132         /** SCP */ String scdRef = "";
     197    public static class FaceBlock extends VecBlock<McdPrimitiveDef> {
    133198        /** CM1 */ EastNorth minCoordinate;
    134199        /** CM2 */ EastNorth maxCoordinate;
     
    136201        /** QAC */ int nQualities;
    137202
    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) {
    146210            case "CM1": minCoordinate = safeGetEastNorth(r); break;
    147211            case "CM2": maxCoordinate = safeGetEastNorth(r); break;
     
    157221     * Object descriptor block.
    158222     */
    159     public static class ObjectBlock extends Block {
    160         /** SCP */ String scdRef = "";
     223    public static class ObjectBlock extends VecBlock<McdObjectDef> {
    161224        /** CM1 */ EastNorth minCoordinate;
    162225        /** CM2 */ EastNorth maxCoordinate;
     
    169232        /** QAP */ final List<String> qualityIndics = new ArrayList<>();
    170233
    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) {
    179241            case "CM1": minCoordinate = safeGetEastNorth(r); break;
    180242            case "CM2": maxCoordinate = safeGetEastNorth(r); break;
     
    195257     * Relation descriptor block.
    196258     */
    197     public static class RelationBlock extends Block {
     259    public static class RelationBlock extends VecBlock<McdRelationDef> {
    198260
    199261        enum Composition {
     
    216278        }
    217279
    218         /** SCP */ String scdRef = "";
    219280        /** FTC */ int nElements;
    220281        /** FTP */ final List<String> elements = new ArrayList<>();
     
    223284        /** QAC */ int nQualities;
    224285
    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) {
    233293            case "FTC": nElements = safeGetInt(r); break;
    234294            case "FTP": safeGet(r, elements); break;
     
    244304    /**
    245305     * Constructs a new {@code EdigeoFileVEC}.
     306     * @param lot parent lot
     307     * @param seId subset id
    246308     * @param path path to VEC file
    247309     * @throws IOException if any I/O error occurs
    248310     */
    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);
    251319    }
    252320
    253321    @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));
    269371    }
    270372}
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/pci/EdigeoPciReader.java

    r33645 r33649  
    1212import org.openstreetmap.josm.io.AbstractReader;
    1313import 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;
    1914import 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;
    2215
    2316/**
     
    4033        } catch (IOException e) {
    4134            throw e;
    42         } catch (Throwable t) {
    43             throw new IOException(t);
     35        } catch (Exception | AssertionError e) {
     36            throw new IOException(e);
    4437        }
    4538    }
    4639
    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;
    6446    }
    6547
Note: See TracChangeset for help on using the changeset viewer.