Changeset 28113 in osm for applications/editors/josm/plugins/opendata/src/org
- Timestamp:
- 2012-03-19T00:23:49+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core
- Files:
-
- 15 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java
r28091 r28113 87 87 public static final String ICON_EMPTY_24 = "empty24.png"; 88 88 89 public static final String ICON_LOOL_48 = "lool48.png"; 90 89 91 /** 90 92 * File extensions. … … 156 158 * Resources 157 159 */ 158 public static final String DICTIONARY_FR = "/org/openstreetmap/josm/plugins/opendata/core/resources/dictionary.fr.csv"; 160 public static final String RESOURCE_PATH = "/org/openstreetmap/josm/plugins/opendata/core/resources/"; 161 public static final String DICTIONARY_FR = RESOURCE_PATH+"dictionary.fr.csv"; 159 162 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataTask.java
r28054 r28113 16 16 package org.openstreetmap.josm.plugins.opendata.core.actions; 17 17 18 import static org.openstreetmap.josm.tools.I18n.tr; 19 18 20 import java.io.File; 21 import java.io.IOException; 19 22 import java.util.concurrent.Future; 20 23 import java.util.regex.Pattern; 24 25 import javax.swing.JOptionPane; 21 26 22 27 import org.openstreetmap.josm.Main; … … 25 30 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 26 31 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 27 import org.openstreetmap.josm.io.AbstractReader;28 32 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 29 33 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 30 34 import org.openstreetmap.josm.plugins.opendata.core.datasets.DataSetUpdater; 35 import org.openstreetmap.josm.plugins.opendata.core.gui.AskLicenseAgreementDialog; 31 36 import org.openstreetmap.josm.plugins.opendata.core.io.NetworkReader; 32 37 import org.openstreetmap.josm.plugins.opendata.core.layers.OdDataLayer; 38 import org.openstreetmap.josm.plugins.opendata.core.licenses.License; 33 39 import org.openstreetmap.josm.plugins.opendata.core.modules.Module; 34 40 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleHandler; … … 37 43 38 44 private AbstractDataSetHandler handler; 45 46 //private static final PdfEditorKit pdfEditorKit = new PdfEditorKit(); 39 47 40 48 @Override … … 45 53 @Override 46 54 public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) { 47 Class<? extends AbstractReader> readerClass = null; // TODO 48 downloadTask = new InternDownloadTasK(newLayer, new NetworkReader(url, handler, readerClass), progressMonitor); 55 downloadTask = new InternalDownloadTasK(newLayer, new NetworkReader(url, handler), progressMonitor); 49 56 currentBounds = null; 50 // Extract .osm filename from URL to set the new layer name 51 //Matcher matcher = Pattern.compile("http://.*/(.*\\.osm)").matcher(url); 52 //newLayerName = matcher.matches() ? matcher.group(1) : null; 53 return Main.worker.submit(downloadTask); 57 if (handler == null || !handler.hasLicenseToBeAccepted() || askLicenseAgreement(handler.getLicense())) { 58 return Main.worker.submit(downloadTask); 59 } else { 60 return null; 61 } 54 62 } 55 63 … … 73 81 } 74 82 75 protected class InternDownloadTasK extends DownloadTask { 83 protected class InternalDownloadTasK extends DownloadTask { 76 84 77 public InternDownloadTasK(boolean newLayer, NetworkReader reader, ProgressMonitor progressMonitor) { 85 public InternalDownloadTasK(boolean newLayer, NetworkReader reader, ProgressMonitor progressMonitor) { 78 86 super(newLayer, reader, progressMonitor); 79 87 } … … 99 107 } 100 108 } 109 110 /** 111 * returns true if the user accepts the license, false if they refuse 112 */ 113 protected final boolean askLicenseAgreement(License license) { 114 if (license == null || (license.getURL() == null && license.getSummaryURL() == null)) { 115 return true; 116 } 117 try { 118 return new AskLicenseAgreementDialog(license).showDialog().getValue() == 1; 119 120 } catch (IOException e) { 121 JOptionPane.showMessageDialog(Main.parent, tr("License URL not available: {0}", license.toString())); 122 return false; 123 } 124 } 101 125 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java
r28091 r28113 19 19 import java.net.MalformedURLException; 20 20 import java.net.URL; 21 import java.nio.charset.Charset;22 21 import java.util.ArrayList; 23 22 import java.util.Collection; … … 25 24 import java.util.regex.Pattern; 26 25 27 import org.geotools.referencing.CRS;28 import org.geotools.referencing.crs.AbstractDerivedCRS;29 import org.geotools.referencing.datum.DefaultEllipsoid;30 import org.geotools.referencing.operation.projection.LambertConformal;31 import org.geotools.referencing.operation.projection.LambertConformal1SP;32 import org.geotools.referencing.operation.projection.LambertConformal2SP;33 import org.geotools.referencing.operation.projection.MapProjection.AbstractProvider;34 import org.opengis.parameter.ParameterDescriptor;35 import org.opengis.parameter.ParameterValueGroup;36 import org.opengis.referencing.FactoryException;37 import org.opengis.referencing.crs.CoordinateReferenceSystem;38 import org.opengis.referencing.crs.GeographicCRS;39 import org.opengis.referencing.datum.GeodeticDatum;40 import org.opengis.referencing.operation.MathTransform;41 import org.openstreetmap.josm.Main;42 26 import org.openstreetmap.josm.data.Bounds; 43 import org.openstreetmap.josm.data.coor.EastNorth;44 27 import org.openstreetmap.josm.data.coor.LatLon; 45 28 import org.openstreetmap.josm.data.osm.DataSet; 46 29 import org.openstreetmap.josm.data.osm.IPrimitive; 47 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 48 import org.openstreetmap.josm.data.projection.AbstractProjection;49 import org.openstreetmap.josm.data.projection.Ellipsoid;50 import org.openstreetmap.josm.data.projection.Projection;51 import org.openstreetmap.josm.data.projection.Projections;52 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic;53 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic.Parameters;54 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic.Parameters1SP;55 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic.Parameters2SP;56 31 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 57 32 import org.openstreetmap.josm.io.AbstractReader; 58 33 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 34 import org.openstreetmap.josm.plugins.opendata.core.io.archive.DefaultZipHandler; 35 import org.openstreetmap.josm.plugins.opendata.core.io.archive.ZipHandler; 36 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.DefaultShpHandler; 37 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.ShpHandler; 38 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.CsvHandler; 39 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.DefaultCsvHandler; 40 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.SpreadSheetHandler; 41 import org.openstreetmap.josm.plugins.opendata.core.licenses.License; 59 42 import org.openstreetmap.josm.plugins.opendata.core.util.NamesFrUtils; 60 43 import org.openstreetmap.josm.tools.Pair; … … 99 82 private String sourceDate; 100 83 private File associatedFile; 101 private URL dataURL;102 84 103 85 public AbstractDataSetHandler() { 86 setShpHandler(new DefaultShpHandler()); 87 setZipHandler(new DefaultZipHandler()); 88 setCsvHandler(new DefaultCsvHandler()); 104 89 } 105 90 … … 178 163 } 179 164 180 public URL getWikiURL() {return null;} 181 182 public URL getLocalPortalURL() {return null;} 183 184 public URL getNationalPortalURL() {return null;} 185 186 public URL getLicenseURL() {return null;} 187 188 public URL getDataURL() {return dataURL;} 189 190 public final void setDataURL(String url) throws MalformedURLException { 191 this.dataURL = new URL(url); 192 } 193 194 public final void setDataURL(URL url) { 195 this.dataURL = url; 165 // -------------------- License -------------------- 166 167 private License license; 168 169 public License getLicense() { 170 return license; 171 } 172 173 public final void setLicense(License license) { 174 this.license = license; 175 } 176 177 // --------------------- URLs --------------------- 178 179 private URL dataURL; 180 private URL wikiURL; 181 private URL localPortalURL; 182 private URL nationalPortalURL; 183 184 public URL getDataURL() { 185 return dataURL; 186 } 187 188 public final void setDataURL(URL dataURL) { 189 this.dataURL = dataURL; 190 } 191 192 public final void setDataURL(String dataURL) throws MalformedURLException { 193 setDataURL(new URL(dataURL)); 194 } 195 196 public URL getWikiURL() { 197 return wikiURL; 198 } 199 200 public final void setWikiURL(URL wikiURL) { 201 this.wikiURL = wikiURL; 202 } 203 204 public final void setWikiURL(String wikiURL) throws MalformedURLException { 205 setWikiURL(new URL(wikiURL)); 206 } 207 208 public URL getLocalPortalURL() { 209 return localPortalURL; 210 } 211 212 public final void setLocalPortalURL(URL localPortalURL) { 213 this.localPortalURL = localPortalURL; 214 } 215 216 public final void setLocalPortalURL(String localPortalURL) throws MalformedURLException { 217 setLocalPortalURL(new URL(localPortalURL)); 218 } 219 220 public URL getNationalPortalURL() { 221 return nationalPortalURL; 222 } 223 224 public final void setNationalPortalURL(URL nationalPortalURL) { 225 this.nationalPortalURL = nationalPortalURL; 226 } 227 228 public final void setNationalPortalURL(String nationalPortalURL) throws MalformedURLException { 229 setNationalPortalURL(new URL(nationalPortalURL)); 196 230 } 197 231 … … 199 233 200 234 public AbstractReader getReaderForUrl(String url) {return null;} 235 236 private boolean hasLicenseToBeAccepted = true; 237 238 public final boolean hasLicenseToBeAccepted() { 239 return hasLicenseToBeAccepted; 240 } 241 242 public final void setHasLicenseToBeAccepted(boolean hasLicenseToBeAccepted) { 243 this.hasLicenseToBeAccepted = hasLicenseToBeAccepted; 244 } 201 245 202 246 public final DataSetCategory getCategory() { … … 226 270 } 227 271 228 public enum OaQueryType {229 NODE ("node"),230 WAY ("way"),231 RELATION ("relation");232 @Override233 public String toString() { return this.value; }234 private OaQueryType(final String value) { this.value = value; }235 private final String value;236 }237 238 public enum OaRecurseType {239 RELATION_RELATION ("relation-relation"),240 RELATION_BACKWARDS ("relation-backwards"),241 RELATION_WAY ("relation-way"),242 RELATION_NODE ("relation-node"),243 WAY_NODE ("way-node"),244 WAY_RELATION ("way-relation"),245 NODE_RELATION ("node-relation"),246 NODE_WAY ("node-way");247 @Override248 public String toString() { return this.value; }249 private OaRecurseType(final String value) { this.value = value; }250 private final String value;251 }252 272 253 273 protected String getOverpassApiRequest(String bbox) {return null;} 254 255 protected final String oaUnion(String ... queries) {256 String result = "<union>\n";257 for (String query : queries) {258 if (query != null) {259 result += query + "\n";260 }261 }262 result += "</union>";263 return result;264 }265 266 protected final String oaQuery(String bbox, OaQueryType type, String ... conditions) {267 String result = "<query type=\""+type+"\" >\n";268 if (bbox != null) {269 result += "<bbox-query "+bbox+"/>\n";270 }271 for (String condition : conditions) {272 if (condition != null) {273 result += condition + "\n";274 }275 }276 result += "</query>";277 return result;278 }279 280 protected final String oaRecurse(OaRecurseType type, String into) {281 return "<recurse type=\""+type+"\" into=\""+into+"\"/>\n";282 }283 284 protected final String oaRecurse(OaRecurseType ... types) {285 String result = "";286 for (OaRecurseType type : types) {287 result += "<recurse type=\""+type+"\"/>\n";288 }289 return result;290 }291 292 protected final String oaPrint() {293 return "<print mode=\"meta\"/>";294 }295 296 protected final String oaHasKey(String key) {297 return oaHasKey(key, null);298 }299 300 protected final String oaHasKey(String key, String value) {301 return "<has-kv k=\""+key+"\" "+(value != null && !value.isEmpty() ? "v=\""+value+"\"" : "")+" />";302 }303 274 304 275 public boolean equals(IPrimitive p1, IPrimitive p2) {return false;} … … 405 376 } 406 377 407 public boolean handlesSpreadSheetProjection() {408 return false;409 }410 411 public List<Projection> getSpreadSheetProjections() {412 return null;413 }414 415 public LatLon getSpreadSheetCoor(EastNorth en, String[] fields) {416 return null;417 }418 419 public Charset getCsvCharset() {420 return null;421 }422 423 public String getCsvSeparator() {424 return null;425 }426 427 public int getSheetNumber() {428 return -1;429 }430 431 378 public ExtendedSourceEntry getMapPaintStyle() { 432 379 return null; … … 446 393 fileNameWithoutExtension+"."+MAPCSS_EXT); 447 394 } 448 449 public boolean preferMultipolygonToSimpleWay() { 450 return false; 451 } 452 395 453 396 public final void setAssociatedFile(File associatedFile) { 454 397 this.associatedFile = associatedFile; … … 457 400 public final File getAssociatedFile() { 458 401 return this.associatedFile; 459 }460 461 private static final List<Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>>462 ellipsoids = new ArrayList<Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>>();463 static {464 ellipsoids.add(new Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>(DefaultEllipsoid.GRS80, Ellipsoid.GRS80));465 ellipsoids.add(new Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>(DefaultEllipsoid.WGS84, Ellipsoid.WGS84));466 }467 468 private static final Double get(ParameterValueGroup values, ParameterDescriptor desc) {469 return (Double) values.parameter(desc.getName().getCode()).getValue();470 }471 472 private static final boolean equals(Double a, Double b) {473 boolean res = Math.abs(a - b) <= Main.pref.getDouble(PREF_CRS_COMPARISON_TOLERANCE, DEFAULT_CRS_COMPARISON_TOLERANCE);474 if (Main.pref.getBoolean(PREF_CRS_COMPARISON_DEBUG, false)) {475 System.out.println("Comparing "+a+" and "+b+" -> "+res);476 }477 return res;478 }479 480 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) throws FactoryException {481 if (sourceCRS instanceof GeographicCRS && sourceCRS.getName().getCode().equalsIgnoreCase("GCS_ETRS_1989")) {482 return CRS.findMathTransform(CRS.decode("EPSG:4258"), targetCRS, lenient);483 } else if (sourceCRS instanceof AbstractDerivedCRS && sourceCRS.getName().getCode().equalsIgnoreCase("Lambert_Conformal_Conic")) {484 List<MathTransform> result = new ArrayList<MathTransform>();485 AbstractDerivedCRS crs = (AbstractDerivedCRS) sourceCRS;486 MathTransform transform = crs.getConversionFromBase().getMathTransform();487 if (transform instanceof LambertConformal && crs.getDatum() instanceof GeodeticDatum) {488 LambertConformal lambert = (LambertConformal) transform;489 GeodeticDatum geo = (GeodeticDatum) crs.getDatum();490 for (Projection p : Projections.getProjections()) {491 if (p instanceof AbstractProjection) {492 AbstractProjection ap = (AbstractProjection) p;493 if (ap.getProj() instanceof LambertConformalConic) {494 for (Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid> pair : ellipsoids) {495 if (pair.a.equals(geo.getEllipsoid()) && pair.b.equals(ap.getEllipsoid())) {496 boolean ok = true;497 ParameterValueGroup values = lambert.getParameterValues();498 Parameters params = ((LambertConformalConic) ap.getProj()).getParameters();499 500 ok = ok ? equals(get(values, AbstractProvider.LATITUDE_OF_ORIGIN), params.latitudeOrigin) : ok;501 ok = ok ? equals(get(values, AbstractProvider.CENTRAL_MERIDIAN), ap.getCentralMeridian()) : ok;502 ok = ok ? equals(get(values, AbstractProvider.SCALE_FACTOR), ap.getScaleFactor()) : ok;503 ok = ok ? equals(get(values, AbstractProvider.FALSE_EASTING), ap.getFalseEasting()) : ok;504 ok = ok ? equals(get(values, AbstractProvider.FALSE_NORTHING), ap.getFalseNorthing()) : ok;505 506 if (lambert instanceof LambertConformal2SP && params instanceof Parameters2SP) {507 Parameters2SP param = (Parameters2SP) params;508 ok = ok ? equals(Math.min(get(values, AbstractProvider.STANDARD_PARALLEL_1),get(values, AbstractProvider.STANDARD_PARALLEL_2)),509 Math.min(param.standardParallel1, param.standardParallel2)) : ok;510 ok = ok ? equals(Math.max(get(values, AbstractProvider.STANDARD_PARALLEL_1), get(values, AbstractProvider.STANDARD_PARALLEL_2)),511 Math.max(param.standardParallel1, param.standardParallel2)) : ok;512 513 } else if (!(lambert instanceof LambertConformal1SP && params instanceof Parameters1SP)) {514 ok = false;515 }516 517 if (ok) {518 try {519 result.add(CRS.findMathTransform(CRS.decode(p.toCode()), targetCRS, lenient));520 } catch (FactoryException e) {521 System.err.println(e.getMessage());522 }523 }524 }525 }526 }527 }528 }529 }530 if (!result.isEmpty()) {531 if (result.size() > 1) {532 System.err.println("Found multiple projections !"); // TODO: something533 }534 return result.get(0);535 }536 }537 return null;538 }539 540 public boolean checkShpNodeProximity() {541 return false;542 402 } 543 403 … … 555 415 return false; 556 416 } 557 558 private boolean setSkipXsdValidationInZipReading = false; 559 560 public final void setSkipXsdValidationInZipReading(boolean skip) { 561 setSkipXsdValidationInZipReading = skip; 562 } 563 564 public boolean skipXsdValidationInZipReading() { 565 return setSkipXsdValidationInZipReading; 566 } 567 568 public void notifyTempFileWritten(File file) { 569 // Do nothing, let handler overload this method if they need it 417 418 // --------- Shapefile handling --------- 419 420 private ShpHandler shpHandler; 421 422 public final void setShpHandler(ShpHandler handler) { 423 shpHandler = handler; 424 } 425 426 public final ShpHandler getShpHandler() { 427 return shpHandler; 428 } 429 430 // ------------ Zip handling ------------ 431 432 private ZipHandler zipHandler; 433 434 public final void setZipHandler(ZipHandler handler) { 435 zipHandler = handler; 436 } 437 438 public ZipHandler getZipHandler() { 439 return zipHandler; 440 } 441 442 // ------ Spreadsheet handling ---------- 443 444 private SpreadSheetHandler ssHandler; 445 446 public final void setSpreadSheetHandler(SpreadSheetHandler handler) { 447 ssHandler = handler; 448 } 449 450 public final SpreadSheetHandler getSpreadSheetHandler() { 451 return ssHandler; 452 } 453 454 public final void setCsvHandler(CsvHandler handler) { 455 setSpreadSheetHandler(handler); 456 } 457 458 public final CsvHandler getCsvHandler() { 459 if (ssHandler instanceof CsvHandler) { 460 return (CsvHandler) ssHandler; 461 } else { 462 return null; 463 } 570 464 } 571 465 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/SimpleDataSetHandler.java
r28000 r28113 1 // JOSM opendata plugin. 2 // Copyright (C) 2011-2012 Don-vip 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 1 16 package org.openstreetmap.josm.plugins.opendata.core.datasets; 2 3 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaQueryType.NODE;4 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaQueryType.WAY;5 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaQueryType.RELATION;6 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.NODE_RELATION;7 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.RELATION_WAY;8 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.WAY_NODE;9 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.WAY_RELATION;10 17 11 18 import java.util.ArrayList; … … 17 24 import org.openstreetmap.josm.data.osm.Tag; 18 25 import org.openstreetmap.josm.data.projection.Projection; 26 import org.openstreetmap.josm.plugins.opendata.core.io.OverpassApi; 27 28 import static org.openstreetmap.josm.plugins.opendata.core.io.OverpassApi.OaQueryType.*; 29 import static org.openstreetmap.josm.plugins.opendata.core.io.OverpassApi.OaRecurseType.*; 19 30 20 31 public abstract class SimpleDataSetHandler extends AbstractDataSetHandler { … … 155 166 List<String> conditions = new ArrayList<String>(); 156 167 for (Tag tag : this.relevantTags) { 157 conditions.add( oaHasKey(tag.getKey(), tag.getValue()));168 conditions.add(OverpassApi.hasKey(tag.getKey(), tag.getValue())); 158 169 } 159 170 return conditions.toArray(new String[0]); … … 162 173 protected String getOverpassApiQueries(String bbox, String ... conditions) { 163 174 String[] mpconditions = new String[conditions.length+1]; 164 mpconditions[0] = oaHasKey("type", "multipolygon");175 mpconditions[0] = OverpassApi.hasKey("type", "multipolygon"); 165 176 for (int i=0; i<conditions.length; i++) { 166 177 mpconditions[i+1] = conditions[i]; 167 178 } 168 return oaQuery(bbox, NODE, conditions) + "\n" + // Nodes169 oaRecurse(NODE_RELATION, RELATION_WAY, WAY_NODE) + "\n" +170 oaQuery(bbox, WAY, conditions) + "\n" + // Full ways and their full relations171 oaRecurse(WAY_NODE, "nodes") + "\n" +172 oaRecurse(WAY_RELATION, RELATION_WAY, WAY_NODE) + "\n" +173 oaQuery(bbox, RELATION, mpconditions) + "\n" + // Full multipolygons174 oaRecurse(RELATION_WAY, WAY_NODE);179 return OverpassApi.query(bbox, NODE, conditions) + "\n" + // Nodes 180 OverpassApi.recurse(NODE_RELATION, RELATION_WAY, WAY_NODE) + "\n" + 181 OverpassApi.query(bbox, WAY, conditions) + "\n" + // Full ways and their full relations 182 OverpassApi.recurse(WAY_NODE, "nodes") + "\n" + 183 OverpassApi.recurse(WAY_RELATION, RELATION_WAY, WAY_NODE) + "\n" + 184 OverpassApi.query(bbox, RELATION, mpconditions) + "\n" + // Full multipolygons 185 OverpassApi.recurse(RELATION_WAY, WAY_NODE); 175 186 } 176 187 … … 183 194 if (this.relevantUnion) { 184 195 for (Tag tag : this.relevantTags) { 185 result += getOverpassApiQueries(bbox, oaHasKey(tag.getKey(), tag.getValue()));186 } 187 result = oaUnion(result);196 result += getOverpassApiQueries(bbox, OverpassApi.hasKey(tag.getKey(), tag.getValue())); 197 } 198 result = OverpassApi.union(result); 188 199 } else { 189 result = oaUnion(getOverpassApiQueries(bbox, getOverpassApiConditions()));190 } 191 return result + oaPrint();200 result = OverpassApi.union(getOverpassApiQueries(bbox, getOverpassApiConditions())); 201 } 202 return result + OverpassApi.print(); 192 203 } 193 204 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/be/BelgianDataSetHandler.java
r28000 r28113 18 18 import java.net.MalformedURLException; 19 19 import java.net.URL; 20 import java.util.Arrays;21 import java.util.List;22 20 import java.util.Locale; 23 21 … … 28 26 import org.openstreetmap.josm.data.projection.Projection; 29 27 import org.openstreetmap.josm.plugins.opendata.core.datasets.SimpleDataSetHandler; 28 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.DefaultCsvHandler; 30 29 31 30 public abstract class BelgianDataSetHandler extends SimpleDataSetHandler implements BelgianConstants { … … 45 44 lambert2008 46 45 }; 46 47 protected class InternalCsvHandler extends DefaultCsvHandler { 48 /*@Override 49 public List<Projection> getSpreadSheetProjections() { 50 if (singleProjection != null) { 51 return Arrays.asList(new Projection[]{singleProjection}); 52 } else { 53 return Arrays.asList(projections); 54 } 55 }*/ 56 57 @Override 58 public LatLon getCoor(EastNorth en, String[] fields) { 59 if (singleProjection != null) { 60 return singleProjection.eastNorth2latlon(en); 61 } else { 62 return super.getCoor(en, fields); 63 } 64 } 65 } 47 66 48 67 public BelgianDataSetHandler() { 49 68 init(); 50 69 } 51 70 52 71 public BelgianDataSetHandler(String relevantTag) { 53 72 super(relevantTag); 73 init(); 54 74 } 55 75 56 76 public BelgianDataSetHandler(boolean relevantUnion, String[] relevantTags) { 57 77 super(relevantUnion, relevantTags); 78 init(); 58 79 } 59 80 60 81 public BelgianDataSetHandler(boolean relevantUnion, Tag[] relevantTags) { 61 82 super(relevantUnion, relevantTags); 83 init(); 62 84 } 63 85 86 private void init() { 87 setCsvHandler(new InternalCsvHandler()); 88 } 89 64 90 protected final void setNationalPortalPath(String nationalPortalPathDe, String nationalPortalPathEn, String nationalPortalPathFr, String nationalPortalPathNl) { 65 91 this.nationalPortalPathDe = nationalPortalPathDe; … … 71 97 protected final void setSingleProjection(Projection singleProjection) { 72 98 this.singleProjection = singleProjection; 99 getCsvHandler().setHandlesProjection(singleProjection != null); 73 100 } 74 101 … … 116 143 return ICON_BE_24; 117 144 } 118 119 /* (non-Javadoc)120 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#handlesCsvProjection()121 */122 @Override123 public boolean handlesSpreadSheetProjection() {124 return singleProjection != null ? true : super.handlesSpreadSheetProjection();125 }126 127 /* (non-Javadoc)128 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvProjections()129 */130 @Override131 public List<Projection> getSpreadSheetProjections() {132 if (singleProjection != null) {133 return Arrays.asList(new Projection[]{singleProjection});134 } else {135 return Arrays.asList(projections);136 }137 }138 139 /* (non-Javadoc)140 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvCoor(org.openstreetmap.josm.data.coor.EastNorth, java.lang.String[])141 */142 @Override143 public LatLon getSpreadSheetCoor(EastNorth en, String[] fields) {144 if (singleProjection != null) {145 return singleProjection.eastNorth2latlon(en);146 } else {147 return super.getSpreadSheetCoor(en, fields);148 }149 }150 145 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchDataSetHandler.java
r28050 r28113 21 21 import java.net.URL; 22 22 import java.util.Arrays; 23 import java.util.List;24 23 import java.util.regex.Matcher; 25 24 import java.util.regex.Pattern; 26 25 27 import org.geotools.referencing.CRS;28 import org.opengis.referencing.FactoryException;29 import org.opengis.referencing.crs.CoordinateReferenceSystem;30 import org.opengis.referencing.operation.MathTransform;31 26 import org.openstreetmap.josm.data.coor.EastNorth; 32 27 import org.openstreetmap.josm.data.coor.LatLon; … … 38 33 import org.openstreetmap.josm.data.projection.UTM.Hemisphere; 39 34 import org.openstreetmap.josm.plugins.opendata.core.datasets.SimpleDataSetHandler; 35 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.DefaultCsvHandler; 40 36 41 37 public abstract class FrenchDataSetHandler extends SimpleDataSetHandler implements FrenchConstants { … … 66 62 utm40, // Reunion 67 63 }; 64 65 protected class InternalCsvHandler extends DefaultCsvHandler { 66 /*@Override 67 public List<Projection> getSpreadSheetProjections() { 68 if (singleProjection != null) { 69 return Arrays.asList(new Projection[]{singleProjection}); 70 } else { 71 return Arrays.asList(projections); 72 } 73 }*/ 74 75 @Override 76 public LatLon getCoor(EastNorth en, String[] fields) { 77 if (singleProjection != null) { 78 return singleProjection.eastNorth2latlon(en); 79 } else { 80 return super.getCoor(en, fields); 81 } 82 } 83 84 @Override 85 public boolean handlesProjection() { 86 return singleProjection != null; 87 } 88 } 68 89 69 90 public FrenchDataSetHandler() { 70 91 init(); 71 92 } 72 93 73 94 public FrenchDataSetHandler(String relevantTag) { 74 95 super(relevantTag); 96 init(); 75 97 } 76 98 77 99 public FrenchDataSetHandler(boolean relevantUnion, String[] relevantTags) { 78 100 super(relevantUnion, relevantTags); 101 init(); 79 102 } 80 103 81 104 public FrenchDataSetHandler(boolean relevantUnion, Tag[] relevantTags) { 82 105 super(relevantUnion, relevantTags); 83 } 84 106 init(); 107 } 108 109 private void init() { 110 setShpHandler(new FrenchShpHandler()); 111 setCsvHandler(new InternalCsvHandler()); 112 } 113 85 114 protected final void setNationalPortalPath(String nationalPortalPath) { 86 115 this.nationalPortalPath = nationalPortalPath; … … 120 149 public String getNationalPortalIconName() { 121 150 return ICON_FR_24; 122 }123 124 /* (non-Javadoc)125 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#handlesCsvProjection()126 */127 @Override128 public boolean handlesSpreadSheetProjection() {129 return singleProjection != null ? true : super.handlesSpreadSheetProjection();130 }131 132 /* (non-Javadoc)133 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvProjections()134 */135 @Override136 public List<Projection> getSpreadSheetProjections() {137 if (singleProjection != null) {138 return Arrays.asList(new Projection[]{singleProjection});139 } else {140 return Arrays.asList(projections);141 }142 }143 144 /* (non-Javadoc)145 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvCoor(org.openstreetmap.josm.data.coor.EastNorth, java.lang.String[])146 */147 @Override148 public LatLon getSpreadSheetCoor(EastNorth en, String[] fields) {149 if (singleProjection != null) {150 return singleProjection.eastNorth2latlon(en);151 } else {152 return super.getSpreadSheetCoor(en, fields);153 }154 151 } 155 152 … … 258 255 return ""; 259 256 } 260 261 /* (non-Javadoc)262 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#findMathTransform(org.opengis.referencing.crs.CoordinateReferenceSystem, org.opengis.referencing.crs.CoordinateReferenceSystem, boolean)263 */264 @Override265 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient)266 throws FactoryException {267 if (sourceCRS.getName().getCode().equalsIgnoreCase("RGM04")) {268 return CRS.findMathTransform(CRS.decode("EPSG:4471"), targetCRS, lenient);269 } else if (sourceCRS.getName().getCode().equalsIgnoreCase("RGFG95_UTM_Zone_22N")) {270 return CRS.findMathTransform(CRS.decode("EPSG:2972"), targetCRS, lenient);271 } else {272 return super.findMathTransform(sourceCRS, targetCRS, lenient);273 }274 }275 257 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NetworkReader.java
r28088 r28113 50 50 private String filename; 51 51 52 public NetworkReader(String url, AbstractDataSetHandler handler , Class<? extends AbstractReader> readerClass) {52 public NetworkReader(String url, AbstractDataSetHandler handler) { 53 53 CheckParameterUtil.ensureParameterNotNull(url, "url"); 54 //CheckParameterUtil.ensureParameterNotNull(readerClass, "readerClass");55 54 this.url = url; 56 this.readerClass = readerClass;57 55 this.handler = handler; 56 this.readerClass = null; 58 57 } 59 58 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ZipReader.java
r28055 r28113 50 50 private final ZipInputStream zis; 51 51 private final AbstractDataSetHandler handler; 52 private final ZipHandler zipHandler; 52 53 53 54 private File file; … … 56 57 this.zis = in instanceof ZipInputStream ? (ZipInputStream) in : new ZipInputStream(in); 57 58 this.handler = handler; 59 this.zipHandler = handler != null ? handler.getZipHandler() : null; 58 60 } 59 61 … … 116 118 fos.close(); 117 119 // Allow handler to perform specific treatments (for example, fix invalid .prj files) 118 if ( handler != null) {119 handler.notifyTempFileWritten(file);120 if (zipHandler != null) { 121 zipHandler.notifyTempFileWritten(file); 120 122 } 121 123 // Set last modification date … … 135 137 } 136 138 // Special treatment for XML files (check supported XSD), unless handler explicitely skip it 137 if (XML_FILE_FILTER.accept(file) && (( handler != null &&handler.skipXsdValidationInZipReading())139 if (XML_FILE_FILTER.accept(file) && ((zipHandler != null && zipHandler.skipXsdValidation()) 138 140 || OdPlugin.getInstance().xmlImporter.acceptFile(file))) { 139 141 candidates.add(file); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java
r28044 r28113 84 84 public class ShpReader extends AbstractReader implements OdConstants { 85 85 86 private final AbstractDataSetHandler handler;86 private final ShpHandler handler; 87 87 88 88 private final CoordinateReferenceSystem wgs84; … … 93 93 private MathTransform transform; 94 94 95 public ShpReader( AbstractDataSetHandler handler) throws NoSuchAuthorityCodeException, FactoryException {95 public ShpReader(ShpHandler handler) throws NoSuchAuthorityCodeException, FactoryException { 96 96 this.handler = handler; 97 97 this.wgs84 = CRS.decode("EPSG:4326"); … … 105 105 } 106 106 try { 107 return new ShpReader(handler).parse(file, instance); 107 return new ShpReader(handler != null ? handler.getShpHandler() : null).parse(file, instance); 108 108 } catch (IOException e) { 109 109 throw e; … … 373 373 private Node getNode(Point p, String key) { 374 374 Node n = nodes.get(key); 375 if (n == null && handler != null && handler.check ShpNodeProximity()) {375 if (n == null && handler != null && handler.checkNodeProximity()) { 376 376 LatLon ll = new LatLon(p.getY(), p.getX()); 377 377 for (Node node : nodes.values()) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/TabReader.java
r28000 r28113 34 34 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 35 35 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 36 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.SpreadSheetHandler; 36 37 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.SpreadSheetReader; 37 38 … … 76 77 77 78 private final DbaseFileReader dbfReader; 78 public TabOsmReader( AbstractDataSetHandler handler, TabFiles tabFiles) throws IOException {79 public TabOsmReader(SpreadSheetHandler handler, TabFiles tabFiles) throws IOException { 79 80 super(handler); 80 81 this.dbfReader = new DbaseFileReader(tabFiles, false, datCharset, null); … … 111 112 try { 112 113 File dataFile = getDataFile(file, ".dat"); 113 ds.mergeFrom(new TabOsmReader(handler, new TabFiles(file, dataFile)). 114 ds.mergeFrom(new TabOsmReader(handler != null ? handler.getSpreadSheetHandler() : null, new TabFiles(file, dataFile)). 114 115 doParse(columns.toArray(new String[0]), instance)); 115 116 } catch (IOException e) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/CsvReader.java
r28033 r28113 35 35 private String line; 36 36 37 public CsvReader( AbstractDataSetHandler handler) {37 public CsvReader(CsvHandler handler) { 38 38 this(handler, ";"); 39 39 } 40 40 41 public CsvReader( AbstractDataSetHandler handler, String defaultSep) {41 public CsvReader(CsvHandler handler, String defaultSep) { 42 42 super(handler); 43 this.charset = handler != null && handler.getC svCharset() != null ? handler.getCsvCharset() : Charset.forName(UTF8);44 this.sep = handler != null && handler.get CsvSeparator() != null ? handler.getCsvSeparator() : defaultSep;43 this.charset = handler != null && handler.getCharset() != null ? handler.getCharset() : Charset.forName(UTF8); 44 this.sep = handler != null && handler.getSeparator() != null ? handler.getSeparator() : defaultSep; 45 45 } 46 46 47 47 public static DataSet parseDataSet(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException { 48 CsvReader csvReader = new CsvReader(handler); 48 CsvHandler csvHandler = null; 49 if (handler.getSpreadSheetHandler() instanceof CsvHandler) { 50 csvHandler = (CsvHandler) handler.getSpreadSheetHandler(); 51 } 52 CsvReader csvReader = new CsvReader(csvHandler); 49 53 try { 50 54 return csvReader.parse(in, instance); 51 55 } catch (IllegalArgumentException e) { 52 if ( handler == null) {56 if (csvHandler == null || (csvHandler.getSeparator() != null && csvHandler.getSeparator().equals(";"))) { 53 57 // If default sep has been used, try comma 54 58 System.out.println(e.getMessage()); 55 CsvReader newReader = new CsvReader( handler, ",");59 CsvReader newReader = new CsvReader(csvHandler, ","); 56 60 newReader.initResources(in, instance); 57 61 newReader.line = csvReader.line; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/OdsReader.java
r28000 r28113 38 38 private static final String SEP = "TextP:\\["; 39 39 40 public OdsReader( AbstractDataSetHandler handler) {40 public OdsReader(SpreadSheetHandler handler) { 41 41 super(handler); 42 42 } … … 44 44 public static DataSet parseDataSet(InputStream in, 45 45 AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException { 46 return new OdsReader(handler).parse(in, instance); 46 return new OdsReader(handler != null ? handler.getSpreadSheetHandler() : null).parse(in, instance); 47 47 } 48 48 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/SpreadSheetReader.java
r28000 r28113 37 37 import org.openstreetmap.josm.io.AbstractReader; 38 38 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 39 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;40 39 import org.openstreetmap.josm.plugins.opendata.core.io.ProjectionChooser; 41 40 import org.openstreetmap.josm.plugins.opendata.core.io.ProjectionPatterns; … … 53 52 } 54 53 55 protected final AbstractDataSetHandler handler;56 57 public SpreadSheetReader( AbstractDataSetHandler handler) {54 protected final SpreadSheetHandler handler; 55 56 public SpreadSheetReader(SpreadSheetHandler handler) { 58 57 this.handler = handler; 59 58 } … … 122 121 } 123 122 124 final boolean handlerOK = handler != null && handler.handles SpreadSheetProjection();123 final boolean handlerOK = handler != null && handler.handlesProjection(); 125 124 126 125 if (proj != null) { … … 168 167 } 169 168 if (en.isValid()) { 170 n.setCoor(proj != null && !handlerOK ? proj.eastNorth2latlon(en) : handler.get SpreadSheetCoor(en, fields));169 n.setCoor(proj != null && !handlerOK ? proj.eastNorth2latlon(en) : handler.getCoor(en, fields)); 171 170 } else { 172 171 System.err.println("Warning: Skipping line "+lineNumber+" because no valid coordinates have been found."); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/XlsReader.java
r28000 r28113 38 38 private int rowIndex; 39 39 40 public XlsReader( AbstractDataSetHandler handler) {40 public XlsReader(SpreadSheetHandler handler) { 41 41 super(handler); 42 42 } … … 44 44 public static DataSet parseDataSet(InputStream in, 45 45 AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException { 46 return new XlsReader(handler).parse(in, instance); 46 return new XlsReader(handler != null ? handler.getSpreadSheetHandler() : null).parse(in, instance); 47 47 } 48 48 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/layers/OdDataLayer.java
r28022 r28113 38 38 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 39 39 import org.openstreetmap.josm.plugins.opendata.core.io.OsmDownloader; 40 import org.openstreetmap.josm.plugins.opendata.core.licenses.License; 40 41 import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils; 41 42 … … 155 156 tr("View National Portal page"), tr("Launch browser to the national portal page of the selected data set"))); 156 157 } 157 if (this.handler.getLicenseURL() != null) { 158 if (this.handler.getLicenseURL().getProtocol().startsWith("http")) { 159 result.add(new OpenLinkAction(this.handler.getLicenseURL(), ICON_AGREEMENT_24, 158 if (this.handler.getLicense() != null) { 159 License lic = this.handler.getLicense(); 160 if (lic.getURL() != null && lic.getURL().getProtocol().startsWith("http")) { 161 result.add(new OpenLinkAction(lic.getURL(), ICON_AGREEMENT_24, 160 162 tr("View License"), tr("Launch browser to the license page of the selected data set"))); 163 } else { 164 // TODO: view embedded licenses 165 } 166 if (lic.getSummaryURL() != null && lic.getSummaryURL().getProtocol().startsWith("http")) { 167 result.add(new OpenLinkAction(lic.getSummaryURL(), ICON_AGREEMENT_24, 168 tr("View License (summary)"), tr("Launch browser to the summary license page of the selected data set"))); 161 169 } else { 162 170 // TODO: view embedded licenses -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/util/OdUtils.java
r28022 r28113 18 18 import java.util.ArrayList; 19 19 import java.util.List; 20 import java.util.Locale; 20 21 21 22 import javax.swing.ImageIcon; 22 23 23 24 import org.apache.commons.lang3.StringUtils; 25 import org.openstreetmap.josm.Main; 24 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 25 27 import org.openstreetmap.josm.data.osm.Relation; … … 56 58 57 59 public static final ImageIcon getImageIcon(String iconName) { 58 return new ImageProvider(iconName).setAdditionalClassLoaders(ModuleHandler.getResourceClassLoaders()).get(); 60 return getImageIcon(iconName, false); 61 } 62 63 public static final ImageIcon getImageIcon(String iconName, boolean optional) { 64 return new ImageProvider(iconName).setOptional(optional).setAdditionalClassLoaders(ModuleHandler.getResourceClassLoaders()).get(); 65 } 66 67 public static final String getJosmLanguage() { 68 String lang = Main.pref.get("language"); 69 if (lang == null || lang.isEmpty()) { 70 lang = Locale.getDefault().toString(); 71 } 72 return lang; 59 73 } 60 74 }
Note:
See TracChangeset
for help on using the changeset viewer.