Changeset 33028 in osm
- Timestamp:
- 2016-10-05T23:02:54+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/ImportImagePlugin
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ImportImagePlugin/.project
r32286 r33028 16 16 </arguments> 17 17 </buildCommand> 18 <buildCommand> 19 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 20 <arguments> 21 </arguments> 22 </buildCommand> 18 23 </buildSpec> 19 24 <natures> 20 25 <nature>org.eclipse.jdt.core.javanature</nature> 26 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 21 27 </natures> 22 28 </projectDescription> -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayer.java
r31746 r33028 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 2 3 … … 66 67 /** 67 68 * Constructor 68 *69 * @param file70 * @throws IOException71 69 */ 72 70 public ImageLayer(File file) throws IOException { … … 80 78 /** 81 79 * create spatial referenced image. 82 *83 * @return84 * @throws IOException85 80 */ 86 81 private Image createImage() throws IOException { … … 97 92 98 93 } catch (FactoryException e) { 99 logger.error("Error while creating GridCoverage:", e);94 logger.error("Error while creating GridCoverage:", e); 100 95 throw new IOException(e.getMessage()); 101 96 } catch (Exception e) { 102 if(e.getMessage().contains("No projection file found")) 103 { 104 ExtendedDialog ex = new ExtendedDialog(Main.parent, tr("Warning"), new String[] {tr("Default image projection"), tr("JOSM''s current projection"), tr("Cancel")}); 97 if (e.getMessage().contains("No projection file found")) { 98 ExtendedDialog ex = new ExtendedDialog(Main.parent, tr("Warning"), 99 new String[] {tr("Default image projection"), tr("JOSM''s current projection"), tr("Cancel")}); 100 // CHECKSTYLE.OFF: LineLength 105 101 ex.setContent(tr("No projection file (.prj) found.<br>" 106 + "You can choose the default image projection ({0}) or JOSM''s current editor projection ({1}) as original image projection.<br>" 107 + "(It can be changed later from the right click menu of the image layer.)", 108 ImportImagePlugin.pluginProps.getProperty("default_crs_srid"), Main.getProjection().toCode())); 102 + "You can choose the default image projection ({0}) or JOSM''s current editor projection ({1}) as original image projection.<br>" 103 + "(It can be changed later from the right click menu of the image layer.)", 104 ImportImagePlugin.pluginProps.getProperty("default_crs_srid"), Main.getProjection().toCode())); 105 // CHECKSTYLE.ON: LineLength 109 106 ex.showDialog(); 110 107 int val = ex.getValue(); … … 128 125 } 129 126 } catch (Exception e1) { 130 logger.error("Error while creating GridCoverage:", e1);127 logger.error("Error while creating GridCoverage:", e1); 131 128 throw new IOException(e1); 132 129 } 133 } 134 else 135 { 136 logger.error("Error while creating GridCoverage:",e); 130 } else { 131 logger.error("Error while creating GridCoverage:", e); 137 132 throw new IOException(e); 138 133 } … … 267 262 @Override 268 263 public String getToolTipText() { 269 // TODO Auto-generated method stub270 264 return this.getName(); 271 265 } 272 273 266 274 267 public File getImageFile() { … … 283 276 * loads the image and reprojects it using a transformation 284 277 * calculated by the new reference system. 285 * 286 * @param newRefSys 287 * @throws IOException 288 * @throws FactoryException 289 * @throws NoSuchAuthorityCodeException 290 */ 291 void resample(CoordinateReferenceSystem refSys) throws IOException, NoSuchAuthorityCodeException, FactoryException 292 { 278 */ 279 void resample(CoordinateReferenceSystem refSys) throws IOException, NoSuchAuthorityCodeException, FactoryException { 293 280 logger.debug("resample"); 294 GridCoverage2D coverage = 281 GridCoverage2D coverage = PluginOperations.createGridFromFile(this.imageFile, refSys, true); 295 282 coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(Main.getProjection().toCode())); 296 283 this.bbox = coverage.getEnvelope2D(); 297 this.image = ((PlanarImage) coverage.getRenderedImage()).getAsBufferedImage();284 this.image = ((PlanarImage) coverage.getRenderedImage()).getAsBufferedImage(); 298 285 299 286 upperLeft = new EastNorth(coverage.getEnvelope2D().x, coverage … … 312 299 * 313 300 */ 314 public class LayerPropertiesAction extends AbstractAction 315 { 301 public class LayerPropertiesAction extends AbstractAction { 316 302 public ImageLayer imageLayer; 317 303 318 public LayerPropertiesAction(ImageLayer imageLayer) {304 public LayerPropertiesAction(ImageLayer imageLayer) { 319 305 super(tr("Layer Properties")); 320 306 this.imageLayer = imageLayer; … … 322 308 323 309 public void actionPerformed(ActionEvent arg0) { 324 325 310 LayerPropertiesDialog layerProps = new LayerPropertiesDialog(imageLayer, PluginOperations.crsDescriptions); 326 layerProps.setLocation(Main.parent.getWidth() / 4 311 layerProps.setLocation(Main.parent.getWidth() / 4, Main.parent.getHeight() / 4); 327 312 layerProps.setVisible(true); 328 313 } -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImageFileImporter.java
r32402 r33028 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 2 3 … … 40 41 @Override 41 42 public void importData(List<File> files, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 42 if (null == files || files.isEmpty()) 43 if (null == files || files.isEmpty()) return; 43 44 44 45 for (File file: files) { -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImagePlugin.java
r32402 r33028 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 2 3 … … 29 30 * 30 31 */ 31 public class ImportImagePlugin extends Plugin {32 public class ImportImagePlugin extends Plugin { 32 33 33 34 private static Logger logger; … … 43 44 44 45 // path constants 45 static final String PLUGIN_DIR = Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/"; 46 static final String PLUGINPROPERTIES_PATH = Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/pluginProperties.properties"; 47 static final String PLUGINLIBRARIES_DIR = Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/lib/"; 46 static final String PLUGIN_DIR = 47 Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/"; 48 static final String PLUGINPROPERTIES_PATH = 49 Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/pluginProperties.properties"; 50 static final String PLUGINLIBRARIES_DIR = 51 Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/lib/"; 48 52 static final String PLUGINPROPERTIES_FILENAME = "pluginProperties.properties"; 49 static final String LOGGING_PROPERTIES_FILEPATH = Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/log4j.properties/"; 53 static final String LOGGING_PROPERTIES_FILEPATH = 54 Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/log4j.properties/"; 50 55 51 56 public Properties getPluginProps() { … … 56 61 * constructor 57 62 * 58 * @param info59 63 * @throws IOException if any I/O error occurs 60 64 */ 61 public ImportImagePlugin(PluginInformation info) throws IOException {65 public ImportImagePlugin(PluginInformation info) throws IOException { 62 66 super(info); 63 67 … … 73 77 74 78 // If resources are available load properties from plugin directory 75 if(pluginProps == null || pluginProps.isEmpty()) 76 { 79 if (pluginProps == null || pluginProps.isEmpty()) { 77 80 pluginProps = new Properties(); 78 81 pluginProps.load(new File(PLUGINPROPERTIES_PATH).toURI().toURL().openStream()); … … 103 106 * Checks whether plugin resources are available. 104 107 * If not, start install procedure. 105 * 106 * @throws IOException 107 */ 108 private void checkInstallation() throws IOException 109 { 108 */ 109 private void checkInstallation() throws IOException { 110 110 // check plugin resource state 111 111 boolean isInstalled = true; 112 if (!new File(PLUGINPROPERTIES_PATH).exists()112 if (!new File(PLUGINPROPERTIES_PATH).exists() 113 113 || !new File(PLUGIN_DIR).exists() 114 114 || !new File(PLUGINLIBRARIES_DIR).exists()) … … 123 123 // check if plugin directory exist 124 124 File pluginDir = new File(PLUGIN_DIR); 125 if (!pluginDir.exists()){125 if (!pluginDir.exists()) { 126 126 Utils.mkDirs(pluginDir); 127 127 } … … 129 129 // check if "lib" directory exist 130 130 File libDir = new File(PLUGINLIBRARIES_DIR); 131 if (!libDir.exists()){131 if (!libDir.exists()) { 132 132 Utils.mkDirs(libDir); 133 133 } … … 136 136 if (pluginProps == null || pluginProps.isEmpty()) { 137 137 try (FileWriter fw = new FileWriter(new File(PLUGINPROPERTIES_PATH))) { 138 139 140 141 138 URL propertiesURL = pluginClassLoader.getResource("resources/" + PLUGINPROPERTIES_FILENAME); 139 pluginProps = new Properties(); 140 pluginProps.load(propertiesURL.openStream()); 141 pluginProps.store(fw, null); 142 142 } 143 143 logger.debug("Plugin properties loaded"); … … 146 146 if (!new File(LOGGING_PROPERTIES_FILEPATH).exists()) { 147 147 try (FileWriter fw = new FileWriter(new File(LOGGING_PROPERTIES_FILEPATH))) { 148 149 150 151 148 URL propertiesURL = pluginClassLoader.getResource("resources/log4j.properties"); 149 Properties loggingProps = new Properties(); 150 loggingProps.load(propertiesURL.openStream()); 151 loggingProps.store(fw, null); 152 152 } 153 153 logger.debug("Logging properties created"); … … 160 160 /** 161 161 * Initialize logger using plugin classloader. 162 *163 * @param cl164 162 */ 165 163 private void initializeLogger(ClassLoader cl) { … … 207 205 /** 208 206 * get a plugin-specific classloader. 209 * 210 * @return 211 * @throws MalformedURLException 212 */ 213 private ClassLoader createPluginClassLoader() throws MalformedURLException 214 { 207 */ 208 private ClassLoader createPluginClassLoader() throws MalformedURLException { 215 209 ClassLoader loader = null; 216 210 loader = URLClassLoader.newInstance( 217 new URL[] { 211 new URL[] {new File(Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin.jar").toURI().toURL()}, 218 212 ImportImagePlugin.class.getClassLoader() 219 213 ); -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/LayerPropertiesDialog.java
r30738 r33028 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 3 2 4 import java.awt.Cursor; 3 5 import java.awt.Dimension; … … 42 44 * 43 45 */ 44 public class LayerPropertiesDialog extends JFrame {46 public class LayerPropertiesDialog extends JFrame { 45 47 46 48 private Vector<String> supportedCRS; … … 194 196 lowerRightValueLabel.setBounds(new Rectangle(210, 315, 134, 16)); 195 197 lowerRightValueLabel.setHorizontalAlignment(SwingConstants.RIGHT); 196 lowerRightValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float)imageLayer.getBbox().getMaxY());198 lowerRightValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float) imageLayer.getBbox().getMaxY()); 197 199 lowerLeftValueLabel = new JLabel(); 198 200 lowerLeftValueLabel.setBounds(new Rectangle(30, 315, 133, 16)); 199 201 lowerLeftValueLabel.setHorizontalAlignment(SwingConstants.LEFT); 200 lowerLeftValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float)imageLayer.getBbox().getMinY());202 lowerLeftValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float) imageLayer.getBbox().getMinY()); 201 203 upperRightValueLabel = new JLabel(); 202 204 upperRightValueLabel.setBounds(new Rectangle(210, 255, 138, 16)); 203 205 upperRightValueLabel.setHorizontalAlignment(SwingConstants.RIGHT); 204 upperRightValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float)imageLayer.getBbox().getMaxY());206 upperRightValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float) imageLayer.getBbox().getMaxY()); 205 207 upperLeftValueLabel = new JLabel(); 206 208 upperLeftValueLabel.setBounds(new Rectangle(30, 255, 133, 16)); 207 209 upperLeftValueLabel.setHorizontalAlignment(SwingConstants.LEFT); 208 upperLeftValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float)imageLayer.getBbox().getMinY());210 upperLeftValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float) imageLayer.getBbox().getMinY()); 209 211 lowerRightLabel = new JLabel(); 210 212 lowerRightLabel.setBounds(new Rectangle(287, 344, 74, 16)); … … 232 234 crsDescription = imageLayer.getBbox().getCoordinateReferenceSystem().getIdentifiers().iterator().next().toString(); 233 235 } catch (Exception e) { 236 Main.debug(e); 234 237 } 235 238 crsValueLabel.setText(crsDescription + "(" + imageLayer.getBbox().getCoordinateReferenceSystem().getName().toString() + ")"); … … 294 297 crsDescription = imageLayer.getSourceRefSys().getIdentifiers().iterator().next().toString(); 295 298 } catch (Exception e) { 299 Main.debug(e); 296 300 } 297 301 currentCRSValueLabel.setText(crsDescription); … … 351 355 okButton.addActionListener(new java.awt.event.ActionListener() { 352 356 @Override 353 public void actionPerformed(java.awt.event.ActionEvent e) { 354 357 public void actionPerformed(java.awt.event.ActionEvent e) { 355 358 setVisible(false); 356 359 dispose(); … … 373 376 searchField.addKeyListener(new java.awt.event.KeyAdapter() { 374 377 @Override 375 378 public void keyTyped(java.awt.event.KeyEvent e) { 376 379 377 380 for (Iterator<String> iterator = supportedCRS.iterator(); iterator.hasNext();) { … … 429 432 useDefaultCRSButton.addActionListener(new java.awt.event.ActionListener() { 430 433 @Override 431 public void actionPerformed(java.awt.event.ActionEvent e) { 432 434 public void actionPerformed(java.awt.event.ActionEvent e) { 433 435 try { 434 436 435 437 setCursor(new Cursor(Cursor.WAIT_CURSOR)); 436 if (PluginOperations.defaultSourceCRS != null){438 if (PluginOperations.defaultSourceCRS != null) { 437 439 imageLayer.resample(PluginOperations.defaultSourceCRS); 438 } else439 {440 JOptionPane.showMessageDialog(getContentPane(),"<html>No default reference system available.<br>Please select one from the list</html>");440 } else { 441 JOptionPane.showMessageDialog(getContentPane(), 442 "<html>No default reference system available.<br>Please select one from the list</html>"); 441 443 } 442 444 … … 450 452 // TODO Auto-generated catch block 451 453 e2.printStackTrace(); 452 } 453 finally{ 454 } finally { 454 455 setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 455 456 } … … 474 475 applySelectedCRSButton.addActionListener(new java.awt.event.ActionListener() { 475 476 @Override 476 477 public void actionPerformed(java.awt.event.ActionEvent e) { 477 478 478 479 String selection = crsJList.getSelectedValue(); … … 496 497 // TODO Auto-generated catch block 497 498 e2.printStackTrace(); 498 } 499 finally{ 499 } finally { 500 500 setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 501 501 } 502 503 504 502 } 505 503 }); … … 521 519 .addActionListener(new java.awt.event.ActionListener() { 522 520 @Override 523 524 525 if (crsJList.getSelectedValue() != null){521 public void actionPerformed(java.awt.event.ActionEvent e) { 522 523 if (crsJList.getSelectedValue() != null) { 526 524 String selection = crsJList.getSelectedValue(); 527 525 String code = selection.substring(selection.indexOf("[-") + 2, selection.indexOf("-]")); … … 531 529 PluginOperations.defaultSourceCRSDescription = selection; 532 530 533 ImportImagePlugin.pluginProps.setProperty("default_crs_eastingfirst", "" + eastingFirstCheckBox.isSelected()); 531 ImportImagePlugin.pluginProps.setProperty("default_crs_eastingfirst", 532 "" + eastingFirstCheckBox.isSelected()); 534 533 ImportImagePlugin.pluginProps.setProperty("default_crs_srid", code); 535 534 try (FileWriter fileWriter = new FileWriter(new File(ImportImagePlugin.PLUGINPROPERTIES_PATH))) { 536 535 ImportImagePlugin.pluginProps.store(fileWriter, null); 537 536 } 538 537 … … 565 564 } 566 565 567 568 569 566 /** 570 567 * Listener setting text in the search field if selection has changed. … … 573 570 class ListSelectionHandler implements ListSelectionListener { 574 571 @Override 575 public void valueChanged(ListSelectionEvent e) { 576 if(e.getValueIsAdjusting()) 577 { 572 public void valueChanged(ListSelectionEvent e) { 573 if (e.getValueIsAdjusting()) { 578 574 searchField.setText(supportedCRS.get(e.getLastIndex())); 579 575 searchField.setEditable(true); -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/LoadImageAction.java
r32402 r33028 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 2 3 … … 29 30 */ 30 31 public LoadImageAction() { 31 super(tr("Import image"), (String) null, tr("Import georeferenced image"), null, true, "importimage/loadimage", true);32 super(tr("Import image"), (String) null, tr("Import georeferenced image"), null, true, "importimage/loadimage", true); 32 33 } 33 34 -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/PluginOperations.java
r31751 r33028 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 2 3 … … 39 40 * 40 41 */ 41 public class PluginOperations {42 public final class PluginOperations { 42 43 43 44 private static final Logger logger = Logger.getLogger(PluginOperations.class); … … 51 52 static String defaultSourceCRSDescription; 52 53 53 54 55 public static enum SUPPORTEDIMAGETYPES { 54 public enum SUPPORTEDIMAGETYPES { 56 55 tiff, tif, jpg, jpeg, bmp, png 57 56 } 58 57 59 public staticenum POSTFIXES_WORLDFILE {58 public enum POSTFIXES_WORLDFILE { 60 59 wld, jgw, jpgw, pgw, pngw, tfw, tifw, bpw, bmpw, 61 }; 60 } 61 62 private PluginOperations() { 63 // Hide default constructor for utilities classes 64 } 62 65 63 66 /** 64 67 * Reprojects a GridCoverage to a given CRS. 65 *66 * @param coverage67 * @param targetCrs68 * @return destination69 * @throws FactoryException70 * @throws NoSuchAuthorityCodeException71 68 */ 72 69 public static GridCoverage2D reprojectCoverage(GridCoverage2D coverage, … … 92 89 /** 93 90 * Creates a org.geotools.coverage.grid.GridCoverage2D from a given file. 94 *95 * @param file96 * @return97 * @throws IOException98 * @throws Exception99 91 */ 100 92 public static GridCoverage2D createGridFromFile(File file, CoordinateReferenceSystem refSys, boolean failIfNoPrjFile) throws IOException { … … 111 103 112 104 /*------- switch for file type -----------*/ 113 if (extension.equalsIgnoreCase(".tif") || extension.equalsIgnoreCase(".tiff")) 114 { 105 if (extension.equalsIgnoreCase(".tif") || extension.equalsIgnoreCase(".tiff")) { 115 106 116 107 // try to read GeoTIFF: … … 119 110 return coverage; 120 111 } catch (DataSourceException dse) { 121 if (!dse.getMessage().contains("Coordinate Reference System is not available")) {112 if (!dse.getMessage().contains("Coordinate Reference System is not available")) { 122 113 dse.printStackTrace(); 123 114 } … … 133 124 for (int i = 0; i < postfixes.length; i++) { 134 125 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]); 135 if (prjFile.exists()) {126 if (prjFile.exists()) { 136 127 tfwReader = new WorldFileReader(prjFile); 137 128 } … … 162 153 double lowerLeft_y = tfwReader.getYULC() - height; 163 154 Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height)); 164 165 155 coverage = createGridCoverage(img, bbox, refSys); 166 } 167 // 168 else if (extension.equalsIgnoreCase(".jpg") 169 || extension.equalsIgnoreCase(".jpeg")) 170 { 156 157 } else if (extension.equalsIgnoreCase(".jpg") 158 || extension.equalsIgnoreCase(".jpeg")) { 171 159 String[] postfixes = {"wld", "jgw", "jpgw"}; 172 160 // try to read Worldfile: … … 174 162 for (int i = 0; i < postfixes.length; i++) { 175 163 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]); 176 if (prjFile.exists()) {164 if (prjFile.exists()) { 177 165 tfwReader = new WorldFileReader(prjFile); 178 166 } … … 197 185 double lowerLeft_y = tfwReader.getYULC() - height; 198 186 Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height)); 199 200 187 coverage = createGridCoverage(img, bbox, refSys); 201 } 202 else if(extension.equalsIgnoreCase(".bmp")) 203 { 188 189 } else if (extension.equalsIgnoreCase(".bmp")) { 204 190 String[] postfixes = {"wld", "bmpw", "bpw"}; 205 191 // try to read Worldfile: … … 207 193 for (int i = 0; i < postfixes.length; i++) { 208 194 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]); 209 if (prjFile.exists()) {195 if (prjFile.exists()) { 210 196 tfwReader = new WorldFileReader(prjFile); 211 197 } … … 230 216 double lowerLeft_y = tfwReader.getYULC() - height; 231 217 Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height)); 232 233 218 coverage = createGridCoverage(img, bbox, refSys); 234 } 235 else if(extension.equalsIgnoreCase(".png")) 236 { 219 220 } else if (extension.equalsIgnoreCase(".png")) { 237 221 238 222 String[] postfixes = {"wld", "pgw", "pngw"}; … … 241 225 for (int i = 0; i < postfixes.length; i++) { 242 226 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]); 243 if (prjFile.exists()) {227 if (prjFile.exists()) { 244 228 tfwReader = new WorldFileReader(prjFile); 245 229 } 246 230 } 247 if (tfwReader == null) throw new IOException("No Worldfile found.");231 if (tfwReader == null) throw new IOException("No Worldfile found."); 248 232 249 233 if (refSys == null) { … … 264 248 double lowerLeft_y = tfwReader.getYULC() - height; 265 249 Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height)); 266 267 250 coverage = createGridCoverage(img, bbox, refSys); 268 } 269 else{251 252 } else { 270 253 throw new IOException("Image type not supported. Supported formats are: \n" + 271 254 Arrays.toString(SUPPORTEDIMAGETYPES.values())); … … 279 262 * tries to parse it. 280 263 * 281 *282 264 * @param file image file, not the real world file (will be searched) 283 * @return 284 * @throws IOException 285 */ 286 public static CoordinateReferenceSystem readPrjFile(File file) throws IOException 287 { 288 265 */ 266 public static CoordinateReferenceSystem readPrjFile(File file) throws IOException { 289 267 CoordinateReferenceSystem refSys = null; 290 268 … … 300 278 StringBuilder sb = new StringBuilder(); 301 279 String content = null; 302 while ((content = br.readLine()) != null) {280 while ((content = br.readLine()) != null) { 303 281 sb.append(content); 304 282 } … … 313 291 /** 314 292 * Method for external use. 315 * 316 * @param img 317 * @param bbox 318 * @param crs 319 * @return 320 */ 321 public static GridCoverage2D createGridCoverage(BufferedImage img, Envelope2D bbox, CoordinateReferenceSystem crs) 322 { 293 */ 294 public static GridCoverage2D createGridCoverage(BufferedImage img, Envelope2D bbox, CoordinateReferenceSystem crs) { 323 295 bbox.setCoordinateReferenceSystem(crs); 324 296 return new GridCoverageFactory().create("", img, bbox); … … 328 300 * Method for reading a GeoTIFF file. 329 301 * 330 * @param file331 302 * @param refSys if delivered, the coverage will be forced to use this crs 332 * @return 333 * @throws IOException 334 * @throws FactoryException 335 */ 336 public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException, FactoryException 337 { 303 */ 304 public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException, FactoryException { 338 305 GridCoverage2D coverage = null; 339 306 Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true); 340 if(refSys != null) 341 { 307 if (refSys != null) { 342 308 hints.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, refSys); 343 309 } … … 354 320 /** 355 321 * Loads CRS data from an EPSG database and creates descriptions for each one. 356 * 357 * @param pluginProps 358 * @throws Exception 359 */ 360 public static void loadCRSData(Properties pluginProps) 361 { 322 */ 323 public static void loadCRSData(Properties pluginProps) { 362 324 String defaultcrsString = pluginProps.getProperty("default_crs_srid"); 363 325 … … 375 337 String description = desc.toString() + " [-EPSG:" + string + "-]"; 376 338 crsDescriptions.add(description); 377 if (defaultcrsString != null && defaultcrsString.equalsIgnoreCase("EPSG:" + string)){339 if (defaultcrsString != null && defaultcrsString.equalsIgnoreCase("EPSG:" + string)) { 378 340 boolean isEastingFirst = Boolean.valueOf(pluginProps.getProperty("default_crs_eastingfirst")); 379 341 defaultSourceCRS = CRS.decode("EPSG:" + string, isEastingFirst); -
applications/editors/josm/plugins/ImportImagePlugin/test/unit/org/openstreetmap/josm/plugins/ImportImagePlugin/GeoTiffReaderTest.java
r32674 r33028 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 2 3
Note:
See TracChangeset
for help on using the changeset viewer.