Changeset 34355 in osm for applications/editors/josm/plugins/cadastre-fr
- Timestamp:
- 2018-06-26T23:54:13+02:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/CadastrePlugin.java
r34115 r34355 33 33 import org.openstreetmap.josm.gui.MainMenu; 34 34 import org.openstreetmap.josm.gui.MapFrame; 35 import org.openstreetmap.josm.gui.download.DownloadDialog; 35 36 import org.openstreetmap.josm.gui.layer.Layer; 36 37 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; … … 49 50 import org.openstreetmap.josm.plugins.fr.cadastre.actions.mapmode.WMSAdjustAction; 50 51 import org.openstreetmap.josm.plugins.fr.cadastre.actions.upload.CheckSourceUploadHook; 52 import org.openstreetmap.josm.plugins.fr.cadastre.download.CadastreDownloadSource; 51 53 import org.openstreetmap.josm.plugins.fr.cadastre.download.CadastreDownloadTask; 52 54 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.pci.EdigeoPciImporter; … … 233 235 234 236 MainApplication.getMenu().openLocation.addDownloadTaskClass(CadastreDownloadTask.class); 235 //DownloadDialog.addDownloadSource(new CadastreDownloadSource());237 DownloadDialog.addDownloadSource(new CadastreDownloadSource()); 236 238 } 237 239 -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/download/CadastreDownloadData.java
r34223 r34355 42 42 } 43 43 44 final boolean isDownloadWater() {44 public final boolean isDownloadWater() { 45 45 return downloadWater; 46 46 } 47 47 48 final boolean isDownloadBuilding() {48 public final boolean isDownloadBuilding() { 49 49 return downloadBuilding; 50 50 } 51 51 52 final boolean isDownloadSymbol() {52 public final boolean isDownloadSymbol() { 53 53 return downloadSymbol; 54 54 } 55 55 56 final boolean isDownloadParcel() {56 public final boolean isDownloadParcel() { 57 57 return downloadParcel; 58 58 } 59 59 60 final boolean isDownloadParcelNumber() {60 public final boolean isDownloadParcelNumber() { 61 61 return downloadParcelNumber; 62 62 } 63 63 64 final boolean isDownloadAddress() {64 public final boolean isDownloadAddress() { 65 65 return downloadAddress; 66 66 } 67 67 68 final boolean isDownloadLocality() {68 public final boolean isDownloadLocality() { 69 69 return downloadLocality; 70 70 } 71 71 72 final boolean isDownloadSection() {72 public final boolean isDownloadSection() { 73 73 return downloadSection; 74 74 } 75 75 76 final boolean isDownloadCommune() {76 public final boolean isDownloadCommune() { 77 77 return downloadCommune; 78 78 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/download/CadastreDownloadSource.java
r33675 r34355 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import org.openstreetmap.josm.actions.downloadtasks.DownloadParams; 7 import org.openstreetmap.josm.data.osm.UploadPolicy; 6 8 import org.openstreetmap.josm.gui.download.AbstractDownloadSourcePanel; 7 9 import org.openstreetmap.josm.gui.download.DownloadDialog; … … 21 23 @Override 22 24 public void doDownload(CadastreDownloadData data, DownloadSettings settings) { 23 // TODO download from cadastre API 25 if (settings.getDownloadBounds().isPresent()) { 26 new CadastreDownloadTask(data).download( 27 new DownloadParams().withUploadPolicy(UploadPolicy.BLOCKED).withNewLayer(settings.asNewLayer()), 28 settings.getDownloadBounds().get(), null); 29 } 24 30 } 25 31 -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/download/CadastreDownloadTask.java
r34290 r34355 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.File; 7 import java.io.IOException; 8 import java.util.ArrayList; 9 import java.util.List; 10 import java.util.Objects; 11 import java.util.concurrent.ExecutionException; 6 12 import java.util.concurrent.Future; 13 import java.util.stream.Stream; 7 14 8 15 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 9 16 import org.openstreetmap.josm.actions.downloadtasks.DownloadParams; 10 17 import org.openstreetmap.josm.data.Bounds; 18 import org.openstreetmap.josm.data.osm.DataSet; 19 import org.openstreetmap.josm.data.osm.DownloadPolicy; 20 import org.openstreetmap.josm.data.osm.UploadPolicy; 11 21 import org.openstreetmap.josm.gui.MainApplication; 12 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 13 23 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 24 import org.openstreetmap.josm.plugins.fr.cadastre.api.CadastreAPI; 25 import org.openstreetmap.josm.tools.Logging; 14 26 15 27 /** … … 18 30 public class CadastreDownloadTask extends DownloadOsmTask { 19 31 32 private static final String CADASTRE_URL = "https://cadastre.data.gouv.fr/data/dgfip-pci-vecteur/latest/edigeo/feuilles"; 33 34 private final CadastreDownloadData data; 35 36 /** 37 * Constructs a new {@code CadastreDownloadTask} with default behaviour. 38 */ 39 public CadastreDownloadTask() { 40 this(new CadastreDownloadData(true, true, true, true, true, true, true, true, true)); 41 } 42 43 /** 44 * Constructs a new {@code CadastreDownloadTask} with parameterizable behaviour. 45 * @param data defines which data has to be downloaded 46 */ 47 public CadastreDownloadTask(CadastreDownloadData data) { 48 this.data = Objects.requireNonNull(data); 49 } 50 20 51 @Override 21 public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) { 22 return null; 52 public Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor) { 53 List<Future<?>> tasks = new ArrayList<>(); 54 try { 55 for (String id : CadastreAPI.getSheets(downloadArea)) { 56 String url = String.join("/", CADASTRE_URL, id.substring(0, 2), id.substring(0, 5), "edigeo-"+id+".tar.bz2"); 57 tasks.add(MainApplication.worker.submit(new InternalDownloadTask(settings, url, progressMonitor))); 58 } 59 } catch (IOException e) { 60 Logging.error(e); 61 } 62 return MainApplication.worker.submit(() -> { 63 for (Future<?> f : tasks) { 64 try { 65 f.get(); 66 } catch (InterruptedException | ExecutionException e) { 67 Logging.error(e); 68 } 69 } 70 }); 23 71 } 24 72 … … 40 88 } 41 89 90 static class CadastreDataLayer extends OsmDataLayer { 91 92 CadastreDataLayer(DataSet data, String name, File associatedFile) { 93 super(data, name, associatedFile); 94 } 95 } 96 42 97 class InternalDownloadTask extends DownloadTask { 43 98 … … 45 100 46 101 InternalDownloadTask(DownloadParams settings, String url, ProgressMonitor progressMonitor) { 47 super(settings, new CadastreServerReader(url ), progressMonitor);102 super(settings, new CadastreServerReader(url, data), progressMonitor); 48 103 this.url = url; 49 104 } 50 105 51 106 @Override 52 protected OsmDataLayer createNewLayer(String layerName) { 53 return super.createNewLayer(layerName != null ? layerName : url.substring(url.lastIndexOf('/')+1)); 107 protected CadastreDataLayer createNewLayer(String layerName) { 108 String realLayerName = layerName != null ? layerName : url.substring(url.lastIndexOf('/')+1); 109 if (realLayerName == null || realLayerName.isEmpty()) { 110 realLayerName = settings.getLayerName(); 111 } 112 if (realLayerName == null || realLayerName.isEmpty()) { 113 realLayerName = OsmDataLayer.createNewName(); 114 } 115 dataSet.setDownloadPolicy(DownloadPolicy.BLOCKED); 116 dataSet.setUploadPolicy(UploadPolicy.BLOCKED); 117 return new CadastreDataLayer(dataSet, realLayerName, null); 118 } 119 120 private Stream<CadastreDataLayer> getCadastreDataLayers() { 121 return MainApplication.getLayerManager().getLayersOfType(CadastreDataLayer.class).stream(); 122 } 123 124 @Override 125 protected long getNumModifiableDataLayers() { 126 return getCadastreDataLayers().count(); 127 } 128 129 @Override 130 protected CadastreDataLayer getFirstModifiableDataLayer() { 131 return getCadastreDataLayers().findFirst().orElse(null); 54 132 } 55 133 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/download/CadastreServerReader.java
r33680 r34355 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.util.Objects; 5 7 6 8 import org.openstreetmap.josm.data.osm.DataSet; … … 16 18 17 19 private final String url; 20 private final CadastreDownloadData data; 18 21 19 22 /** 20 23 * Constructs a new {@code CadastreServerReader}. 21 24 * @param url source URL 25 * @param data defines which data has to be downloaded 22 26 */ 23 public CadastreServerReader(String url) { 24 this.url = url; 27 public CadastreServerReader(String url, CadastreDownloadData data) { 28 this.url = Objects.requireNonNull(url); 29 this.data = Objects.requireNonNull(data); 25 30 } 26 31 … … 29 34 try { 30 35 progressMonitor.beginTask(tr("Contacting Server...", 10)); 31 return new EdigeoPciImporter().parseDataSet(url );36 return new EdigeoPciImporter().parseDataSet(url, data); 32 37 } catch (Exception e) { 33 38 throw new OsmTransferException(e); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFile.java
r33661 r34355 17 17 import org.openstreetmap.josm.data.coor.EastNorth; 18 18 import org.openstreetmap.josm.data.osm.DataSet; 19 import org.openstreetmap.josm.plugins.fr.cadastre.download.CadastreDownloadData; 19 20 import org.openstreetmap.josm.tools.Logging; 20 21 … … 212 213 } 213 214 214 EdigeoFile fill(DataSet ds ) {215 EdigeoFile fill(DataSet ds, CadastreDownloadData data) { 215 216 // To be overriden if relevant 216 217 return this; -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileTHF.java
r33663 r34355 15 15 import org.openstreetmap.josm.command.SequenceCommand; 16 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.plugins.fr.cadastre.download.CadastreDownloadData; 17 18 import org.openstreetmap.josm.tools.Logging; 18 19 … … 278 279 } 279 280 280 void fill(DataSet ds ) {281 allFiles.forEach(f -> f.fill(ds ));281 void fill(DataSet ds, CadastreDownloadData data) { 282 allFiles.forEach(f -> f.fill(ds, data)); 282 283 } 283 284 … … 487 488 488 489 @Override 489 public EdigeoFileTHF fill(DataSet ds ) {490 super.fill(ds );490 public EdigeoFileTHF fill(DataSet ds, CadastreDownloadData data) { 491 super.fill(ds, data); 491 492 for (Lot lot : getLots()) { 492 493 //ds.addDataSource(new DataSource(lot.gen.getGeoBounds().getBounds(), support.author)); 493 lot.fill(ds );494 lot.fill(ds, data); 494 495 } 495 496 ds.getWays().forEach(w -> { -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileVEC.java
r34140 r34355 12 12 import java.util.Objects; 13 13 import java.util.function.BiConsumer; 14 import java.util.function.BiPredicate; 14 15 import java.util.function.Predicate; 15 16 import java.util.stream.Collectors; … … 17 18 18 19 import org.openstreetmap.josm.actions.CreateMultipolygonAction; 20 import org.openstreetmap.josm.command.PurgeCommand; 19 21 import org.openstreetmap.josm.command.SequenceCommand; 20 22 import org.openstreetmap.josm.data.coor.EastNorth; … … 29 31 import org.openstreetmap.josm.data.projection.Projection; 30 32 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin; 33 import org.openstreetmap.josm.plugins.fr.cadastre.download.CadastreDownloadData; 31 34 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.McdAttributeDef; 32 35 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.McdConstructionRelationDef; … … 437 440 438 441 private static final List<Predicate<ObjectBlock>> ignoredObjects = new ArrayList<>(); 439 private static final List< Pair<Predicate<ObjectBlock>, BiConsumer<ObjectBlock, OsmPrimitive>>> postProcessors = new ArrayList<>();442 private static final List<EdigeoPostProcessor> postProcessors = new ArrayList<>(); 440 443 441 444 /** … … 482 485 * @param predicate predicate to match 483 486 */ 484 public static void addObjectPostProcessor(BiConsumer<ObjectBlock, OsmPrimitive> consumer, Predicate<ObjectBlock> predicate) { 485 postProcessors.add(new Pair<>(Objects.requireNonNull(predicate, "predicate"), Objects.requireNonNull(consumer, "consumer"))); 487 public static void addObjectPostProcessor( 488 BiConsumer<ObjectBlock, OsmPrimitive> consumer, 489 Predicate<ObjectBlock> predicate, BiPredicate<CadastreDownloadData, OsmPrimitive> filter) { 490 postProcessors.add(new EdigeoPostProcessor(predicate, filter, consumer)); 486 491 } 487 492 … … 492 497 * @param values attribute values 493 498 */ 494 public static void addObjectPostProcessor(BiConsumer<ObjectBlock, OsmPrimitive> consumer, String key, String... values) { 495 postProcessors.add(new Pair<>(predicate(key, values), Objects.requireNonNull(consumer, "consumer"))); 499 public static void addObjectPostProcessor( 500 BiConsumer<ObjectBlock, OsmPrimitive> consumer, 501 BiPredicate<CadastreDownloadData, OsmPrimitive> filter, String key, String... values) { 502 postProcessors.add(new EdigeoPostProcessor(predicate(key, values), filter, consumer)); 496 503 } 497 504 … … 501 508 * @param keyValues OSM attribute key/values (int the form {@code foo=bar;bar=baz}) 502 509 */ 503 public static void addObjectPostProcessor(String symId, String keyValues) {504 postProcessors.add(new Pair<>(predicate("SYM_id", symId), (o, p) -> {510 public static void addObjectPostProcessor(String symId, BiPredicate<CadastreDownloadData, OsmPrimitive> filter, String keyValues) { 511 postProcessors.add(new EdigeoPostProcessor(predicate("SYM_id", symId), filter, (o, p) -> { 505 512 p.remove("SYM_id"); 506 513 for (String tag : keyValues.split(";")) { … … 545 552 546 553 @Override 547 EdigeoFileVEC fill(DataSet ds ) {548 super.fill(ds );554 EdigeoFileVEC fill(DataSet ds, CadastreDownloadData data) { 555 super.fill(ds, data); 549 556 Projection proj = lot.geo.getCoorReference().getProjection(); 557 List<OsmPrimitive> toPurge = new ArrayList<>(); 550 558 for (ObjectBlock obj : getObjects()) { 551 559 if (!ignoredObjects.stream().anyMatch(p -> p.test(obj))) { … … 559 567 } 560 568 if (p != null) { 561 for (Pair<Predicate<ObjectBlock>, BiConsumer<ObjectBlock, OsmPrimitive>> e : postProcessors) { 562 if (e.a.test(obj)) { 563 e.b.accept(obj, p); 569 boolean purged = false; 570 for (EdigeoPostProcessor e : postProcessors) { 571 if (e.predicate.test(obj)) { 572 if (e.filter.test(data, p)) { 573 purged = toPurge.add(p); 574 if (p instanceof Relation) { 575 toPurge.addAll(((Relation) p).getMemberPrimitivesList()); 576 } 577 } else { 578 e.consumer.accept(obj, p); 579 } 564 580 } 565 581 } 566 if ( p.isTagged()) {582 if (!purged && p.isTagged()) { 567 583 p.put("source", CadastrePlugin.source); 568 584 } 569 585 } 570 586 } 587 } 588 if (!toPurge.isEmpty()) { 589 PurgeCommand.build(toPurge, null).executeCommand(); 571 590 } 572 591 return this; -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/pci/EdigeoPciImporter.java
r33680 r34355 9 9 import java.io.IOException; 10 10 import java.io.InputStream; 11 import java.util.Objects; 11 12 12 13 import org.openstreetmap.josm.actions.ExtensionFileFilter; … … 17 18 import org.openstreetmap.josm.io.CachedFile; 18 19 import org.openstreetmap.josm.io.IllegalDataException; 20 import org.openstreetmap.josm.plugins.fr.cadastre.download.CadastreDownloadData; 19 21 import org.openstreetmap.josm.tools.Logging; 20 22 … … 28 30 29 31 protected File file; 32 protected CadastreDownloadData data; 30 33 31 34 /** … … 52 55 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) throws IllegalDataException { 53 56 try { 54 return EdigeoPciReader.parseDataSet(in, file, instance);57 return EdigeoPciReader.parseDataSet(in, file, data, instance); 55 58 } catch (IOException e) { 56 59 throw new IllegalDataException(e); … … 61 64 * Import data from an URL. 62 65 * @param source source URL 66 * @param data defines which data has to be downloaded 63 67 * @return imported data set 64 68 * @throws IOException if any I/O error occurs 65 69 * @throws IllegalDataException if an error was found while parsing the data 66 70 */ 67 public DataSet parseDataSet(final String source ) throws IOException, IllegalDataException {71 public DataSet parseDataSet(final String source, CadastreDownloadData data) throws IOException, IllegalDataException { 68 72 try (CachedFile cf = new CachedFile(source)) { 69 73 this.file = cf.getFile(); 74 this.data = Objects.requireNonNull(data); 70 75 return parseDataSet(cf.getInputStream(), NullProgressMonitor.INSTANCE); 71 76 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/pci/EdigeoPciReader.java
r34115 r34355 14 14 import java.util.Map; 15 15 import java.util.Map.Entry; 16 import java.util.function.BiPredicate; 16 17 import java.util.function.Predicate; 17 18 … … 29 30 import org.openstreetmap.josm.io.AbstractReader; 30 31 import org.openstreetmap.josm.io.IllegalDataException; 32 import org.openstreetmap.josm.plugins.fr.cadastre.download.CadastreDownloadData; 31 33 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF; 32 34 import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileVEC; 35 import org.openstreetmap.josm.tools.Logging; 33 36 import org.openstreetmap.josm.tools.Utils; 34 37 … … 37 40 */ 38 41 public class EdigeoPciReader extends AbstractReader { 42 43 private static final BiPredicate<CadastreDownloadData, OsmPrimitive> water = (x, p) -> !x.isDownloadWater(); 44 private static final BiPredicate<CadastreDownloadData, OsmPrimitive> build = (x, p) -> !x.isDownloadBuilding(); 45 private static final BiPredicate<CadastreDownloadData, OsmPrimitive> symbo = (x, p) -> !x.isDownloadSymbol(); 46 private static final BiPredicate<CadastreDownloadData, OsmPrimitive> parce = (x, p) -> !x.isDownloadParcel(); 47 private static final BiPredicate<CadastreDownloadData, OsmPrimitive> parcn = (x, p) -> !x.isDownloadParcelNumber(); 48 private static final BiPredicate<CadastreDownloadData, OsmPrimitive> addre = (x, p) -> !x.isDownloadAddress(); 49 private static final BiPredicate<CadastreDownloadData, OsmPrimitive> local = (x, p) -> !x.isDownloadLocality(); 50 private static final BiPredicate<CadastreDownloadData, OsmPrimitive> secti = (x, p) -> !x.isDownloadSection(); 51 private static final BiPredicate<CadastreDownloadData, OsmPrimitive> commu = (x, p) -> !x.isDownloadCommune(); 39 52 40 53 private static final Map<String, List<String>> highways = new HashMap<>(); … … 56 69 "31", // Connecting arrows between parcelles and numbers 57 70 "62", // "Sports ground, small streams". What the fuck France? 58 "64" // "parking, terrace, overhang". What the fuck France? 71 "64", // "parking, terrace, overhang". What the fuck France? 72 "98" // "various punctual objects". What the fuck France? 59 73 ); 60 74 61 75 // SYM_id mapping 62 EdigeoFileVEC.addObjectPostProcessor("12", "historic=wayside_cross"); // Calvaire63 EdigeoFileVEC.addObjectPostProcessor("14", "amenity=place_of_worship;religion=christian"); // Church64 EdigeoFileVEC.addObjectPostProcessor("15", "amenity=place_of_worship;religion=muslim"); // Mosque65 EdigeoFileVEC.addObjectPostProcessor("16", "amenity=place_of_worship;religion=jewish"); // Synagogue66 EdigeoFileVEC.addObjectPostProcessor("17", "boundary=administrative;admin_level=2"); // State limit67 EdigeoFileVEC.addObjectPostProcessor("18", "boundary=administrative;admin_level=6"); // Department limit68 EdigeoFileVEC.addObjectPostProcessor("19", "boundary=administrative;admin_level=8"); // Municipality limit trigger69 EdigeoFileVEC.addObjectPostProcessor("21", "highway=road"); // Way70 EdigeoFileVEC.addObjectPostProcessor("22", "highway=road"); // Road trigger76 EdigeoFileVEC.addObjectPostProcessor("12", symbo, "historic=wayside_cross"); // Calvaire 77 EdigeoFileVEC.addObjectPostProcessor("14", symbo, "amenity=place_of_worship;religion=christian"); // Church 78 EdigeoFileVEC.addObjectPostProcessor("15", symbo, "amenity=place_of_worship;religion=muslim"); // Mosque 79 EdigeoFileVEC.addObjectPostProcessor("16", symbo, "amenity=place_of_worship;religion=jewish"); // Synagogue 80 EdigeoFileVEC.addObjectPostProcessor("17", commu, "boundary=administrative;admin_level=2"); // State limit 81 EdigeoFileVEC.addObjectPostProcessor("18", commu, "boundary=administrative;admin_level=6"); // Department limit 82 EdigeoFileVEC.addObjectPostProcessor("19", commu, "boundary=administrative;admin_level=8"); // Municipality limit trigger 83 EdigeoFileVEC.addObjectPostProcessor("21", symbo, "highway=road"); // Way 84 EdigeoFileVEC.addObjectPostProcessor("22", symbo, "highway=road"); // Road trigger 71 85 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { // Path / Footway 72 86 String highwayValue = "path"; … … 81 95 p.put("highway", highwayValue); 82 96 p.remove("SYM_id"); 83 }, "SYM_id", "23"); // Path / Footway84 EdigeoFileVEC.addObjectPostProcessor("24", "man_made=pipeline"); // Pipeline85 EdigeoFileVEC.addObjectPostProcessor("25", "man_made=pipeline"); // Aqueduct86 EdigeoFileVEC.addObjectPostProcessor("26", "aerialway=cable_car"); // Aerialway87 EdigeoFileVEC.addObjectPostProcessor("27", "power=line"); // Force transport line88 EdigeoFileVEC.addObjectPostProcessor("29", "railway=rail"); // Railway89 EdigeoFileVEC.addObjectPostProcessor("33", "bridge=yes"); // Bridge90 EdigeoFileVEC.addObjectPostProcessor("34", "landuse=reservoir;natural=water;water=reservoir"); // reservoir, lake91 EdigeoFileVEC.addObjectPostProcessor("37", "tunnel=yes"); // Tunnel92 EdigeoFileVEC.addObjectPostProcessor("47", "railway=halt"); // Halt93 EdigeoFileVEC.addObjectPostProcessor("48", "railway=stop"); // Stop94 EdigeoFileVEC.addObjectPostProcessor("49", "railway=station"); // Station95 EdigeoFileVEC.addObjectPostProcessor("50", "man_made=mast"); // Pylon96 EdigeoFileVEC.addObjectPostProcessor("51", "landuse=cemetery;religion=christian"); // Christian cemetery97 EdigeoFileVEC.addObjectPostProcessor("52", "landuse=cemetery;religion=muslim"); // Muslim cemetery98 EdigeoFileVEC.addObjectPostProcessor("53", "landuse=cemetery;religion=jewish"); // Jewish cemetery99 EdigeoFileVEC.addObjectPostProcessor("63", "man_made=water_well"); // Well100 EdigeoFileVEC.addObjectPostProcessor("65", "leisure=swimming_pool;access=private"); // Swimming pool97 }, symbo, "SYM_id", "23"); // Path / Footway 98 EdigeoFileVEC.addObjectPostProcessor("24", symbo, "man_made=pipeline"); // Pipeline 99 EdigeoFileVEC.addObjectPostProcessor("25", symbo, "man_made=pipeline"); // Aqueduct 100 EdigeoFileVEC.addObjectPostProcessor("26", symbo, "aerialway=cable_car"); // Aerialway 101 EdigeoFileVEC.addObjectPostProcessor("27", symbo, "power=line"); // Force transport line 102 EdigeoFileVEC.addObjectPostProcessor("29", symbo, "railway=rail"); // Railway 103 EdigeoFileVEC.addObjectPostProcessor("33", symbo, "bridge=yes"); // Bridge 104 EdigeoFileVEC.addObjectPostProcessor("34", water, "landuse=reservoir;natural=water;water=reservoir"); // reservoir, lake 105 EdigeoFileVEC.addObjectPostProcessor("37", symbo, "tunnel=yes"); // Tunnel 106 EdigeoFileVEC.addObjectPostProcessor("47", symbo, "railway=halt"); // Halt 107 EdigeoFileVEC.addObjectPostProcessor("48", symbo, "railway=stop"); // Stop 108 EdigeoFileVEC.addObjectPostProcessor("49", symbo, "railway=station"); // Station 109 EdigeoFileVEC.addObjectPostProcessor("50", symbo, "man_made=mast"); // Pylon 110 EdigeoFileVEC.addObjectPostProcessor("51", symbo, "landuse=cemetery;religion=christian"); // Christian cemetery 111 EdigeoFileVEC.addObjectPostProcessor("52", symbo, "landuse=cemetery;religion=muslim"); // Muslim cemetery 112 EdigeoFileVEC.addObjectPostProcessor("53", symbo, "landuse=cemetery;religion=jewish"); // Jewish cemetery 113 EdigeoFileVEC.addObjectPostProcessor("63", symbo, "man_made=water_well"); // Well 114 EdigeoFileVEC.addObjectPostProcessor("65", water, "leisure=swimming_pool;access=private"); // Swimming pool 101 115 102 116 // Mapping TEX*_id => name (first step) … … 113 127 } 114 128 setName(p, sb.toString()); 115 }, "TEX_id");129 }, (x, p) -> false, "TEX_id"); 116 130 117 131 // Objects mapping … … 131 145 } 132 146 } 133 }, o -> o.hasScdIdentifier("ZONCOMMUNI_id") );147 }, o -> o.hasScdIdentifier("ZONCOMMUNI_id"), symbo); 134 148 135 149 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { … … 140 154 p.remove("IDU_id"); 141 155 p.remove("TEX2_id"); 142 }, o -> o.hasScdIdentifier("COMMUNE_id") );156 }, o -> o.hasScdIdentifier("COMMUNE_id"), commu); 143 157 144 158 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { … … 158 172 p.remove("SUPF_id"); 159 173 }, o -> o.hasScdIdentifier("SECTION_id") || o.hasScdIdentifier("SUBDSECT_id") 160 || o.hasScdIdentifier("PARCELLE_id") || o.hasScdIdentifier("SUBDFISC_id") || o.hasScdIdentifier("CHARGE_id") );161 162 EdigeoFileVEC.addObjectPostProcessor((o, p) -> p.put("wall", "no"), "DUR_id", "02");174 || o.hasScdIdentifier("PARCELLE_id") || o.hasScdIdentifier("SUBDFISC_id") || o.hasScdIdentifier("CHARGE_id"), parce); 175 176 EdigeoFileVEC.addObjectPostProcessor((o, p) -> p.put("wall", "no"), build, "DUR_id", "02"); 163 177 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 164 178 p.put("building", "yes"); 165 179 p.remove("DUR_id"); 166 }, o -> o.hasScdIdentifier("BATIMENT_id") );180 }, o -> o.hasScdIdentifier("BATIMENT_id"), build); 167 181 168 182 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 169 183 p.put("addr:housenumber", p.get("name")); 170 184 p.remove("name"); 171 }, o -> o.hasScdIdentifier("NUMVOIE_id") );185 }, o -> o.hasScdIdentifier("NUMVOIE_id"), addre); 172 186 173 187 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 174 188 p.put("place", "unknown"); 175 189 p.put("fixme", "place type"); 176 }, o -> o.hasScdIdentifier("LIEUDIT_id") );190 }, o -> o.hasScdIdentifier("LIEUDIT_id"), local); 177 191 178 192 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 179 193 p.remove("ORI_id"); 180 }, o -> o.hasScdIdentifier("TPOINT_id") );194 }, o -> o.hasScdIdentifier("TPOINT_id"), (x, p) -> false); 181 195 182 196 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 183 197 p.put("highway", "road"); 184 198 p.put("area", "yes"); 185 }, o -> o.hasScdIdentifier("TRONROUTE_id") );199 }, o -> o.hasScdIdentifier("TRONROUTE_id"), symbo); 186 200 187 201 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 188 202 p.put("waterway", "riverbank"); 189 }, o -> o.hasScdIdentifier("TRONFLUV_id") );203 }, o -> o.hasScdIdentifier("TRONFLUV_id"), water); 190 204 191 205 // Mapping TEX*_id => name (last step) … … 194 208 setName(p, p.get(t)); 195 209 p.remove(t); 196 }, t); 197 } 210 }, (x, p) -> false, t); 211 } 212 213 // Allow to filter parcel numbers 214 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 215 // Do nothing 216 }, o -> true, (x, p) -> { 217 try { 218 return !x.isDownloadParcelNumber() && p.getNumKeys() == 1 && p.hasKey("name") && Integer.parseInt(p.get("name")) > -1; 219 } catch (NumberFormatException e) { 220 Logging.trace(e); 221 return false; 222 } 223 }); 224 225 // Allow to filter labels 226 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 227 // Do nothing 228 }, o -> true, (x, p) -> { 229 try { 230 return !x.isDownloadSymbol() && p.getNumKeys() == 1 && p.hasKey("name") && Integer.parseInt(p.get("name")) <= -1; 231 } catch (NumberFormatException e) { 232 Logging.trace(e); 233 return true; 234 } 235 }); 198 236 } 199 237 … … 228 266 } 229 267 230 static DataSet parseDataSet(InputStream in, File file, ProgressMonitor instance) throws IOException {268 static DataSet parseDataSet(InputStream in, File file, CadastreDownloadData data, ProgressMonitor instance) throws IOException { 231 269 if (in != null) { 232 270 in.close(); 233 271 } 234 272 try { 235 return new EdigeoPciReader().parse(file.toPath(), instance);273 return new EdigeoPciReader().parse(file.toPath(), data, instance); 236 274 } catch (IOException e) { 237 275 throw e; … … 241 279 } 242 280 243 DataSet parse(Path path, ProgressMonitor instance) throws IOException, ReflectiveOperationException {281 DataSet parse(Path path, CadastreDownloadData data, ProgressMonitor instance) throws IOException, ReflectiveOperationException { 244 282 Path tmpDir = null; 245 283 Path thfPath = path; … … 265 303 } 266 304 } 267 DataSet d ata= new DataSet();268 d ata.setUploadPolicy(UploadPolicy.DISCOURAGED);269 EdigeoFileTHF thf = new EdigeoFileTHF(thfPath).read().fill(d ata);270 d ata.setName(thf.getSupport().getBlockIdentifier());271 return d ata;305 DataSet ds = new DataSet(); 306 ds.setUploadPolicy(UploadPolicy.BLOCKED); 307 EdigeoFileTHF thf = new EdigeoFileTHF(thfPath).read().fill(ds, data); 308 ds.setName(thf.getSupport().getBlockIdentifier()); 309 return ds; 272 310 } finally { 273 311 if (tmpDir != null) {
Note:
See TracChangeset
for help on using the changeset viewer.