Ignore:
Timestamp:
2017-09-24T18:59:50+02:00 (7 years ago)
Author:
donvip
Message:

Edigeo: decoding of composed attributes

Location:
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFile.java

    r33659 r33661  
    7474        }
    7575
    76         void resolve() {
    77             // To be overriden if relevant
     76        void resolvePhase1() {
     77            // To be overriden if relevant (before relations are resolved)
     78        }
     79
     80        void resolvePhase2() {
     81            // To be overriden if relevant (after relations are resolved)
    7882        }
    7983
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileSCD.java

    r33660 r33661  
    5555
    5656        @Override
    57         void resolve() {
    58             super.resolve();
     57        void resolvePhase1() {
     58            super.resolvePhase1();
    5959            for (List<String> values : lAttributes) {
    6060                attributes.add(lot.scd.find(values, McdAttributeDef.class));
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileVEC.java

    r33660 r33661  
    7777
    7878        @Override
    79         void resolve() {
    80             super.resolve();
     79        void resolvePhase1() {
     80            super.resolvePhase1();
    8181            for (EdigeoRecord r : lAttributeValues) {
     82                // Does not work for composed attributes, the value is overriden in phase 2
     83                attributeValues.add(r.values.get(0));
     84            }
     85        }
     86
     87        @Override
     88        void resolvePhase2() {
     89            super.resolvePhase2();
     90            for (int i = 0; i < nAttributes; i++) {
     91                EdigeoRecord r = lAttributeValues.get(i);
    8292                if (r.nature == Nature.COMPOSED) {
    83                     //attributeValues.add(lot.scd.find(r.values, McdAttributeDef.class).dictRef);
    84                     attributeValues.add(r.values.toString()); // FIXME
    85                 } else {
    86                     attributeValues.add(r.values.get(0));
     93                    assert !parentRelations.isEmpty();
     94                    McdAttributeDef def = lot.scd.find(r.values, McdAttributeDef.class);
     95                    List<RelationBlock> relations = getSemanticRelations().stream().filter(
     96                            rel -> rel.elements.stream().anyMatch(e -> e.attributeDefs.contains(def))).collect(Collectors.toList());
     97                    assert relations.size() == 1;
     98                    List<VecBlock<?>> elements = relations.get(0).elements.stream().filter(
     99                            e -> e.attributeDefs.contains(def)).collect(Collectors.toList());
     100                    assert elements.size() == 1;
     101                    VecBlock<?> e = elements.get(0);
     102                    attributeValues.set(i, e.attributeValues.get(e.attributeDefs.indexOf(def)));
     103                    attributeDefs.set(i, def);
    87104                }
    88105            }
     
    384401
    385402        @Override
    386         final void resolve() {
    387             super.resolve();
     403        final void resolvePhase1() {
     404            super.resolvePhase1();
    388405            for (List<String> values : lElements) {
    389406                VecBlock<?> b = lot.vec.stream().filter(v -> v.subsetId.equals(values.get(1))).findAny()
     
    472489        for (ObjectBlock obj : getObjects()) {
    473490            if (!ignoredObjects.stream().anyMatch(p -> p.test(obj))) {
    474                 List<RelationBlock> constructionRelations = obj.getConstructionRelations();
    475491                switch (obj.scdRef.kind) {
    476                     case POINT: fillPoint(ds, proj, obj, constructionRelations); break;
    477                     case LINE: fillLine(ds, proj, obj, constructionRelations); break;
    478                     case AREA: fillArea(ds, proj, obj, constructionRelations); break;
     492                    case POINT: fillPoint(ds, proj, obj, obj.getConstructionRelations(), obj.getSemanticRelations()); break;
     493                    case LINE: fillLine(ds, proj, obj, obj.getConstructionRelations(), obj.getSemanticRelations()); break;
     494                    case AREA: fillArea(ds, proj, obj, obj.getConstructionRelations(), obj.getSemanticRelations()); break;
    479495                    case COMPLEX: break; // TODO (not used in PCI)
    480496                    default: throw new IllegalArgumentException(obj.toString());
     
    492508    }
    493509
    494     private static void fillPoint(DataSet ds, Projection proj, ObjectBlock obj, List<RelationBlock> constructionRelations) {
    495         assert constructionRelations.size() == 1 : constructionRelations;
    496         RelationBlock rel = constructionRelations.get(0);
    497         assert rel.scdRef instanceof McdConstructionRelationDef : rel;
    498         if (rel.scdRef instanceof McdConstructionRelationDef) {
    499             McdConstructionRelationDef crd = (McdConstructionRelationDef) rel.scdRef;
    500             assert crd.kind == RelationKind.IS_MADE_OF;
    501             assert crd.nAttributes == 0;
    502         }
    503         for (VecBlock<?> e : rel.elements) {
    504             if (e instanceof NodeBlock) {
    505                 NodeBlock nb = (NodeBlock) e;
    506                 assert nb.nAttributes == 0;
    507                 LatLon ll = proj.eastNorth2latlon(nb.getCoordinate());
    508                 //if (ds.searchNodes(around(ll)).isEmpty()) {
    509                 addPrimitiveAndTags(ds, obj, new Node(ll));
    510                 //}
    511                 break;
    512             }
    513         }
    514     }
    515 
    516     private static void fillLine(DataSet ds, Projection proj, ObjectBlock obj, List<RelationBlock> constructionRelations) {
    517         assert constructionRelations.size() >= 1 : constructionRelations;
    518         // Retrieve all arcs for the linear object
    519         final List<ArcBlock> arcs = new ArrayList<>();
     510    @SuppressWarnings("unchecked")
     511    private static <T extends VecBlock<?>> List<T> extract(Class<T> klass, List<RelationBlock> constructionRelations, RelationKind kind) {
     512        final List<T> list = new ArrayList<>();
    520513        for (RelationBlock rel : constructionRelations) {
    521514            assert rel.scdRef instanceof McdConstructionRelationDef : rel;
    522515            if (rel.scdRef instanceof McdConstructionRelationDef) {
    523516                McdConstructionRelationDef crd = (McdConstructionRelationDef) rel.scdRef;
    524                 assert crd.kind == RelationKind.IS_MADE_OF_ARC;
     517                assert crd.kind == kind;
    525518                assert crd.nAttributes == 0;
    526519            }
    527520            for (VecBlock<?> e : rel.elements) {
    528                 if (e instanceof ArcBlock) {
    529                     arcs.add((ArcBlock) e);
     521                if (klass.isInstance(e)) {
     522                    list.add((T) e);
    530523                }
    531524            }
    532525        }
     526        return list;
     527    }
     528
     529    private static void fillPoint(DataSet ds, Projection proj, ObjectBlock obj,
     530            List<RelationBlock> constructionRelations, List<RelationBlock> semanticRelations) {
     531        assert constructionRelations.size() == 1 : constructionRelations;
     532        List<NodeBlock> nodes = extract(NodeBlock.class, constructionRelations, RelationKind.IS_MADE_OF);
     533        assert nodes.size() == 1 : nodes;
     534        NodeBlock nb = nodes.get(0);
     535        assert nb.nAttributes == 0;
     536        LatLon ll = proj.eastNorth2latlon(nb.getCoordinate());
     537        //if (ds.searchNodes(around(ll)).isEmpty()) {
     538        addPrimitiveAndTags(ds, obj, new Node(ll));
     539        //}
     540    }
     541
     542    private static void fillLine(DataSet ds, Projection proj, ObjectBlock obj,
     543            List<RelationBlock> constructionRelations, List<RelationBlock> semanticRelations) {
     544        assert constructionRelations.size() >= 1 : constructionRelations;
     545        // Retrieve all arcs for the linear object
     546        final List<ArcBlock> arcs = extract(ArcBlock.class, constructionRelations, RelationKind.IS_MADE_OF_ARC);
    533547        final double EPSILON = 1e-2;
    534548        assert arcs.size() >= 1;
    535         Way w = new Way();
    536549        // Some lines are made of several arcs, but they need to be sorted
    537550        if (arcs.size() > 1) {
     
    553566            arcs.clear();
    554567            arcs.addAll(newArcs);
    555             w.put(new Tag("fixme", "several_arcs")); // FIXME
    556         }
     568        }
     569        Way w = new Way();
    557570        // Add first node of first arc
    558571        w.addNode(getNodeAt(ds, proj, arcs.get(0).points.get(0)));
     
    569582    }
    570583
    571     private static void fillArea(DataSet ds, Projection proj, ObjectBlock obj, List<RelationBlock> constructionRelations) {
     584    private static void fillArea(DataSet ds, Projection proj, ObjectBlock obj,
     585            List<RelationBlock> constructionRelations, List<RelationBlock> semanticRelations) {
    572586        assert constructionRelations.size() >= 1 : constructionRelations;
     587        // TODO
    573588    }
    574589
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoLotFile.java

    r33659 r33661  
    5757    @Override
    5858    final void resolve() {
    59         blocks.forEach((k, v) -> v.forEach(Block::resolve));
     59        blocks.forEach((k, v) -> v.forEach(Block::resolvePhase1));
     60        blocks.forEach((k, v) -> v.forEach(Block::resolvePhase2));
    6061    }
    6162
Note: See TracChangeset for help on using the changeset viewer.