Ignore:
Timestamp:
2017-09-24T15:54:56+02:00 (7 years ago)
Author:
donvip
Message:

Edigeo: better support of lines, with theorical multi-arc support (not tested)

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

Legend:

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

    r33659 r33660  
    164164        @Override
    165165        public String toString() {
    166             return "McdAttributeDef [dictRef=" + dictRef + ", nMaxChars=" + nMaxChars + ", nMaxDigits=" + nMaxDigits
    167                     + ", nMaxExponent=" + nMaxExponent + ", unit=" + unit + ", min=" + min + ", max=" + max + ", type="
    168                     + type + ", identifier=" + identifier + ']';
     166            return "McdAttributeDef [identifier=" + identifier + ']';
    169167        }
    170168    }
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileVEC.java

    r33659 r33660  
    1010import java.util.Map;
    1111import java.util.Objects;
     12import java.util.function.Predicate;
    1213import java.util.stream.Collectors;
     14import java.util.stream.Stream;
    1315
    1416import org.openstreetmap.josm.data.coor.EastNorth;
     
    3335import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileVEC.VecBlock;
    3436import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoRecord.Nature;
     37import org.openstreetmap.josm.tools.Logging;
    3538
    3639/**
     
    105108            return parentRelations.stream().filter(r -> r.scdRef instanceof McdSemanticRelationDef).collect(Collectors.toList());
    106109        }
     110
     111        /**
     112         * Returns the number of attributes.
     113         * @return the number of attributes
     114         */
     115        public final int getNumberOfAttributes() {
     116            return nAttributes;
     117        }
     118
     119        public final List<McdAttributeDef> getAttributeDefinitions() {
     120            return Collections.unmodifiableList(attributeDefs);
     121        }
     122
     123        public final McdAttributeDef getAttributeDefinition(int i) {
     124            return attributeDefs.get(i);
     125        }
     126
     127        public final String getAttributeValue(int i) {
     128            return attributeValues.get(i);
     129        }
    107130    }
    108131
     
    197220
    198221        /**
    199          * Returns the number of attributes.
    200          * @return the number of attributes
    201          */
    202         public final int getNumberOfAttributes() {
    203             return nAttributes;
    204         }
    205 
    206         /**
    207222         * Returns the number of quality indicators.
    208223         * @return the number of quality indicators
     
    312327        @Override
    313328        public String toString() {
    314             return "ObjectBlock [identifier=" + identifier + ']';
     329            return "ObjectBlock [identifier=" + identifier + ", attributeDefs=" + attributeDefs +", attributeValues=" + attributeValues + ']';
    315330        }
    316331    }
     
    389404    }
    390405
     406    private static final List<Predicate<ObjectBlock>> ignoredObjects = new ArrayList<>();
     407
     408    /**
     409     * Adds a predicate to ignore a special type of object.
     410     * @param predicate defines how to identify the object to ignore
     411     * @return {@code true}
     412     */
     413    public static boolean addIgnoredObject(Predicate<ObjectBlock> predicate) {
     414        return ignoredObjects.add(Objects.requireNonNull(predicate, "predicate"));
     415    }
     416
     417    /**
     418     * Adds a predicate to ignore a special type of object based on a key/value attribute.
     419     * @param key attribute key
     420     * @param value attribute value
     421     * @return {@code true}
     422     */
     423    public static boolean addIgnoredObject(String key, String value) {
     424        return addIgnoredObject(o -> {
     425            for (int i = 0; i < o.nAttributes; i++) {
     426                if (key.equals(o.attributeDefs.get(i).identifier)
     427                        && value.equals(o.attributeValues.get(i))) {
     428                    return true;
     429                }
     430            }
     431            return false;
     432        });
     433    }
     434
    391435    /**
    392436     * Constructs a new {@code EdigeoFileVEC}.
     
    427471        Projection proj = lot.geo.getCoorReference().getProjection();
    428472        for (ObjectBlock obj : getObjects()) {
    429             List<RelationBlock> constructionRelations = obj.getConstructionRelations();
    430             switch (obj.scdRef.kind) {
    431             case POINT: fillPoint(ds, proj, obj, constructionRelations); break;
    432             case LINE: fillLine(ds, proj, obj, constructionRelations); break;
    433             case COMPLEX: break; // TODO
    434             case AREA: break; // TODO
    435             default: throw new IllegalArgumentException(obj.toString());
     473            if (!ignoredObjects.stream().anyMatch(p -> p.test(obj))) {
     474                List<RelationBlock> constructionRelations = obj.getConstructionRelations();
     475                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;
     479                    case COMPLEX: break; // TODO (not used in PCI)
     480                    default: throw new IllegalArgumentException(obj.toString());
     481                }
    436482            }
    437483        }
     
    470516    private static void fillLine(DataSet ds, Projection proj, ObjectBlock obj, List<RelationBlock> constructionRelations) {
    471517        assert constructionRelations.size() >= 1 : constructionRelations;
    472         // TODO sort relations
    473         Way w = new Way();
     518        // Retrieve all arcs for the linear object
     519        final List<ArcBlock> arcs = new ArrayList<>();
    474520        for (RelationBlock rel : constructionRelations) {
    475521            assert rel.scdRef instanceof McdConstructionRelationDef : rel;
     
    481527            for (VecBlock<?> e : rel.elements) {
    482528                if (e instanceof ArcBlock) {
    483                     ArcBlock ab = (ArcBlock) e;
    484                     assert ab.nAttributes == 0 : ab;
    485                     assert ab.nQualities == 0 : ab;
    486                     for (EastNorth en : ab.points) {
    487                         w.addNode(getNodeAt(ds, proj, en));
    488                     }
     529                    arcs.add((ArcBlock) e);
    489530                }
     531            }
     532        }
     533        final double EPSILON = 1e-2;
     534        assert arcs.size() >= 1;
     535        Way w = new Way();
     536        // Some lines are made of several arcs, but they need to be sorted
     537        if (arcs.size() > 1) {
     538            List<ArcBlock> newArcs = arcs.stream().filter(
     539                    a -> arcs.stream().noneMatch(
     540                            b -> b.points.get(0).equalsEpsilon(a.points.get(a.nPoints - 1), EPSILON))).collect(Collectors.toList());
     541            if (newArcs.size() != 1) {
     542                Logging.warn("Unable to process geometry of: " + obj);
     543                return;
     544            }
     545            while (newArcs.size() < arcs.size()) {
     546                ArcBlock ab = newArcs.get(newArcs.size() - 1);
     547                EastNorth en = ab.points.get(ab.nPoints - 1);
     548                Stream<ArcBlock> stream = arcs.stream().filter(a -> a.points.get(0).equalsEpsilon(en, EPSILON));
     549                assert stream.count() == 1;
     550                newArcs.add(stream.findAny().get());
     551            }
     552            assert newArcs.size() == arcs.size();
     553            arcs.clear();
     554            arcs.addAll(newArcs);
     555            w.put(new Tag("fixme", "several_arcs")); // FIXME
     556        }
     557        // Add first node of first arc
     558        w.addNode(getNodeAt(ds, proj, arcs.get(0).points.get(0)));
     559        // For each arc, add all nodes except first one
     560        for (ArcBlock ab : arcs) {
     561            assert ab.nAttributes == 0 : ab;
     562            assert ab.nQualities == 0 : ab;
     563            for (int i = 1; i < ab.nPoints; i++) {
     564                w.addNode(getNodeAt(ds, proj, ab.points.get(i)));
    490565            }
    491566        }
     
    494569    }
    495570
     571    private static void fillArea(DataSet ds, Projection proj, ObjectBlock obj, List<RelationBlock> constructionRelations) {
     572        assert constructionRelations.size() >= 1 : constructionRelations;
     573    }
     574
    496575    /**
    497576     * Returns the list of node descriptors.
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/pci/EdigeoPciReader.java

    r33659 r33660  
    1313import org.openstreetmap.josm.io.IllegalDataException;
    1414import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF;
     15import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileVEC;
    1516
    1617/**
     
    1819 */
    1920public class EdigeoPciReader extends AbstractReader {
     21
     22    static {
     23        EdigeoFileVEC.addIgnoredObject("SYM_id", "31");
     24    }
    2025
    2126    /**
Note: See TracChangeset for help on using the changeset viewer.