Changeset 30723 in osm
- Timestamp:
- 2014-10-15T09:44:47+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata
- Files:
-
- 102 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java
r30607 r30723 48 48 public final class OdPlugin extends Plugin { 49 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 50 private static OdPlugin instance; 51 52 public final XmlImporter xmlImporter = new XmlImporter(); 53 54 private final JMenu menu; 55 56 private OdDialog dialog; 57 58 public OdPlugin(PluginInformation info) { 59 super(info); 60 if (instance == null) { 61 instance = this; 62 } else { 63 throw new IllegalAccessError("Cannot instantiate plugin twice !"); 64 } 65 65 // Allow JOSM to import more files 66 67 68 69 66 for (AbstractImporter importer : Arrays.asList(new AbstractImporter[]{ 67 new CsvImporter(), new OdsImporter(), new XlsImporter(), // Tabular file formats 68 new KmlKmzImporter(), new ShpImporter(), new MifTabImporter(), new GmlImporter(), // Geographic file formats 69 new ZipImporter(), // Zip archive containing any of the others 70 70 new SevenZipImporter(), // 7Zip archive containing any of the others 71 72 73 74 71 xmlImporter // Generic importer for XML files (currently used for Neptune files) 72 })) { 73 ExtensionFileFilter.importers.add(0, importer); 74 } 75 75 // Load modules 76 76 loadModules(); … … 83 83 // Delete previous temp dirs if any (old plugin versions did not remove them correctly) 84 84 OdUtils.deletePreviousTempDirs(); 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 85 } 86 87 public static final OdPlugin getInstance() { 88 return instance; 89 } 90 91 private JMenu getModuleMenu(Module module) { 92 String moduleName = module.getDisplayedName(); 93 if (moduleName == null || moduleName.isEmpty()) { 94 moduleName = module.getModuleInformation().getName(); 95 } 96 JMenu moduleMenu = new JMenu(moduleName); 97 moduleMenu.setIcon(module.getModuleInformation().getScaledIcon()); 98 return moduleMenu; 99 } 100 101 private void buildMenu() { 102 102 for (Module module : ModuleHandler.moduleList) { 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 103 Map<DataSetCategory, JMenu> catMenus = new HashMap<>(); 104 JMenu moduleMenu = null; 105 for (AbstractDataSetHandler handler: module.getNewlyInstanciatedHandlers()) { 106 URL dataURL = handler.getDataURL(); 107 List<Pair<String, URL>> dataURLs = handler.getDataURLs(); 108 if (dataURL != null || (dataURLs != null && !dataURLs.isEmpty())) { 109 if (moduleMenu == null) { 110 moduleMenu = getModuleMenu(module); 111 } 112 DataSetCategory cat = handler.getCategory(); 113 JMenu endMenu = null; 114 if (cat != null) { 115 if ((endMenu = catMenus.get(cat)) == null) { 116 catMenus.put(cat, endMenu = new JMenu(cat.getName())); 117 setMenuItemIcon(cat.getIcon(), endMenu); 118 moduleMenu.add(endMenu); 119 } 120 } 121 if (endMenu == null) { 122 endMenu = moduleMenu; 123 } 124 String handlerName = handler.getName(); 125 if (handlerName == null || handlerName.isEmpty()) { 126 handlerName = handler.getClass().getName(); 127 } 128 JMenuItem handlerItem = null; 129 if (dataURL != null) { 130 handlerItem = endMenu.add(new DownloadDataAction(module, handlerName, dataURL)); 131 } else if (dataURLs != null) { 132 JMenu handlerMenu = new JMenu(handlerName); 133 JMenuItem item = null; 134 for (Pair<String, URL> pair : dataURLs) { 135 if (pair != null && pair.a != null && pair.b != null) { 136 item = handlerMenu.add(new DownloadDataAction(module, pair.a, pair.b)); 137 } 138 } 139 if (item != null) { 140 MenuScroller.setScrollerFor(handlerMenu); 141 handlerItem = endMenu.add(handlerMenu); 142 } 143 } 144 if (handlerItem != null) { 145 setMenuItemIcon(handler.getMenuIcon(), handlerItem); 146 } 147 } 148 } 149 if (moduleMenu != null) { 150 menu.add(moduleMenu); 151 } 152 152 } 153 153 menu.addSeparator(); 154 154 MainMenu.add(menu, new OpenPreferencesActions()); 155 156 157 155 } 156 157 private void setMenuItemIcon(ImageIcon icon, JMenuItem menuItem) { 158 158 if (icon != null) { 159 159 if (icon.getIconHeight() != 16 || icon.getIconWidth() != 16) { … … 162 162 menuItem.setIcon(icon); 163 163 } 164 165 166 167 168 169 170 171 172 173 174 164 } 165 166 @Override 167 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 168 if (newFrame != null) { 169 newFrame.addToggleDialog(dialog = new OdDialog()); 170 } else { 171 dialog = null; 172 } 173 } 174 175 175 @Override 176 176 public PreferenceSetting getPreferenceSetting() { … … 185 185 186 186 ModuleHandler.installDownloadedModules(true); 187 187 ModuleHandler.loadModules(Main.parent, modulesToLoad, null); 188 188 } 189 189 190 190 private final File getSubDirectory(String name) { 191 191 File dir = new File(getPluginDir()+File.separator+name); 192 192 if (!dir.exists()) { 193 193 dir.mkdirs(); … … 197 197 198 198 public final File getModulesDirectory() { 199 199 return getSubDirectory("modules"); 200 200 } 201 201 202 202 public final File getResourcesDirectory() { 203 203 return getSubDirectory("resources"); 204 204 } 205 205 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java
r30563 r30723 10 10 11 11 public abstract class OdConstants { 12 13 14 15 16 17 18 12 13 /** 14 * Encodings 15 */ 16 public static final String UTF8 = "UTF-8"; 17 public static final String ISO8859_15 = "ISO-8859-15"; 18 public static final String CP850 = "Cp850"; 19 19 public static final String CP1251 = "Cp1251"; 20 21 22 23 24 25 26 27 28 29 30 31 /* 32 33 20 public static final String CP1252 = "Cp1252"; 21 public static final String MAC_ROMAN = "MacRoman"; 22 23 /** 24 * Patterns 25 */ 26 public static final String PATTERN_LANG = "{lang}"; 27 28 /** 29 * Preferences 30 */ 31 /* public static final String PREF_COORDINATES = "opendata.coordinates"; 32 public static final String VALUE_CC9ZONES = "cc9zones"; 33 public static final String VALUE_WGS84 = "wgs84";*/ 34 34 35 35 public static final String PREF_OAPI = "opendata.oapi"; 36 36 public static final String DEFAULT_OAPI = "http://www.overpass-api.de/api/interpreter?"; 37 37 38 38 public static final String PREF_XAPI = "opendata.xapi"; 39 39 public static final String DEFAULT_XAPI = "http://www.overpass-api.de/api/xapi?"; 40 40 41 41 public static final String PREF_RAWDATA = "opendata.rawdata"; 42 42 public static final boolean DEFAULT_RAWDATA = false; 43 43 44 44 public static final String PREF_MAXDISTANCE = "opendata.maxdistance"; 45 45 public static final double DEFAULT_MAXDISTANCE = 10; 46 46 … … 58 58 public static final String PREF_CRS_COMPARISON_DEBUG = "opendata.crs.comparison_debug"; 59 59 60 61 62 63 64 65 66 67 68 60 /** 61 * Icons 62 */ 63 public static final String ICON_CORE_16 = "o16.png"; 64 public static final String ICON_CORE_24 = "o24.png"; 65 public static final String ICON_CORE_48 = "o48.png"; 66 67 public static final String ICON_OSM_16 = "osm16.png"; 68 public static final String ICON_OSM_24 = "osm24.png"; 69 69 70 71 70 public static final String ICON_AGREEMENT_24 = "agreement24.png"; 71 public static final String ICON_EMPTY_24 = "empty24.png"; 72 72 73 73 public static final String ICON_LOOL_48 = "lool48.png"; 74 74 75 75 /** -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataAction.java
r30340 r30723 14 14 public class DownloadDataAction extends JosmAction { 15 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 16 private final URL url; 17 18 public DownloadDataAction(Module module, String name, URL url) { 19 super(false); 20 CheckParameterUtil.ensureParameterNotNull(name, "name"); 21 CheckParameterUtil.ensureParameterNotNull(url, "url"); 22 putValue(Action.NAME, name); 23 putValue("toolbar", ("opendata_download_"+module.getDisplayedName()+"_"+name).toLowerCase().replace(" ", "_")); 24 this.url = url; 25 } 26 27 @Override 28 public void actionPerformed(ActionEvent e) { 29 Main.main.menu.openLocation.openUrl(true, url.toString()); 30 } 31 31 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataTask.java
r30607 r30723 27 27 public class DownloadDataTask extends DownloadOsmTask { 28 28 29 30 31 32 33 34 29 private AbstractDataSetHandler handler; 30 31 @Override 32 public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) { 33 return null; 34 } 35 35 36 37 36 @Override 37 public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) { 38 38 downloadTask = new InternalDownloadTasK(newLayer, new NetworkReader(url, handler, true), progressMonitor); 39 39 currentBounds = null; 40 40 if (handler == null || !handler.hasLicenseToBeAccepted() || askLicenseAgreement(handler.getLicense())) { 41 41 return Main.worker.submit(downloadTask); 42 42 } else { 43 43 return null; 44 44 } 45 45 } 46 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 47 @Override 48 public boolean acceptsUrl(String url) { 49 this.handler = null; 50 for (Module module : ModuleHandler.moduleList) { 51 for (AbstractDataSetHandler handler : module.getNewlyInstanciatedHandlers()) { 52 if (handler.acceptsUrl(url)) { 53 this.handler = handler; 54 return true; 55 } 56 } 57 } 58 for (String ext : NetworkReader.FILE_AND_ARCHIVE_READERS.keySet()) { 59 if (Pattern.compile(".*\\."+ext, Pattern.CASE_INSENSITIVE).matcher(url).matches()) { 60 return true; 61 } 62 } 63 return false; 64 } 65 66 66 @Override 67 67 public String[] getPatterns() { … … 83 83 protected class InternalDownloadTasK extends DownloadTask { 84 84 85 86 87 85 public InternalDownloadTasK(boolean newLayer, NetworkReader reader, ProgressMonitor progressMonitor) { 86 super(newLayer, reader, progressMonitor); 87 } 88 88 89 90 89 @Override 90 protected OsmDataLayer createNewLayer(String layerName) { 91 91 File associatedFile = ((NetworkReader)reader).getReadFile(); 92 92 String filename = ((NetworkReader)reader).getReadFileName(); 93 93 if (layerName == null || layerName.isEmpty()) { 94 95 96 97 98 99 100 94 if (associatedFile != null) { 95 layerName = associatedFile.getName(); 96 } else if (filename != null && !filename.isEmpty()) { 97 layerName = filename; 98 } else { 99 layerName = OsmDataLayer.createNewName(); 100 } 101 101 } 102 103 104 105 106 102 DataSetUpdater.updateDataSet(dataSet, handler, associatedFile); 103 return new OdDataLayer(dataSet, layerName, associatedFile, handler); 104 } 105 } 106 107 107 /** 108 108 * returns true if the user accepts the license, false if they refuse 109 109 */ 110 110 protected final boolean askLicenseAgreement(License license) { 111 112 113 114 115 116 117 111 if (license == null || (license.getURL() == null && license.getSummaryURL() == null)) { 112 return true; 113 } 114 try { 115 return new AskLicenseAgreementDialog(license).showDialog().getValue() == 1; 116 117 } catch (IOException e) { 118 118 JOptionPane.showMessageDialog(Main.parent, tr("License URL not available: {0}", license.toString())); 119 119 return false; 120 120 } 121 121 } 122 122 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/OpenLinkAction.java
r30563 r30723 29 29 public void actionPerformed(ActionEvent e) { 30 30 try { 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 31 System.out.println("Opening "+url); 32 OpenBrowser.displayUrl(url.toURI()); 33 } catch (URISyntaxException e1) { 34 try { 35 System.err.println(e1.getLocalizedMessage()); 36 int index = e1.getIndex(); 37 if (index > -1) { 38 String s = url.toString().substring(index, index+1); 39 s = url.toString().replace(s, URLEncoder.encode(s, OdConstants.UTF8)); 40 URI uri = new URI(s); 41 System.out.println("Opening "+uri); 42 OpenBrowser.displayUrl(uri); 43 } 44 } catch (Exception e2) { 45 e2.printStackTrace(); 46 } 47 } 48 48 } 49 49 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/OpenPreferencesActions.java
r30563 r30723 14 14 15 15 public class OpenPreferencesActions extends JosmAction { 16 16 17 17 public OpenPreferencesActions() { 18 18 super(false); 19 19 putValue(NAME, tr("OpenData preferences")); 20 20 putValue(SMALL_ICON, ImageProvider.get("dialogs", OdConstants.ICON_CORE_24)); 21 21 putValue("toolbar", "opendata_open_preferences"); 22 22 } 23 23 24 25 24 @Override 25 public void actionPerformed(ActionEvent e) { 26 26 final PreferenceDialog p = new PreferenceDialog(Main.parent); 27 27 p.selectPreferencesTabByClass(OdPreferenceSetting.class); 28 28 p.setVisible(true); 29 29 } 30 30 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/ViewLicenseAction.java
r30563 r30723 16 16 public class ViewLicenseAction extends JosmAction { 17 17 18 19 20 21 22 23 18 private final License license; 19 20 public ViewLicenseAction(License license, String title, String description) { 21 super(title, null, description, null, false); 22 CheckParameterUtil.ensureParameterNotNull(license, "license"); 23 this.license = license; 24 24 putValue(Action.SMALL_ICON, OdUtils.getImageIcon(OdConstants.ICON_AGREEMENT_24)); 25 25 } 26 26 27 28 29 30 31 32 33 34 27 @Override 28 public void actionPerformed(ActionEvent e) { 29 try { 30 new ViewLicenseDialog(license).showDialog(); 31 } catch (IOException ex) { 32 ex.printStackTrace(); 33 } 34 } 35 35 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java
r30583 r30723 37 37 38 38 public abstract class AbstractDataSetHandler { 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 39 40 public abstract boolean acceptsFilename(String filename); 41 42 public boolean acceptsFile(File file) { 43 return acceptsFilename(file.getName()); 44 } 45 46 public abstract void updateDataSet(DataSet ds); 47 48 public void checkDataSetSource(DataSet ds) { 49 if (ds != null) { 50 for (OsmPrimitive p : ds.allPrimitives()) { 51 if (p.hasKeys() || p.getReferrers().isEmpty()) { 52 if (getSource() != null && p.get("source") == null) { 53 p.put("source", getSource()); 54 } 55 if (sourceDate != null && p.get("source:date") == null) { 56 p.put("source:date", sourceDate); 57 } 58 } 59 } 60 } 61 } 62 63 public void checkNames(DataSet ds) { 64 if (ds != null) { 65 for (OsmPrimitive p : ds.allPrimitives()) { 66 if (p.get("name") != null) { 67 p.put("name", NamesFrUtils.checkDictionary(p.get("name"))); 68 } 69 } 70 } 71 } 72 73 private String name; 74 private DataSetCategory category; 75 private String sourceDate; 76 private File associatedFile; 77 private ImageIcon menuIcon; 78 79 public AbstractDataSetHandler() { 80 setShpHandler(new DefaultShpHandler()); 81 setArchiveHandler(new DefaultArchiveHandler()); 82 setCsvHandler(new DefaultCsvHandler()); 83 setGmlHandler(new DefaultGmlHandler()); 84 } 85 86 private final boolean acceptsFilename(String filename, String[] expected, String ... extensions ) { 87 if (filename != null) { 88 for (String name : expected) { 89 for (String ext : extensions) { 90 if (Pattern.compile(name+"\\."+ext, Pattern.CASE_INSENSITIVE).matcher(filename).matches()) { 91 //if (filename.equalsIgnoreCase(name+"."+ext)) { 92 return true; 93 } 94 } 95 } 96 } 97 return false; 98 } 99 100 protected final boolean acceptsCsvFilename(String filename, String ... expected) { 101 return acceptsFilename(filename, expected, OdConstants.CSV_EXT); 102 } 103 104 protected final boolean acceptsXlsFilename(String filename, String ... expected) { 105 return acceptsFilename(filename, expected, OdConstants.XLS_EXT); 106 } 107 108 protected final boolean acceptsOdsFilename(String filename, String ... expected) { 109 return acceptsFilename(filename, expected, OdConstants.ODS_EXT); 110 } 111 112 protected final boolean acceptsShpFilename(String filename, String ... expected) { 113 return acceptsFilename(filename, expected, OdConstants.SHP_EXT); 114 } 115 116 protected final boolean acceptsMifFilename(String filename, String ... expected) { 117 return acceptsFilename(filename, expected, OdConstants.MIF_EXT); 118 } 119 120 protected final boolean acceptsMifTabFilename(String filename, String ... expected) { 121 return acceptsFilename(filename, expected, OdConstants.MIF_EXT, OdConstants.TAB_EXT); 122 } 123 124 protected final boolean acceptsShpMifFilename(String filename, String ... expected) { 125 return acceptsFilename(filename, expected, OdConstants.SHP_EXT, OdConstants.MIF_EXT); 126 } 127 128 protected final boolean acceptsKmlFilename(String filename, String ... expected) { 129 return acceptsFilename(filename, expected, OdConstants.KML_EXT); 130 } 131 132 protected final boolean acceptsKmzFilename(String filename, String ... expected) { 133 return acceptsFilename(filename, expected, OdConstants.KMZ_EXT); 134 } 135 136 protected final boolean acceptsKmzShpFilename(String filename, String ... expected) { 137 return acceptsFilename(filename, expected, OdConstants.KMZ_EXT, OdConstants.SHP_EXT); 138 } 139 140 protected final boolean acceptsKmzTabFilename(String filename, String ... expected) { 141 return acceptsFilename(filename, expected, OdConstants.KMZ_EXT, OdConstants.TAB_EXT); 142 } 143 144 protected final boolean acceptsZipFilename(String filename, String ... expected) { 145 return acceptsFilename(filename, expected, OdConstants.ZIP_EXT); 146 } 147 147 148 148 protected final boolean accepts7ZipFilename(String filename, String ... expected) { … … 150 150 } 151 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 return new ExtendedSourceEntry(displayName,OdConstants.PROTO_RSRC+//"/"+391 392 393 394 152 protected final boolean acceptsCsvKmzFilename(String filename, String ... expected) { 153 return acceptsFilename(filename, expected, OdConstants.CSV_EXT, OdConstants.KMZ_EXT); 154 } 155 156 protected final boolean acceptsCsvKmzTabFilename(String filename, String ... expected) { 157 return acceptsFilename(filename, expected, OdConstants.CSV_EXT, OdConstants.KMZ_EXT, OdConstants.TAB_EXT); 158 } 159 160 protected final boolean acceptsCsvXlsFilename(String filename, String ... expected) { 161 return acceptsFilename(filename, expected, OdConstants.CSV_EXT, OdConstants.XLS_EXT); 162 } 163 164 // -------------------- License -------------------- 165 166 private License license; 167 168 public License getLicense() { 169 return license; 170 } 171 172 public final void setLicense(License license) { 173 this.license = license; 174 } 175 176 // --------------------- URLs --------------------- 177 178 private URL dataURL; 179 private URL wikiURL; 180 private URL localPortalURL; 181 private URL nationalPortalURL; 182 183 public URL getDataURL() { 184 return dataURL; 185 } 186 187 public final void setDataURL(URL dataURL) { 188 this.dataURL = dataURL; 189 } 190 191 public final void setDataURL(String dataURL) throws MalformedURLException { 192 setDataURL(new URL(dataURL)); 193 } 194 195 public URL getWikiURL() { 196 return wikiURL; 197 } 198 199 public final void setWikiURL(URL wikiURL) { 200 this.wikiURL = wikiURL; 201 } 202 203 public final void setWikiURL(String wikiURL) throws MalformedURLException { 204 setWikiURL(new URL(wikiURL)); 205 } 206 207 public URL getLocalPortalURL() { 208 return localPortalURL; 209 } 210 211 public final void setLocalPortalURL(URL localPortalURL) { 212 this.localPortalURL = localPortalURL; 213 } 214 215 public final void setLocalPortalURL(String localPortalURL) throws MalformedURLException { 216 setLocalPortalURL(new URL(localPortalURL)); 217 } 218 219 public URL getNationalPortalURL() { 220 return nationalPortalURL; 221 } 222 223 public final void setNationalPortalURL(URL nationalPortalURL) { 224 this.nationalPortalURL = nationalPortalURL; 225 } 226 227 public final void setNationalPortalURL(String nationalPortalURL) throws MalformedURLException { 228 setNationalPortalURL(new URL(nationalPortalURL)); 229 } 230 231 public List<Pair<String,URL>> getDataURLs() {return null;} 232 233 public AbstractReader getReaderForUrl(String url) {return null;} 234 235 private boolean hasLicenseToBeAccepted = true; 236 237 public final boolean hasLicenseToBeAccepted() { 238 return hasLicenseToBeAccepted; 239 } 240 241 public final void setHasLicenseToBeAccepted(boolean hasLicenseToBeAccepted) { 242 this.hasLicenseToBeAccepted = hasLicenseToBeAccepted; 243 } 244 245 public final DataSetCategory getCategory() { 246 return category; 247 } 248 249 public final void setCategory(DataSetCategory category) { 250 this.category = category; 251 } 252 253 public final Collection<String> getOsmXapiRequests(Bounds bounds) { 254 return getOsmXapiRequests( 255 LatLon.roundToOsmPrecisionStrict(bounds.getMin().lon())+","+ 256 LatLon.roundToOsmPrecisionStrict(bounds.getMin().lat())+","+ 257 LatLon.roundToOsmPrecisionStrict(bounds.getMax().lon())+","+ 258 LatLon.roundToOsmPrecisionStrict(bounds.getMax().lat())); 259 } 260 261 protected Collection<String> getOsmXapiRequests(String bbox) {return null;} 262 263 public final String getOverpassApiRequest(Bounds bounds) { 264 return getOverpassApiRequest( 265 "w=\""+LatLon.roundToOsmPrecisionStrict(bounds.getMin().lon())+"\" "+ 266 "s=\""+LatLon.roundToOsmPrecisionStrict(bounds.getMin().lat())+"\" "+ 267 "e=\""+LatLon.roundToOsmPrecisionStrict(bounds.getMax().lon())+"\" "+ 268 "n=\""+LatLon.roundToOsmPrecisionStrict(bounds.getMax().lat())+"\""); 269 } 270 271 272 protected String getOverpassApiRequest(String bbox) {return null;} 273 274 public boolean equals(IPrimitive p1, IPrimitive p2) {return false;} 275 276 public boolean isRelevant(IPrimitive p) {return false;} 277 278 public final Collection<IPrimitive> extractRelevantPrimitives(DataSet ds) { 279 ArrayList<IPrimitive> result = new ArrayList<>(); 280 for (IPrimitive p : ds.allPrimitives()) { 281 if (isRelevant(p)) { 282 result.add(p); 283 } 284 } 285 return result; 286 } 287 288 public boolean isForbidden(IPrimitive p) {return false;} 289 290 public boolean hasForbiddenTags() {return false;} 291 292 public interface ValueReplacer { 293 public String replace(String value); 294 } 295 296 protected final void replace(IPrimitive p, String dataKey, String osmKey) { 297 addOrReplace(p, dataKey, osmKey, null, null, null, true); 298 } 299 300 protected final void replace(IPrimitive p, String dataKey, String osmKey, ValueReplacer replacer) { 301 addOrReplace(p, dataKey, osmKey, null, null, replacer, true); 302 } 303 304 protected final void replace(IPrimitive p, String dataKey, String osmKey, String[] dataValues, String[] osmValues) { 305 addOrReplace(p, dataKey, osmKey, dataValues, osmValues, null, true); 306 } 307 308 protected final void add(IPrimitive p, String dataKey, String osmKey, ValueReplacer replacer) { 309 addOrReplace(p, dataKey, osmKey, null, null, replacer, false); 310 } 311 312 protected final void add(IPrimitive p, String dataKey, String osmKey, String[] dataValues, String[] osmValues) { 313 addOrReplace(p, dataKey, osmKey, dataValues, osmValues, null, false); 314 } 315 316 private final void addOrReplace(IPrimitive p, String dataKey, String osmKey, String[] dataValues, String[] osmValues, ValueReplacer replacer, boolean replace) { 317 String value = p.get(dataKey); 318 if (value != null) { 319 int index = -1; 320 for (int i = 0; dataValues != null && index == -1 && i < dataValues.length; i++) { 321 if (Pattern.compile(dataValues[i], Pattern.CASE_INSENSITIVE).matcher(value).matches()) { 322 index = i; 323 } 324 /*if (value.equalsIgnoreCase(csvValues[i])) { 325 index = i; 326 }*/ 327 } 328 if (index > -1 && osmValues != null) { 329 doAddReplace(p, dataKey, osmKey, osmValues[index], replace); 330 } else if (replacer != null) { 331 doAddReplace(p, dataKey, osmKey, replacer.replace(value), replace); 332 } else if (dataValues == null || osmValues == null) { 333 doAddReplace(p, dataKey, osmKey, value, replace); 334 } 335 } 336 } 337 338 private final void doAddReplace(IPrimitive p, String dataKey, String osmKey, String osmValue, boolean replace) { 339 if (replace) { 340 p.remove(dataKey); 341 } 342 p.put(osmKey, osmValue); 343 } 344 345 public String getSource() { 346 return null; 347 } 348 349 public final String getSourceDate() { 350 return sourceDate; 351 } 352 353 public final void setSourceDate(String sourceDate) { 354 this.sourceDate = sourceDate; 355 } 356 357 public final String getName() { 358 return name; 359 } 360 361 public final void setName(String name) { 362 this.name = name; 363 } 364 365 public String getLocalPortalIconName() { 366 return OdConstants.ICON_CORE_24; 367 } 368 369 public String getNationalPortalIconName() { 370 return OdConstants.ICON_CORE_24; 371 } 372 373 public String getDataLayerIconName() { 374 return OdConstants.ICON_CORE_16; 375 } 376 377 public ExtendedSourceEntry getMapPaintStyle() { 378 return null; 379 } 380 381 public ExtendedSourceEntry getTaggingPreset() { 382 return null; 383 } 384 385 protected final ExtendedSourceEntry getMapPaintStyle(String displayName) { 386 return getMapPaintStyle(displayName, this.getClass().getSimpleName().replace("Handler", "")); 387 } 388 389 protected final ExtendedSourceEntry getMapPaintStyle(String displayName, String fileNameWithoutExtension) { 390 return new ExtendedSourceEntry(displayName, OdConstants.PROTO_RSRC+//"/"+ 391 this.getClass().getPackage().getName().replace(".", "/")+"/"+ 392 fileNameWithoutExtension+"."+OdConstants.MAPCSS_EXT); 393 } 394 395 395 public final ImageIcon getMenuIcon() { 396 396 return menuIcon; … … 405 405 } 406 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 407 public final void setAssociatedFile(File associatedFile) { 408 this.associatedFile = associatedFile; 409 } 410 411 public final File getAssociatedFile() { 412 return this.associatedFile; 413 } 414 415 public boolean acceptsUrl(String url) { 416 URL dataURL = getDataURL(); 417 if (dataURL != null && url.equals(dataURL.toString())) { 418 return true; 419 } 420 List<Pair<String, URL>> dataURLs = getDataURLs(); 421 if (dataURLs != null) { 422 for (Pair<String, URL> pair : dataURLs) { 423 if (pair.b != null && url.equals(pair.b.toString())) { 424 return true; 425 } 426 } 427 } 428 return false; 429 } 430 431 // --------- Shapefile handling --------- 432 433 private ShpHandler shpHandler; 434 435 public final void setShpHandler(ShpHandler handler) { 436 shpHandler = handler; 437 } 438 439 public final ShpHandler getShpHandler() { 440 return shpHandler; 441 } 442 442 443 443 // --------- MIF handling --------- … … 453 453 } 454 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 455 // --------- GML handling --------- 456 457 private GmlHandler gmlHandler; 458 459 public final void setGmlHandler(GmlHandler handler) { 460 gmlHandler = handler; 461 } 462 463 public final GmlHandler getGmlHandler() { 464 return gmlHandler; 465 } 466 467 // ------------ Archive handling ------------ 468 469 private ArchiveHandler archiveHandler; 470 471 public final void setArchiveHandler(ArchiveHandler handler) { 472 archiveHandler = handler; 473 } 474 475 public ArchiveHandler getArchiveHandler() { 476 return archiveHandler; 477 } 478 479 // ------ Spreadsheet handling ---------- 480 481 private SpreadSheetHandler ssHandler; 482 483 public final void setSpreadSheetHandler(SpreadSheetHandler handler) { 484 ssHandler = handler; 485 } 486 487 public final SpreadSheetHandler getSpreadSheetHandler() { 488 return ssHandler; 489 } 490 491 public final void setCsvHandler(CsvHandler handler) { 492 setSpreadSheetHandler(handler); 493 } 494 495 public final CsvHandler getCsvHandler() { 496 if (ssHandler instanceof CsvHandler) { 497 return (CsvHandler) ssHandler; 498 } else { 499 return null; 500 } 501 } 502 503 // Tools 504 505 private final Collection<JosmAction> tools = new ArrayList<>(); 506 507 public final Collection<JosmAction> getTools() { 508 return tools; 509 } 510 511 public final boolean addTool(JosmAction tool) { 512 512 return tool != null ? tools.add(tool) : false; 513 514 515 516 517 513 } 514 515 public final boolean removeTool(JosmAction tool) { 516 return tool != null ? tools.remove(tool) : false; 517 } 518 518 519 519 public void notifyActive() { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/DataSetCategory.java
r30340 r30723 8 8 public class DataSetCategory { 9 9 10 11 12 13 14 15 16 17 18 19 20 10 private final String name; 11 private final ImageIcon icon; 12 13 public DataSetCategory(String name, ImageIcon icon) { 14 this.name = name; 15 this.icon = icon; 16 } 17 18 public DataSetCategory(String name, String iconName) { 19 this(name, iconName != null && !iconName.isEmpty() ? OdUtils.getImageIcon(iconName, true) : null); 20 } 21 21 22 23 24 22 public final String getName() { 23 return name; 24 } 25 25 26 27 28 26 public final ImageIcon getIcon() { 27 return icon; 28 } 29 29 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/DataSetUpdater.java
r30563 r30723 16 16 public abstract class DataSetUpdater { 17 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 18 public static final void updateDataSet(DataSet dataSet, AbstractDataSetHandler handler, File associatedFile) { 19 if (dataSet != null && handler != null) { 20 if (associatedFile != null) { 21 handler.setAssociatedFile(associatedFile); 22 long lastmodified = associatedFile.lastModified(); 23 if (lastmodified > 0) { 24 handler.setSourceDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date(lastmodified))); 25 } 26 } 27 if (!Main.pref.getBoolean(OdConstants.PREF_RAWDATA)) { 28 handler.updateDataSet(dataSet); 29 } 30 handler.checkDataSetSource(dataSet); 31 handler.checkNames(dataSet); 32 // Replace multipolygons with single untagged member by their sole member 33 for (Relation r : dataSet.getRelations()) { 34 if (r.isMultipolygon() && r.getMembersCount() == 1) { 35 OsmPrimitive outer = r.getMember(0).getMember(); 36 if (!outer.isTagged()) { 37 r.remove("type"); 38 r.removeMember(0); 39 39 outer.setKeys(r.getKeys()); 40 41 42 43 44 45 46 47 48 49 50 51 52 40 dataSet.removePrimitive(r); 41 } 42 } 43 } 44 // Simplify ways geometries 45 for (Way w : dataSet.getWays()) { 46 SequenceCommand command = Main.main.menu.simplifyWay.simplifyWay(w, 0.25); 47 if (command != null) { 48 Main.main.undoRedo.addNoRedraw(command); 49 } 50 } 51 } 52 } 53 53 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/NationalHandlers.java
r30340 r30723 9 9 public abstract class NationalHandlers { 10 10 11 12 13 11 public static final GmlHandler[] DEFAULT_GML_HANDLERS = new GmlHandler[]{ 12 new AustrianGmlHandler() 13 }; 14 14 15 16 17 15 public static final ShpHandler[] DEFAULT_SHP_HANDLERS = new ShpHandler[]{ 16 new FrenchShpHandler() 17 }; 18 18 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/SimpleDataSetHandler.java
r30563 r30723 24 24 public abstract class SimpleDataSetHandler extends AbstractDataSetHandler { 25 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 26 protected static final Projection wgs84 = OdConstants.PRJ_WGS84.getProjection(); 27 28 private final List<Tag> relevantTags = new ArrayList<>(); 29 private final List<Tag> forbiddenTags = new ArrayList<>(); 30 31 private final boolean relevantUnion; 32 33 public SimpleDataSetHandler() { 34 this.relevantUnion = false; 35 } 36 37 public SimpleDataSetHandler(String relevantTag) { 38 addRelevantTag(relevantTag); 39 this.relevantUnion = false; 40 40 Tag tag; 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 41 String[] kv = relevantTag.split("="); 42 if (kv != null && kv.length == 2) { 43 tag = new Tag(kv[0], kv[1]); 44 } else { 45 tag = new Tag(relevantTag); 46 } 47 setMenuIcon(MapPaintStyles.getNodeIcon(tag)); 48 } 49 50 public SimpleDataSetHandler(boolean relevantUnion, String ... relevantTags) { 51 addRelevantTag(relevantTags); 52 this.relevantUnion = relevantUnion; 53 } 54 55 public SimpleDataSetHandler(String ... relevantTags) { 56 this(false, relevantTags); 57 } 58 59 public SimpleDataSetHandler(Tag relevantTag) { 60 addRelevantTag(relevantTag); 61 this.relevantUnion = false; 62 } 63 64 public SimpleDataSetHandler(boolean relevantUnion, Tag ... relevantTags) { 65 addRelevantTag(relevantTags); 66 this.relevantUnion = relevantUnion; 67 } 68 69 public SimpleDataSetHandler(Tag ... relevantTags) { 70 this(false, relevantTags); 71 } 72 73 public void addRelevantTag(String ... relevantTags) { 74 addTags(this.relevantTags, relevantTags); 75 } 76 77 public void addRelevantTag(Tag ... relevantTags) { 78 addTags(this.relevantTags, relevantTags); 79 } 80 81 public void addForbiddenTag(String ... forbiddenTags) { 82 addTags(this.forbiddenTags, forbiddenTags); 83 } 84 85 public void addForbiddenTag(Tag ... forbiddenTags) { 86 addTags(this.forbiddenTags, forbiddenTags); 87 } 88 89 private final void addTags(final List<Tag> list, String ... tags) { 90 if (tags != null) { 91 for (String tag : tags) { 92 if (tag != null) { 93 if (tag.contains("=")) { 94 String[] tab = tag.split("="); 95 list.add(new Tag(tab[0], tab[1])); 96 } else { 97 list.add(new Tag(tag)); 98 } 99 } 100 } 101 } 102 } 103 104 private final void addTags(final List<Tag> list, Tag ... tags) { 105 if (tags != null) { 106 for (Tag tag : tags) { 107 if (tag != null) { 108 list.add(tag); 109 } 110 } 111 } 112 } 113 114 @Override 115 public boolean equals(IPrimitive p1, IPrimitive p2) { 116 for (Tag tag : this.relevantTags) { 117 if (!p1.get(tag.getKey()).equals(p2.get(tag.getKey()))) { 118 return false; 119 } 120 } 121 return true; 122 } 123 124 @Override 125 public boolean isRelevant(IPrimitive p) { 126 for (Tag tag : this.relevantTags) { 127 String value = p.get(tag.getKey()); 128 if (value == null || (tag.getValue() != null && !tag.getValue().equals(value))) { 129 return false; 130 } 131 } 132 if (isForbidden(p)) { 133 return false; 134 } 135 return true; 136 } 137 138 @Override 139 public boolean isForbidden(IPrimitive p) { 140 for (Tag tag : this.forbiddenTags) { 141 String value = p.get(tag.getKey()); 142 if (value != null && (tag.getValue() == null || tag.getValue().equals(value))) { 143 return true; 144 } 145 } 146 return false; 147 } 148 149 @Override 150 public boolean hasForbiddenTags() { 151 return !this.forbiddenTags.isEmpty(); 152 } 153 154 protected final String[] getOverpassApiConditions() { 155 List<String> conditions = new ArrayList<>(); 156 for (Tag tag : this.relevantTags) { 157 conditions.add(OverpassApi.hasKey(tag.getKey(), tag.getValue())); 158 } 159 return conditions.toArray(new String[0]); 160 } 161 162 protected String getOverpassApiQueries(String bbox, String ... conditions) { 163 String[] mpconditions = new String[conditions.length+1]; 164 mpconditions[0] = OverpassApi.hasKey("type", "multipolygon"); 165 for (int i=0; i<conditions.length; i++) { 166 mpconditions[i+1] = conditions[i]; 167 } 168 return OverpassApi.query(bbox, NODE, conditions) + "\n" + // Nodes 169 OverpassApi.recurse(NODE_RELATION, RELATION_WAY, WAY_NODE) + "\n" + 170 OverpassApi.query(bbox, WAY, conditions) + "\n" + // Full ways and their full relations 171 OverpassApi.recurse(WAY_NODE, "nodes") + "\n" + 172 OverpassApi.recurse(WAY_RELATION, RELATION_WAY, WAY_NODE) + "\n" + 173 OverpassApi.query(bbox, RELATION, mpconditions) + "\n" + // Full multipolygons 174 OverpassApi.recurse(RELATION_WAY, WAY_NODE); 175 } 176 177 @Override 178 protected String getOverpassApiRequest(String bbox) { 179 String result = ""; 180 if (this.relevantUnion) { 181 for (Tag tag : this.relevantTags) { 182 result += getOverpassApiQueries(bbox, OverpassApi.hasKey(tag.getKey(), tag.getValue())); 183 } 184 result = OverpassApi.union(result); 185 } else { 186 result = OverpassApi.union(getOverpassApiQueries(bbox, getOverpassApiConditions())); 187 } 188 return result + OverpassApi.print(); 189 } 190 191 @Override 192 protected Collection<String> getOsmXapiRequests(String bbox) { 193 String relevantTags = ""; 194 for (Tag tag : this.relevantTags) { 195 relevantTags += "["+tag.getKey()+"="+(tag.getValue() == null ? "*" : tag.getValue())+"]"; 196 } 197 String forbiddenTags = ""; 198 for (Tag tag : this.forbiddenTags) { 199 forbiddenTags += "[not("+tag.getKey()+"="+(tag.getValue() == null ? "*" : tag.getValue())+")]"; 200 } 201 return Collections.singleton("*[bbox="+bbox+"]"+relevantTags+forbiddenTags+"[@meta]"); 202 } 203 203 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/WayCombiner.java
r30532 r30723 27 27 // FIXME: Try to refactor CombineWayAction instead of using this class 28 28 public class WayCombiner { 29 29 30 30 protected static Way getTargetWay(Collection<Way> combinedWays) { 31 31 // init with an arbitrary way … … 155 155 targetWay.cloneFrom(modifiedTargetWay); 156 156 /*for (Command c : dialog.buildResolutionCommands()) { 157 157 c.executeCommand();//FIXME 158 158 }*/ 159 159 //new DeleteCommand(deletedWays).executeCommand(); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/at/AustrianConstants.java
r30563 r30723 5 5 public interface AustrianConstants { 6 6 7 8 9 10 7 /** 8 * Icon 9 */ 10 public static final String ICON_AT_24 = "at24.png"; 11 11 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/at/AustrianGmlHandler.java
r30340 r30723 10 10 public class AustrianGmlHandler extends DefaultGmlHandler { 11 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 12 @Override 13 public CoordinateReferenceSystem getCrsFor(String crsName) 14 throws NoSuchAuthorityCodeException, FactoryException { 15 16 // See http://www.esri-austria.at/downloads/coords_at.html 17 18 if (crsName != null && crsName.startsWith("AUT")) { 19 if (crsName.equalsIgnoreCase("AUT-GK28")) { // Gauß-Krüger, Meridianstreifen M28 20 return CRS.decode("EPSG:31281"); 21 22 } else if (crsName.equalsIgnoreCase("AUT-GK31")) { // Gauß-Krüger, Meridianstreifen M31 23 return CRS.decode("EPSG:31282"); 24 25 } else if (crsName.equalsIgnoreCase("AUT-GK34")) { // Gauß-Krüger, Meridianstreifen M34 26 return CRS.decode("EPSG:31283"); 27 28 } else if (crsName.equalsIgnoreCase("AUT-GK28-5")) { // Gauß-Krüger, Meridianstreifen M28, ohne 5 Mio. im Hochwert 29 return CRS.decode("EPSG:31251"); 30 31 } else if (crsName.equalsIgnoreCase("AUT-GK31-5")) { // Gauß-Krüger, Meridianstreifen M31, ohne 5 Mio. im Hochwert 32 return CRS.decode("EPSG:31252"); 33 34 } else if (crsName.equalsIgnoreCase("AUT-GK34-5")) { // Gauß-Krüger, Meridianstreifen M34, ohne 5 Mio. im Hochwert 35 return CRS.decode("EPSG:31253"); 36 37 } else if (crsName.equalsIgnoreCase("AUT-BM28")) { // Bundesmeldenetz, Meridianstreifen M28 38 return CRS.decode("EPSG:31288"); 39 40 } else if (crsName.equalsIgnoreCase("AUT-BM31")) { // Bundesmeldenetz, Meridianstreifen M31 41 return CRS.decode("EPSG:31289"); 42 43 } else if (crsName.equalsIgnoreCase("AUT-BM34")) { // Bundesmeldenetz, Meridianstreifen M34 44 return CRS.decode("EPSG:31290"); 45 46 } else if (crsName.equalsIgnoreCase("AUT-LM")) { // Lambertsche Kegelprojektion (geogr. Breite des Koo.Ursprungs = 47°30') 47 return CRS.decode("EPSG:31287"); 48 49 } else if (crsName.equalsIgnoreCase("AUT-LL-BESSEL")) { // Geographische Koordinaten auf dem Bessel-Ellipsoid, Längenzählung nach Greenwich 50 // See http://josebatiz.com/granvision/Almap/Install/Data1/_B5694C166D6A4B5390B1E547C6A1FAF6 51 // FIXME 52 } 53 } 54 return super.getCrsFor(crsName); 55 } 56 56 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/au/AustralianConstants.java
r30563 r30723 5 5 public interface AustralianConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String AUSTRALIAN_PORTAL = "http://data.gov.au/dataset/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_AU_24 = "au24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/be/BelgianConstants.java
r30563 r30723 6 6 public interface BelgianConstants { 7 7 8 9 10 11 12 13 14 15 16 8 /** 9 * Portal 10 */ 11 public static final String BELGIAN_PORTAL = "http://data.gov.be/"+OdConstants.PATTERN_LANG+"/dataset/"; 12 13 /** 14 * Icon 15 */ 16 public static final String ICON_BE_24 = "be24.png"; 17 17 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/be/BelgianDataSetHandler.java
r30563 r30723 17 17 public abstract class BelgianDataSetHandler extends SimpleDataSetHandler implements BelgianConstants { 18 18 19 19 private Projection singleProjection; 20 20 21 22 23 24 21 private String nationalPortalPathDe; 22 private String nationalPortalPathEn; 23 private String nationalPortalPathFr; 24 private String nationalPortalPathNl; 25 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 26 protected static final Projection lambert1972 = OdConstants.PRJ_LAMBERT_1972.getProjection(); 27 protected static final Projection lambert2008 = OdConstants.PRJ_LAMBERT_2008.getProjection(); 28 29 protected static final Projection[] projections = new Projection[]{ 30 lambert1972, 31 lambert2008 32 }; 33 34 protected class InternalCsvHandler extends DefaultCsvHandler { 35 /*@Override 36 public List<Projection> getSpreadSheetProjections() { 37 if (singleProjection != null) { 38 return Arrays.asList(new Projection[]{singleProjection}); 39 } else { 40 return Arrays.asList(projections); 41 } 42 }*/ 43 44 @Override 45 public LatLon getCoor(EastNorth en, String[] fields) { 46 if (singleProjection != null) { 47 return singleProjection.eastNorth2latlon(en); 48 } else { 49 return super.getCoor(en, fields); 50 } 51 } 52 } 53 53 54 55 56 54 public BelgianDataSetHandler() { 55 init(); 56 } 57 57 58 59 60 61 58 public BelgianDataSetHandler(String relevantTag) { 59 super(relevantTag); 60 init(); 61 } 62 62 63 64 65 66 63 public BelgianDataSetHandler(boolean relevantUnion, String[] relevantTags) { 64 super(relevantUnion, relevantTags); 65 init(); 66 } 67 67 68 69 70 71 72 73 74 75 68 public BelgianDataSetHandler(boolean relevantUnion, Tag[] relevantTags) { 69 super(relevantUnion, relevantTags); 70 init(); 71 } 72 73 private void init() { 74 setCsvHandler(new InternalCsvHandler()); 75 } 76 76 77 78 79 80 81 82 77 protected final void setNationalPortalPath(String nationalPortalPathDe, String nationalPortalPathEn, String nationalPortalPathFr, String nationalPortalPathNl) { 78 this.nationalPortalPathDe = nationalPortalPathDe; 79 this.nationalPortalPathEn = nationalPortalPathEn; 80 this.nationalPortalPathFr = nationalPortalPathFr; 81 this.nationalPortalPathNl = nationalPortalPathNl; 82 } 83 83 84 85 86 87 84 protected final void setSingleProjection(Projection singleProjection) { 85 this.singleProjection = singleProjection; 86 getCsvHandler().setHandlesProjection(singleProjection != null); 87 } 88 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 89 @Override 90 public URL getNationalPortalURL() { 91 try { 92 String nationalPortalPath = ""; 93 String lang = Main.pref.get("language"); 94 if (lang == null || lang.isEmpty()) { 95 lang = Locale.getDefault().toString(); 96 } 97 98 if (lang.startsWith("de") && nationalPortalPathDe != null) { 99 nationalPortalPath = nationalPortalPathDe; 100 } else if (lang.startsWith("fr") && nationalPortalPathFr != null) { 101 nationalPortalPath = nationalPortalPathFr; 102 } else if (lang.startsWith("nl") && nationalPortalPathNl != null) { 103 nationalPortalPath = nationalPortalPathNl; 104 } else { 105 nationalPortalPath = nationalPortalPathEn; 106 } 107 return new URL(BELGIAN_PORTAL.replace(OdConstants.PATTERN_LANG, lang.substring(0, 2))+nationalPortalPath);//FIXME 108 } catch (MalformedURLException e) { 109 e.printStackTrace(); 110 } 111 return null; 112 } 113 113 114 115 116 117 114 @Override 115 public String getLocalPortalIconName() { 116 return ICON_BE_24; 117 } 118 118 119 120 121 122 119 @Override 120 public String getNationalPortalIconName() { 121 return ICON_BE_24; 122 } 123 123 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/ca/CanadianConstants.java
r30563 r30723 5 5 public interface CanadianConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String CANADIAN_PORTAL = "http://www.data.gc.ca/geo/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_CA_24 = "ca24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/cl/ChileanConstants.java
r30563 r30723 5 5 public interface ChileanConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String CHILEAN_PORTAL = "http://datos.gob.cl/datasets/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_CL_24 = "cl24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/es/SpanishConstants.java
r30563 r30723 5 5 public interface SpanishConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String SPANISH_PORTAL = "http://datos.gob.es/datos/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_ES_24 = "es24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchAdministrativeUnit.java
r30340 r30723 3 3 4 4 public abstract class FrenchAdministrativeUnit { 5 6 7 8 9 10 11 5 private final String code; 6 private final String name; 7 8 private FrenchAdministrativeUnit(String code, String name) { 9 this.code = code; 10 this.name = name; 11 } 12 12 13 14 15 13 public final String getCode() { 14 return code; 15 } 16 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 17 public final String getName() { 18 return name; 19 } 20 21 public static final class FrenchDepartment extends FrenchAdministrativeUnit { 22 private FrenchDepartment(String code, String name) { 23 super(code, name); 24 } 25 } 26 27 public static final class FrenchRegion extends FrenchAdministrativeUnit { 28 private FrenchRegion(String code, String name) { 29 super(code, name); 30 } 31 } 32 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 33 public static final FrenchDepartment[] allDepartments = new FrenchDepartment[] { 34 new FrenchDepartment("001", "Ain"), 35 new FrenchDepartment("002", "Aisne"), 36 new FrenchDepartment("003", "Allier"), 37 new FrenchDepartment("004", "Alpes-de-Haute-Provence"), 38 new FrenchDepartment("005", "Hautes-Alpes"), 39 new FrenchDepartment("006", "Alpes-Maritimes"), 40 new FrenchDepartment("007", "Ardèche"), 41 new FrenchDepartment("008", "Ardennes"), 42 new FrenchDepartment("009", "Ariège"), 43 new FrenchDepartment("010", "Aube"), 44 new FrenchDepartment("011", "Aude"), 45 new FrenchDepartment("012", "Aveyron"), 46 new FrenchDepartment("013", "Bouches-du-Rhône"), 47 new FrenchDepartment("014", "Calvados"), 48 new FrenchDepartment("015", "Cantal"), 49 new FrenchDepartment("016", "Charente"), 50 new FrenchDepartment("017", "Charente-Maritime"), 51 new FrenchDepartment("018", "Cher"), 52 new FrenchDepartment("019", "Corrèze"), 53 new FrenchDepartment("02A", "Corse-du-Sud"), 54 new FrenchDepartment("02B", "Haute-Corse"), 55 new FrenchDepartment("021", "Côte-d'Or"), 56 new FrenchDepartment("022", "Côtes-d'Armor"), 57 new FrenchDepartment("023", "Creuse"), 58 new FrenchDepartment("024", "Dordogne"), 59 new FrenchDepartment("025", "Doubs"), 60 new FrenchDepartment("026", "Drôme"), 61 new FrenchDepartment("027", "Eure"), 62 new FrenchDepartment("028", "Eure-et-Loir"), 63 new FrenchDepartment("029", "Finistère"), 64 new FrenchDepartment("030", "Gard"), 65 new FrenchDepartment("031", "Haute-Garonne"), 66 new FrenchDepartment("032", "Gers"), 67 new FrenchDepartment("033", "Gironde"), 68 new FrenchDepartment("034", "Hérault"), 69 new FrenchDepartment("035", "Ille-et-Vilaine"), 70 new FrenchDepartment("036", "Indre"), 71 new FrenchDepartment("037", "Indre-et-Loire"), 72 new FrenchDepartment("038", "Isère"), 73 new FrenchDepartment("039", "Jura"), 74 new FrenchDepartment("040", "Landes"), 75 new FrenchDepartment("041", "Loir-et-Cher"), 76 new FrenchDepartment("042", "Loire"), 77 new FrenchDepartment("043", "Haute-Loire"), 78 new FrenchDepartment("044", "Loire-Atlantique"), 79 new FrenchDepartment("045", "Loiret"), 80 new FrenchDepartment("046", "Lot"), 81 new FrenchDepartment("047", "Lot-et-Garonne"), 82 new FrenchDepartment("048", "Lozère"), 83 new FrenchDepartment("049", "Maine-et-Loire"), 84 new FrenchDepartment("050", "Manche"), 85 new FrenchDepartment("051", "Marne"), 86 new FrenchDepartment("052", "Haute-Marne"), 87 new FrenchDepartment("053", "Mayenne"), 88 new FrenchDepartment("054", "Meurthe-et-Moselle"), 89 new FrenchDepartment("055", "Meuse"), 90 new FrenchDepartment("056", "Morbihan"), 91 new FrenchDepartment("057", "Moselle"), 92 new FrenchDepartment("058", "Nièvre"), 93 new FrenchDepartment("059", "Nord"), 94 new FrenchDepartment("060", "Oise"), 95 new FrenchDepartment("061", "Orne"), 96 new FrenchDepartment("062", "Pas-de-Calais"), 97 new FrenchDepartment("063", "Puy-de-Dôme"), 98 new FrenchDepartment("064", "Pyrénées-Atlantiques"), 99 new FrenchDepartment("065", "Hautes-Pyrénées"), 100 new FrenchDepartment("066", "Pyrénées-Orientales"), 101 new FrenchDepartment("067", "Bas-Rhin"), 102 new FrenchDepartment("068", "Haut-Rhin"), 103 new FrenchDepartment("069", "Rhône"), 104 new FrenchDepartment("070", "Haute-Saône"), 105 new FrenchDepartment("071", "Saône-et-Loire"), 106 new FrenchDepartment("072", "Sarthe"), 107 new FrenchDepartment("073", "Savoie"), 108 new FrenchDepartment("074", "Haute-Savoie"), 109 new FrenchDepartment("075", "Paris"), 110 new FrenchDepartment("076", "Seine-Maritime"), 111 new FrenchDepartment("077", "Seine-et-Marne"), 112 new FrenchDepartment("078", "Yvelines"), 113 new FrenchDepartment("079", "Deux-Sèvres"), 114 new FrenchDepartment("080", "Somme"), 115 new FrenchDepartment("081", "Tarn"), 116 new FrenchDepartment("082", "Tarn-et-Garonne"), 117 new FrenchDepartment("083", "Var"), 118 new FrenchDepartment("084", "Vaucluse"), 119 new FrenchDepartment("085", "Vendée"), 120 new FrenchDepartment("086", "Vienne"), 121 new FrenchDepartment("087", "Haute-Vienne"), 122 new FrenchDepartment("088", "Vosges"), 123 new FrenchDepartment("089", "Yonne"), 124 new FrenchDepartment("090", "Territoire de Belfort"), 125 new FrenchDepartment("091", "Essonne"), 126 new FrenchDepartment("092", "Hauts-de-Seine"), 127 new FrenchDepartment("093", "Seine-Saint-Denis"), 128 new FrenchDepartment("094", "Val-de-Marne"), 129 new FrenchDepartment("095", "Val-d'Oise"), 130 new FrenchDepartment("971", "Guadeloupe"), 131 new FrenchDepartment("972", "Martinique"), 132 new FrenchDepartment("973", "Guyane"), 133 new FrenchDepartment("974", "La Réunion"), 134 new FrenchDepartment("976", "Mayotte"), 135 }; 136 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 137 public static final FrenchRegion[] allRegions = new FrenchRegion[] { 138 new FrenchRegion("42", "Alsace"), 139 new FrenchRegion("72", "Aquitaine"), 140 new FrenchRegion("83", "Auvergne"), 141 new FrenchRegion("25", "Basse-Normandie"), 142 new FrenchRegion("26", "Bourgogne"), 143 new FrenchRegion("53", "Bretagne"), 144 new FrenchRegion("24", "Centre"), 145 new FrenchRegion("21", "Champagne-Ardenne"), 146 new FrenchRegion("94", "Corse"), 147 new FrenchRegion("43", "Franche-Comté"), 148 new FrenchRegion("23", "Haute-Normandie"), 149 new FrenchRegion("11", "Île-de-France"), 150 new FrenchRegion("91", "Languedoc-Roussillon"), 151 new FrenchRegion("74", "Limousin"), 152 new FrenchRegion("41", "Lorraine"), 153 new FrenchRegion("73", "Midi-Pyrénées"), 154 new FrenchRegion("31", "Nord-Pas-de-Calais"), 155 new FrenchRegion("52", "Pays de la Loire"), 156 new FrenchRegion("22", "Picardie"), 157 new FrenchRegion("54", "Poitou-Charentes"), 158 new FrenchRegion("93", "Provence-Alpes-Côte d'Azur"), 159 new FrenchRegion("82", "Rhône-Alpes"), 160 new FrenchRegion("01", "Guadeloupe"), 161 new FrenchRegion("02", "Martinique"), 162 new FrenchRegion("03", "Guyane"), 163 new FrenchRegion("04", "La Réunion"), 164 new FrenchRegion("05", "Mayotte") 165 }; 166 166 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchConstants.java
r30563 r30723 5 5 public interface FrenchConstants { 6 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 7 /** 8 * Portal 9 */ 10 public static final String FRENCH_PORTAL = "http://www.data.gouv.fr/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_FR_24 = "fr24.png"; 16 17 /** 18 * NEPTUNE XML Schema 19 */ 20 public static final String NEPTUNE_XSD = "/resources/neptune/neptune.xsd"; 21 21 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchDataSetHandler.java
r30563 r30723 21 21 public abstract class FrenchDataSetHandler extends SimpleDataSetHandler implements FrenchConstants { 22 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 if (dpt.equals("971") || dpt.equals("972") || dpt.equals("977") || dpt.equals("978")) {// Antilles129 130 } else if (dpt.equals("973")) {// Guyane131 132 } else if (dpt.equals("974")) {// La Réunion133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 23 private Projection singleProjection; 24 25 private String nationalPortalPath; 26 27 protected static final Projection lambert93 = OdConstants.PRJ_LAMBERT_93.getProjection(); // France metropolitaine 28 protected static final Projection utm20 = Projections.getProjectionByCode("EPSG:32620"); // UTM 20 N - Guadeloupe, Martinique 29 protected static final Projection utm22 = Projections.getProjectionByCode("EPSG:32622"); // UTM 22 N - Guyane 30 protected static final Projection utm38 = Projections.getProjectionByCode("EPSG:32738"); // UTM 38 S - Mayotte 31 protected static final Projection utm40 = Projections.getProjectionByCode("EPSG:32740"); // UTM 40 S - Reunion 32 33 protected static final Projection[] lambert4Zones = new Projection[4]; 34 static { 35 for (int i=0; i<lambert4Zones.length; i++) { 36 lambert4Zones[i] = Projections.getProjectionByCode("EPSG:"+Integer.toString(27561+i)); 37 } 38 } 39 40 protected static final Projection[] projections = new Projection[]{ 41 lambert93, // France metropolitaine 42 utm20, // Guadeloupe, Martinique 43 utm22, // Guyane 44 utm38, // Mayotte 45 utm40, // Reunion 46 }; 47 48 protected class InternalCsvHandler extends DefaultCsvHandler { 49 /*@Override 50 public List<Projection> getSpreadSheetProjections() { 51 if (singleProjection != null) { 52 return Arrays.asList(new Projection[]{singleProjection}); 53 } else { 54 return Arrays.asList(projections); 55 } 56 }*/ 57 58 @Override 59 public LatLon getCoor(EastNorth en, String[] fields) { 60 if (singleProjection != null) { 61 return singleProjection.eastNorth2latlon(en); 62 } else { 63 return super.getCoor(en, fields); 64 } 65 } 66 67 @Override 68 public boolean handlesProjection() { 69 return singleProjection != null; 70 } 71 } 72 73 public FrenchDataSetHandler() { 74 init(); 75 } 76 77 public FrenchDataSetHandler(String relevantTag) { 78 super(relevantTag); 79 init(); 80 } 81 82 public FrenchDataSetHandler(boolean relevantUnion, String[] relevantTags) { 83 super(relevantUnion, relevantTags); 84 init(); 85 } 86 87 public FrenchDataSetHandler(boolean relevantUnion, Tag[] relevantTags) { 88 super(relevantUnion, relevantTags); 89 init(); 90 } 91 92 private void init() { 93 setShpHandler(new FrenchShpHandler()); 94 setCsvHandler(new InternalCsvHandler()); 95 } 96 97 protected final void setNationalPortalPath(String nationalPortalPath) { 98 this.nationalPortalPath = nationalPortalPath; 99 } 100 101 protected final void setSingleProjection(Projection singleProjection) { 102 this.singleProjection = singleProjection; 103 } 104 105 @Override 106 public URL getNationalPortalURL() { 107 try { 108 if (nationalPortalPath != null && !nationalPortalPath.isEmpty()) { 109 return new URL(FRENCH_PORTAL + "donnees/view/" + nationalPortalPath); 110 } 111 } catch (MalformedURLException e) { 112 e.printStackTrace(); 113 } 114 return null; 115 } 116 117 @Override 118 public String getLocalPortalIconName() { 119 return ICON_FR_24; 120 } 121 122 @Override 123 public String getNationalPortalIconName() { 124 return ICON_FR_24; 125 } 126 127 protected static final LatLon getLatLonByDptCode(EastNorth en, String dpt, boolean useCC9) { 128 if (dpt.equals("971") || dpt.equals("972") || dpt.equals("977") || dpt.equals("978")) { // Antilles 129 return utm20.eastNorth2latlon(en); 130 } else if (dpt.equals("973")) { // Guyane 131 return utm22.eastNorth2latlon(en); 132 } else if (dpt.equals("974")) { // La Réunion 133 return utm40.eastNorth2latlon(en); 134 } else if (dpt.equals("976") || dpt.equals("985")) { // 985 = ancien code de Mayotte ? (présent dans geofla) 135 return utm38.eastNorth2latlon(en); 136 } else if (!useCC9) { 137 return lambert93.eastNorth2latlon(en); 138 } else if (dpt.endsWith("2A") || dpt.endsWith("2B") || dpt.endsWith("20")) { 139 return lambertCC9Zones[0].eastNorth2latlon(en); 140 } else if (dpt.endsWith("64") || dpt.endsWith("65") || dpt.endsWith("31") || dpt.endsWith("09") || dpt.endsWith("11") || dpt.endsWith("66") || dpt.endsWith("34") || dpt.endsWith("83")) { 141 return lambertCC9Zones[1].eastNorth2latlon(en); 142 } else if (dpt.endsWith("40") || dpt.endsWith("32") || dpt.endsWith("47") || dpt.endsWith("82") || dpt.endsWith("81") || dpt.endsWith("12") || dpt.endsWith("48") || dpt.endsWith("30") || dpt.endsWith("13") || dpt.endsWith("84") || dpt.endsWith("04") || dpt.endsWith("06")) { 143 return lambertCC9Zones[2].eastNorth2latlon(en); 144 } else if (dpt.endsWith("33") || dpt.endsWith("24") || dpt.endsWith("46") || dpt.endsWith("19") || dpt.endsWith("15") || dpt.endsWith("43") || dpt.endsWith("07") || dpt.endsWith("26") || dpt.endsWith("05") || dpt.endsWith("38") || dpt.endsWith("73")) { 145 return lambertCC9Zones[3].eastNorth2latlon(en); 146 } else if (dpt.endsWith("17") || dpt.endsWith("16") || dpt.endsWith("87") || dpt.endsWith("23") || dpt.endsWith("63") || dpt.endsWith("03") || dpt.endsWith("42") || dpt.endsWith("69") || dpt.endsWith("01") || dpt.endsWith("74")) { 147 return lambertCC9Zones[4].eastNorth2latlon(en); 148 } else if (dpt.endsWith("44") || dpt.endsWith("85") || dpt.endsWith("49") || dpt.endsWith("79") || dpt.endsWith("37") || dpt.endsWith("86") || dpt.endsWith("36") || dpt.endsWith("18") || dpt.endsWith("58") || dpt.endsWith("71") || dpt.endsWith("21") || dpt.endsWith("39") || dpt.endsWith("25")) { 149 return lambertCC9Zones[5].eastNorth2latlon(en); 150 } else if (dpt.endsWith("29") || dpt.endsWith("56") || dpt.endsWith("22") || dpt.endsWith("35") || dpt.endsWith("53") || dpt.endsWith("72") || dpt.endsWith("41") || dpt.endsWith("28") || dpt.endsWith("45") || dpt.endsWith("89") || dpt.endsWith("10") || dpt.endsWith("52") || dpt.endsWith("70") || dpt.endsWith("88") || dpt.endsWith("68") || dpt.endsWith("90")) { 151 return lambertCC9Zones[6].eastNorth2latlon(en); 152 } else if (dpt.endsWith("50") || dpt.endsWith("14") || dpt.endsWith("61") || dpt.endsWith("27") || dpt.endsWith("60") || dpt.endsWith("95") || dpt.endsWith("78") || dpt.endsWith("91") || dpt.endsWith("92") || dpt.endsWith("93") || dpt.endsWith("94") || dpt.endsWith("75") || dpt.endsWith("77") || dpt.endsWith("60") || dpt.endsWith("02") || dpt.endsWith("51") || dpt.endsWith("55") || dpt.endsWith("54") || dpt.endsWith("57") || dpt.endsWith("67")) { 153 return lambertCC9Zones[7].eastNorth2latlon(en); 154 } else if (dpt.endsWith("76") || dpt.endsWith("80") || dpt.endsWith("62") || dpt.endsWith("59") || dpt.endsWith("08")) { 155 return lambertCC9Zones[8].eastNorth2latlon(en); 156 } else { 157 throw new IllegalArgumentException("Unsupported department code: "+dpt); 158 } 159 } 160 161 private void replaceFaxPhone(OsmPrimitive p, String dataKey, String osmKey) { 162 String phone = p.get(dataKey); 163 if (phone != null) { 164 p.put(osmKey, phone.replace(" ", "").replace(".", "").replaceFirst("0", "+33")); 165 p.remove(dataKey); 166 } 167 } 168 169 protected void replaceFax(OsmPrimitive p, String dataKey) { 170 replaceFaxPhone(p, dataKey, "contact:fax"); 171 } 172 173 protected void replacePhone(OsmPrimitive p, String dataKey) { 174 replaceFaxPhone(p, dataKey, "contact:phone"); 175 } 176 177 private static final String dayFr = "L|Lu|M|Ma|Me|J|Je|V|Ve|S|Sa|D|Di"; 178 private static final String dayEn = "Mo|Mo|Tu|Tu|We|Th|Th|Fr|Fr|Sa|Sa|Su|Su"; 179 180 private static final String[] dayFrSplit = dayFr.split("\\|"); 181 private static final String[] dayEnSplit = dayEn.split("\\|"); 182 183 protected void replaceOpeningHours(OsmPrimitive p, String dataKey) { 184 String hours = p.get(dataKey); 185 if (hours != null) { 186 hours = hours.replace("h", ":").replace(": ", ":00 "); 187 hours = hours.replace(" - ", "-").replace(" au ", "-").replace(" à ", "-"); 188 hours = hours.replace(" et ", ",").replace("/", ","); 189 hours = hours.replace(" (sf vacances)", "; PH off"); 190 if (hours.endsWith(":")) { 191 hours += "00"; 192 } 193 String dayGroup = "("+dayFr+")"; 194 String dayNcGroup = "(?:"+dayFr+")"; 195 // FIXME: this doesn't work yet 196 for (String sep : new String[]{"-",","}) { 197 boolean finished = false; 198 while (!finished) { 199 Matcher m = Pattern.compile(".*("+dayNcGroup+"(?:"+sep+dayNcGroup+")+).*").matcher(hours); 200 if (m.matches()) { 201 String range = m.group(1); 202 Matcher m2 = Pattern.compile(dayGroup+"(?:"+sep+dayGroup+")+").matcher(range); 203 if (m2.matches()) { 204 String replacement = ""; 205 for (int i=0; i<m2.groupCount(); i++) { 206 if (i > 0) { 207 replacement += sep; 208 } 209 replacement += getEnDay(m2.group(i+1)); 210 } 211 hours = hours.replace(range, replacement); 212 } 213 } else { 214 finished = true; 215 } 216 } 217 } 218 p.put("opening_hours", hours); 219 p.remove(dataKey); 220 } 221 } 222 223 private String getEnDay(String frDay) { 224 for (int i=0; i<dayFrSplit.length; i++) { 225 if (dayFrSplit[i].equals(frDay)) { 226 return dayEnSplit[i]; 227 } 228 } 229 return ""; 230 } 231 231 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchShpHandler.java
r30340 r30723 15 15 public class FrenchShpHandler extends DefaultShpHandler { 16 16 17 18 19 20 21 22 23 24 25 26 17 @Override 18 public CoordinateReferenceSystem getCrsFor(String crsName) throws NoSuchAuthorityCodeException, FactoryException { 19 if (crsName.equalsIgnoreCase("RGM04")) { 20 return CRS.decode("EPSG:4471"); 21 } else if (crsName.equalsIgnoreCase("RGFG95_UTM_Zone_22N")) { 22 return CRS.decode("EPSG:2972"); 23 } else { 24 return super.getCrsFor(crsName); 25 } 26 } 27 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 28 @Override 29 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) 30 throws FactoryException { 31 if (sourceCRS.getName().getCode().equalsIgnoreCase("Lambert I Nord")) { 32 if (sourceCRS instanceof ProjectedCRS) { 33 GeodeticDatum datum = ((ProjectedCRS) sourceCRS).getDatum(); 34 if (datum.getPrimeMeridian().getGreenwichLongitude() > 0.0 && ((ProjectedCRS) sourceCRS).getConversionFromBase().getMathTransform() instanceof LambertConformal2SP) { 35 LambertConformal2SP lambert = (LambertConformal2SP) ((ProjectedCRS) sourceCRS).getConversionFromBase().getMathTransform(); 36 Double falseNorthing = get(lambert.getParameterValues(), AbstractProvider.FALSE_NORTHING); 37 Double centralmeridian = get(lambert.getParameterValues(), AbstractProvider.CENTRAL_MERIDIAN); 38 if (centralmeridian.equals(0.0)) { 39 if (falseNorthing.equals(200000.0)) { 40 return CRS.findMathTransform(CRS.decode("EPSG:27561"), targetCRS, lenient); 41 } else if (falseNorthing.equals(1200000.0)) { 42 return CRS.findMathTransform(CRS.decode("EPSG:27571"), targetCRS, lenient); 43 } 44 } 45 } 46 } 47 } 48 return super.findMathTransform(sourceCRS, targetCRS, lenient); 49 } 50 50 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/it/ItalianConstants.java
r30563 r30723 5 5 public interface ItalianConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String ITALIAN_PORTAL = "http://www.dati.gov.it/content/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_IT_24 = "it24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/ke/KenyanConstants.java
r30563 r30723 5 5 public interface KenyanConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String KENYAN_PORTAL = "https://opendata.go.ke/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_KE_24 = "ke24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/nl/DutchConstants.java
r30563 r30723 5 5 public interface DutchConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String NORWEGIAN_PORTAL = "http://data.overheid.nl/package/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_NL_24 = "nl24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/no/NorwegianConstants.java
r30563 r30723 5 5 public interface NorwegianConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String NORWEGIAN_PORTAL = "http://data.norge.no/data/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_NO_24 = "no24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/nz/NewZealanderConstants.java
r30563 r30723 5 5 public interface NewZealanderConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String NEW_ZEALANDER_PORTAL = "http://data.govt.nz/dataset/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_NZ_24 = "nz24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/pt/PortugueseConstants.java
r30563 r30723 5 5 public interface PortugueseConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String PORTUGUESE_PORTAL = "http://www.dados.gov.pt/PT/CatalogoDados/Dados.aspx?name="; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_PT_24 = "pt24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/uk/BritishConstants.java
r30563 r30723 5 5 public interface BritishConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String BRITISH_PORTAL = "http://data.gov.uk/dataset/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_UK_24 = "uk24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/us/AmericanConstants.java
r30563 r30723 5 5 public interface AmericanConstants { 6 6 7 8 9 10 11 12 13 14 15 7 /** 8 * Portal 9 */ 10 public static final String AMERICAN_PORTAL = "http://explore.data.gov/"; 11 12 /** 13 * Icon 14 */ 15 public static final String ICON_US_24 = "us24.png"; 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/AskLicenseAgreementDialog.java
r30340 r30723 10 10 11 11 public class AskLicenseAgreementDialog extends ViewLicenseDialog { 12 13 14 15 12 13 public AskLicenseAgreementDialog(License license) throws IOException { 14 super(license, Main.parent, tr("License Agreement"), new String[] {tr("Accept"), "", tr("Refuse")}); 15 16 16 setToolTipTexts(new String[] { 17 17 tr("I understand and accept these terms and conditions"), 18 18 tr("View the full text of this license"), 19 19 tr("I refuse these terms and conditions. Cancel download.")}); 20 20 } 21 21 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/DialogPrompter.java
r30563 r30723 9 9 10 10 public class DialogPrompter <T extends ExtendedDialog> implements Runnable { 11 12 13 11 12 private T dialog; 13 private int value = -1; 14 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 15 protected T buildDialog() {return null;} // To be overriden if needed 16 17 public DialogPrompter() { 18 this(null); 19 } 20 21 public DialogPrompter(T dialog) { 22 this.dialog = dialog; 23 } 24 25 public final T getDialog() { 26 return dialog; 27 } 28 29 @Override 30 public final void run() { 31 if (dialog == null) { 32 dialog = buildDialog(); 33 } 34 if (dialog != null) { 35 value = dialog.showDialog().getValue(); 36 } 37 } 38 39 public final DialogPrompter<T> promptInEdt() { 40 if (SwingUtilities.isEventDispatchThread()) { 41 run(); 42 } else { 43 try { 44 SwingUtilities.invokeAndWait(this); 45 } catch (InterruptedException e) { 46 e.printStackTrace(); 47 } catch (InvocationTargetException e) { 48 e.printStackTrace(); 49 } 50 } 51 return this; 52 } 53 53 54 55 56 54 public final int getValue() { 55 return value; 56 } 57 57 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/ModulePreference.java
r30563 r30723 527 527 } 528 528 529 530 531 532 533 534 535 536 537 529 @Override 530 public boolean isExpert() { 531 return false; 532 } 533 534 @Override 535 public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) { 536 return gui.getSetting(OdPreferenceSetting.class); 537 } 538 538 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/ModulePreferencesModel.java
r30563 r30723 29 29 30 30 protected Collection<String> getModules(Collection<String> def) { 31 31 return Main.pref.getCollection(OdConstants.PREF_MODULES, def); 32 32 } 33 33 34 34 public ModulePreferencesModel() { 35 36 35 currentActiveModules = new HashSet<>(); 36 currentActiveModules.addAll(getModules(currentActiveModules)); 37 37 } 38 38 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/OdDialog.java
r30563 r30723 46 46 47 47 private class DownloadAction extends JosmAction { 48 49 50 51 52 53 54 55 56 57 48 public DownloadAction() { 49 super(marktr("Download"), "download", tr("Download OSM data corresponding to the current data set."), null, false); 50 } 51 @Override 52 public void actionPerformed(ActionEvent e) { 53 if (Main.main.getEditLayer() instanceof OdLayer) { 54 dataLayer.downloadOsmData(); 55 diffButton.setEnabled(dataLayer.osmLayer != null); 56 } 57 } 58 58 } 59 59 60 60 private class SelectAction extends JosmAction { 61 62 63 64 65 66 67 61 public SelectAction() { 62 super(marktr("Select"), "dialogs/select", tr("Set the selected elements on the map to the selected items in the list above."), null, false); 63 } 64 @Override 65 public void actionPerformed(ActionEvent e) { 66 // TODO 67 } 68 68 } 69 69 70 70 private class DiffAction extends JosmAction { 71 72 73 74 75 76 77 78 79 71 public DiffAction() { 72 super(marktr("Diff"), "dialogs/diff", tr("Perform diff between current data set and existing OSM data."), null, false); 73 } 74 @Override 75 public void actionPerformed(ActionEvent e) { 76 if (Main.main.getEditLayer() instanceof OdLayer) { 77 dataLayer.makeDiff(); 78 } 79 } 80 80 } 81 81 … … 90 90 } 91 91 92 93 94 95 96 97 98 99 100 101 92 public OdDialog() { 93 super("OpenData", OdConstants.ICON_CORE_24, tr("Open the OpenData window."), 94 Shortcut.registerShortcut("subwindow:opendata", tr("Toggle: {0}", "OpenData"), 95 KeyEvent.VK_A, Shortcut.ALT_CTRL_SHIFT), 150, false, OdPreferenceSetting.class); 96 97 this.buttons = Arrays.asList(new SideButton[] { 98 /*selectButton =*/ new SideButton(new SelectAction()), 99 downloadButton = new SideButton(new DownloadAction()), 100 diffButton = new SideButton(new DiffAction()), 101 toolsButton = new SideButton(new ToolsAction()) 102 102 }); 103 104 105 106 107 103 104 this.toolsButton.addMouseListener(new MouseAdapter() { 105 @Override 106 public void mousePressed(MouseEvent e) { 107 if (Main.main.getEditLayer() instanceof OdLayer) { 108 108 JPopupMenu popup = new JPopupMenu(); 109 110 111 109 for (JosmAction tool : dataLayer.handler.getTools()) { 110 popup.add(tool); 111 } 112 112 popup.show(e.getComponent(), e.getX(), e.getY()); 113 114 113 } 114 } 115 115 }); 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 116 117 disableAllButtons(); 118 119 this.treeModel = new DefaultTreeModel(null); // TODO: treeNode 120 this.dataLayer = null; 121 122 createLayout(new JTree(treeModel), true, buttons); 123 124 MapView.addEditLayerChangeListener(this); 125 } 126 127 private void disableAllButtons() { 128 for (SideButton button : buttons) { 129 button.setEnabled(false); 130 } 131 } 132 132 133 134 135 136 133 @Override 134 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 135 activeLayerChange(oldLayer, newLayer); 136 } 137 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 138 @Override 139 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 140 if (newLayer instanceof OdLayer) { 141 dataLayer = ((OdLayer) newLayer).getDataLayer(); 142 } else { 143 dataLayer = null; 144 } 145 146 if (dataLayer != null) { 147 if (dataLayer.osmLayer == null) { 148 downloadButton.setEnabled(true); 149 } else if (dataLayer.diffLayer == null) { 150 diffButton.setEnabled(true); 151 } 152 toolsButton.setEnabled(dataLayer.handler != null && !dataLayer.handler.getTools().isEmpty()); 153 } else { 154 disableAllButtons(); 155 } 156 } 157 157 158 159 160 158 @Override 159 public void layerAdded(Layer newLayer) { 160 } 161 161 162 163 164 162 @Override 163 public void layerRemoved(Layer oldLayer) { 164 } 165 165 166 166 @Override -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/OdPreferenceSetting.java
r30563 r30723 46 46 47 47 public OdPreferenceSetting() { 48 48 super(OdConstants.ICON_CORE_48, tr("OpenData Preferences"), 49 49 tr("A special handler for various Open Data portals<br/><br/>"+ 50 50 "Please read the Terms and Conditions of Use of each portal<br/>"+ … … 66 66 * @param sites the site URLs 67 67 */ 68 69 68 public static void setModuleSites(List<String> sites) { 69 Main.pref.putCollection(OdConstants.PREF_MODULES_SITES, sites); 70 70 } 71 71 … … 81 81 } 82 82 83 83 protected JPanel createGeneralSettings() { 84 84 JPanel general = new JPanel(new GridBagLayout()); 85 85 general.setBorder(BorderFactory.createEmptyBorder(0,0,0,0)); … … 104 104 String currentCoordinates = Main.pref.get(PREF_COORDINATES, VALUE_CC9ZONES); 105 105 if (currentCoordinates.equals(VALUE_WGS84)) 106 106 rbWGS84.setSelected(true); 107 107 else 108 108 rbCC43.setSelected(true); 109 109 p.add(rbCC43, GBC.std().insets(5, 0, 5, 0)); 110 110 p.add(rbWGS84, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5));*/ … … 132 132 @Override 133 133 public boolean ok() { 134 135 136 137 138 134 boolean result = modulePref.ok(); 135 //Main.pref.put(PREF_COORDINATES, rbWGS84.isSelected() ? VALUE_WGS84 : VALUE_CC9ZONES); 136 Main.pref.put(OdConstants.PREF_OAPI, oapi.getText()); 137 Main.pref.put(OdConstants.PREF_XAPI, xapi.getText()); 138 Main.pref.put(OdConstants.PREF_RAWDATA, rawData.isSelected()); 139 139 140 140 // create a task for downloading modules if the user has activated, yet not downloaded, … … 146 146 task = new ModuleDownloadTask(masterPanel, toDownload, tr("Download modules")); 147 147 } else { 148 148 task = null; 149 149 } 150 150 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/ProjectionChooser.java
r30583 r30723 65 65 private static final GBC projSubPrefPanelGBC = GBC.std().fill(GBC.BOTH).weight(1.0, 1.0); 66 66 67 68 69 70 71 72 73 74 75 76 77 67 public ProjectionChooser(Component parent) { 68 this(parent, tr("Projection method"), new String[] {tr("OK"), tr("Cancel")}); 69 } 70 71 protected ProjectionChooser(Component parent, String title, String[] buttonTexts) { 72 super(parent, title, buttonTexts); 73 setMinimumSize(new Dimension(600, 200)); 74 addGui(); 75 } 76 77 public void addGui() { 78 78 projPanel.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 79 79 projPanel.setLayout(new GridBagLayout()); … … 101 101 }); 102 102 setContent(projPanel); 103 104 105 103 } 104 105 private void selectedProjectionChanged(final ProjectionChoice pc) { 106 106 // Don't try to update if we're still starting up 107 107 int size = projPanel.getComponentCount(); … … 124 124 updateMeta(pc); 125 125 } 126 126 127 127 private void updateMeta(ProjectionChoice pc) { 128 128 pc.setPreferences(pc.getPreferences(projSubPrefPanel)); … … 148 148 149 149 public Projection getProjection() { 150 151 152 153 154 155 156 157 150 ProjectionChoice pc = (ProjectionChoice) projectionCombo.getSelectedItem(); 151 if (pc != null) { 152 Main.info("Chosen projection: "+pc+" ("+pc.getProjection()+")"); 153 return pc.getProjection(); 154 } else { 155 return null; 156 } 157 } 158 158 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/ViewLicenseDialog.java
r30340 r30723 21 21 public class ViewLicenseDialog extends ExtendedDialog { 22 22 23 24 25 26 27 28 29 23 private final License license; 24 private final JEditorPane htmlPane; 25 private boolean summary; 26 27 public ViewLicenseDialog(License license) throws IOException { 28 this(license, Main.parent, tr("License"), new String[] {tr("OK"), "", tr("Cancel")}); 29 } 30 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 31 public ViewLicenseDialog(License license, Component parent, String title, String[] buttonTexts) throws IOException { 32 super(parent, title, buttonTexts); 33 34 this.license = license; 35 this.htmlPane = new JEditorPane(); 36 htmlPane.setEditable(false); 37 if (license.getSummaryURL() != null) { 38 htmlPane.setPage(license.getSummaryURL()); 39 summary = true; 40 } else { 41 htmlPane.setPage(license.getURL()); 42 summary = false; 43 } 44 JScrollPane scrollPane = new JScrollPane(htmlPane); 45 scrollPane.setPreferredSize(new Dimension(800, 600)); 46 46 47 47 setButtonIcons(new Icon[] { … … 55 55 null}); 56 56 if (license.getIcon() != null) { 57 57 setIcon(license.getIcon()); 58 58 } else { 59 59 setIcon(JOptionPane.INFORMATION_MESSAGE); 60 60 } 61 61 setCancelButton(3); 62 62 setMinimumSize(new Dimension(300, 200)); 63 63 setContent(scrollPane, false); 64 64 } 65 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 66 @Override 67 protected void buttonAction(int buttonIndex, ActionEvent evt) { 68 if (buttonIndex == 1) { 69 try { 70 if (summary) { 71 buttons.get(1).setText(tr("View summary")); 72 htmlPane.setPage(license.getURL()); 73 } else { 74 buttons.get(1).setText(tr("View full text")); 75 htmlPane.setPage(license.getSummaryURL()); 76 } 77 } catch (IOException e) { 78 e.printStackTrace(); 79 } 80 summary = !summary; 81 } else { 82 super.buttonAction(buttonIndex, evt); 83 } 84 } 85 85 86 87 88 89 90 91 92 93 94 95 86 @Override 87 public void setupDialog() { 88 super.setupDialog(); 89 buttons.get(1).setEnabled(license.getSummaryURL() != null && license.getURL() != null); 90 if (summary) { 91 buttons.get(1).setText(tr("View full text")); 92 } else { 93 buttons.get(1).setText(tr("View summary")); 94 } 95 } 96 96 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/AbstractImporter.java
r30573 r30723 24 24 25 25 public abstract class AbstractImporter extends OsmImporter { 26 27 28 29 30 26 27 protected AbstractDataSetHandler handler; 28 29 protected File file; 30 31 31 public AbstractImporter(ExtensionFileFilter filter) { 32 32 super(filter); … … 34 34 35 35 protected final AbstractDataSetHandler findDataSetHandler(File file) { 36 37 38 39 40 41 42 43 36 for (Module module : ModuleHandler.moduleList) { 37 for (AbstractDataSetHandler dsh : module.getNewlyInstanciatedHandlers()) { 38 if (dsh.acceptsFile(file)) { 39 return dsh; 40 } 41 } 42 } 43 return null; 44 44 } 45 45 46 47 48 49 50 51 52 53 46 @Override 47 public void importData(File file, ProgressMonitor progressMonitor) 48 throws IOException, IllegalDataException { 49 if (file != null) { 50 this.file = file; 51 this.handler = findDataSetHandler(file); 52 } 53 // Do not call super.importData because Compression.getUncompressedFileInputStream skips the first entry 54 54 try (InputStream in = new FileInputStream(file)) { 55 55 importData(in, file, progressMonitor); … … 58 58 throw new IOException(tr("File ''{0}'' does not exist.", file.getName()), e); 59 59 } 60 60 } 61 61 62 63 64 65 66 62 @Override 63 protected OsmDataLayer createLayer(DataSet dataSet, File associatedFile, String layerName) { 64 DataSetUpdater.updateDataSet(dataSet, handler, associatedFile); 65 return new OdDataLayer(dataSet, layerName, associatedFile, handler); 66 } 67 67 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/LambertCC9ZonesProjectionPatterns.java
r30340 r30723 10 10 11 11 public class LambertCC9ZonesProjectionPatterns extends ProjectionPatterns { 12 13 14 15 16 17 18 12 13 public static final Projection[] lambertCC9Zones = new Projection[9]; 14 static { 15 for (int i=0; i<lambertCC9Zones.length; i++) { 16 lambertCC9Zones[i] = Projections.getProjectionByCode("EPSG:"+Integer.toString(3942+i)); 17 } 18 } 19 19 20 21 22 20 public LambertCC9ZonesProjectionPatterns(String proj) { 21 super(proj); 22 } 23 23 24 25 24 @Override 25 public Projection getProjection(String xFieldName, String yFieldName) { 26 26 27 28 29 30 31 32 33 34 35 36 37 27 Matcher mx = getXPattern().matcher(xFieldName); 28 Matcher my = getYPattern().matcher(yFieldName); 29 mx.find(); 30 my.find(); 31 String ccx = mx.group(1); 32 String ccy = mx.group(1); 33 if (!ccx.equals(ccy)) { 34 throw new IllegalArgumentException(tr("''Lambert CC 9 zones'' coordinates found with different zone codes for X and Y: "+xFieldName+", "+yFieldName)); 35 } 36 return lambertCC9Zones[Integer.parseInt(ccx)-42]; 37 } 38 38 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NeptuneReader.java
r30568 r30723 58 58 public class NeptuneReader extends AbstractReader implements FrenchConstants { 59 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 60 public static final String OSM_PUBLIC_TRANSPORT = "public_transport"; 61 public static final String OSM_STOP = "stop"; 62 public static final String OSM_STOP_AREA = "stop_area"; 63 public static final String OSM_STOP_POSITION = "stop_position"; 64 public static final String OSM_PLATFORM = "platform"; 65 public static final String OSM_STATION = "station"; 66 public static final String OSM_NETWORK = "network"; 67 public static final String OSM_ROUTE = "route"; 68 public static final String OSM_ROUTE_MASTER = "route_master"; 69 70 public static final String OSM_TRAIN = "train"; 71 public static final String OSM_SUBWAY = "subway"; 72 public static final String OSM_MONORAIL = "monorail"; 73 public static final String OSM_TRAM = "tram"; 74 public static final String OSM_BUS = "bus"; 75 public static final String OSM_TROLLEYBUS = "trolleybus"; 76 public static final String OSM_AERIALWAY = "aerialway"; 77 public static final String OSM_FERRY = "ferry"; 78 79 private static final List<URL> schemas = new ArrayList<>(); 80 static { 81 schemas.add(NeptuneReader.class.getResource(NEPTUNE_XSD)); 82 } 83 84 private ChouettePTNetworkType root; 85 86 private final Map<String, OsmPrimitive> tridentObjects = new HashMap<>(); 87 88 public static final boolean acceptsXmlNeptuneFile(File file) { 89 return acceptsXmlNeptuneFile(file, null); 90 } 91 92 public static final boolean acceptsXmlNeptuneFile(File file, URL schemaURL) { 93 94 if (schemaURL == null) { 95 schemaURL = schemas.get(0); 96 } 97 98 try { 99 FileInputStream in = new FileInputStream(file); 100 Source xmlFile = new StreamSource(in); 101 try { 102 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 103 Schema schema = schemaFactory.newSchema(schemaURL); 104 Validator validator = schema.newValidator(); 105 validator.validate(xmlFile); 106 Main.info(xmlFile.getSystemId() + " is valid"); 107 return true; 108 } catch (SAXException e) { 109 Main.error(xmlFile.getSystemId() + " is NOT valid"); 110 Main.error("Reason: " + e.getLocalizedMessage()); 111 } catch (IOException e) { 112 Main.error(xmlFile.getSystemId() + " is NOT valid"); 113 Main.error("Reason: " + e.getLocalizedMessage()); 114 } finally { 115 try { 116 in.close(); 117 } catch (IOException e) { 118 // Ignore exception 119 } 120 } 121 } catch (FileNotFoundException e) { 122 Main.error(e.getMessage()); 123 } 124 125 return false; 126 } 127 128 public static DataSet parseDataSet(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance) throws JAXBException { 129 return new NeptuneReader().parse(in, instance); 130 } 131 132 protected static final <T> T unmarshal(Class<T> docClass, InputStream inputStream) throws JAXBException { 133 String packageName = docClass.getPackage().getName(); 134 JAXBContext jc = JAXBContext.newInstance(packageName, NeptuneReader.class.getClassLoader()); 135 Unmarshaller u = jc.createUnmarshaller(); 136 @SuppressWarnings("unchecked") 137 137 JAXBElement<T> doc = (JAXBElement<T>)u.unmarshal(inputStream); 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 138 return doc.getValue(); 139 } 140 141 private final void linkTridentObjectToOsmPrimitive(TridentObjectType object, OsmPrimitive p) { 142 p.put("ref:neptune", object.getObjectId()); 143 if (tridentObjects.put(object.getObjectId(), p) != null) { 144 System.err.println("Trident object duplicated !!! : "+object.getObjectId()); 145 } 146 } 147 148 protected Node createNode(LatLon latlon){ 149 Node n = new Node(latlon); 150 ds.addPrimitive(n); 151 return n; 152 } 153 154 private Node createPlatform(StopPointType stop) { 155 Node n = createNode(createLatLon(stop)); 156 n.put(OSM_PUBLIC_TRANSPORT, OSM_PLATFORM); 157 linkTridentObjectToOsmPrimitive(stop, n); 158 n.put("name", stop.getName()); 159 return n; 160 } 161 /* 162 private Node createStopPosition(StopPointType stop) { 163 Node n = createNode(createLatLon(stop)); 164 n.put(OSM_PUBLIC_TRANSPORT, OSM_STOP_POSITION); 165 linkTridentObjectToOsmPrimitive(stop, n); 166 n.put("name", stop.getName()); 167 return n; 168 } 169 169 */ 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 170 protected Relation createRelation(String type){ 171 Relation r = new Relation(); 172 r.put("type", type); 173 ds.addPrimitive(r); 174 return r; 175 } 176 177 protected Relation createPtRelation(String pt, TridentObjectType object){ 178 Relation r = createRelation(OSM_PUBLIC_TRANSPORT); 179 r.put(OSM_PUBLIC_TRANSPORT, pt); 180 linkTridentObjectToOsmPrimitive(object, r); 181 return r; 182 } 183 184 protected Relation createNetwork(PTNetworkType network) { 185 Relation r = createRelation(OSM_NETWORK); 186 linkTridentObjectToOsmPrimitive(network, r); 187 r.put("name", network.getName()); 188 return r; 189 } 190 191 protected Relation createRouteMaster(LineType line) { 192 Relation r = createPtRelation(OSM_ROUTE_MASTER, line); 193 switch (line.getTransportModeName()) { 194 case BUS: 195 r.put(OSM_ROUTE_MASTER, OSM_BUS); break; 196 case AIR: 197 r.put(OSM_ROUTE_MASTER, OSM_AERIALWAY); break; 198 case FERRY: 199 r.put(OSM_ROUTE_MASTER, OSM_FERRY); break; 200 case METRO: 201 r.put(OSM_ROUTE_MASTER, OSM_SUBWAY); break; 202 case TRAIN: 203 r.put(OSM_ROUTE_MASTER, OSM_TRAIN); break; 204 case TRAMWAY: 205 r.put(OSM_ROUTE_MASTER, OSM_TRAM); break; 206 case TROLLEYBUS: 207 r.put(OSM_ROUTE_MASTER, OSM_TROLLEYBUS); break; 208 default: 209 System.err.println("Unsupported transport mode: "+line.getTransportModeName()); 210 } 211 r.put("ref", line.getNumber()); 212 r.put("name", line.getTransportModeName().value()+" "+line.getNumber()+": "+line.getName()); 213 return r; 214 } 215 216 private Relation createRoute(ChouetteRoute route) { 217 Relation r = createPtRelation(OSM_ROUTE, route); 218 r.put("name", route.getName()); 219 return r; 220 } 221 222 protected Relation createStopArea(StopAreaType sa) { 223 Relation r = createPtRelation(OSM_STOP_AREA, sa); 224 r.put("name", sa.getName()); 225 return r; 226 } 227 228 protected LatLon createLatLon(PointType point) { 229 return new LatLon(point.getLatitude().doubleValue(), point.getLongitude().doubleValue()); 230 } 231 232 protected final <T extends TridentObjectType> T findTridentObject(List<T> list, String id) { 233 for (T object : list) { 234 if (object.getObjectId().equals(id)) { 235 return object; 236 } 237 } 238 return null; 239 } 240 241 protected StopPoint findStopPoint(String id) { 242 return findTridentObject(root.getChouetteLineDescription().getStopPoint(), id); 243 } 244 245 protected StopArea findStopArea(String id) { 246 return findTridentObject(root.getChouetteArea().getStopArea(), id); 247 } 248 249 protected AreaCentroid findAreaCentroid(String id) { 250 return findTridentObject(root.getChouetteArea().getAreaCentroid(), id); 251 } 252 253 protected PTLinkType findPtLink(String id) { 254 return findTridentObject(root.getChouetteLineDescription().getPtLink(), id); 255 } 256 257 protected static final boolean isNullLatLon(LatLon ll) { 258 return ll.lat() == 0.0 && ll.lon() == 0.0; 259 } 260 261 private DataSet parse(InputStream in, ProgressMonitor instance) throws JAXBException { 262 root = unmarshal(ChouettePTNetworkType.class, in); 263 264 Relation network = createNetwork(root.getPTNetwork()); 265 266 // Parsing Stop areas 267 for (StopArea sa : root.getChouetteArea().getStopArea()) { 268 if (sa.getStopAreaExtension().getAreaType().equals(ChouetteAreaType.COMMERCIAL_STOP_POINT)) { 269 Relation stopArea = createStopArea(sa); 270 stopArea.put("name", sa.getName()); 271 for (String childId : sa.getContains()) { 272 if (childId.contains("StopArea")) { 273 StopArea child = findStopArea(childId); 274 if (child == null) { 275 System.err.println("Cannot find StopArea: "+childId); 276 } else { 277 if (child.getStopAreaExtension().getAreaType().equals(ChouetteAreaType.BOARDING_POSITION)) { 278 for (String grandchildId : child.getContains()) { 279 if (grandchildId.contains("StopPoint")) { 280 StopPoint grandchild = findStopPoint(grandchildId); 281 if (grandchild == null) { 282 System.err.println("Cannot find StopPoint: "+grandchildId); 283 } else { 284 if (grandchild.getLongLatType().equals(LongLatTypeType.WGS_84)) { 285 Node platform = createPlatform(grandchild); 286 stopArea.addMember(new RelationMember(OSM_PLATFORM, platform)); 287 } else { 288 System.err.println("Unsupported long/lat type: "+grandchild.getLongLatType()); 289 } 290 } 291 } else { 292 System.err.println("Unsupported grandchild: "+grandchildId); 293 } 294 } 295 String centroidId = child.getCentroidOfArea(); 296 AreaCentroid areaCentroid = findAreaCentroid(centroidId); 297 if (areaCentroid == null) { 298 System.err.println("Cannot find AreaCentroid: "+centroidId); 299 } else if (!areaCentroid.getLongLatType().equals(LongLatTypeType.WGS_84)) { 300 System.err.println("Unsupported long/lat type: "+areaCentroid.getLongLatType()); 301 } else { 302 for (RelationMember member : stopArea.getMembers()) { 303 // Fix stop coordinates if needed 304 if (member.getRole().equals(OSM_PLATFORM) && isNullLatLon(member.getNode().getCoor())) { 305 member.getNode().setCoor(createLatLon(areaCentroid)); 306 } 307 } 308 } 309 } else { 310 System.err.println("Unsupported child type: "+child.getStopAreaExtension().getAreaType()); 311 } 312 } 313 314 } else if (childId.contains("StopPoint")) { 315 StopPoint child = findStopPoint(childId); 316 if (child == null) { 317 System.err.println("Cannot find StopPoint: "+childId); 318 } else { 319 // TODO 320 Main.info("TODO: handle StopPoint "+childId); 321 } 322 323 } else { 324 Main.warn("Unsupported child: "+childId); 325 } 326 } 327 } else if (sa.getStopAreaExtension().getAreaType().equals(ChouetteAreaType.BOARDING_POSITION)) { 328 //Main.info("skipping StopArea with type "+sa.getStopAreaExtension().getAreaType()+": "+sa.getObjectId()); 329 } else { 330 Main.warn("Unsupported StopArea type: "+sa.getStopAreaExtension().getAreaType()); 331 } 332 } 333 334 Relation routeMaster = createRouteMaster(root.getChouetteLineDescription().getLine()); 335 network.addMember(new RelationMember(null, routeMaster)); 336 337 for (ChouetteRoute cr : root.getChouetteLineDescription().getChouetteRoute()) { 338 Relation route = createRoute(cr); 339 routeMaster.addMember(new RelationMember(null, route)); 340 for (String id : cr.getPtLinkId()) { 341 PTLinkType ptlink = findPtLink(id); 342 if (ptlink == null) { 343 System.err.println("Cannot find PTLinkType: "+id); 344 } else { 345 /*StopPoint start = findStopPoint(ptlink.getStartOfLink()); 346 StopPoint end = findStopPoint(ptlink.getEndOfLink());*/ 347 OsmPrimitive start = tridentObjects.get(ptlink.getStartOfLink()); 348 OsmPrimitive end = tridentObjects.get(ptlink.getEndOfLink()); 349 if (start == null) { 350 System.err.println("Cannot find start StopPoint: "+ptlink.getStartOfLink()); 351 } else if (start.get(OSM_PUBLIC_TRANSPORT).equals(OSM_STOP) || start.get(OSM_PUBLIC_TRANSPORT).equals(OSM_PLATFORM)) { 352 addStopToRoute(route, start); 353 } 354 355 if (end == null) { 356 System.err.println("Cannot find end StopPoint: "+ptlink.getEndOfLink()); 357 } else if (end.get(OSM_PUBLIC_TRANSPORT).equals(OSM_STOP) || end.get(OSM_PUBLIC_TRANSPORT).equals(OSM_PLATFORM)) { 358 addStopToRoute(route, end); 359 } 360 } 361 } 362 } 363 364 return ds; 365 } 366 367 private static final boolean addStopToRoute(Relation route, OsmPrimitive stop) { 368 if (route.getMembersCount() == 0 || !route.getMember(route.getMembersCount()-1).getMember().equals(stop) ) { 369 route.addMember(new RelationMember(stop.get(OSM_PUBLIC_TRANSPORT), stop)); 370 return true; 371 } else { 372 return false; 373 } 374 } 375 376 public static List<URL> getSchemas() { 377 return schemas; 378 } 379 380 public static void registerSchema(URL resource) { 381 if (resource != null && !schemas.contains(resource)) { 382 schemas.add(resource); 383 } 384 } 385 385 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NetworkReader.java
r30563 r30723 34 34 public class NetworkReader extends OsmServerReader { 35 35 36 37 38 39 36 private final String url; 37 private final AbstractDataSetHandler handler; 38 private Class<? extends AbstractReader> readerClass; 39 private final boolean promptUser; 40 40 41 42 41 private File file; 42 private String filename; 43 43 44 44 /** … … 66 66 public NetworkReader(String url, AbstractDataSetHandler handler, boolean promptUser) { 67 67 CheckParameterUtil.ensureParameterNotNull(url, "url"); 68 68 this.url = url; 69 69 this.handler = handler; 70 70 this.readerClass = null; … … 72 72 } 73 73 74 75 76 74 public final File getReadFile() { 75 return file; 76 } 77 77 78 79 80 78 public final String getReadFileName() { 79 return filename; 80 } 81 81 82 83 84 85 86 87 88 89 90 91 92 82 private Class<? extends AbstractReader> findReaderByAttachment() { 83 String cdisp = this.activeConnection.getHeaderField("Content-disposition"); 84 if (cdisp != null) { 85 Matcher m = Pattern.compile("attachment;.?filename=(.*)").matcher(cdisp); 86 if (m.matches()) { 87 filename = m.group(1); 88 return findReaderByExtension(filename); 89 } 90 } 91 return null; 92 } 93 93 94 95 96 97 94 private Class<? extends AbstractReader> findReaderByContentType() { 95 String contentType = this.activeConnection.getContentType(); 96 if (contentType.startsWith("application/zip")) { 97 return ZipReader.class; 98 98 } else if (contentType.startsWith("application/x-7z-compressed")) { 99 99 return SevenZipReader.class; 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 100 } else if (contentType.startsWith("application/vnd.ms-excel")) { 101 return XlsReader.class; 102 } else if (contentType.startsWith("application/octet-stream")) { 103 //return OdsReader.class;//FIXME, can be anything 104 } else if (contentType.startsWith("text/csv")) { 105 return CsvReader.class; 106 } else if (contentType.startsWith("text/plain")) {//TODO: extract charset 107 return CsvReader.class; 108 } else if (contentType.startsWith("tdyn/html")) { 109 //return CsvReader.class;//FIXME, can also be .tar.gz 110 } else { 111 System.err.println("Unsupported content type: "+contentType); 112 } 113 return null; 114 } 115 115 116 117 118 119 120 121 122 123 124 116 private Class<? extends AbstractReader> findReaderByExtension(String filename) { 117 filename = filename.replace("\"", "").toLowerCase(); 118 for (String ext : FILE_AND_ARCHIVE_READERS.keySet()) { 119 if (filename.endsWith("."+ext)) { 120 return FILE_AND_ARCHIVE_READERS.get(ext); 121 } 122 } 123 return null; 124 } 125 125 126 127 126 @Override 127 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 128 128 InputStream in = null; 129 129 ProgressMonitor instance = null; 130 130 try { 131 131 in = getInputStreamRaw(url, progressMonitor); 132 132 if (in == null) 133 133 return null; 134 134 progressMonitor.subTask(tr("Downloading data...")); 135 135 if (readerClass == null) { 136 136 readerClass = findReaderByAttachment(); 137 137 } 138 138 if (readerClass == null) { … … 140 140 } 141 141 if (readerClass == null) { 142 142 readerClass = findReaderByContentType(); 143 143 } 144 144 if (readerClass == null) { 145 145 throw new OsmTransferException("Cannot find appropriate reader !");//TODO handler job ? 146 146 } else if (findReaderByExtension(url) != null) { 147 147 filename = url.substring(url.lastIndexOf('/')+1); 148 148 } 149 149 instance = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 150 150 if (readerClass.equals(ZipReader.class) || readerClass.equals(SevenZipReader.class)) { 151 152 153 154 155 151 ArchiveReader zipReader = readerClass.equals(ZipReader.class) 152 ? new ZipReader(in, handler, promptUser) : new SevenZipReader(in, handler, promptUser); 153 DataSet ds = zipReader.parseDoc(instance); 154 file = zipReader.getReadFile(); 155 return ds; 156 156 } else if (readerClass.equals(KmlReader.class)) { 157 157 return KmlReader.parseDataSet(in, instance); 158 158 } else if (readerClass.equals(KmzReader.class)) { 159 159 return KmzReader.parseDataSet(in, instance); 160 160 } else if (readerClass.equals(MifReader.class)) { 161 161 return MifReader.parseDataSet(in, null, handler, instance); 162 162 } else if (readerClass.equals(ShpReader.class)) { 163 163 return ShpReader.parseDataSet(in, null, handler, instance); 164 164 } else if (readerClass.equals(TabReader.class)) { 165 165 return TabReader.parseDataSet(in, null, handler, instance); 166 166 } else if (readerClass.equals(CsvReader.class)) { 167 167 return CsvReader.parseDataSet(in, handler, instance); 168 168 } else if (readerClass.equals(OdsReader.class)) { 169 169 return OdsReader.parseDataSet(in, handler, instance); 170 170 } else if (readerClass.equals(XlsReader.class)) { 171 171 return XlsReader.parseDataSet(in, handler, instance); 172 172 } else if (readerClass.equals(GmlReader.class)) { 173 173 return GmlReader.parseDataSet(in, handler, instance); 174 174 } else { 175 175 throw new IllegalArgumentException("Unsupported reader class: "+readerClass.getName()); 176 176 } 177 177 } catch (OsmTransferException e) { … … 190 190 } catch (Exception e) {/* ignore it */} 191 191 } 192 192 } 193 193 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/OsmDownloader.java
r30568 r30723 10 10 11 11 public class OsmDownloader { 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 12 13 public static final void downloadOapi(String oapiReq) { 14 if (oapiReq != null) { 15 try { 16 String oapiServer = Main.pref.get(OdConstants.PREF_OAPI, OdConstants.DEFAULT_OAPI); 17 Main.info(oapiReq); 18 String oapiReqEnc = URLEncoder.encode(oapiReq, OdConstants.UTF8); 19 Main.main.menu.openLocation.openUrl(false, oapiServer+"data="+oapiReqEnc); 20 } catch (UnsupportedEncodingException e) { 21 e.printStackTrace(); 22 } 23 } 24 } 25 26 public static final void downloadXapi(Collection<String> xapiReqs) { 27 if (xapiReqs != null) { 28 String xapiServer = Main.pref.get(OdConstants.PREF_XAPI, OdConstants.DEFAULT_XAPI); 29 for (String xapiReq : xapiReqs) { 30 Main.main.menu.openLocation.openUrl(false, xapiServer+xapiReq); 31 } 32 } 33 } 34 34 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/OverpassApi.java
r30340 r30723 4 4 public abstract class OverpassApi { 5 5 6 7 8 9 10 11 12 13 14 6 public enum OaQueryType { 7 NODE ("node"), 8 WAY ("way"), 9 RELATION ("relation"); 10 @Override 11 public String toString() { return this.value; } 12 private OaQueryType(final String value) { this.value = value; } 13 private final String value; 14 } 15 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 16 public enum OaRecurseType { 17 RELATION_RELATION ("relation-relation"), 18 RELATION_BACKWARDS ("relation-backwards"), 19 RELATION_WAY ("relation-way"), 20 RELATION_NODE ("relation-node"), 21 WAY_NODE ("way-node"), 22 WAY_RELATION ("way-relation"), 23 NODE_RELATION ("node-relation"), 24 NODE_WAY ("node-way"); 25 @Override 26 public String toString() { return this.value; } 27 private OaRecurseType(final String value) { this.value = value; } 28 private final String value; 29 } 30 31 public static final String union(String ... queries) { 32 String result = "<union>\n"; 33 for (String query : queries) { 34 if (query != null) { 35 result += query + "\n"; 36 } 37 } 38 result += "</union>"; 39 return result; 40 } 41 42 public static final String query(String bbox, OaQueryType type, String ... conditions) { 43 String result = "<query type=\""+type+"\" >\n"; 44 if (bbox != null) { 45 result += "<bbox-query "+bbox+"/>\n"; 46 } 47 for (String condition : conditions) { 48 if (condition != null) { 49 result += condition + "\n"; 50 } 51 } 52 result += "</query>"; 53 return result; 54 } 55 55 56 57 58 56 public static final String recurse(OaRecurseType type, String into) { 57 return "<recurse type=\""+type+"\" into=\""+into+"\"/>\n"; 58 } 59 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 60 public static final String recurse(OaRecurseType ... types) { 61 String result = ""; 62 for (OaRecurseType type : types) { 63 result += "<recurse type=\""+type+"\"/>\n"; 64 } 65 return result; 66 } 67 68 public static final String print() { 69 return "<print mode=\"meta\"/>"; 70 } 71 72 public static final String hasKey(String key) { 73 return hasKey(key, null); 74 } 75 75 76 77 78 76 public static final String hasKey(String key, String value) { 77 return "<has-kv k=\""+key+"\" "+(value != null && !value.isEmpty() ? "v=\""+value+"\"" : "")+" />"; 78 } 79 79 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/ProjectionPatterns.java
r30563 r30723 9 9 public class ProjectionPatterns { 10 10 11 12 13 14 15 16 17 18 19 20 11 private final Pattern xPattern; 12 private final Pattern yPattern; 13 private final Projection projection; 14 15 public ProjectionPatterns(Pattern xPattern, Pattern yPattern, Projection projection) { 16 this.xPattern = xPattern; 17 this.yPattern = yPattern; 18 this.projection = projection; 19 OdConstants.PROJECTIONS.add(this); 20 } 21 21 22 23 24 22 public ProjectionPatterns(Pattern xPattern, Pattern yPattern) { 23 this(xPattern, yPattern, null); 24 } 25 25 26 27 28 26 public ProjectionPatterns(String proj, Projection projection) { 27 this(getCoordinatePattern(OdConstants.X_STRING, proj), getCoordinatePattern(OdConstants.Y_STRING, proj), projection); 28 } 29 29 30 31 32 33 34 35 36 37 38 39 40 30 public ProjectionPatterns(String proj) { 31 this(getCoordinatePattern(OdConstants.X_STRING, proj), getCoordinatePattern(OdConstants.Y_STRING, proj), null); 32 } 33 34 public final Pattern getXPattern() { 35 return xPattern; 36 } 37 38 public final Pattern getYPattern() { 39 return yPattern; 40 } 41 41 42 43 44 42 public Projection getProjection(String xFieldName, String yFieldName) { 43 return getProjection(); 44 } 45 45 46 47 48 46 public final Projection getProjection() { 47 return projection; 48 } 49 49 50 51 52 53 54 55 50 public static final Pattern getCoordinatePattern(String coor, String proj) { 51 if (proj != null && !proj.isEmpty()) { 52 return Pattern.compile("(?:.*(?:"+coor+").*(?:"+proj+").*)|(?:.*("+proj+").*(?:"+coor+").*)", Pattern.CASE_INSENSITIVE); 53 } else { 54 return Pattern.compile(coor, Pattern.CASE_INSENSITIVE); 55 } 56 56 } 57 57 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/XmlImporter.java
r30563 r30723 21 21 OdConstants.XML_EXT, OdConstants.XML_EXT, tr("OpenData XML files") + " (*."+OdConstants.XML_EXT+")"); 22 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 23 public XmlImporter() { 24 super(XML_FILE_FILTER); 25 } 26 27 @Override 28 public boolean acceptFile(File pathname) { 29 if (super.acceptFile(pathname)) { 30 for (URL schemaURL : NeptuneReader.getSchemas()) { 31 if (NeptuneReader.acceptsXmlNeptuneFile(pathname, schemaURL)) { 32 return true; 33 } 34 } 35 } 36 return false; 37 } 38 38 39 40 41 42 43 44 45 46 47 39 @Override 40 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) 41 throws IllegalDataException { 42 try { 43 return NeptuneReader.parseDataSet(in, handler, instance); 44 } catch (JAXBException e) { 45 throw new IllegalDataException(e); 46 } 47 } 48 48 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ArchiveHandler.java
r30340 r30723 6 6 public interface ArchiveHandler { 7 7 8 8 public void notifyTempFileWritten(File file); 9 9 10 10 public boolean skipXsdValidation(); 11 11 12 12 public void setSkipXsdValidation(boolean skip); 13 13 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/CandidateChooser.java
r30532 r30723 29 29 private final JComboBox<File> fileCombo; 30 30 31 32 33 34 35 31 public CandidateChooser(Component parent, List<File> candidates) { 32 this(parent, tr("File to load"), new String[] {tr("OK"), tr("Cancel")}, candidates); 33 } 34 35 private class Renderer extends DefaultListCellRenderer { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 37 @Override 38 public Component getListCellRendererComponent(JList<?> list, Object value, 39 int index, boolean isSelected, boolean cellHasFocus) { 40 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 41 if (value instanceof File) { 42 setText(((File)value).getName()); 43 } 44 return this; 45 } 46 } 47 48 protected CandidateChooser(Component parent, String title, String[] buttonTexts, List<File> candidates) { 49 super(parent, title, buttonTexts); 50 this.fileCombo = new JComboBox<>(candidates.toArray(new File[0])); 51 this.fileCombo.setRenderer(new Renderer()); 52 addGui(candidates); 53 } 54 55 public void addGui(List<File> candidates) { 56 56 projPanel.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 57 57 projPanel.setLayout(new GridBagLayout()); … … 59 59 projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 60 60 /*for (File file : candidates) { 61 62 63 61 JCheckBox cbox = new JCheckBox(file.getName()); 62 checkBoxes.put(cbox, file); 63 projPanel.add(cbox, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 64 64 }*/ 65 65 projPanel.add(fileCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 66 66 setContent(projPanel); 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 67 } 68 69 /*public List<File> getSelectedFiles() { 70 List<File> result = new ArrayList<File>(); 71 for (JCheckBox cbox : checkBoxes.keySet()) { 72 if (cbox.isSelected()) { 73 result.add(checkBoxes.get(cbox)); 74 } 75 } 76 return result; 77 }*/ 78 79 public File getSelectedFile() { 80 return (File) fileCombo.getSelectedItem(); 81 } 82 82 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/DefaultArchiveHandler.java
r30340 r30723 6 6 public class DefaultArchiveHandler implements ArchiveHandler { 7 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 8 private boolean skipXsdValidation = false; 9 10 @Override 11 public final void setSkipXsdValidation(boolean skip) { 12 skipXsdValidation = skip; 13 } 14 15 @Override 16 public boolean skipXsdValidation() { 17 return skipXsdValidation; 18 } 19 20 @Override 21 public void notifyTempFileWritten(File file) { 22 // Do nothing, let subclass override this method if they need it 23 } 24 24 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/SevenZipImporter.java
r30563 r30723 18 18 OdConstants.SEVENZIP_EXT, OdConstants.SEVENZIP_EXT, tr("7Zip Files") + " (*."+OdConstants.SEVENZIP_EXT+")"); 19 19 20 21 22 20 public SevenZipImporter() { 21 super(SEVENZIP_FILE_FILTER); 22 } 23 23 24 25 26 27 28 29 30 31 32 24 @Override 25 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) 26 throws IllegalDataException { 27 try { 28 return SevenZipReader.parseDataSet(in, handler, instance, true); 29 } catch (Exception e) { 30 throw new IllegalDataException(e); 31 } 32 } 33 33 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ZipImporter.java
r30563 r30723 19 19 OdConstants.ZIP_EXT, OdConstants.ZIP_EXT, tr("Zip Files") + " (*."+OdConstants.ZIP_EXT+")"); 20 20 21 22 23 21 public ZipImporter() { 22 super(ZIP_FILE_FILTER); 23 } 24 24 25 26 27 28 29 30 31 32 33 25 @Override 26 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) 27 throws IllegalDataException { 28 try { 29 return ZipReader.parseDataSet(in, handler, instance, true); 30 } catch (Exception e) { 31 throw new IllegalDataException(e); 32 } 33 } 34 34 35 35 @Override -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ZipReader.java
r30573 r30723 25 25 public class ZipReader extends ArchiveReader { 26 26 27 28 29 30 27 private final ZipInputStream zis; 28 29 private ZipEntry entry; 30 31 31 public ZipReader(InputStream in, AbstractDataSetHandler handler, boolean promptUser) { 32 32 super(handler, handler != null ? handler.getArchiveHandler() : null, promptUser); … … 34 34 } 35 35 36 37 38 39 36 public static DataSet parseDataSet(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 37 throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 38 return new ZipReader(in, handler, promptUser).parseDoc(instance); 39 } 40 40 41 41 public static Map<File, DataSet> parseDataSets(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/AbstractMapInfoReader.java
r30576 r30723 17 17 public abstract class AbstractMapInfoReader extends AbstractReader { 18 18 19 20 21 22 19 protected static final String VERSION_1 = "1"; 20 protected static final String VERSION_2 = "2"; 21 protected static final String VERSION_300 = "300"; 22 protected static final String VERSION_450 = "450"; 23 23 24 24 protected static final String CHARSET_WINDOWS_LATIN = "WindowsLatin1"; 25 25 protected static final String CHARSET_WINDOWS_CYRILLIC = "WindowsCyrillic"; 26 27 28 29 26 protected static final String CHARSET_NEUTRAL = "Neutral"; 27 protected static final String CHARSET_MAC = "MacRoman"; 28 29 protected BufferedReader headerReader; 30 30 31 32 31 protected String line; 32 protected int lineNum = 0; 33 33 34 34 protected String version; 35 35 36 37 38 36 // Columns 37 protected int numcolumns = -1; 38 protected List<String> columns; 39 39 40 41 42 43 44 45 46 47 48 49 50 51 52 40 protected final File getDataFile(File headerFile, String extension) { 41 String filename = headerFile.getName().substring(0, headerFile.getName().lastIndexOf('.')); 42 File dataFile = new File(headerFile.getParent() + File.separator + filename + extension.toUpperCase()); 43 if (!dataFile.exists()) { 44 dataFile = new File(headerFile.getParent() + File.separator + filename + extension.toLowerCase()); 45 } 46 return dataFile; 47 } 48 49 protected final BufferedReader getDataReader(File headerFile, String extension, Charset charset) throws IOException { 50 File dataFile = getDataFile(headerFile, extension); 51 return dataFile.exists() ? Files.newBufferedReader(dataFile.toPath(), charset) : null; 52 } 53 53 54 55 56 54 protected Charset parseCharset(String[] words) throws IllegalCharsetNameException, UnsupportedCharsetException { 55 return parseCharset(words, 1); 56 } 57 57 58 59 60 61 58 protected Charset parseCharset(String[] words, int index) throws IllegalCharsetNameException, UnsupportedCharsetException { 59 words[index] = words[index].replace("\"", ""); 60 if (words[index].equalsIgnoreCase(CHARSET_WINDOWS_LATIN)) { 61 return Charset.forName(OdConstants.CP1252); 62 62 } else if (words[index].equalsIgnoreCase(CHARSET_WINDOWS_CYRILLIC)) { 63 63 return Charset.forName(OdConstants.CP1251); 64 65 66 67 68 69 70 71 72 64 } else if (words[index].equalsIgnoreCase(CHARSET_NEUTRAL)) { 65 return Charset.forName(OdConstants.ISO8859_15); 66 } else if (words[index].equalsIgnoreCase(CHARSET_MAC)) { 67 return Charset.forName(OdConstants.MAC_ROMAN); 68 } else { 69 System.err.println("Line "+lineNum+". Unknown charset detected: "+line); 70 return Charset.forName(words[index]); 71 } 72 } 73 73 74 75 76 77 78 79 80 81 74 protected void parseVersion(String[] words) { 75 version = words[1]; 76 } 77 78 protected void parseColumns(String[] words) { 79 columns = new ArrayList<>(); 80 numcolumns = Integer.parseInt(words[1]); 81 } 82 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 83 protected final void parseHeader() throws IOException { 84 while ((line = headerReader.readLine()) != null) { 85 lineNum++; 86 while (line.contains(" ")) { 87 line = line.replace(" ", " "); 88 } 89 String [] words = line.isEmpty() ? null : line.trim().split(" "); 90 if (words != null && words.length > 0) { 91 parseHeaderLine(words); 92 } 93 } 94 } 95 96 protected abstract void parseHeaderLine(String[] words) throws IOException; 97 97 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/DefaultGeographicHandler.java
r30340 r30723 9 9 public abstract class DefaultGeographicHandler implements GeographicHandler { 10 10 11 12 13 11 private boolean useNodeMap = true; 12 private boolean checkNodeProximity = false; 13 private boolean preferMultipolygonToSimpleWay = false; 14 14 15 16 17 18 15 @Override 16 public boolean preferMultipolygonToSimpleWay() { 17 return preferMultipolygonToSimpleWay; 18 } 19 19 20 21 22 23 20 @Override 21 public void setPreferMultipolygonToSimpleWay(boolean prefer) { 22 preferMultipolygonToSimpleWay = prefer; 23 } 24 24 25 26 27 28 25 @Override 26 public boolean checkNodeProximity() { 27 return checkNodeProximity; 28 } 29 29 30 31 32 33 30 @Override 31 public void setCheckNodeProximity(boolean check) { 32 checkNodeProximity = check; 33 } 34 34 35 36 37 38 35 @Override 36 public void setUseNodeMap(boolean use) { 37 useNodeMap = use; 38 } 39 39 40 41 42 43 40 @Override 41 public boolean useNodeMap() { 42 return useNodeMap; 43 } 44 44 45 46 47 48 49 50 51 45 @Override 46 public CoordinateReferenceSystem getCrsFor(String crsName) throws NoSuchAuthorityCodeException, FactoryException { 47 if (crsName.equalsIgnoreCase("GCS_ETRS_1989")) { 48 return CRS.decode("EPSG:4258"); 49 } 50 return null; 51 } 52 52 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/DefaultGmlHandler.java
r30340 r30723 9 9 public class DefaultGmlHandler extends DefaultGeographicHandler implements GmlHandler { 10 10 11 12 13 14 15 11 @Override 12 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) 13 throws FactoryException { 14 return CRS.findMathTransform(sourceCRS, targetCRS, lenient); 15 } 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/DefaultShpHandler.java
r30568 r30723 37 37 public class DefaultShpHandler extends DefaultGeographicHandler implements ShpHandler { 38 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 39 private static final List<Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>> 40 ellipsoids = new ArrayList<>(); 41 static { 42 ellipsoids.add(new Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>(DefaultEllipsoid.GRS80, Ellipsoid.GRS80)); 43 ellipsoids.add(new Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>(DefaultEllipsoid.WGS84, Ellipsoid.WGS84)); 44 } 45 46 protected static final Double get(ParameterValueGroup values, ParameterDescriptor<?> desc) { 47 return (Double) values.parameter(desc.getName().getCode()).getValue(); 48 } 49 50 private static final boolean equals(Double a, Double b) { 51 boolean res = Math.abs(a - b) <= Main.pref.getDouble(OdConstants.PREF_CRS_COMPARISON_TOLERANCE, OdConstants.DEFAULT_CRS_COMPARISON_TOLERANCE); 52 if (Main.pref.getBoolean(OdConstants.PREF_CRS_COMPARISON_DEBUG, false)) { 53 Main.debug("Comparing "+a+" and "+b+" -> "+res); 54 } 55 return res; 56 } 57 58 private Charset dbfCharset = null; 59 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 60 @Override 61 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) 62 throws FactoryException { 63 if (getCrsFor(sourceCRS.getName().getCode()) != null) { 64 return CRS.findMathTransform(getCrsFor(sourceCRS.getName().getCode()), targetCRS, lenient); 65 } else if (sourceCRS instanceof AbstractDerivedCRS && sourceCRS.getName().getCode().equalsIgnoreCase("Lambert_Conformal_Conic")) { 66 List<MathTransform> result = new ArrayList<>(); 67 AbstractDerivedCRS crs = (AbstractDerivedCRS) sourceCRS; 68 MathTransform transform = crs.getConversionFromBase().getMathTransform(); 69 if (transform instanceof LambertConformal && crs.getDatum() instanceof GeodeticDatum) { 70 LambertConformal lambert = (LambertConformal) transform; 71 GeodeticDatum geo = (GeodeticDatum) crs.getDatum(); 72 for (ProjectionChoice choice : ProjectionPreference.getProjectionChoices()) { 73 Projection p = choice.getProjection(); 74 if (p instanceof AbstractProjection) { 75 AbstractProjection ap = (AbstractProjection) p; 76 if (ap.getProj() instanceof LambertConformalConic) { 77 for (Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid> pair : ellipsoids) { 78 if (pair.a.equals(geo.getEllipsoid()) && pair.b.equals(ap.getEllipsoid())) { 79 boolean ok = true; 80 ParameterValueGroup values = lambert.getParameterValues(); 81 Parameters params = ((LambertConformalConic) ap.getProj()).getParameters(); 82 83 ok = ok ? equals(get(values, AbstractProvider.LATITUDE_OF_ORIGIN), params.latitudeOrigin) : ok; 84 ok = ok ? equals(get(values, AbstractProvider.CENTRAL_MERIDIAN), ap.getCentralMeridian()) : ok; 85 ok = ok ? equals(get(values, AbstractProvider.SCALE_FACTOR), ap.getScaleFactor()) : ok; 86 ok = ok ? equals(get(values, AbstractProvider.FALSE_EASTING), ap.getFalseEasting()) : ok; 87 ok = ok ? equals(get(values, AbstractProvider.FALSE_NORTHING), ap.getFalseNorthing()) : ok; 88 89 if (lambert instanceof LambertConformal2SP && params instanceof Parameters2SP) { 90 Parameters2SP param = (Parameters2SP) params; 91 ok = ok ? equals(Math.min(get(values, AbstractProvider.STANDARD_PARALLEL_1),get(values, AbstractProvider.STANDARD_PARALLEL_2)), 92 Math.min(param.standardParallel1, param.standardParallel2)) : ok; 93 ok = ok ? equals(Math.max(get(values, AbstractProvider.STANDARD_PARALLEL_1), get(values, AbstractProvider.STANDARD_PARALLEL_2)), 94 Math.max(param.standardParallel1, param.standardParallel2)) : ok; 95 96 } else if (!(lambert instanceof LambertConformal1SP && params instanceof Parameters1SP)) { 97 ok = false; 98 } 99 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 100 if (ok) { 101 try { 102 result.add(CRS.findMathTransform(CRS.decode(p.toCode()), targetCRS, lenient)); 103 } catch (FactoryException e) { 104 System.err.println(e.getMessage()); 105 } 106 } 107 } 108 } 109 } 110 } 111 } 112 } 113 if (!result.isEmpty()) { 114 if (result.size() > 1) { 115 System.err.println("Found multiple projections !"); // TODO: something 116 } 117 return result.get(0); 118 } 119 } 120 return null; 121 } 122 122 123 124 125 126 123 @Override 124 public void notifyFeatureParsed(Object feature, DataSet result, Set<OsmPrimitive> featurePrimitives) { 125 // To be overriden by modules handlers 126 } 127 127 128 129 130 131 132 133 134 135 136 128 @Override 129 public void setDbfCharset(Charset charset) { 130 dbfCharset = charset; 131 } 132 133 @Override 134 public Charset getDbfCharset() { 135 return dbfCharset; 136 } 137 137 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeoCrsException.java
r30340 r30723 4 4 public class GeoCrsException extends Exception { 5 5 6 7 8 6 public GeoCrsException() { 7 super(); 8 } 9 9 10 11 12 10 public GeoCrsException(String message, Throwable cause) { 11 super(message, cause); 12 } 13 13 14 15 16 14 public GeoCrsException(String message) { 15 super(message); 16 } 17 17 18 19 20 18 public GeoCrsException(Throwable cause) { 19 super(cause); 20 } 21 21 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeoMathTransformException.java
r30340 r30723 4 4 public class GeoMathTransformException extends Exception { 5 5 6 7 8 6 public GeoMathTransformException() { 7 super(); 8 } 9 9 10 11 12 10 public GeoMathTransformException(String message, Throwable cause) { 11 super(message, cause); 12 } 13 13 14 15 16 14 public GeoMathTransformException(String message) { 15 super(message); 16 } 17 17 18 19 20 18 public GeoMathTransformException(Throwable cause) { 19 super(cause); 20 } 21 21 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicHandler.java
r30340 r30723 8 8 9 9 public interface GeographicHandler { 10 11 10 11 public void setPreferMultipolygonToSimpleWay(boolean prefer); 12 12 13 13 public boolean preferMultipolygonToSimpleWay(); 14 14 15 16 17 18 19 20 21 22 23 15 public void setCheckNodeProximity(boolean check); 16 17 public boolean checkNodeProximity(); 18 19 public void setUseNodeMap(boolean use); 20 21 public boolean useNodeMap(); 22 23 public CoordinateReferenceSystem getCrsFor(String crsName) throws NoSuchAuthorityCodeException, FactoryException; 24 24 25 25 public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) throws FactoryException; 26 26 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicReader.java
r30568 r30723 54 54 public abstract class GeographicReader extends AbstractReader { 55 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 56 protected static CoordinateReferenceSystem wgs84; 57 static { 58 try { 59 wgs84 = CRS.decode("EPSG:4326"); 60 } catch (NoSuchAuthorityCodeException e) { 61 e.printStackTrace(); 62 } catch (FactoryException e) { 63 e.printStackTrace(); 64 } 65 } 66 67 private final GeographicHandler handler; 68 private final GeographicHandler[] defaultHandlers; 69 70 protected final Map<LatLon, Node> nodes; 71 72 protected CoordinateReferenceSystem crs; 73 protected MathTransform transform; 74 75 public GeographicReader(GeographicHandler handler, GeographicHandler[] defaultHandlers) { 76 this.nodes = new HashMap<>(); 77 this.handler = handler; 78 this.defaultHandlers = defaultHandlers; 79 } 80 81 protected Node getNode(Point p, LatLon key) { 82 Node n = nodes.get(key); 83 if (n == null && handler != null && handler.checkNodeProximity()) { 84 LatLon ll = new LatLon(p.getY(), p.getX()); 85 for (Node node : nodes.values()) { 86 if (node.getCoor().equalsEpsilon(ll)) { 87 return node; 88 } 89 } 90 } 91 return n; 92 } 93 94 protected Node createOrGetNode(Point p) throws MismatchedDimensionException, TransformException { 95 return createOrGetNode(p, null); 96 } 97 98 protected Node createOrGetNode(Point p, String ele) throws MismatchedDimensionException, TransformException { 99 Point p2 = (Point) JTS.transform(p, transform); 100 LatLon key = new LatLon(p2.getY(), p2.getX()); 101 Node n = getNode(p2, key); 102 if (n == null) { 103 n = new Node(key); 104 if (ele != null) { 105 n.put("ele", ele); 106 } 107 if (handler == null || handler.useNodeMap()) { 108 nodes.put(key, n); 109 } 110 ds.addPrimitive(n); 111 } else if (n.getDataSet() == null) { 112 // handler may have removed the node from DataSet (see Paris public light handler for example) 113 ds.addPrimitive(n); 114 } 115 return n; 116 } 117 118 118 protected Node createOrGetEmptyNode(Point p) throws MismatchedDimensionException, TransformException { 119 119 Point p2 = (Point) JTS.transform(p, transform); … … 136 136 } 137 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 138 protected <T extends OsmPrimitive> T addOsmPrimitive(T p) { 139 ds.addPrimitive(p); 140 return p; 141 } 142 143 protected final Way createWay() { 144 return addOsmPrimitive(new Way()); 145 } 146 147 protected final Way createWay(LineString ls) { 148 Way w = createWay(); 149 if (ls != null) { 150 for (int i=0; i<ls.getNumPoints(); i++) { 151 try { 152 w.addNode(createOrGetNode(ls.getPointN(i))); 153 } catch (Exception e) { 154 System.err.println(e.getMessage()); 155 } 156 } 157 } 158 return w; 159 } 160 161 protected final Relation createMultipolygon() { 162 Relation r = new Relation(); 163 r.put("type", "multipolygon"); 164 return addOsmPrimitive(r); 165 } 166 167 protected final void addWayToMp(Relation r, String role, Way w) { 168 r.addMember(new RelationMember(role, w)); 169 } 170 171 171 /** 172 172 * returns true if the user wants to cancel, false if they … … 174 174 */ 175 175 protected static final boolean warnLenientMethod(final Component parent, final CoordinateReferenceSystem crs) { 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 } 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 176 return new DialogPrompter<ExtendedDialog>() { 177 @Override 178 protected ExtendedDialog buildDialog() { 179 final ExtendedDialog dlg = new ExtendedDialog(parent, 180 tr("Cannot transform to WGS84"), 181 new String[] {tr("Cancel"), tr("Continue")}); 182 dlg.setContent("<html>" + 183 tr("JOSM was unable to find a strict mathematical transformation between ''{0}'' and WGS84.<br /><br />"+ 184 "Do you want to try a <i>lenient</i> method, which will perform a non-precise transformation (<b>with location errors up to 1 km</b>) ?<br/><br/>"+ 185 "If so, <b>do NOT upload</b> such data to OSM !", crs.getName())+ 186 "</html>"); 187 dlg.setButtonIcons(new Icon[] { 188 ImageProvider.get("cancel"), 189 ImageProvider.overlay( 190 ImageProvider.get("ok"), 191 new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(10 , 10, Image.SCALE_SMOOTH)), 192 ImageProvider.OverlayPosition.SOUTHEAST)}); 193 dlg.setToolTipTexts(new String[] { 194 tr("Cancel"), 195 tr("Try lenient method")}); 196 dlg.setIcon(JOptionPane.WARNING_MESSAGE); 197 dlg.setCancelButton(1); 198 return dlg; 199 } 200 }.promptInEdt().getValue() != 2; 201 } 202 203 private static final void compareDebug(CoordinateReferenceSystem crs1, CoordinateReferenceSystem crs2) { 204 Main.debug("-- COMPARING "+crs1.getName()+" WITH "+crs2.getName()+" --"); 205 compareDebug("class", crs1.getClass(), crs2.getClass()); 206 CoordinateSystem cs1 = crs1.getCoordinateSystem(); 207 CoordinateSystem cs2 = crs2.getCoordinateSystem(); 208 if (!compareDebug("cs", cs1, cs2)) { 209 Integer dim1 = cs1.getDimension(); 210 Integer dim2 = cs2.getDimension(); 211 if (compareDebug("cs.dim", dim1, dim2)) { 212 for (int i = 0; i<dim1; i++) { 213 compareDebug("cs.axis"+i, cs1.getAxis(i), cs1.getAxis(i)); 214 } 215 } 216 } 217 if (crs1 instanceof AbstractSingleCRS) { 218 Datum datum1 = ((AbstractSingleCRS) crs1).getDatum(); 219 Datum datum2 = ((AbstractSingleCRS) crs2).getDatum(); 220 if (!compareDebug("datum", datum1, datum2)) { 221 AbstractIdentifiedObject adatum1 = (AbstractIdentifiedObject) datum1; 222 AbstractIdentifiedObject adatum2 = (AbstractIdentifiedObject) datum2; 223 compareDebug("datum.name1", adatum1.nameMatches(adatum2.getName().getCode()), adatum1.getName(), adatum2.getName()); 224 compareDebug("datum.name2", adatum2.nameMatches(adatum1.getName().getCode()), adatum2.getName(), adatum1.getName()); 225 } 226 if (crs1 instanceof AbstractDerivedCRS) { 227 AbstractDerivedCRS adcrs1 = (AbstractDerivedCRS) crs1; 228 AbstractDerivedCRS adcrs2 = (AbstractDerivedCRS) crs2; 229 compareDebug("baseCRS", adcrs1.getBaseCRS(), adcrs2.getBaseCRS()); 230 compareDebug("conversionFromBase", adcrs1.getConversionFromBase(), adcrs2.getConversionFromBase()); 231 } 232 } 233 Main.debug("-- COMPARING FINISHED --"); 234 } 235 236 private static final boolean compareDebug(String text, Object o1, Object o2) { 237 return compareDebug(text, o1.equals(o2), o1, o2); 238 } 239 240 private static final boolean compareDebug(String text, IdentifiedObject o1, IdentifiedObject o2) { 241 return compareDebug(text, (AbstractIdentifiedObject)o1, (AbstractIdentifiedObject)o2); 242 } 243 244 private static final boolean compareDebug(String text, AbstractIdentifiedObject o1, AbstractIdentifiedObject o2) { 245 return compareDebug(text, o1.equals(o2, false), o1, o2); 246 } 247 248 private static final boolean compareDebug(String text, boolean result, Object o1, Object o2) { 249 Main.debug(text + ": " + result + "("+o1+", "+o2+")"); 250 return result; 251 } 252 253 protected void findMathTransform(Component parent, boolean findSimiliarCrs) throws FactoryException, UserCancelException, GeoMathTransformException { 254 try { 255 transform = CRS.findMathTransform(crs, wgs84); 256 } catch (OperationNotFoundException e) { 257 Main.info(crs.getName()+": "+e.getMessage()); // Bursa wolf parameters required. 258 259 if (findSimiliarCrs) { 260 List<CoordinateReferenceSystem> candidates = new ArrayList<>(); 261 262 // Find matching CRS with Bursa Wolf parameters in EPSG database 263 for (String code : CRS.getAuthorityFactory(false).getAuthorityCodes(ProjectedCRS.class)) { 264 try { 265 CoordinateReferenceSystem candidate = CRS.decode(code); 266 if (candidate instanceof AbstractCRS && crs instanceof AbstractIdentifiedObject) { 267 268 Hints.putSystemDefault(Hints.COMPARISON_TOLERANCE, 269 Main.pref.getDouble(OdConstants.PREF_CRS_COMPARISON_TOLERANCE, OdConstants.DEFAULT_CRS_COMPARISON_TOLERANCE)); 270 if (((AbstractCRS)candidate).equals((AbstractIdentifiedObject)crs, false)) { 271 Main.info("Found a potential CRS: "+candidate.getName()); 272 candidates.add(candidate); 273 } else if (Main.pref.getBoolean(OdConstants.PREF_CRS_COMPARISON_DEBUG, false)) { 274 compareDebug(crs, candidate); 275 } 276 Hints.removeSystemDefault(Hints.COMPARISON_TOLERANCE); 277 } 278 } catch (FactoryException ex) { 279 // Silently ignore exceptions 280 //System.err.println("Warning: cannot decode "+code+". "+ex.getMessage()); 281 } 282 } 283 284 if (candidates.size() > 1) { 285 Main.warn("Found several potential CRS: "+Arrays.toString(candidates.toArray())); 286 // TODO: ask user which one to use 287 } 288 289 if (candidates.size() > 0) { 290 CoordinateReferenceSystem newCRS = candidates.get(0); 291 try { 292 transform = CRS.findMathTransform(newCRS, wgs84, false); 293 } catch (OperationNotFoundException ex) { 294 System.err.println(newCRS.getName()+": "+e.getMessage()); 295 } 296 } 297 } 298 299 if (transform == null) { 300 if (handler != null) { 301 // ask handler if it can provide a math transform 302 try { 303 transform = handler.findMathTransform(crs, wgs84, false); 304 } catch (OperationNotFoundException ex) { 305 Main.warn(crs.getName()+": "+ex.getMessage()); // Bursa wolf parameters required. 306 } 307 } else { 308 // ask default known handlers 309 for (GeographicHandler geoHandler : defaultHandlers) { 310 try { 311 if ((transform = geoHandler.findMathTransform(crs, wgs84, false)) != null) { 312 break; 313 } 314 } catch (OperationNotFoundException ex) { 315 Main.warn(crs.getName()+": "+ex.getMessage()); // Bursa wolf parameters required. 316 } 317 } 318 } 319 if (transform == null) { 320 // ask user before trying lenient method, unless in headless mode (unit tests) 321 if (!GraphicsEnvironment.isHeadless() && warnLenientMethod(parent, crs)) { 322 // User canceled 323 throw new UserCancelException(); 324 } 325 Main.info("Searching for a lenient math transform."); 326 transform = CRS.findMathTransform(crs, wgs84, true); 327 } 328 } 329 } 330 if (transform == null) { 331 throw new GeoMathTransformException("Unable to find math transform !"); 332 } 333 } 334 334 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GmlImporter.java
r30563 r30723 14 14 15 15 public class GmlImporter extends AbstractImporter { 16 16 17 17 public static final ExtensionFileFilter GML_FILE_FILTER = new ExtensionFileFilter( 18 18 OdConstants.GML_EXT, OdConstants.GML_EXT, tr("GML files") + " (*."+OdConstants.GML_EXT+")"); … … 22 22 } 23 23 24 25 26 27 28 29 30 31 32 24 @Override 25 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) 26 throws IllegalDataException { 27 try { 28 return GmlReader.parseDataSet(in, handler, instance); 29 } catch (Exception e) { 30 throw new IllegalDataException(e); 31 } 32 } 33 33 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GmlReader.java
r30568 r30723 48 48 public static final String GML_POS_LIST = "posList"; 49 49 50 50 private final GeometryFactory geometryFactory = new GeometryFactory(); 51 51 52 52 private final GmlHandler gmlHandler; 53 53 54 54 private XMLStreamReader parser; 55 55 … … 57 57 58 58 private final class CrsData { 59 60 61 62 63 64 65 66 59 public CoordinateReferenceSystem crs; 60 public MathTransform transform; 61 public int dim; 62 public CrsData(CoordinateReferenceSystem crs, MathTransform transform, int dim) { 63 this.crs = crs; 64 this.transform = transform; 65 this.dim = dim; 66 } 67 67 } 68 68 … … 70 70 71 71 public GmlReader(XMLStreamReader parser, GmlHandler handler) { 72 72 super(handler, NationalHandlers.DEFAULT_GML_HANDLERS); 73 73 this.parser = parser; 74 74 this.gmlHandler = handler; 75 75 } 76 76 77 77 public static DataSet parseDataSet(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException, XMLStreamException { 78 78 InputStreamReader ir = UTFInputStreamReader.create(in, OdConstants.UTF8); 79 79 XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ir); 80 80 try { 81 81 return new GmlReader(parser, handler != null ? handler.getGmlHandler() : null).parseDoc(instance); 82 82 } catch (Exception e) { 83 83 throw new IOException(e); 84 84 } 85 86 87 88 89 85 } 86 87 private final boolean isElement(String element) { 88 return parser.getLocalName().matches("(gml:)?"+element); 89 } 90 90 91 92 93 91 private DataSet parseDoc(ProgressMonitor instance) throws XMLStreamException, GeoCrsException, FactoryException, GeoMathTransformException, MismatchedDimensionException, TransformException { 92 Component parent = instance != null ? instance.getWindowParent() : Main.parent; 93 while (parser.hasNext()) { 94 94 int event = parser.next(); 95 95 if (event == XMLStreamConstants.START_ELEMENT) { 96 96 if (isElement(GML_FEATURE_MEMBER)) { 97 98 99 100 101 97 try { 98 parseFeatureMember(parent); 99 } catch (UserCancelException e) { 100 return ds; 101 } 102 102 } 103 103 } 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 104 } 105 return ds; 106 } 107 108 private void findCRS(String srs) throws NoSuchAuthorityCodeException, FactoryException { 109 Main.info("Finding CRS for "+srs); 110 if (gmlHandler != null) { 111 crs = gmlHandler.getCrsFor(srs); 112 } else { 113 for (GmlHandler h : NationalHandlers.DEFAULT_GML_HANDLERS) { 114 if ((crs = h.getCrsFor(srs)) != null) { 115 return; 116 } 117 } 118 } 119 } 120 121 private void parseSrs(Component parent) throws GeoCrsException, FactoryException, UserCancelException, GeoMathTransformException { 122 String srs = parser.getAttributeValue(null, GML_SRS_NAME); 123 dim = Integer.parseInt(parser.getAttributeValue(null, GML_SRS_DIMENSION)); 124 CrsData crsData = crsDataMap.get(srs); 125 if (crsData == null) { 126 try { 127 findCRS(srs); 128 } catch (NoSuchAuthorityCodeException e) { 129 e.printStackTrace(); 130 } catch (FactoryException e) { 131 e.printStackTrace(); 132 } 133 if (crs == null) { 134 throw new GeoCrsException("Unable to detect CRS for srs '"+srs+"' !"); 135 } else { 136 findMathTransform(parent, false); 137 } 138 crsDataMap.put(srs, new CrsData(crs, transform, dim)); 139 } else { 140 crs = crsData.crs; 141 transform = crsData.transform; 142 dim = crsData.dim; 143 } 144 } 145 146 private void parseFeatureMember(Component parent) throws XMLStreamException, GeoCrsException, FactoryException, UserCancelException, GeoMathTransformException, MismatchedDimensionException, TransformException { 147 List<OsmPrimitive> list = new ArrayList<>(); 148 Way way = null; 149 Node node = null; 150 Map<String, String> tags = new HashMap<>(); 151 while (parser.hasNext()) { 152 152 int event = parser.next(); 153 153 if (event == XMLStreamConstants.START_ELEMENT) { 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 154 if (isElement(GML_LINE_STRING)) { 155 list.add(way = createWay()); 156 parseSrs(parent); 157 } else if (isElement(GML_LINEAR_RING)) { 158 list.add(way = createWay()); 159 } else if (isElement(GML_SURFACE)) { 160 parseSrs(parent); 161 } else if (isElement(GML_POS_LIST)) { 162 String[] tab = parser.getElementText().split(" "); 163 for (int i = 0; i < tab.length; i += dim) { 164 Point p = geometryFactory.createPoint(new Coordinate(Double.valueOf(tab[i]), Double.valueOf(tab[i+1]))); 165 node = createOrGetNode(p, dim > 2 && !tab[i+2].equals("0") ? tab[i+2] : null); 166 if (way != null) { 167 way.addNode(node); 168 } 169 } 170 } 171 171 } else if (event == XMLStreamConstants.END_ELEMENT) { 172 172 if (isElement(GML_FEATURE_MEMBER)) { 173 173 break; 174 174 } 175 175 } 176 177 178 179 180 181 182 176 } 177 for (OsmPrimitive p : list) { 178 for (String key : tags.keySet()) { 179 p.put(key, tags.get(key)); 180 } 181 } 182 } 183 183 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmlKmzImporter.java
r30563 r30723 14 14 15 15 public class KmlKmzImporter extends AbstractImporter { 16 16 17 17 public static final ExtensionFileFilter KML_KMZ_FILE_FILTER = new ExtensionFileFilter( 18 18 OdConstants.KML_EXT+","+OdConstants.KMZ_EXT, OdConstants.KMZ_EXT, tr("KML/KMZ files") + " (*."+OdConstants.KML_EXT+",*."+OdConstants.KMZ_EXT+")"); … … 22 22 } 23 23 24 25 26 27 28 29 30 31 32 33 34 35 36 24 @Override 25 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) 26 throws IllegalDataException { 27 try { 28 if (file.getName().toLowerCase().endsWith(OdConstants.KML_EXT)) { 29 return KmlReader.parseDataSet(in, instance); 30 } else { 31 return KmzReader.parseDataSet(in, instance); 32 } 33 } catch (Exception e) { 34 throw new IllegalDataException(e); 35 } 36 } 37 37 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmlReader.java
r30563 r30723 32 32 33 33 public static final String KML_PLACEMARK = "Placemark"; 34 public static final String KML_NAME 34 public static final String KML_NAME = "name"; 35 35 public static final String KML_COLOR = "color"; 36 36 public static final String KML_SIMPLE_DATA = "SimpleData"; … … 51 51 } 52 52 53 53 public static DataSet parseDataSet(InputStream in, ProgressMonitor instance) throws IOException, XMLStreamException, FactoryConfigurationError { 54 54 InputStreamReader ir = UTFInputStreamReader.create(in); 55 55 XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ir); 56 56 //XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(in, UTF8); 57 57 return new KmlReader(parser).parseDoc(); 58 58 } 59 59 60 61 62 60 private DataSet parseDoc() throws XMLStreamException { 61 DataSet ds = new DataSet(); 62 while (parser.hasNext()) { 63 63 int event = parser.next(); 64 64 if (event == XMLStreamConstants.START_ELEMENT) { 65 65 if (parser.getLocalName().equals(KML_PLACEMARK)) { 66 66 parsePlaceMark(ds); 67 67 } 68 68 } 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 69 } 70 return ds; 71 } 72 73 private static boolean keyIsIgnored(String key) { 74 for (ProjectionPatterns pp : OdConstants.PROJECTIONS) { 75 if (pp.getXPattern().matcher(key).matches() || pp.getYPattern().matcher(key).matches()) { 76 return true; 77 } 78 } 79 return false; 80 } 81 82 private void parsePlaceMark(DataSet ds) throws XMLStreamException { 83 List<OsmPrimitive> list = new ArrayList<>(); 84 Way way = null; 85 Node node = null; 86 Relation relation = null; 87 String role = ""; 88 Map<String, String> tags = new HashMap<>(); 89 while (parser.hasNext()) { 90 90 int event = parser.next(); 91 91 if (event == XMLStreamConstants.START_ELEMENT) { 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 92 if (parser.getLocalName().equals(KML_COLOR)) { 93 String s = parser.getElementText(); 94 // KML color format is aabbggrr, convert it to OSM (web) format: #rrggbb 95 String rgbColor = '#'+s.substring(6,8)+s.substring(4,6)+s.substring(2,4); 96 tags.put(KML_COLOR, rgbColor); 97 } else if (parser.getLocalName().equals(KML_NAME)) { 98 tags.put(KML_NAME, parser.getElementText()); 99 } else if (parser.getLocalName().equals(KML_SIMPLE_DATA)) { 100 String key = parser.getAttributeValue(null, "name"); 101 if (!keyIsIgnored(key)) { 102 tags.put(key, parser.getElementText()); 103 } 104 } else if (parser.getLocalName().equals(KML_POLYGON)) { 105 ds.addPrimitive(relation = new Relation()); 106 relation.put("type", "multipolygon"); 107 list.add(relation); 108 } else if (parser.getLocalName().equals(KML_OUTER_BOUND)) { 109 role = "outer"; 110 } else if (parser.getLocalName().equals(KML_INNER_BOUND)) { 111 role = "inner"; 112 } else if (parser.getLocalName().equals(KML_LINEAR_RING)) { 113 if (relation != null) { 114 ds.addPrimitive(way = new Way()); 115 relation.addMember(new RelationMember(role, way)); 116 } 117 } else if (parser.getLocalName().equals(KML_LINE_STRING)) { 118 ds.addPrimitive(way = new Way()); 119 list.add(way); 120 } else if (parser.getLocalName().equals(KML_COORDINATES)) { 121 String[] tab = parser.getElementText().trim().split("\\s"); 122 for (int i = 0; i < tab.length; i ++) { 123 String[] values = tab[i].split(","); 124 if (values.length >= 2) { 125 LatLon ll = new LatLon(Double.valueOf(values[1]), Double.valueOf(values[0])).getRoundedToOsmPrecisionStrict(); 126 node = nodes.get(ll); 127 if (node == null) { 128 ds.addPrimitive(node = new Node(ll)); 129 nodes.put(ll, node); 130 if (values.length > 2 && !values[2].equals("0")) { 131 node.put("ele", values[2]); 132 } 133 } 134 if (way != null) { 135 way.addNode(node); 136 } 137 } 138 } 139 } 140 140 } else if (event == XMLStreamConstants.END_ELEMENT) { 141 141 if (parser.getLocalName().equals(KML_PLACEMARK)) { 142 142 break; 143 143 } else if (parser.getLocalName().equals(KML_POINT)) { 144 144 list.add(node); 145 145 } 146 146 } 147 148 149 150 151 152 153 147 } 148 for (OsmPrimitive p : list) { 149 for (String key : tags.keySet()) { 150 p.put(key, tags.get(key)); 151 } 152 } 153 } 154 154 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmzReader.java
r30563 r30723 19 19 public class KmzReader extends AbstractReader { 20 20 21 21 private ZipInputStream zis; 22 22 23 23 public KmzReader(ZipInputStream zis) { … … 25 25 } 26 26 27 28 29 27 public static DataSet parseDataSet(InputStream in, ProgressMonitor instance) throws IOException, XMLStreamException, FactoryConfigurationError { 28 return new KmzReader(new ZipInputStream(in)).parseDoc(instance); 29 } 30 30 31 32 33 34 35 36 37 38 39 40 41 42 31 private DataSet parseDoc(ProgressMonitor instance) throws IOException, XMLStreamException, FactoryConfigurationError { 32 ZipEntry entry; 33 do { 34 entry = zis.getNextEntry(); 35 if (entry == null) { 36 Main.warn("No KML file found"); 37 return null; 38 } 39 } while (!entry.getName().toLowerCase().endsWith(".kml")); 40 long size = entry.getSize(); 41 byte[] buffer; 42 if (size > 0) { 43 43 buffer = new byte[(int) size]; 44 44 int off = 0; … … 59 59 buffer = out.toByteArray(); 60 60 } 61 62 63 61 62 return KmlReader.parseDataSet(new ByteArrayInputStream(buffer), instance); 63 } 64 64 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifDatum.java
r30573 r30723 11 11 */ 12 12 public enum MifDatum { 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 13 Adindan(1, "Ethiopia, Mali, Senegal, Sudan", Clarke_1880), 14 Afgooye(2, "Somalia", Krassovsky), 15 Ain_el_Abd_1970(3, "Bahrain Island", International), 16 Anna_1_Astro_1965(4, "Cocos Islands", Australian_National), 17 Arc_1950(5, "Botswana, Lesotho, Malawi, Swaziland, Zaire, Zambia, Zimbabwe", Clarke_1880), 18 Arc_1960(6, "Kenya, Tanzania", Clarke_1880), 19 Ascension_Island_1958(7, "Ascension Island", International), 20 Astro_Beacon_E(8, "Iwo Jima Island", International), 21 Astro_B4_Sorol_Atoll(9, "Tern Island", International), 22 Astro_DOS_71_4(10, "St. Helena Island", International), 23 Astronomic_Station_1952(11, "Marcus Island", International), 24 Australian_Geodetic_1966_AGD_66(12, "Australia and Tasmania Island", Australian_National), 25 Australian_Geodetic_1984_AGD_84(13, "Australia and Tasmania Island", Australian_National), 26 Belgium(110, "Belgium", International), 27 Bellevue_IGN(14, "Efate and Erromango Islands", International), 28 Bermuda_1957(15, "Bermuda Islands", Clarke_1866), 29 Bogota_Observatory(16, "Colombia", International), 30 Campo_Inchauspe(17, "Argentina", International), 31 31 Canton_Astro_1966(18, "Phoenix Islands", International), 32 32 Cape(19, "South Africa", Clarke_1880), … … 40 40 DOS_1968(26, "Gizo Island (New Georgia Islands)", International), 41 41 Easter_Island_1967(27, "Easter Island", International), 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 42 European_1950_ED_50(28, "Austria, Belgium, Denmark, Finland, France, Germany, Gibraltar, Greece, Italy, Luxembourg, Netherlands, Norway, Portugal, Spain, Sweden, Switzerland", International), 43 European_1979_ED_79(29, "Austria, Finland, Netherlands, Norway, Spain, Sweden, Switzerland", International), 44 European_1987_ED_87(108, "Europe", International), 45 Gandajika_Base(30, "Republic of Maldives", International), 46 Geodetic_Datum_1949(31, "New Zealand", International), 47 Geodetic_Reference_System_1967_GRS_67(32, "Worldwide", GRS_67), 48 Geodetic_Reference_System_1980_GRS_80(33, "Worldwide", GRS_80), 49 Guam_1963(34, "Guam Island", Clarke_1866), 50 GUX_1_Astro(35, "Guadalcanal Island", International), 51 Hito_XVIII_1963(36, "South Chile (near 53°S)", International), 52 Hjorsey_1955(37, "Iceland", International), 53 Hong_Kong_1963(38, "Hong Kong", International), 54 Hu_Tzu_Shan(39, "Taiwan", International), 55 Indian_40(40, "Thailand and Vietnam", Everest), 56 Indian_41(41, "Bangladesh, India, Nepal", Everest), 57 Ireland_1965(42, "Ireland", Modified_Airy), 58 ISTS_073_Astro_1969(43, "Diego Garcia", International), 59 Johnston_Island_1961(44, "Johnston Island", International), 60 Kandawala(45, "Sri Lanka", Everest), 61 Kerguelen_Island(46, "Kerguelen Island", International), 62 Kertau_1948(47, "West Malaysia and Singapore", Modified_Everest), 63 LC_5_Astro(48, "Cayman Brac Island", Clarke_1866), 64 Liberia_1964(49, "Liberia", Clarke_1880), 65 Lisboa_DLx(113, "Portugal", International), 66 Luzon_50(50, "Philippines (excluding Mindanao Island)", Clarke_1866), 67 Luzon_51(51, "Mindanao Island", Clarke_1866), 68 68 Mahe_1971(52, "Mahe Island", Clarke_1880), 69 69 Marco_Astro(53, "Salvage Islands", International), … … 78 78 Naparima_BWI(61, "Trinidad and Tobago", International), 79 79 Netherlands(109, "Netherlands", Bessel), 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 80 North_American_1927_NAD_27_CONTINENTAL(62, "Continental US", Clarke_1866), 81 North_American_1927_NAD_27_ALASKA(63, "Alaska", Clarke_1866), 82 North_American_1927_NAD_27_BAHAMAS(64, "Bahamas (excluding San Salvador Island)", Clarke_1866), 83 North_American_1927_NAD_27_SAN_SALVADOR(65, "San Salvador Island", Clarke_1866), 84 North_American_1927_NAD_27_CANADA(66, "Canada (including Newfoundland Island)", Clarke_1866), 85 North_American_1927_NAD_27_CANAL_ZONE(67, "Canal Zone", Clarke_1866), 86 North_American_1927_NAD_27_CARIBBEAN(68, "Caribbean (Turks and Caicos Islands)", Clarke_1866), 87 North_American_1927_NAD_27_CENTRAL_AMERICA(69, "Central America (Belize, Costa Rica, El Salvador, Guatemala, Honduras, Nicaragua)", Clarke_1866), 88 North_American_1927_NAD_27_CUBA(70, "Cuba", Clarke_1866), 89 North_American_1927_NAD_27_GREENLAND(71, "Greenland (Hayes Peninsula)", Clarke_1866), 90 North_American_1927_NAD_27_MEXICO(72, "Mexico", Clarke_1866), 91 North_American_1927_NAD_27_MICHIGAN(73, "Michigan (used only for State Plane Coordinate System 1927)", Modified_Clarke_1866), 92 North_American_1983_NAD_83(74, "Alaska, Canada, Central America, Continental US, Mexico", GRS_80), 93 Nouvelle_Triangulation_Francaise_NTF(107, "France", Clarke_1880), 94 Nouvelle_Triangulation_Francaise_NTF_Greenwich_Prime_Meridian(1002, "France", Clarke_1880), 95 NWGL_10(111, "Worldwide", WGS_72), 96 96 Observatorio_1966(75, "Corvo and Flores Islands (Azores)", International), 97 97 Old_Egyptian(76, "Egypt", Helmert_1906), … … 125 125 Tristan_Astro_1968(98, "Tristan da Cunha", International), 126 126 Viti_Levu_1916(99, "Viti Levu Island (Fiji Islands)", Clarke_1880), 127 128 129 130 131 132 133 134 135 136 127 Wake_Eniwetok_1960(100, "", Hough), 128 World_Geodetic_System_1960_WGS_60(101, "", WGS_60), 129 World_Geodetic_System_1966_WGS_66(102, "", WGS_66), 130 World_Geodetic_System_1972_WGS_72(103, "", WGS_72), 131 World_Geodetic_System_1984_WGS_84(104, "", WGS_84), 132 Yacare(105, "", International), 133 Zanderij(106, "", International), 134 Custom(999, null, null); 135 136 private final Integer code; 137 137 private final String area; 138 139 140 141 142 143 144 145 146 138 private final MifEllipsoid ellipsoid; 139 private MifDatum(Integer code, String area, MifEllipsoid ellipsoid) { 140 this.code = code; 141 this.area = area; 142 this.ellipsoid = ellipsoid; 143 } 144 public final Integer getCode() { 145 return code; 146 } 147 147 public final String getArea() { 148 148 return area; 149 149 } 150 151 152 153 154 155 156 157 158 159 160 150 public final MifEllipsoid getEllipsoid() { 151 return ellipsoid; 152 } 153 public static MifDatum forCode(Integer code) { 154 for (MifDatum p : values()) { 155 if (p.getCode().equals(code)) { 156 return p; 157 } 158 } 159 return null; 160 } 161 161 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifEllipsoid.java
r30573 r30723 9 9 */ 10 10 public enum MifEllipsoid { 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 11 Airy, 12 Modified_Airy, 13 Australian_National, 14 Bessel, 15 Bessel_1841, 16 Clarke_1866, 17 Modified_Clarke_1866, 18 Clarke_1880, 19 Modified_Clarke_1880, 20 Everest, 21 Modified_Fischer_1960, 22 Helmert_1906, 23 Hough, 24 Modified_Everest, 25 GRS_67, 26 GRS_80, 27 International, 28 Krassovsky, 29 South_American_1969, 30 WGS_60, 31 WGS_66, 32 WGS_72, 33 WGS_84 34 34 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifProjection.java
r30573 r30723 9 9 */ 10 10 public enum MifProjection { 11 Albers_Equal_Area_Conic(9, "aea"), 12 Azimuthal_Equidistant_polar_aspect_only(5, "aeqd"), 13 Cylindrical_Equal_Area(2, "cea"), 14 Eckert_IV(14, "eck4"), 15 Eckert_VI(15, "eck6"), 16 Equidistant_Conic_also_known_as_Simple_Conic(6, "eqdc"), 17 Gall(17, "gall"), 18 Hotine_Oblique_Mercator(7, "omerc"), 19 Lambert_Azimuthal_Equal_Area_polar_aspect_only(4, "laea"), 20 Lambert_Conformal_Conic(3, "lcc"), 21 Lambert_Conformal_Conic_modified_for_Belgium_1972(19, "lcca"), 22 Longitude_Latitude(1, "lonlat"), 23 Mercator(10, "merc"), 24 Miller_Cylindrical(11, "mill"), 25 New_Zealand_Map_Grid(18, "nzmg"), 26 Mollweide(13, "moll"), 27 Polyconic(27, "poly"), 28 Regional_Mercator(26, "merc"), 29 Robinson(12, "robin"), 30 Sinusoidal(16, "sinu"), 31 Stereographic(20, "stere"), 32 Swiss_Oblique_Mercator(25, "somerc"), 33 Transverse_Mercator_also_known_as_Gauss_Kruger(8, "tmerc"), 34 Transverse_Mercator_modified_for_Danish_System_34_Jylland_Fyn(21, "tmerc"), 35 Transverse_Mercator_modified_for_Sjaelland(22, "tmerc"), 36 Transverse_Mercator_modified_for_Danish_System_45_Bornholm(23, "tmerc"), 37 Transverse_Mercator_modified_for_Finnish_KKJ(24, "tmerc"); 38 39 private final Integer code; 40 private final String proj4id; 41 42 private MifProjection(Integer code, String proj4id) { 43 this.code = code; 44 this.proj4id = proj4id; 45 } 46 47 public final Integer getCode() { 48 return code; 49 } 11 Albers_Equal_Area_Conic(9, "aea"), 12 Azimuthal_Equidistant_polar_aspect_only(5, "aeqd"), 13 Cylindrical_Equal_Area(2, "cea"), 14 Eckert_IV(14, "eck4"), 15 Eckert_VI(15, "eck6"), 16 Equidistant_Conic_also_known_as_Simple_Conic(6, "eqdc"), 17 Gall(17, "gall"), 18 Hotine_Oblique_Mercator(7, "omerc"), 19 Lambert_Azimuthal_Equal_Area_polar_aspect_only(4, "laea"), 20 Lambert_Conformal_Conic(3, "lcc"), 21 Lambert_Conformal_Conic_modified_for_Belgium_1972(19, "lcca"), 22 Longitude_Latitude(1, "lonlat"), 23 Mercator(10, "merc"), 24 Miller_Cylindrical(11, "mill"), 25 New_Zealand_Map_Grid(18, "nzmg"), 26 Mollweide(13, "moll"), 27 Polyconic(27, "poly"), 28 Regional_Mercator(26, "merc"), 29 Robinson(12, "robin"), 30 Sinusoidal(16, "sinu"), 31 Stereographic(20, "stere"), 32 Swiss_Oblique_Mercator(25, "somerc"), 33 Transverse_Mercator_also_known_as_Gauss_Kruger(8, "tmerc"), 34 Transverse_Mercator_modified_for_Danish_System_34_Jylland_Fyn(21, "tmerc"), 35 Transverse_Mercator_modified_for_Sjaelland(22, "tmerc"), 36 Transverse_Mercator_modified_for_Danish_System_45_Bornholm(23, "tmerc"), 37 Transverse_Mercator_modified_for_Finnish_KKJ(24, "tmerc"); 50 38 51 /** 39 private final Integer code; 40 private final String proj4id; 41 42 private MifProjection(Integer code, String proj4id) { 43 this.code = code; 44 this.proj4id = proj4id; 45 } 46 47 public final Integer getCode() { 48 return code; 49 } 50 51 /** 52 52 * Replies the Proj.4 identifier. 53 53 * … … 59 59 } 60 60 61 62 63 64 65 66 67 68 61 public static MifProjection forCode(Integer code) { 62 for (MifProjection p : values()) { 63 if (p.getCode().equals(code)) { 64 return p; 65 } 66 } 67 return null; 68 } 69 69 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifTabImporter.java
r30563 r30723 15 15 16 16 public class MifTabImporter extends AbstractImporter { 17 17 18 18 public static final ExtensionFileFilter MIF_TAB_FILE_FILTER = new ExtensionFileFilter( 19 19 OdConstants.MIF_EXT+","+OdConstants.TAB_EXT, OdConstants.MIF_EXT, tr("MapInfo files") + " (*."+OdConstants.MIF_EXT+",*."+OdConstants.TAB_EXT+")"); … … 23 23 } 24 24 25 26 27 28 29 30 31 32 33 34 35 36 37 25 @Override 26 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) 27 throws IllegalDataException { 28 try { 29 if (file.getName().toLowerCase().endsWith(OdConstants.MIF_EXT)) { 30 return MifReader.parseDataSet(in, file, handler, instance); 31 } else { 32 return TabReader.parseDataSet(in, file, handler, instance); 33 } 34 } catch (IOException e) { 35 throw new IllegalDataException(e); 36 } 37 } 38 38 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifUnit.java
r30573 r30723 9 9 */ 10 10 public enum MifUnit { 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 11 Centimeters(6), 12 Chains(31), 13 Feet(3), 14 Inches(2), 15 Kilometers(1), 16 Links(30), 17 Meters(7), 18 Miles(0), 19 Millimeters(5), 20 Nautical_Miles(9), 21 Rods(32), 22 US_Survey_Feet(8), 23 Yards(4); 24 25 private final Integer code; 26 private MifUnit(Integer code) { 27 this.code = code; 28 } 29 public final Integer getCode() { 30 return code; 31 } 32 public static MifUnit forCode(Integer code) { 33 for (MifUnit p : values()) { 34 if (p.getCode().equals(code)) { 35 return p; 36 } 37 } 38 return null; 39 } 40 40 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpHandler.java
r30340 r30723 10 10 public interface ShpHandler extends GeographicHandler { 11 11 12 12 public void notifyFeatureParsed(Object feature, DataSet result, Set<OsmPrimitive> featurePrimitives); 13 13 14 15 16 14 public void setDbfCharset(Charset charset); 15 16 public Charset getDbfCharset(); 17 17 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpImporter.java
r30563 r30723 15 15 16 16 public class ShpImporter extends AbstractImporter { 17 17 18 18 public static final ExtensionFileFilter SHP_FILE_FILTER = new ExtensionFileFilter( 19 19 OdConstants.SHP_EXT, OdConstants.SHP_EXT, tr("Shapefiles") + " (*."+OdConstants.SHP_EXT+")"); … … 23 23 } 24 24 25 26 27 28 29 30 31 32 33 25 @Override 26 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) 27 throws IllegalDataException { 28 try { 29 return ShpReader.parseDataSet(in, file, handler, instance); 30 } catch (IOException e) { 31 throw new IllegalDataException(e); 32 } 33 } 34 34 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java
r30568 r30723 57 57 public class ShpReader extends GeographicReader { 58 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 59 private final ShpHandler handler; 60 private final Set<OsmPrimitive> featurePrimitives = new HashSet<>(); 61 62 public ShpReader(ShpHandler handler) { 63 super(handler, NationalHandlers.DEFAULT_SHP_HANDLERS); 64 this.handler = handler; 65 } 66 67 public static DataSet parseDataSet(InputStream in, File file, 68 AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException { 69 if (in != null) { 70 in.close(); 71 } 72 try { 73 return new ShpReader(handler != null ? handler.getShpHandler() : null).parse(file, instance); 74 } catch (IOException e) { 75 throw e; 76 } catch (Throwable t) { 77 throw new IOException(t); 78 } 79 } 80 81 private void parseFeature(Feature feature, final Component parent) 82 throws UserCancelException, GeoMathTransformException, FactoryException, GeoCrsException, MismatchedDimensionException, TransformException { 83 featurePrimitives.clear(); 84 GeometryAttribute geometry = feature.getDefaultGeometryProperty(); 85 if (geometry != null) { 86 87 GeometryDescriptor desc = geometry.getDescriptor(); 88 89 if (crs == null) { 90 if (desc != null && desc.getCoordinateReferenceSystem() != null) { 91 crs = desc.getCoordinateReferenceSystem(); 92 } else if (!GraphicsEnvironment.isHeadless()) { 93 GuiHelper.runInEDTAndWait(new Runnable() { 94 94 @Override 95 95 public void run() { … … 104 104 } 105 105 }); 106 107 108 109 106 } else { 107 // Always use WGS84 in headless mode (used for unit tests only) 108 crs = wgs84; 109 } 110 110 if (crs != null) { 111 111 findMathTransform(parent, true); … … 113 113 throw new GeoCrsException(tr("Unable to detect CRS !")); 114 114 } 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 115 } 116 117 OsmPrimitive primitive = null; 118 119 if (geometry.getValue() instanceof Point) { 120 primitive = createOrGetEmptyNode((Point) geometry.getValue()); 121 122 } else if (geometry.getValue() instanceof GeometryCollection) { // Deals with both MultiLineString and MultiPolygon 123 GeometryCollection mp = (GeometryCollection) geometry.getValue(); 124 int nGeometries = mp.getNumGeometries(); 125 if (nGeometries < 1) { 126 System.err.println("Error: empty geometry collection found"); 127 } else { 128 Relation r = null; 129 Way w = null; 130 131 for (int i=0; i<nGeometries; i++) { 132 Geometry g = mp.getGeometryN(i); 133 if (g instanceof Polygon) { 134 Polygon p = (Polygon) g; 135 // Do not create relation if there's only one polygon without interior ring 136 // except if handler prefers it 137 if (r == null && (nGeometries > 1 || p.getNumInteriorRing() > 0 || (handler != null && handler.preferMultipolygonToSimpleWay()))) { 138 r = createMultipolygon(); 139 } 140 w = createWay(p.getExteriorRing()); 141 if (r != null) { 142 addWayToMp(r, "outer", w); 143 for (int j=0; j<p.getNumInteriorRing(); j++) { 144 addWayToMp(r, "inner", createWay(p.getInteriorRingN(j))); 145 } 146 } 147 } else if (g instanceof LineString) { 148 w = createWay((LineString) g); 149 } else if (g instanceof Point) { 150 // Some belgian data sets hold points into collections ?! 151 readNonGeometricAttributes(feature, createOrGetNode((Point) g)); 152 } else { 153 System.err.println("Error: unsupported geometry : "+g); 154 } 155 } 156 primitive = r != null ? r : w; 157 } 158 } else { 159 // Debug unknown geometry 160 Main.debug("\ttype: "+geometry.getType()); 161 Main.debug("\tbounds: "+geometry.getBounds()); 162 Main.debug("\tdescriptor: "+desc); 163 Main.debug("\tname: "+geometry.getName()); 164 Main.debug("\tvalue: "+geometry.getValue()); 165 Main.debug("\tid: "+geometry.getIdentifier()); 166 Main.debug("-------------------------------------------------------------"); 167 } 168 169 if (primitive != null) { 170 // Read primitive non geometric attributes 171 readNonGeometricAttributes(feature, primitive); 172 } 173 } 174 } 175 176 public DataSet parse(File file, ProgressMonitor instance) throws IOException { 177 crs = null; 178 transform = null; 179 try { 180 if (file != null) { 181 Map<String, Serializable> params = new HashMap<>(); 182 Charset charset = null; 183 params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL()); 184 if (handler != null && handler.getDbfCharset() != null) { 185 charset = handler.getDbfCharset(); 186 } else { 187 String path = file.getAbsolutePath(); 188 // See http://gis.stackexchange.com/a/3663/17245 189 path = path.substring(0, path.lastIndexOf('.')) + ".cpg"; 190 190 Path cpg = new File(path).toPath(); 191 192 193 191 if (Files.exists(cpg)) { 192 try (BufferedReader reader = Files.newBufferedReader(cpg, StandardCharsets.UTF_8)) { 193 charset = Charset.forName(reader.readLine()); 194 194 } catch (IOException | UnsupportedCharsetException | IllegalCharsetNameException e) { 195 195 Main.warn(e); 196 196 } 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 197 } 198 } 199 if (charset != null) { 200 Main.info("Using charset "+charset); 201 params.put(ShapefileDataStoreFactory.DBFCHARSET.key, charset.name()); 202 } 203 DataStore dataStore = new ShapefileDataStoreFactory().createDataStore(params); 204 if (dataStore == null) { 205 throw new IOException(tr("Unable to find a data store for file {0}", file.getName())); 206 } 207 208 String[] typeNames = dataStore.getTypeNames(); 209 String typeName = typeNames[0]; 210 211 FeatureSource<?,?> featureSource = dataStore.getFeatureSource(typeName); 212 FeatureCollection<?,?> collection = featureSource.getFeatures(); 213 FeatureIterator<?> iterator = collection.features(); 214 215 if (instance != null) { 216 instance.beginTask(tr("Loading shapefile ({0} features)", collection.size()), collection.size()); 217 } 218 219 int n = 0; 220 221 Component parent = instance != null ? instance.getWindowParent() : Main.parent; 222 223 try { 224 while (iterator.hasNext()) { 225 n++; 226 try { 227 Feature feature = iterator.next(); 228 parseFeature(feature, parent); 229 if (handler != null) { 230 handler.notifyFeatureParsed(feature, ds, featurePrimitives); 231 } 232 } catch (UserCancelException e) { 233 233 e.printStackTrace(); 234 235 236 237 238 239 240 241 234 return ds; 235 } 236 if (instance != null) { 237 instance.worked(1); 238 instance.setCustomText(n+"/"+collection.size()); 239 } 240 } 241 } catch (Throwable e) { 242 242 e.printStackTrace(); 243 244 245 246 247 248 249 250 251 243 } finally { 244 iterator.close(); 245 nodes.clear(); 246 if (instance != null) { 247 instance.setCustomText(null); 248 } 249 } 250 } 251 } catch (IOException e) { 252 252 e.printStackTrace(); 253 254 253 throw e; 254 } catch (Throwable t) { 255 255 t.printStackTrace(); 256 257 258 259 260 261 256 throw new IOException(t); 257 } 258 return ds; 259 } 260 261 private static final void readNonGeometricAttributes(Feature feature, OsmPrimitive primitive) { 262 262 try { 263 264 265 266 267 268 269 270 263 for (Property prop : feature.getProperties()) { 264 if (!(prop instanceof GeometryAttribute)) { 265 Name name = prop.getName(); 266 Object value = prop.getValue(); 267 if (name != null && value != null) { 268 String sName = name.toString(); 269 String sValue = value.toString(); 270 if (!sName.isEmpty() && !sValue.isEmpty()) { 271 271 primitive.put(sName, sValue); 272 273 274 275 272 } 273 } 274 } 275 } 276 276 } catch (Exception e) { 277 277 e.printStackTrace(); 278 278 } 279 280 281 282 283 284 285 286 287 288 289 290 291 292 279 } 280 281 @Override 282 protected Node createOrGetNode(Point p) throws MismatchedDimensionException, TransformException { 283 Node n = super.createOrGetNode(p); 284 featurePrimitives.add(n); 285 return n; 286 } 287 288 @Override 289 protected <T extends OsmPrimitive> T addOsmPrimitive(T p) { 290 featurePrimitives.add(p); 291 return super.addOsmPrimitive(p); 292 } 293 293 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/TabReader.java
r30575 r30723 29 29 public class TabReader extends AbstractMapInfoReader { 30 30 31 32 33 34 35 36 31 private Charset datCharset; 32 private final AbstractDataSetHandler handler; 33 34 public TabReader(AbstractDataSetHandler handler) { 35 this.handler = handler; 36 } 37 37 38 39 40 41 42 43 38 public static DataSet parseDataSet(InputStream in, File file, 39 AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException { 40 return new TabReader(handler).parse(in, file, instance, Charset.forName(OdConstants.ISO8859_15)); 41 } 42 43 private class TabOsmReader extends SpreadSheetReader { 44 44 45 46 47 48 49 45 private final DbaseFileReader dbfReader; 46 public TabOsmReader(SpreadSheetHandler handler, TabFiles tabFiles) throws IOException { 47 super(handler); 48 this.dbfReader = new DbaseFileReader(tabFiles, false, datCharset, null); 49 } 50 50 51 52 53 54 51 @Override 52 protected void initResources(InputStream in, 53 ProgressMonitor progressMonitor) throws IOException { 54 } 55 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 56 @Override 57 protected String[] readLine(ProgressMonitor progressMonitor) 58 throws IOException { 59 if (!dbfReader.hasNext()) { 60 return null; 61 } 62 List<String> result = new ArrayList<>(); 63 Row row = dbfReader.readRow(); 64 for (int i=0; i<columns.size(); i++) { 65 Object o = row.read(i); 66 if (o != null) { 67 result.add(o.toString()); 68 } else { 69 result.add(""); 70 } 71 } 72 return result.toArray(new String[0]); 73 } 74 } 75 75 76 77 78 76 private DataSet parse(InputStream in, File file, ProgressMonitor instance, Charset charset) throws IOException { 77 headerReader = new BufferedReader(new InputStreamReader(in, charset)); 78 parseHeader(); 79 79 try { 80 81 82 80 File dataFile = getDataFile(file, ".dat"); 81 ds = new TabOsmReader(handler != null ? handler.getSpreadSheetHandler() : null, new TabFiles(file, dataFile)). 82 doParse(columns.toArray(new String[0]), instance); 83 83 } catch (IOException e) { 84 84 System.err.println(e.getMessage()); 85 85 } 86 87 86 return ds; 87 } 88 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 89 @Override 90 protected void parseHeaderLine(String[] words) throws IOException { 91 if (words[0].equalsIgnoreCase("!table")) { 92 // Do nothing 93 } else if (words[0].equalsIgnoreCase("!version")) { 94 parseVersion(words); 95 } else if (words[0].equalsIgnoreCase("!charset")) { 96 parseCharset(words); 97 } else if (numcolumns > 0) { 98 parseField(words); 99 } else if (words[0].equalsIgnoreCase("Definition")) { 100 // Do nothing 101 } else if (words[0].equalsIgnoreCase("Type")) { 102 parseType(words); 103 } else if (words[0].equalsIgnoreCase("Fields")) { 104 parseColumns(words); 105 } else if (!line.isEmpty()) { 106 System.err.println("Line "+lineNum+". Unknown clause in header: "+line); 107 } 108 } 109 109 110 111 112 113 110 private void parseField(String[] words) { 111 columns.add(words[0]); 112 --numcolumns; 113 } 114 114 115 116 117 118 119 120 121 115 private void parseType(String[] words) throws IllegalCharsetNameException, UnsupportedCharsetException { 116 if (words[1].equalsIgnoreCase("NATIVE") && words[2].equalsIgnoreCase("Charset")) { 117 datCharset = parseCharset(words, 3); 118 } else { 119 System.err.println("Line "+lineNum+". Unknown Type clause in header: "+line); 120 } 121 } 122 122 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/CsvHandler.java
r30340 r30723 6 6 public interface CsvHandler extends SpreadSheetHandler { 7 7 8 8 public void setCharset(Charset charset); 9 9 10 10 public void setCharset(String charset); 11 11 12 12 public Charset getCharset(); 13 13 14 15 16 14 public void setSeparator(String sep); 15 16 public String getSeparator(); 17 17 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/CsvImporter.java
r30563 r30723 23 23 24 24 public static final String COLOMBUS_HEADER = "INDEX,TAG,DATE,TIME,LATITUDE N/S,LONGITUDE E/W,HEIGHT,SPEED,HEADING,FIX MODE,VALID,PDOP,HDOP,VDOP,VOX"; 25 25 26 26 public CsvImporter() { 27 27 super(CSV_FILE_FILTER); 28 28 } 29 29 30 31 32 33 34 35 36 37 38 30 @Override 31 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) 32 throws IllegalDataException { 33 try { 34 return CsvReader.parseDataSet(in, handler, instance); 35 } catch (IOException e) { 36 throw new IllegalDataException(e); 37 } 38 } 39 39 40 40 @Override -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/CsvReader.java
r30568 r30723 17 17 public class CsvReader extends SpreadSheetReader { 18 18 19 20 21 22 23 19 private final Charset charset; 20 private String sep; 21 22 private BufferedReader reader; 23 private String line; 24 24 25 26 27 25 public CsvReader(CsvHandler handler) { 26 this(handler, ";"); 27 } 28 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 29 public CsvReader(CsvHandler handler, String defaultSep) { 30 super(handler); 31 this.charset = handler != null && handler.getCharset() != null ? handler.getCharset() : Charset.forName(OdConstants.UTF8); 32 this.sep = handler != null && handler.getSeparator() != null ? handler.getSeparator() : defaultSep; 33 } 34 35 public static DataSet parseDataSet(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException { 36 CsvHandler csvHandler = null; 37 if (handler != null && handler.getSpreadSheetHandler() instanceof CsvHandler) { 38 csvHandler = (CsvHandler) handler.getSpreadSheetHandler(); 39 } 40 CsvReader csvReader = new CsvReader(csvHandler); 41 try { 42 return csvReader.parse(in, instance); 43 } catch (IllegalArgumentException e) { 44 if (csvHandler == null || csvHandler.getSeparator() == null || ";".equals(csvHandler.getSeparator())) { 45 // If default sep has been used, try comma 46 Main.warn(e.getMessage()); 47 csvReader.sep = ","; 48 return csvReader.doParse(csvReader.splitLine(), instance); 49 } else { 50 throw e; 51 } 52 } 53 } 54 54 55 56 57 55 @Override 56 protected void initResources(InputStream in, ProgressMonitor progressMonitor) throws IOException { 57 Main.info("Parsing CSV file using charset "+charset+" and separator '"+sep+"'"); 58 58 59 60 59 reader = new BufferedReader(new InputStreamReader(in, charset)); 60 } 61 61 62 63 64 65 66 67 68 69 70 71 72 73 74 62 @Override 63 protected String[] readLine(ProgressMonitor progressMonitor) throws IOException { 64 line = reader.readLine(); 65 return splitLine(); 66 } 67 68 private final String[] splitLine() { 69 if (line != null) { 70 return OdUtils.stripQuotesAndExtraChars(line.split(sep), sep); 71 } else { 72 return null; 73 } 74 } 75 75 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/DefaultCsvHandler.java
r30340 r30723 6 6 public class DefaultCsvHandler extends DefaultSpreadSheetHandler implements CsvHandler { 7 7 8 9 10 11 12 13 14 8 private Charset charset = null; 9 private String separator = null; 10 11 @Override 12 public void setCharset(Charset cs) { 13 charset = cs; 14 } 15 15 16 17 18 19 16 @Override 17 public void setCharset(String charset) { 18 setCharset(Charset.forName(charset)); 19 } 20 20 21 22 23 24 21 @Override 22 public Charset getCharset() { 23 return charset; 24 } 25 25 26 27 28 29 26 @Override 27 public void setSeparator(String sep) { 28 separator = sep; 29 } 30 30 31 32 33 34 31 @Override 32 public String getSeparator() { 33 return separator; 34 } 35 35 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/DefaultSpreadSheetHandler.java
r30340 r30723 12 12 public class DefaultSpreadSheetHandler implements SpreadSheetHandler { 13 13 14 15 16 17 18 19 20 21 22 23 24 14 private int sheetNumber = -1; 15 private int lineNumber = -1; 16 private boolean handlesProjection = false; 17 18 private int xCol = -1; 19 private int yCol = -1; 20 21 @Override 22 public int getSheetNumber() { 23 return sheetNumber; 24 } 25 25 26 27 28 29 30 31 32 33 34 26 @Override 27 public void setSheetNumber(int n) { 28 sheetNumber = n; 29 } 30 31 @Override 32 public boolean handlesProjection() { 33 return handlesProjection; 34 } 35 35 36 37 38 39 36 @Override 37 public void setHandlesProjection(boolean handle) { 38 handlesProjection = handle; 39 } 40 40 41 42 43 44 41 @Override 42 public LatLon getCoor(EastNorth en, String[] fields) { 43 return null; 44 } 45 45 46 47 48 49 46 @Override 47 public void setLineNumber(int n) { 48 lineNumber = n; 49 } 50 50 51 52 53 54 51 @Override 52 public int getLineNumber() { 53 return lineNumber; 54 } 55 55 56 57 58 59 56 @Override 57 public void setXCol(int i) { 58 xCol = i; 59 } 60 60 61 62 63 64 61 @Override 62 public void setYCol(int i) { 63 yCol = i; 64 } 65 65 66 67 68 69 66 @Override 67 public int getXCol() { 68 return xCol; 69 } 70 70 71 72 73 74 71 @Override 72 public int getYCol() { 73 return yCol; 74 } 75 75 76 76 @Override -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/OdsDocument.java
r30568 r30723 18 18 public class OdsDocument extends OpenDocument { 19 19 20 21 22 23 24 20 public OdsDocument(InputStream in) { 21 loadFrom(in); 22 } 23 24 private InputSource getEntryInputSource(ZipInputStream zis) throws IOException { 25 25 int n = -1; 26 26 final byte[] buffer = new byte[4096]; 27 27 final ByteArrayOutputStream baos = new ByteArrayOutputStream(); 28 28 while ((n = zis.read(buffer, 0, buffer.length)) != -1) { 29 29 baos.write(buffer, 0, n); 30 30 } 31 32 31 return new InputSource(new ByteArrayInputStream(baos.toByteArray())); 32 } 33 33 34 34 public void loadFrom(final InputStream in) { … … 43 43 44 44 while (!contentParsed && (entry = zis.getNextEntry()) != null) { 45 45 if (entry.getName().equals("content.xml")) { 46 46 rdr.setContentHandler(contentHandler); 47 47 Main.info("Parsing content.xml"); 48 48 rdr.parse(getEntryInputSource(zis)); 49 50 49 contentParsed = true; 50 } 51 51 } 52 52 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/OdsImporter.java
r30563 r30723 15 15 16 16 public class OdsImporter extends AbstractImporter { 17 17 18 18 public static final ExtensionFileFilter ODS_FILE_FILTER = new ExtensionFileFilter( 19 19 OdConstants.ODS_EXT, OdConstants.ODS_EXT, tr("ODS files") + " (*."+OdConstants.ODS_EXT+")"); … … 23 23 } 24 24 25 26 27 28 29 30 31 32 33 25 @Override 26 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) 27 throws IllegalDataException { 28 try { 29 return OdsReader.parseDataSet(in, handler, instance); 30 } catch (IOException e) { 31 throw new IllegalDataException(e); 32 } 33 } 34 34 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/OdsReader.java
r30568 r30723 20 20 public class OdsReader extends SpreadSheetReader { 21 21 22 23 24 25 26 27 28 29 30 31 22 private OpenDocument doc; 23 private TableTable sheet; 24 private List<TableTableRow> rows; 25 private int rowIndex; 26 27 private static final String SEP = "TextP:["; 28 29 public OdsReader(SpreadSheetHandler handler) { 30 super(handler); 31 } 32 32 33 34 35 36 33 public static DataSet parseDataSet(InputStream in, 34 AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException { 35 return new OdsReader(handler != null ? handler.getSpreadSheetHandler() : null).parse(in, instance); 36 } 37 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 38 @Override 39 protected void initResources(InputStream in, ProgressMonitor progressMonitor) throws IOException { 40 try { 41 Main.info("Parsing ODS file"); 42 doc = new OdsDocument(in); 43 List<OfficeSpreadsheet> spreadsheets = doc.getBody().getOfficeSpreadsheets(); 44 if (spreadsheets != null && spreadsheets.size() > 0) { 45 List<TableTable> tables = spreadsheets.get(0).getTables(); 46 if (tables != null && tables.size() > 0) { 47 sheet = tables.get(getSheetNumber()); 48 if (sheet != null) { 49 rows = sheet.getRows(); 50 } 51 } 52 } 53 rowIndex = 0; 54 } catch (Exception e) { 55 throw new IOException(e); 56 } 57 } 58 58 59 60 61 62 59 @Override 60 protected String[] readLine(ProgressMonitor progressMonitor) throws IOException { 61 if (rows != null && rowIndex < rows.size()) { 62 TableTableRow row = rows.get(rowIndex++); 63 63 64 65 66 64 if (rowIndex % 5000 == 0) { 65 Main.info("Lines read: "+rowIndex); 66 } 67 67 68 69 70 71 72 68 List<String> result = new ArrayList<>(); 69 boolean allFieldsBlank = true; 70 for (TableTableCell cell : row.getAllCells()) { 71 TextP textP = cell.getTextP(); 72 String text = textP == null ? "" : textP.toString().replace(SEP, "").replace("]", "").replace("null", "").trim(); 73 73 result.add(text); 74 74 if (allFieldsBlank && !text.isEmpty()) { 75 75 allFieldsBlank = false; 76 76 } 77 78 79 80 81 82 77 } 78 79 return rowIndex == 1 || !allFieldsBlank ? result.toArray(new String[0]) : null; 80 } 81 return null; 82 } 83 83 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/SpreadSheetHandler.java
r30340 r30723 12 12 public interface SpreadSheetHandler { 13 13 14 15 16 14 public void setSheetNumber(int n); 15 16 public int getSheetNumber(); 17 17 18 19 20 18 public void setHandlesProjection(boolean handle); 19 20 public boolean handlesProjection(); 21 21 22 22 public LatLon getCoor(EastNorth en, String[] fields); 23 23 24 25 26 24 public void setLineNumber(int n); 25 26 public int getLineNumber(); 27 27 28 28 public void setXCol(int i); 29 29 30 31 32 30 public void setYCol(int i); 31 32 public int getXCol(); 33 33 34 34 public int getYCol(); 35 35 36 36 public void nodesAdded(DataSet ds, Map<CoordinateColumns, Node> nodes, String[] fields, int lineNumber); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/SpreadSheetReader.java
r30583 r30723 28 28 29 29 public abstract class SpreadSheetReader extends AbstractReader { 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 30 31 private static final NumberFormat formatFrance = NumberFormat.getInstance(Locale.FRANCE); 32 private static final NumberFormat formatUK = NumberFormat.getInstance(Locale.UK); 33 34 protected final SpreadSheetHandler handler; 35 36 public SpreadSheetReader(SpreadSheetHandler handler) { 37 this.handler = handler; 38 } 39 40 protected static double parseDouble(String value) throws ParseException { 41 if (value.contains(",")) { 42 return formatFrance.parse(value.replace(" ", "")).doubleValue(); 43 } else { 44 return formatUK.parse(value.replace(" ", "")).doubleValue(); 45 } 46 } 47 48 protected abstract void initResources(InputStream in, ProgressMonitor progressMonitor) throws IOException; 49 50 protected abstract String[] readLine(ProgressMonitor progressMonitor) throws IOException; 51 52 protected final int getSheetNumber() { 53 return handler != null && handler.getSheetNumber() > -1 ? handler.getSheetNumber() : 0; 54 } 55 56 protected final int getLineNumber() { 57 return handler != null ? handler.getLineNumber() : -1; 58 } 59 60 public static class CoordinateColumns { 61 61 public Projection proj = null; 62 63 64 65 66 62 public int xCol = -1; 63 public int yCol = -1; 64 public final boolean isOk() { 65 return xCol > -1 && yCol > -1; 66 } 67 67 @Override 68 68 public String toString() { 69 69 return "CoordinateColumns [proj=" + proj + ", xCol=" + xCol + ", yCol=" + yCol + "]"; 70 70 } 71 72 73 71 } 72 73 private final CoordinateColumns addCoorColIfNeeded(List<CoordinateColumns> columns, CoordinateColumns col) { 74 74 if (col == null || col.isOk()) { 75 75 columns.add(col = new CoordinateColumns()); 76 76 } 77 77 return col; 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 78 } 79 80 public DataSet doParse(String[] header, ProgressMonitor progressMonitor) throws IOException { 81 Main.info("Header: "+Arrays.toString(header)); 82 83 Map<ProjectionPatterns, List<CoordinateColumns>> projColumns = new HashMap<>(); 84 85 for (int i = 0; i<header.length; i++) { 86 for (ProjectionPatterns pp : OdConstants.PROJECTIONS) { 87 List<CoordinateColumns> columns = projColumns.get(pp); 88 if (columns == null) { 89 projColumns.put(pp, columns = new ArrayList<>()); 90 } 91 CoordinateColumns col = columns.isEmpty() ? null : columns.get(columns.size()-1); 92 if (pp.getXPattern().matcher(header[i]).matches()) { 93 addCoorColIfNeeded(columns, col).xCol = i; 94 break; 95 } else if (pp.getYPattern().matcher(header[i]).matches()) { 96 addCoorColIfNeeded(columns, col).yCol = i; 97 break; 98 } 99 } 100 } 101 102 final List<CoordinateColumns> columns = new ArrayList<>(); 103 104 for (ProjectionPatterns pp : projColumns.keySet()) { 105 for (CoordinateColumns col : projColumns.get(pp)) { 106 if (col.isOk()) { 107 107 columns.add(col); 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 108 if (col.proj == null) { 109 col.proj = pp.getProjection(header[col.xCol], header[col.yCol]); 110 } 111 } 112 } 113 } 114 115 final boolean handlerOK = handler != null && handler.handlesProjection(); 116 117 boolean projFound = false; 118 119 for (CoordinateColumns c : columns) { 120 if (c.proj != null) { 121 projFound = true; 122 break; 123 } 124 } 125 126 if (projFound) { 127 // projection identified, do nothing 128 } else if (!columns.isEmpty()) { 129 if (!handlerOK) { 130 130 if (GraphicsEnvironment.isHeadless()) { 131 131 throw new IllegalArgumentException("No valid coordinates have been found and cannot prompt user in headless mode."); 132 133 132 } 133 // TODO: filter proposed projections with min/max values ? 134 134 Projection p = ChooserLauncher.askForProjection(progressMonitor); 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 135 if (p == null) { 136 return null; // User clicked Cancel 137 } 138 for (CoordinateColumns c : columns) { 139 c.proj = p; 140 } 141 } 142 143 } else { 144 throw new IllegalArgumentException(tr("No valid coordinates have been found.")); 145 } 146 147 String message = ""; 148 for (CoordinateColumns c : columns) { 149 if (!message.isEmpty()) { 150 message += "; "; 151 } 152 message += c.proj + "("+header[c.xCol]+", "+header[c.yCol]+")"; 153 } 154 155 Main.info("Loading data using projections "+message); 156 157 final DataSet ds = new DataSet(); 158 int lineNumber = 1; 159 160 String[] fields; 161 while ((fields = readLine(progressMonitor)) != null) { 162 lineNumber++; 163 if (handler != null) { 164 handler.setXCol(-1); 165 handler.setYCol(-1); 166 } 167 168 168 final Map<CoordinateColumns, EastNorth> ens = new HashMap<>(); 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 169 final Map<CoordinateColumns, Node> nodes = new HashMap<>(); 170 for (CoordinateColumns c : columns) { 171 nodes.put(c, new Node()); 172 ens.put(c, new EastNorth(Double.NaN, Double.NaN)); 173 } 174 175 if (fields.length > header.length) { 176 Main.warn(tr("Invalid file. Bad length on line {0}. Expected {1} columns, got {2}.", lineNumber, header.length, fields.length)); 177 Main.warn(Arrays.toString(fields)); 178 } 179 180 for (int i = 0; i<Math.min(fields.length, header.length); i++) { 181 try { 182 boolean coordinate = false; 183 for (CoordinateColumns c : columns) { 184 EastNorth en = ens.get(c); 185 185 if (i == c.xCol) { 186 186 coordinate = true; … … 195 195 handler.setYCol(i); 196 196 } 197 } 198 197 } 198 } 199 199 if (!coordinate) { 200 200 if (!fields[i].isEmpty()) { … … 202 202 } 203 203 } 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 204 } catch (ParseException e) { 205 System.err.println("Warning: Parsing error on line "+lineNumber+": "+e.getMessage()); 206 } 207 } 208 Node firstNode = null; 209 for (CoordinateColumns c : columns) { 210 Node n = nodes.get(c); 211 EastNorth en = ens.get(c); 212 if (en.isValid()) { 213 n.setCoor(c.proj != null && !handlerOK ? c.proj.eastNorth2latlon(en) : handler.getCoor(en, fields)); 214 } else { 215 System.err.println("Warning: Skipping line "+lineNumber+" because no valid coordinates have been found at columns "+c); 216 } 217 if (n.getCoor() != null) { 218 if (firstNode == null) { 219 firstNode = n; 220 } 221 if (n == firstNode || n.getCoor().greatCircleDistance(firstNode.getCoor()) > Main.pref.getDouble(OdConstants.PREF_TOLERANCE, OdConstants.DEFAULT_TOLERANCE)) { 222 ds.addPrimitive(n); 223 } else { 224 nodes.remove(c); 225 } 226 } 227 } 228 if (handler != null && !Main.pref.getBoolean(OdConstants.PREF_RAWDATA)) { 229 handler.nodesAdded(ds, nodes, header, lineNumber); 230 } 231 } 232 233 return ds; 234 } 235 236 public final DataSet parse(InputStream in, ProgressMonitor progressMonitor) throws IOException { 237 238 initResources(in, progressMonitor); 239 240 String[] header = null; 241 int length = 0; 242 int n = 0; 243 244 while (header == null || length == 0) { 245 n++; 246 header = readLine(progressMonitor); 247 length = 0; 248 if (header == null && n > getLineNumber()) { 249 return null; 250 } else if (header != null && (getLineNumber() == -1 || getLineNumber() == n)) { 251 for (String field : header) { 252 length += field.length(); 253 } 254 } 255 } 256 257 return doParse(header, progressMonitor); 258 } 259 259 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/XlsImporter.java
r30563 r30723 15 15 16 16 public class XlsImporter extends AbstractImporter { 17 17 18 18 public static final ExtensionFileFilter XLS_FILE_FILTER = new ExtensionFileFilter( 19 19 OdConstants.XLS_EXT, OdConstants.XLS_EXT, tr("XLS files") + " (*."+OdConstants.XLS_EXT+")"); … … 23 23 } 24 24 25 26 27 28 29 30 31 32 33 25 @Override 26 protected DataSet parseDataSet(InputStream in, ProgressMonitor instance) 27 throws IllegalDataException { 28 try { 29 return XlsReader.parseDataSet(in, handler, instance); 30 } catch (IOException e) { 31 throw new IllegalDataException(e); 32 } 33 } 34 34 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/XlsReader.java
r30568 r30723 21 21 public class XlsReader extends SpreadSheetReader { 22 22 23 24 25 26 27 28 29 23 private Workbook wb; 24 private Sheet sheet; 25 private int rowIndex; 26 27 public XlsReader(SpreadSheetHandler handler) { 28 super(handler); 29 } 30 30 31 32 33 34 31 public static DataSet parseDataSet(InputStream in, 32 AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException { 33 return new XlsReader(handler != null ? handler.getSpreadSheetHandler() : null).parse(in, instance); 34 } 35 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 36 @Override 37 protected void initResources(InputStream in, ProgressMonitor progressMonitor) throws IOException { 38 Main.info("Parsing XLS file"); 39 try { 40 wb = new HSSFWorkbook(new POIFSFileSystem(in)); 41 sheet = wb.getSheetAt(getSheetNumber()); 42 rowIndex = 0; 43 } catch (ExceptionInInitializerError e) { 44 Throwable ex = e.getException(); 45 if (ex != null && ex.getMessage() != null) { 46 System.err.println(ex.getClass()+": "+ex.getMessage()); 47 } 48 throw new IOException(e); 49 } catch (Throwable t) { 50 throw new IOException(t); 51 } 52 } 53 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 54 @Override 55 protected String[] readLine(ProgressMonitor progressMonitor) throws IOException { 56 if (sheet != null) { 57 Row row = sheet.getRow(rowIndex++); 58 if (row != null) { 59 List<String> result = new ArrayList<>(); 60 for (Cell cell : row) { 61 switch (cell.getCellType()) { 62 case Cell.CELL_TYPE_STRING: 63 result.add(cell.getRichStringCellValue().getString()); 64 break; 65 case Cell.CELL_TYPE_NUMERIC: 66 if (DateUtil.isCellDateFormatted(cell)) { 67 result.add(cell.getDateCellValue().toString()); 68 } else { 69 result.add(Double.toString(cell.getNumericCellValue())); 70 } 71 break; 72 case Cell.CELL_TYPE_BOOLEAN: 73 result.add(Boolean.toString(cell.getBooleanCellValue())); 74 break; 75 case Cell.CELL_TYPE_FORMULA: 76 result.add(cell.getCellFormula()); 77 break; 78 default: 79 result.add(""); 80 } 81 } 82 return result.toArray(new String[0]); 83 } 84 } 85 return null; 86 } 87 87 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/layers/OdDataLayer.java
r30563 r30723 30 30 public class OdDataLayer extends OsmDataLayer implements OdLayer, LayerChangeListener { 31 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 32 public OdDiffLayer diffLayer; 33 public OdOsmDataLayer osmLayer; 34 35 public final AbstractDataSetHandler handler; 36 37 private Bounds bounds; 38 39 public OdDataLayer(DataSet data, String name, File associatedFile, AbstractDataSetHandler handler) { 40 super(data, name, associatedFile); 41 setUploadDiscouraged(true); 42 this.handler = handler; 43 for (Node node : data.getNodes()) { 44 if (this.bounds == null) { 45 this.bounds = new Bounds(node.getCoor()); 46 } else { 47 this.bounds.extend(node.getCoor()); 48 } 49 } 50 MapView.addLayerChangeListener(this); 51 } 52 53 53 @Override public Icon getBaseIcon() { 54 54 return OdUtils.getImageIcon(handler != null ? handler.getDataLayerIconName() : OdConstants.ICON_CORE_16); 55 55 } 56 56 57 57 public void addOsmLayer(OdOsmDataLayer layer) { 58 59 60 58 removeOsmLayer(); 59 osmLayer = layer; 60 Main.main.addLayer(osmLayer); 61 61 } 62 62 63 63 public void removeOsmLayer() { 64 65 66 67 64 if (osmLayer != null) { 65 Main.main.removeLayer(osmLayer); 66 osmLayer = null; 67 } 68 68 } 69 69 70 70 public void addDiffLayer(OdDiffLayer layer) { 71 72 73 71 removeDiffLayer(); 72 diffLayer = layer; 73 Main.main.addLayer(diffLayer); 74 74 } 75 75 76 76 public void removeDiffLayer() { 77 78 79 80 77 if (diffLayer != null) { 78 Main.main.removeLayer(diffLayer); 79 diffLayer = null; 80 } 81 81 } 82 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 83 public final void downloadOsmData() { 84 String oapiReq = handler.getOverpassApiRequest(bounds); 85 Collection<String> xapiReqs = handler.getOsmXapiRequests(bounds); 86 if (oapiReq != null || xapiReqs != null) { 87 DataSet dataSet = new DataSet(); 88 final OdOsmDataLayer layer = new OdOsmDataLayer(this, dataSet, getName()+"/OSM"); 89 addOsmLayer(layer); 90 Main.map.mapView.setActiveLayer(osmLayer); 91 if (oapiReq != null) { 92 OsmDownloader.downloadOapi(oapiReq); 93 // Overpass API does not allow to exclude tags :( 94 layer.removeForbiddenTags(); 95 } else { 96 OsmDownloader.downloadXapi(xapiReqs); 97 } 98 } 99 } 100 100 101 102 103 104 105 106 101 @Override 102 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 103 if (newLayer == this && this.handler != null) { 104 this.handler.notifyActive(); 105 } 106 } 107 107 108 109 110 108 @Override 109 public void layerAdded(Layer newLayer) { 110 } 111 111 112 113 114 115 116 117 118 119 120 121 122 112 @Override 113 public void layerRemoved(Layer oldLayer) { 114 if (oldLayer == this) { 115 removeOsmLayer(); 116 removeDiffLayer(); 117 } else if (oldLayer == osmLayer) { 118 osmLayer = null; 119 } else if (oldLayer == diffLayer) { 120 diffLayer = null; 121 } 122 } 123 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 124 @Override 125 public Action[] getMenuEntries() { 126 List<Action> result = new ArrayList<>(); 127 for (Action entry : super.getMenuEntries()) { 128 result.add(entry); 129 } 130 if (this.handler != null) { 131 if (this.handler.getWikiURL() != null || this.handler.getLocalPortalURL() != null || this.handler.getNationalPortalURL() != null) { 132 result.add(SeparatorLayerAction.INSTANCE); 133 } 134 if (this.handler.getWikiURL() != null) { 135 result.add(new OpenLinkAction(this.handler.getWikiURL(), OdConstants.ICON_OSM_24, 136 tr("View OSM Wiki page"), tr("Launch browser to the OSM Wiki page of the selected data set"))); 137 } 138 if (this.handler.getLocalPortalURL() != null) { 139 result.add(new OpenLinkAction(this.handler.getLocalPortalURL(), this.handler.getLocalPortalIconName(), 140 tr("View Local Portal page"), tr("Launch browser to the local portal page of the selected data set"))); 141 } 142 if (this.handler.getNationalPortalURL() != null) { 143 result.add(new OpenLinkAction(this.handler.getNationalPortalURL(), this.handler.getNationalPortalIconName(), 144 tr("View National Portal page"), tr("Launch browser to the national portal page of the selected data set"))); 145 } 146 if (this.handler.getLicense() != null) { 147 License lic = this.handler.getLicense(); 148 if (lic.getURL() != null && lic.getURL().getProtocol().startsWith("http")) { 149 result.add(new OpenLinkAction(lic.getURL(), OdConstants.ICON_AGREEMENT_24, 150 tr("View License"), tr("Launch browser to the license page of the selected data set"))); 151 } 152 if (lic.getSummaryURL() != null && lic.getSummaryURL().getProtocol().startsWith("http")) { 153 result.add(new OpenLinkAction(lic.getSummaryURL(), OdConstants.ICON_AGREEMENT_24, 154 tr("View License (summary)"), tr("Launch browser to the summary license page of the selected data set"))); 155 } 156 if ((lic.getURL() != null && !lic.getURL().getProtocol().startsWith("http")) || (lic.getSummaryURL() != null && !lic.getSummaryURL().getProtocol().startsWith("http"))) { 157 result.add(new ViewLicenseAction(lic, tr("View License"), tr("View the license of the selected data set"))); 158 } 159 } 160 } 161 return result.toArray(new Action[0]); 162 } 163 163 164 165 166 167 164 @Override 165 public OdDataLayer getDataLayer() { 166 return this; 167 } 168 168 169 170 171 172 173 169 public void makeDiff() { 170 final OdDiffLayer layer = new OdDiffLayer(this, getName()+"/Diff"); 171 addDiffLayer(layer); 172 Main.map.mapView.setActiveLayer(diffLayer); 173 } 174 174 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/layers/OdDiffLayer.java
r30563 r30723 22 22 public class OdDiffLayer extends Layer implements OdLayer { 23 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 24 private final OdDataLayer dataLayer; 25 26 public final List<Pair<OsmPrimitive,OsmPrimitive>> differentPrimitives; 27 public final List<OsmPrimitive> onlyInTlsPrimitives; 28 public final List<OsmPrimitive> onlyInOsmPrimitives; 29 30 public OdDiffLayer(OdDataLayer dataLayer, String name) { 31 super(name); 32 this.dataLayer = dataLayer; 33 this.differentPrimitives = new ArrayList<>(); 34 this.onlyInTlsPrimitives = new ArrayList<>(); 35 this.onlyInOsmPrimitives = new ArrayList<>(); 36 initDiff(dataLayer.data, dataLayer.osmLayer.data); 37 } 38 39 private void initDiff(DataSet tlsData, DataSet osmData) { 40 for (OsmPrimitive p1 : tlsData.allPrimitives()) { 41 if (dataLayer.handler.isRelevant(p1)) { 42 OsmPrimitive p2 = findPrimitiveAt(osmData, p1); 43 if (p2 == null) { 44 onlyInTlsPrimitives.add(p1); 45 } else if (!dataLayer.handler.equals(p1, p2)) { 46 differentPrimitives.add(new Pair<>(p1, p2)); 47 } 48 } 49 } 50 for (OsmPrimitive p1 : osmData.allPrimitives()) { 51 if (dataLayer.handler.isRelevant(p1)) { 52 if (findPrimitiveAt(tlsData, p1) == null) { 53 onlyInOsmPrimitives.add(p1); 54 } 55 } 56 } 57 } 58 59 private double distance(OsmPrimitive p1, OsmPrimitive p2) { 60 return p1.getBBox().getCenter().greatCircleDistance(p2.getBBox().getCenter()); 61 } 62 63 private OsmPrimitive findPrimitiveAt(DataSet dataSet, OsmPrimitive source) { 64 double maxDistance = Main.pref.getDouble(OdConstants.PREF_MAXDISTANCE, OdConstants.DEFAULT_MAXDISTANCE); 65 //List<OsmPrimitive> samePrimitives = new ArrayList<OsmPrimitive>(); 66 OsmPrimitive nearestSamePrimitive = null; 67 //List<OsmPrimitive> potentialPrimitives = new ArrayList<OsmPrimitive>(); 68 OsmPrimitive nearestPotentialPrimitive = null; 69 for (OsmPrimitive p : dataSet.allPrimitives()) { 70 if (dataLayer.handler.isRelevant(p)) { 71 double dist = distance(source, p); 72 if (dist <= maxDistance) { 73 if (dataLayer.handler.equals(p, source)) { 74 //samePrimitives.add(p); 75 if (nearestSamePrimitive == null || distance(p, nearestSamePrimitive) > dist) { 76 nearestSamePrimitive = p; 77 } 78 } else { 79 //potentialPrimitives.add(p); 80 if (nearestPotentialPrimitive == null || distance(p, nearestPotentialPrimitive) > dist) { 81 nearestPotentialPrimitive = p; 82 } 83 } 84 } 85 } 86 } 87 return nearestSamePrimitive != null ? nearestSamePrimitive : nearestPotentialPrimitive; 88 } 89 89 90 91 92 93 90 @Override 91 public void paint(Graphics2D g, MapView mv, Bounds box) { 92 // TODO Auto-generated method stub 93 } 94 94 95 96 97 98 95 @Override 96 public Icon getIcon() { 97 return ImageProvider.get("layer", "diff"); 98 } 99 99 100 101 102 103 104 100 @Override 101 public String getToolTipText() { 102 // TODO Auto-generated method stub 103 return null; 104 } 105 105 106 107 108 106 @Override 107 public void mergeFrom(Layer from) { 108 } 109 109 110 111 112 113 110 @Override 111 public boolean isMergable(Layer other) { 112 return false; 113 } 114 114 115 116 117 118 115 @Override 116 public void visitBoundingBox(BoundingXYVisitor v) { 117 // TODO Auto-generated method stub 118 } 119 119 120 121 122 123 124 120 @Override 121 public Object getInfoComponent() { 122 // TODO Auto-generated method stub 123 return null; 124 } 125 125 126 127 128 129 126 @Override 127 public Action[] getMenuEntries() { 128 return null; 129 } 130 130 131 132 133 134 131 @Override 132 public OdDataLayer getDataLayer() { 133 return dataLayer; 134 } 135 135 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/layers/OdLayer.java
r30340 r30723 3 3 4 4 public interface OdLayer { 5 5 public OdDataLayer getDataLayer(); 6 6 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/layers/OdOsmDataLayer.java
r30532 r30723 16 16 public class OdOsmDataLayer extends OsmDataLayer implements OdLayer { 17 17 18 18 private final OdDataLayer dataLayer; 19 19 20 21 22 23 24 20 public OdOsmDataLayer(OdDataLayer dataLayer, DataSet data, String name) { 21 super(data, name, null); 22 this.dataLayer = dataLayer; 23 } 24 25 25 public final void removeForbiddenTags() { 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 26 if (dataLayer != null && dataLayer.handler != null && dataLayer.handler.hasForbiddenTags()) { 27 Main.worker.submit(new Runnable() { 28 @Override 29 public void run() { 30 data.clearSelection(); 31 for (Iterator<OsmPrimitive> it = data.allPrimitives().iterator(); it.hasNext();) { 32 OsmPrimitive p = it.next(); 33 if (dataLayer.handler.isForbidden(p)) { 34 data.addSelected(p); 35 36 List<Node> nodes = null; 37 if (p instanceof Way) { 38 nodes = ((Way) p).getNodes(); 39 } 40 //data.removePrimitive(p); 41 if (nodes != null) { 42 for (Node n : nodes) { 43 List<OsmPrimitive> refferingAllowedWays = new ArrayList<>(); 44 for (OsmPrimitive referrer : n.getReferrers()) { 45 if (referrer instanceof Way && !dataLayer.handler.isForbidden(referrer)) { 46 refferingAllowedWays.add(referrer); 47 } 48 } 49 50 if (refferingAllowedWays.isEmpty()) { 51 //data.removePrimitive(n); 52 data.addSelected(n); 53 } 54 } 55 } 56 /*for (OsmPrimitive referrer : p.getReferrers()) { 57 System.out.println(referrer); 58 }*/ 59 } 60 } 61 Collection<OsmPrimitive> sel = data.getSelected(); 62 if (!sel.isEmpty()) { 63 Main.main.menu.purge.actionPerformed(null); 64 } 65 } 66 }); 67 } 68 68 } 69 69 70 71 72 73 70 @Override 71 public OdDataLayer getDataLayer() { 72 return dataLayer; 73 } 74 74 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/licenses/LOOL.java
r30563 r30723 6 6 7 7 public class LOOL extends License { 8 8 9 9 //public static final String URL_FR = "http://www.data.gouv.fr/Licence-Ouverte-Open-Licence"; 10 10 11 12 13 14 15 11 public LOOL() { 12 setIcon(OdUtils.getImageIcon(OdConstants.ICON_LOOL_48, true)); 13 setURL(LOOL.class.getResource(OdConstants.RESOURCE_PATH+"Licence-Ouverte-Open-Licence-ENG.rtf"), "en"); 14 setURL(LOOL.class.getResource(OdConstants.RESOURCE_PATH+"Licence-Ouverte-Open-Licence.rtf"), "fr"); 15 } 16 16 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/licenses/License.java
r30532 r30723 13 13 14 14 public abstract class License { 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 15 16 public static final ODbL ODbL = new ODbL(); 17 public static final LOOL LOOL = new LOOL(); 18 19 private final Map<String, URL> urls = new HashMap<>(); 20 private final Map<String, URL> summaryURLs = new HashMap<>(); 21 22 private Icon icon; 23 24 private static final URL getURL(Map<String, URL> map) { 25 // Find URL for current language 26 String lang = OdUtils.getJosmLanguage(); 27 for (String l : map.keySet()) { 28 if (lang.startsWith(l)) { 29 return map.get(l); 30 } 31 } 32 // If not found, return english URL 33 URL url = map.get("en"); 34 if (url != null) { 35 return url; 36 } 37 // If not found, return first non-null url 38 if (map.keySet().size() > 0) { 39 for (Iterator<String> it=map.keySet().iterator(); it.hasNext(); ) { 40 url = map.get(it.next()); 41 if (url != null) { 42 return url; 43 } 44 } 45 } 46 // If empty, return null 47 return null; 48 } 49 49 50 51 52 50 public URL getURL() { 51 return getURL(urls); 52 } 53 53 54 55 56 57 58 59 60 54 public URL getSummaryURL() { 55 return getURL(summaryURLs); 56 } 57 58 public final void setURL(URL url) { 59 setURL(url, "en"); 60 } 61 61 62 63 64 62 public final void setURL(String url, String lang) throws MalformedURLException { 63 setURL(new URL(url), lang); 64 } 65 65 66 67 68 66 public final void setURL(String url) throws MalformedURLException { 67 setURL(new URL(url), "en"); 68 } 69 69 70 71 72 73 74 70 public final void setURL(URL url, String lang) { 71 if (url != null) { 72 urls.put(lang, url); 73 } 74 } 75 75 76 77 78 76 public final void setSummaryURL(URL url) { 77 setSummaryURL(url, "en"); 78 } 79 79 80 81 82 80 public final void setSummaryURL(String url, String lang) throws MalformedURLException { 81 setSummaryURL(new URL(url), lang); 82 } 83 83 84 85 86 84 public final void setSummaryURL(String url) throws MalformedURLException { 85 setSummaryURL(new URL(url), "en"); 86 } 87 87 88 89 90 91 92 88 public final void setSummaryURL(URL url, String lang) { 89 if (url != null) { 90 summaryURLs.put(lang, url); 91 } 92 } 93 93 94 95 96 94 public final Icon getIcon() { 95 return icon; 96 } 97 97 98 99 100 98 public final void setIcon(Icon icon) { 99 this.icon = icon; 100 } 101 101 102 103 104 105 106 107 102 @Override 103 public String toString() { 104 return "License [" + (urls != null ? "urls=" + urls + ", " : "") 105 + (summaryURLs != null ? "summaryURLs=" + summaryURLs : "") 106 + "]"; 107 } 108 108 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/licenses/ODbL.java
r30563 r30723 5 5 6 6 public class ODbL extends License { 7 7 8 8 //public static final String URL = "http://opendatacommons.org/licenses/odbl/1-0"; 9 9 //public static final String SUMMARY_URL = "http://opendatacommons.org/licenses/odbl/summary"; … … 11 11 //public static final String SUMMARY_URL_FR = "http://vvlibri.org/fr/licence/odbl/10/fr"; 12 12 13 14 15 16 17 18 19 20 21 22 23 13 public ODbL() { 14 for (String lang : new String[]{"", "fr"}) { 15 if (lang.isEmpty()) { 16 setURL(ODbL.class.getResource(OdConstants.RESOURCE_PATH+"odbl-1.0.htm")); 17 setSummaryURL(ODbL.class.getResource(OdConstants.RESOURCE_PATH+"odbl-summary-1.0.htm")); 18 } else { 19 setURL(ODbL.class.getResource(OdConstants.RESOURCE_PATH+"odbl-1.0-"+lang+".htm"), lang); 20 setSummaryURL(ODbL.class.getResource(OdConstants.RESOURCE_PATH+"odbl-summary-1.0-"+lang+".htm"), lang); 21 } 22 } 23 } 24 24 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/AbstractModule.java
r30563 r30723 19 19 public abstract class AbstractModule implements Module { 20 20 21 21 protected final List<Class<? extends AbstractDataSetHandler>> handlers = new ArrayList<>(); 22 22 23 23 private final List<AbstractDataSetHandler> instanciatedHandlers = new ArrayList<>(); 24 24 25 26 27 28 29 25 protected final ModuleInformation info; 26 27 public AbstractModule(ModuleInformation info) { 28 this.info = info; 29 } 30 30 31 32 33 34 31 @Override 32 public ModuleInformation getModuleInformation() { 33 return info; 34 } 35 35 36 37 38 39 36 @Override 37 public List<Class<? extends AbstractDataSetHandler>> getHandlers() { 38 return handlers; 39 } 40 40 41 42 43 44 41 @Override 42 public String getDisplayedName() { 43 return info.name; 44 } 45 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 46 @Override 47 public SourceProvider getMapPaintStyleSourceProvider() { 48 final List<SourceEntry> sources = new ArrayList<>(); 49 for (AbstractDataSetHandler handler : getInstanciatedHandlers()) { 50 ExtendedSourceEntry src; 51 if (handler != null && (src = handler.getMapPaintStyle()) != null) { 52 try { 53 // Copy style sheet to disk to allow JOSM to load it at startup (even making the plugin "early" does not allow it) 54 String path = OdPlugin.getInstance().getResourcesDirectory()+File.separator+src.url.replace(OdConstants.PROTO_RSRC, "").replace('/', File.separatorChar); 55 56 int n = 0; 57 byte[] buffer = new byte[4096]; 58 InputStream in = getClass().getResourceAsStream(src.url.substring(OdConstants.PROTO_RSRC.length()-1)); 59 new File(path.substring(0, path.lastIndexOf(File.separatorChar))).mkdirs(); 60 FileOutputStream out = new FileOutputStream(path); 61 while ((n = in.read(buffer)) > 0) { 62 out.write(buffer, 0, n); 63 } 64 out.close(); 65 in.close(); 66 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 67 // Add source pointing to the local file 68 src.url = OdConstants.PROTO_FILE+path; 69 sources.add(src); 70 } catch (IOException e) { 71 System.err.println(e.getMessage()); 72 } 73 } 74 } 75 return sources.isEmpty() ? null : new SourceProvider() { 76 @Override 77 public Collection<SourceEntry> getSources() { 78 return sources; 79 } 80 }; 81 } 82 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 83 @Override 84 public SourceProvider getPresetSourceProvider() { 85 final List<SourceEntry> sources = new ArrayList<>(); 86 for (AbstractDataSetHandler handler : getInstanciatedHandlers()) { 87 if (handler != null && handler.getTaggingPreset() != null) { 88 sources.add(handler.getTaggingPreset()); 89 } 90 } 91 return sources.isEmpty() ? null : new SourceProvider() { 92 @Override 93 public Collection<SourceEntry> getSources() { 94 return sources; 95 } 96 }; 97 } 98 99 @Override 100 public final List<AbstractDataSetHandler> getNewlyInstanciatedHandlers() { 101 List<AbstractDataSetHandler> result = new ArrayList<>(); 102 for (Class<? extends AbstractDataSetHandler> handlerClass : handlers) { 103 if (handlerClass != null) { 104 try { 105 result.add(handlerClass.newInstance()); 106 } catch (Throwable t) { 107 System.err.println("Cannot instantiate "+handlerClass+" because of "+t.getClass().getName()+": "+t.getMessage()); 108 } 109 } 110 } 111 return result; 112 } 113 113 114 115 116 117 118 119 114 private final List<AbstractDataSetHandler> getInstanciatedHandlers() { 115 if (instanciatedHandlers.isEmpty()) { 116 instanciatedHandlers.addAll(getNewlyInstanciatedHandlers()); 117 } 118 return instanciatedHandlers; 119 } 120 120 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/Module.java
r30340 r30723 9 9 public interface Module { 10 10 11 11 public String getDisplayedName(); 12 12 13 13 public List<Class<? extends AbstractDataSetHandler>> getHandlers(); 14 14 15 15 public List<AbstractDataSetHandler> getNewlyInstanciatedHandlers(); 16 16 17 18 19 20 21 17 public SourceProvider getMapPaintStyleSourceProvider(); 18 19 public SourceProvider getPresetSourceProvider(); 20 21 public ModuleInformation getModuleInformation(); 22 22 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ModuleHandler.java
r30563 r30723 230 230 Module mod = module.load(klass); 231 231 if (moduleList.add(mod)) { 232 233 234 235 236 237 238 239 232 SourceProvider styleProvider = mod.getMapPaintStyleSourceProvider(); 233 if (styleProvider != null) { 234 MapPaintPreference.registerSourceProvider(styleProvider); 235 } 236 SourceProvider presetProvider = mod.getPresetSourceProvider(); 237 if (presetProvider != null) { 238 TaggingPresetPreference.registerSourceProvider(presetProvider); 239 } 240 240 } 241 241 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ModuleInformation.java
r30563 r30723 145 145 146 146 private static final ImageIcon extractIcon(String iconPath, File jarFile, boolean suppressWarnings) { 147 147 return new ImageProvider(iconPath).setArchive(jarFile).setMaxWidth(24).setMaxHeight(24).setOptional(true).setSuppressWarnings(suppressWarnings).get(); 148 148 } 149 149 … … 159 159 try { 160 160 @SuppressWarnings("unused") 161 161 URL url = new URL(s); 162 162 } catch (MalformedURLException e) { 163 163 System.out.println(tr("Invalid URL ''{0}'' in module {1}", s, name)); … … 183 183 // if not found, extract icon from the plugin jar file 184 184 if (icon == null) { 185 185 icon = extractIcon(iconPath, OdPlugin.getInstance().getPluginInformation().file, true); 186 186 } 187 187 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/util/NamesFrUtils.java
r30563 r30723 16 16 17 17 public abstract class NamesFrUtils { 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 18 19 private static Map<String, String> dictionary = initDictionary(); 20 21 public static final String checkDictionary(String value) { 22 String result = ""; 23 for (String word : value.split(" ")) { 24 if (!result.isEmpty()) { 25 result += " "; 26 } 27 result += dictionary.containsKey(word) ? dictionary.get(word) : word; 28 } 29 return result; 30 } 31 32 private static Map<String, String> initDictionary() { 33 Map<String, String> result = new HashMap<>(); 34 try { 35 BufferedReader reader = new BufferedReader(new InputStreamReader( 36 SimpleDataSetHandler.class.getResourceAsStream(OdConstants.DICTIONARY_FR), OdConstants.UTF8)); 37 String line = reader.readLine(); // Skip first line 38 while ((line = reader.readLine()) != null) { 39 String[] tab = line.split(";"); 40 result.put(tab[0].replace("\"", ""), tab[1].replace("\"", "")); 41 } 42 reader.close(); 43 } catch (IOException e) { 44 e.printStackTrace(); 45 } 46 return result; 47 } 48 49 public static final String getStreetLabel(String label) { 50 if (label == null) { 51 return label; 52 } else if (label.equals("All")) { 53 return "Allée"; 54 } else if (label.equals("Autoroute")) { 55 return label; 56 } else if (label.startsWith("Anc")) { // Anc, Ancien 57 return "Ancien"; 58 } else if (label.equals("Av")) { 59 return "Avenue"; 60 } else if (label.equals("Bd")) { 61 return "Boulevard"; 62 } else if (label.equals("Bre")) { 63 return "Bré"; 64 } else if (label.equals("Caminot")) { 65 return label; 66 } else if (label.equals("Carrefour")) { 67 return label; 68 } else if (label.startsWith("Che")) { // Che, Chem 69 return "Chemin"; 70 } else if (label.equals("Cite")) { 71 return "Cité"; 72 } else if (label.equals("Clos")) { 73 return label; 74 } else if (label.equals("Cote")) { 75 return "Côte"; 76 } else if (label.equals("Cours")) { 77 return label; 78 } else if (label.equals("Dom")) { 79 return "Domaine"; 80 } else if (label.equals("Dsc")) { 81 return "Descente"; 82 } else if (label.equals("Esp")) { 83 return "Esplanade"; 84 } else if (label.equals("Espa")) { 85 return "Espace"; 86 } else if (label.equals("Giratoire")) { 87 return label; 88 } else if (label.equals("Grande-rue")) { 89 return label; 90 } else if (label.equals("Hameau")) { 91 return label; 92 } else if (label.equals("Imp")) { 93 return "Impasse"; 94 } else if (label.equals("Itineraire")) { 95 return "Itinéraire"; 96 } else if (label.equals("Jardin")) { 97 return label; 98 } else if (label.startsWith("L'") || label.equals("La") || label.equals("Le") || label.equals("Les") || label.equals("Saint")) { // Lieux-dits 99 return label; 100 } else if (label.equals("Lot")) { 101 return "Lotissement"; 102 } else if (label.equals("Mail")) { 103 return label; 104 } else if (label.equals("Mas")) { 105 return label; 106 } else if (label.equals("Parc")) { 107 return label; 108 } else if (label.equals("Pas")) { 109 return "Passage"; 110 } else if (label.equals("Passerelle")) { 111 return label; 112 } else if (label.equals("Pch")) { 113 return "Petit Chemin"; 114 } else if (label.equals("Petit")) { 115 return label; 116 } else if (label.equals("Petite-allée")) { 117 return label; 118 } else if (label.equals("Petite-rue")) { 119 return label; 120 } else if (label.equals("Pl")) { 121 return "Place"; 122 } else if (label.equals("Plan")) { 123 return label; 124 } else if (label.equals("Pont")) { 125 return label; 126 } else if (label.equals("Port")) { 127 return label; 128 } else if (label.equals("Porte")) { 129 return label; 130 } else if (label.equals("Prom")) { 131 return "Promenade"; 132 } else if (label.equals("Prv")) { 133 return "Parvis"; 134 } else if (label.equals("Qu")) { 135 return "Quai"; 136 } else if (label.equals("Rampe")) { 137 return label; 138 } else if (label.equals("Residence")) { 139 return "Résidence"; 140 } else if (label.equals("Rocade")) { 141 return label; 142 } else if (label.equals("Rpt")) { 143 return "Rond-Point"; 144 } else if (label.equals("Rte")) { 145 return "Route"; 146 } else if (label.equals("Rue")) { 147 return label; 148 } else if (label.equals("Sentier")) { 149 return label; 150 } else if (label.equals("Sq")) { 151 return "Square"; 152 } else if (label.equals("Tra")) { 153 return "Traverse"; 154 } else if (label.equals("Vieux")) { 155 return label; 156 } else if (label.equals("Voie")) { 157 return label; 158 } else if (label.equals("Zone")) { 159 return label; 160 } else { 161 System.err.println("Warning: unknown street label: "+label); 162 return label; 163 } 164 } 165 166 public static final String checkStreetName(OsmPrimitive p, String key) { 167 String value = null; 168 if (p != null) { 169 value = p.get(key); 170 if (value != null) { 171 value = WordUtils.capitalizeFully(value); 172 // Cas particuliers 173 if (value.equals("Boulingrin")) { // square Boulingrin, mal formé 174 value = "Sq Boulingrin"; 175 } else if (value.matches("A[0-9]+")) { // Autoroutes sans le mot "Autoroute" 176 value = "Autoroute "+value; 177 } else if (value.equals("All A61")) { // A61 qualifiée d'Allée ? 178 value = "Autoroute A61"; 179 } else if (value.startsWith("Che Vieux Che")) { // "Che" redondant 180 value = value.replaceFirst("Che ", ""); 181 } else if (value.startsWith("Petite Allee ")) { // Tiret, comme grand-rue, petite-rue 182 value = value.replaceFirst("Petite Allee ", "Petite-allée "); 183 } else if (value.startsWith("Ld De ")) { // Lieux-dit 184 value = value.replaceFirst("Ld De ", ""); 185 } 186 while (value.startsWith("Ld ")) { // Lieux-dit, inutile. Plus le cas avec "Ld Ld" 187 value = value.replaceFirst("Ld ", ""); 188 } 189 if (value.startsWith("L ")) { 190 value = value.replaceFirst("L ", "L'"); 191 } 192 String[] words = value.split(" "); 193 if (words.length > 0) { 194 value = ""; 195 List<String> list = Arrays.asList(words); 196 words[0] = getStreetLabel(words[0]); 197 if (words[0].equals("Ancien") && words.length > 1 && words[1].equals("Che")) { 198 words[1] = "Chemin"; 199 } 200 for (int i = 0; i < words.length; i++) { 201 if (i > 0) { 202 value += " "; 203 // Prénoms/Noms propres abrégés 204 if (words[i].equals("A") && list.contains("Bernard")) { 205 words[i] = "Arnaud"; 206 } else if (words[i].equals("A") && list.contains("Passerieu")) { 207 words[i] = "Ariste"; 208 } else if (words[i].equals("A") && list.contains("Bougainville")) { 209 words[i] = "Antoine"; 210 } else if (words[i].equals("Ch") && list.contains("Leconte")) { 211 words[i] = "Charles"; 212 } else if (words[i].equals("Frs") && list.contains("Dugua")) { 213 words[i] = "François"; 214 } else if (words[i].equals("G") && list.contains("Latecoere")) { 215 words[i] = "Georges"; 216 } else if (words[i].equals("H") && list.contains("Lautrec")) { 217 words[i] = "Henri"; 218 } else if (words[i].equals("J") && list.contains("Dieulafoy")) { 219 words[i] = "Jane"; 220 } else if (words[i].equals("J") && (list.contains("Champollion") || list.contains("Stanislas"))) { 221 words[i] = "Jean"; 222 } else if (words[i].equals("L") && list.contains("Zamenhof")) { 223 words[i] = "Ludwik"; 224 } else if (words[i].equals("L") && list.contains("Sacha")) { 225 words[i] = "Lucien"; 226 if (!list.contains("Et")) { 227 words[i] += " et"; 228 } 229 } else if (words[i].equals("L") && (list.contains("Vauquelin") || list.contains("Bougainville"))) { 230 words[i] = "Louis"; 231 } else if (words[i].equals("M") && list.contains("Dieulafoy")) { 232 words[i] = "Marcel"; 233 } else if (words[i].equals("M") && list.contains("Arifat")) { 234 words[i] = "Marie"; 235 } else if (words[i].equals("N") && list.contains("Djamena")) { 236 words[i] = "N'"; 237 } else if (words[i].equals("Oo")) { 238 words[i] = "Oô"; 239 } else if (words[i].equals("Ph") && list.contains("Ravary")) { 240 words[i] = "Philippe"; 241 } else if (words[i].equals("R") && list.contains("Folliot")) { 242 words[i] = "Raphaël"; 243 } else if (words[i].equals("W") && list.contains("Booth")) { 244 words[i] = "William"; 245 // Mots de liaison non couverts par le dictionnaire 246 } else if (words[i].equals("A")) { 247 words[i] = "à"; 248 } else if (words[i].equals("D") || words[i].equals("L")) { 249 words[i] = words[i].toLowerCase()+"'"; 250 } else if (words[i].equals("La") || words[i].equals("Le")) { 251 words[i] = words[i].toLowerCase(); 252 } 253 } 254 value += words[i]; 255 } 256 } 257 // Ponctuation 258 value = value.replace("' ", "'"); 259 // Dictionnaire 260 value = checkDictionary(value); 261 p.put(key, value); 262 } 263 } 264 return value; 265 } 266 266 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/util/OdUtils.java
r30532 r30723 21 21 22 22 public abstract class OdUtils { 23 23 24 24 private static final String TEMP_DIR_PREFIX = "josm_opendata_temp_"; 25 25 … … 28 28 } 29 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 30 public static final String[] stripQuotesAndExtraChars(String[] split, String sep) { 31 List<String> result = new ArrayList<>(); 32 boolean append = false; 33 for (int i = 0; i<split.length; i++) { 34 if (append) { 35 int index = result.size()-1; 36 if (split[i].endsWith("\"") && StringUtils.countMatches(split[i], "\"") % 2 == 1) { 37 append = false; 38 } 39 result.set(index, result.get(index)+sep+split[i].replaceAll("\"", "")); 40 } else if (split[i].startsWith("\"")) { 41 if (!(split[i].endsWith("\"") && StringUtils.countMatches(split[i], "\"") % 2 == 0)) { 42 append = true; 43 } 44 result.add(split[i].replaceAll("\"", "")); 45 } else { 46 result.add(split[i]); 47 } 48 } 49 // Remove exotic characters such as U+FEFF found in some CSV files 50 for (ListIterator<String> it = result.listIterator(); it.hasNext();) { 51 it.set(Utils.strip(it.next())); 52 } 53 return result.toArray(new String[0]); 54 } 55 56 public static final ImageIcon getImageIcon(String iconName) { 57 return getImageIcon(iconName, false); 58 } 59 60 public static final ImageIcon getImageIcon(String iconName, boolean optional) { 61 return new ImageProvider(iconName).setOptional(optional).setAdditionalClassLoaders(ModuleHandler.getResourceClassLoaders()).get(); 62 } 63 64 public static final String getJosmLanguage() { 65 String lang = Main.pref.get("language"); 66 if (lang == null || lang.isEmpty()) { 67 lang = Locale.getDefault().toString(); 68 } 69 return lang; 70 } 71 72 72 public static final double convertMinuteSecond(double minute, double second) { 73 73 return (minute/60.0) + (second/3600.0);
Note:
See TracChangeset
for help on using the changeset viewer.