Changeset 33660 in osm for applications/editors/josm/plugins/cadastre-fr
- Timestamp:
- 2017-09-24T15:54:56+02:00 (7 years ago)
- 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 164 164 @Override 165 165 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 + ']'; 169 167 } 170 168 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileVEC.java
r33659 r33660 10 10 import java.util.Map; 11 11 import java.util.Objects; 12 import java.util.function.Predicate; 12 13 import java.util.stream.Collectors; 14 import java.util.stream.Stream; 13 15 14 16 import org.openstreetmap.josm.data.coor.EastNorth; … … 33 35 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileVEC.VecBlock; 34 36 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoRecord.Nature; 37 import org.openstreetmap.josm.tools.Logging; 35 38 36 39 /** … … 105 108 return parentRelations.stream().filter(r -> r.scdRef instanceof McdSemanticRelationDef).collect(Collectors.toList()); 106 109 } 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 } 107 130 } 108 131 … … 197 220 198 221 /** 199 * Returns the number of attributes.200 * @return the number of attributes201 */202 public final int getNumberOfAttributes() {203 return nAttributes;204 }205 206 /**207 222 * Returns the number of quality indicators. 208 223 * @return the number of quality indicators … … 312 327 @Override 313 328 public String toString() { 314 return "ObjectBlock [identifier=" + identifier + ']';329 return "ObjectBlock [identifier=" + identifier + ", attributeDefs=" + attributeDefs +", attributeValues=" + attributeValues + ']'; 315 330 } 316 331 } … … 389 404 } 390 405 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 391 435 /** 392 436 * Constructs a new {@code EdigeoFileVEC}. … … 427 471 Projection proj = lot.geo.getCoorReference().getProjection(); 428 472 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 } 436 482 } 437 483 } … … 470 516 private static void fillLine(DataSet ds, Projection proj, ObjectBlock obj, List<RelationBlock> constructionRelations) { 471 517 assert constructionRelations.size() >= 1 : constructionRelations; 472 // TODO sort relations473 Way w = new Way();518 // Retrieve all arcs for the linear object 519 final List<ArcBlock> arcs = new ArrayList<>(); 474 520 for (RelationBlock rel : constructionRelations) { 475 521 assert rel.scdRef instanceof McdConstructionRelationDef : rel; … … 481 527 for (VecBlock<?> e : rel.elements) { 482 528 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); 489 530 } 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))); 490 565 } 491 566 } … … 494 569 } 495 570 571 private static void fillArea(DataSet ds, Projection proj, ObjectBlock obj, List<RelationBlock> constructionRelations) { 572 assert constructionRelations.size() >= 1 : constructionRelations; 573 } 574 496 575 /** 497 576 * 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 13 13 import org.openstreetmap.josm.io.IllegalDataException; 14 14 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF; 15 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileVEC; 15 16 16 17 /** … … 18 19 */ 19 20 public class EdigeoPciReader extends AbstractReader { 21 22 static { 23 EdigeoFileVEC.addIgnoredObject("SYM_id", "31"); 24 } 20 25 21 26 /**
Note:
See TracChangeset
for help on using the changeset viewer.