Changeset 26413 in osm for applications/editors/josm/plugins/ImportImagePlugin
- Timestamp:
- 2011-07-28T23:31:27+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/ImportImagePlugin
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ImportImagePlugin/build.xml
r26174 r26413 1 <?xml version="1.0" encoding=" utf-8"?>1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <!-- 3 3 ** This is a template build file for a JOSM plugin. … … 29 29 --> 30 30 <project name="ImportImagePlugin" default="dist" basedir="."> 31 <!-- enter the SVN commit message --> 32 <property name="commit.message" value="use consistent plugin name (don't mix up the words)"/> 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 <property name="plugin.main.version" value="4065"/> 35 <!-- 31 32 <!-- enter the SVN commit message --> 33 <property name="commit.message" value="use consistent plugin name (don't mix up the words)" /> 34 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 35 <property name="plugin.main.version" value="3376" /> 36 37 38 <!-- 36 39 ************************************************ 37 40 ** should not be necessary to change the following properties 38 41 --> 39 <property name="josm" location="../../core/dist/josm-custom.jar"/> 40 <property name="plugin.build.dir" value="build"/> 41 <property name="plugin.src.dir" value="src"/> 42 <!-- this is the directory where the plugin jar is copied to --> 43 <property name="plugin.dist.dir" value="../../dist"/> 44 <property name="ant.build.javac.target" value="1.5"/> 45 <property name="plugin.dist.dir" value="../../dist"/> 46 <property name="plugin.jar" value="${plugin.dist.dir}/${ant.project.name}.jar"/> 47 <!-- 42 <property name="josm" location="../../core/dist/josm-custom.jar"/> 43 <property name="plugin.build.dir" value="build"/> 44 <property name="plugin.src.dir" value="src"/> 45 <!-- this is the directory where the plugin jar is copied to --> 46 <property name="plugin.dist.dir" value="../../dist"/> 47 <property name="ant.build.javac.target" value="1.5"/> 48 <property name="plugin.dist.dir" value="../../dist"/> 49 <property name="plugin.jar" value="${plugin.dist.dir}/${ant.project.name}.jar"/> 50 51 <!-- 48 52 ********************************************************** 49 53 ** init - initializes the build 50 54 ********************************************************** 51 55 --> 52 <target name="init"> 53 <mkdir dir="${plugin.build.dir}"/> 54 </target> 55 <!-- 56 <target name="init"> 57 <mkdir dir="${plugin.build.dir}"/> 58 </target> 59 60 <!-- 56 61 ********************************************************** 57 62 ** compile - complies the source tree 58 63 ********************************************************** 59 64 --> 60 61 62 65 <target name="compile" depends="init"> 66 <echo message="compiling sources for ${plugin.jar} ... "/> 67 <javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}"> 63 68 <classpath> 64 69 <pathelement location="${josm}"/> … … 67 72 </fileset> 68 73 </classpath> 69 <compilerarg value="-Xlint:deprecation"/> 70 <compilerarg value="-Xlint:unchecked"/> 71 </javac> 72 </target> 73 <!-- 74 <compilerarg value="-Xlint:deprecation"/> 75 <compilerarg value="-Xlint:unchecked"/> 76 </javac> 77 </target> 78 79 <!-- 74 80 ********************************************************** 75 81 ** dist - creates the plugin jar 76 82 ********************************************************** 77 83 --> 78 <target name="dist" depends="compile,revision"> 79 <echo message="creating ${ant.project.name}.jar ... "/> 80 <copy todir="${plugin.build.dir}/lib"> 81 <fileset dir="lib"> 82 <not> 83 <filename name="log4j-1.2.12.jar"/> 84 </not> 85 </fileset> 86 </copy> 84 <target name="dist" depends="compile,revision"> 85 <echo message="creating ${ant.project.name}.jar ... "/> 86 87 <copy todir="${plugin.build.dir}/lib"> 88 <fileset dir="lib"> 89 <not> 90 <filename name="log4j-1.2.12.jar"/> 91 </not> 92 </fileset> 93 </copy> 87 94 <unjar src="lib/log4j-1.2.12.jar" dest="${plugin.build.dir}"/> 88 <copy todir="${plugin.build.dir}/images"> 89 <fileset dir="images"/> 90 </copy> 91 <copy todir="${plugin.build.dir}/data"> 92 <fileset dir="data"/> 93 </copy> 94 <copy todir="${plugin.build.dir}/resources"> 95 <fileset dir="resources"/> 96 </copy> 97 <copy todir="${plugin.build.dir}"> 98 <fileset dir="."> 99 <include name="README"/> 100 <include name="LICENSE"/> 101 </fileset> 102 </copy> 103 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}"> 104 <!-- 95 <copy todir="${plugin.build.dir}/images"> 96 <fileset dir="images"/> 97 </copy> 98 <copy todir="${plugin.build.dir}/resources"> 99 <fileset dir="resources"/> 100 </copy> 101 <copy todir="${plugin.build.dir}"> 102 <fileset dir="."> 103 <include name="README" /> 104 <include name="LICENSE" /> 105 </fileset> 106 </copy> 107 108 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}"> 109 <!-- 105 110 ************************************************ 106 111 ** configure these properties. Most of them will be copied to the plugins … … 110 115 ************************************************ 111 116 --> 112 <manifest> 117 118 <manifest> 113 119 <attribute name="Author" value="Christoph Beekmans, Fabian Kowitz, Anna Robaszkiewicz, Oliver Kuhn, Martin Ulitzny"/> 114 120 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.ImportImagePlugin.ImportImagePlugin"/> … … 118 124 <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> 119 125 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 120 </manifest> 121 </jar> 122 </target> 123 <!-- 126 </manifest> 127 </jar> 128 </target> 129 130 <!-- 124 131 ********************************************************** 125 132 ** revision - extracts the current revision number for the … … 128 135 ********************************************************** 129 136 --> 130 <target name="revision"> 131 <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false"> 132 <env key="LANG" value="C"/> 133 <arg value="info"/> 134 <arg value="--xml"/> 135 <arg value="."/> 136 </exec> 137 <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true"/> 138 <delete file="REVISION"/> 139 </target> 140 <!-- 137 <target name="revision"> 138 139 <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false"> 140 <env key="LANG" value="C"/> 141 <arg value="info"/> 142 <arg value="--xml"/> 143 <arg value="."/> 144 </exec> 145 <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true"/> 146 <delete file="REVISION"/> 147 </target> 148 149 <!-- 141 150 ********************************************************** 142 151 ** clean - clean up the build environment 143 152 ********************************************************** 144 153 --> 145 <target name="clean"> 146 <delete dir="${plugin.build.dir}"/> 147 <delete file="${plugin.jar}"/> 148 </target> 149 <!-- 154 <target name="clean"> 155 <delete dir="${plugin.build.dir}"/> 156 <delete file="${plugin.jar}"/> 157 </target> 158 159 <!-- 150 160 ********************************************************** 151 161 ** install - install the plugin in your local JOSM installation 152 162 ********************************************************** 153 163 --> 154 <target name="install" depends="dist"> 155 <property environment="env"/> 156 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins"> 157 <and> 158 <os family="windows"/> 159 </and> 160 </condition> 161 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/> 162 </target> 163 <!-- 164 ************************** Publishing the plugin *********************************** 165 --> 166 <!-- 167 ** extracts the JOSM release for the JOSM version in ../core and saves it in the 168 ** property ${coreversion.info.entry.revision} 169 ** 170 --> 171 <target name="core-info"> 172 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false"> 173 <env key="LANG" value="C"/> 174 <arg value="info"/> 175 <arg value="--xml"/> 176 <arg value="../../core"/> 177 </exec> 178 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/> 179 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo> 180 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo> 181 <delete file="core.info.xml"/> 182 </target> 183 <!-- 184 ** commits the source tree for this plugin 185 --> 186 <target name="commit-current"> 187 <echo>Commiting the plugin source with message '${commit.message}' ...</echo> 188 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 189 <env key="LANG" value="C"/> 190 <arg value="commit"/> 191 <arg value="-m '${commit.message}'"/> 192 <arg value="."/> 193 </exec> 194 </target> 195 <!-- 196 ** updates (svn up) the source tree for this plugin 197 --> 198 <target name="update-current"> 199 <echo>Updating plugin source ...</echo> 200 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 201 <env key="LANG" value="C"/> 202 <arg value="up"/> 203 <arg value="."/> 204 </exec> 205 <echo>Updating ${plugin.jar} ...</echo> 206 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 207 <env key="LANG" value="C"/> 208 <arg value="up"/> 209 <arg value="../dist/${plugin.jar}"/> 210 </exec> 211 </target> 212 <!-- 213 ** commits the plugin.jar 214 --> 215 <target name="commit-dist"> 216 <echo> 217 ***** Properties of published ${plugin.jar} ***** 218 Commit message : '${commit.message}' 219 Plugin-Mainversion: ${plugin.main.version} 220 JOSM build version: ${coreversion.info.entry.revision} 221 Plugin-Version : ${version.entry.commit.revision} 222 ***** / Properties of published ${plugin.jar} ***** 223 224 Now commiting ${plugin.jar} ... 225 </echo> 226 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 227 <env key="LANG" value="C"/> 228 <arg value="-m '${commit.message}'"/> 229 <arg value="commit"/> 230 <arg value="${plugin.jar}"/> 231 </exec> 232 </target> 233 <!-- ** make sure svn is present as a command line tool ** --> 234 <target name="ensure-svn-present"> 235 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code"> 236 <env key="LANG" value="C"/> 237 <arg value="--version"/> 238 </exec> 239 <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system."> 240 <!-- return code not set at all? Most likely svn isn't installed --> 241 <condition> 242 <not> 243 <isset property="svn.exit.code"/> 244 </not> 245 </condition> 246 </fail> 247 <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system."> 248 <!-- error code from SVN? Most likely svn is not what we are looking on this system --> 249 <condition> 250 <isfailure code="${svn.exit.code}"/> 251 </condition> 252 </fail> 253 </target> 254 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist"> 255 </target> 256 <target name="unjar-test"> 164 <target name="install" depends="dist"> 165 <property environment="env"/> 166 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins"> 167 <and> 168 <os family="windows"/> 169 </and> 170 </condition> 171 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/> 172 </target> 173 174 175 <!-- 176 ************************** Publishing the plugin *********************************** 177 --> 178 <!-- 179 ** extracts the JOSM release for the JOSM version in ../core and saves it in the 180 ** property ${coreversion.info.entry.revision} 181 ** 182 --> 183 <target name="core-info"> 184 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false"> 185 <env key="LANG" value="C"/> 186 <arg value="info"/> 187 <arg value="--xml"/> 188 <arg value="../../core"/> 189 </exec> 190 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/> 191 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo> 192 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo> 193 <delete file="core.info.xml" /> 194 </target> 195 196 <!-- 197 ** commits the source tree for this plugin 198 --> 199 <target name="commit-current"> 200 <echo>Commiting the plugin source with message '${commit.message}' ...</echo> 201 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 202 <env key="LANG" value="C"/> 203 <arg value="commit"/> 204 <arg value="-m '${commit.message}'"/> 205 <arg value="."/> 206 </exec> 207 </target> 208 209 <!-- 210 ** updates (svn up) the source tree for this plugin 211 --> 212 <target name="update-current"> 213 <echo>Updating plugin source ...</echo> 214 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 215 <env key="LANG" value="C"/> 216 <arg value="up"/> 217 <arg value="."/> 218 </exec> 219 <echo>Updating ${plugin.jar} ...</echo> 220 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 221 <env key="LANG" value="C"/> 222 <arg value="up"/> 223 <arg value="../dist/${plugin.jar}"/> 224 </exec> 225 </target> 226 227 <!-- 228 ** commits the plugin.jar 229 --> 230 <target name="commit-dist"> 231 <echo> 232 ***** Properties of published ${plugin.jar} ***** 233 Commit message : '${commit.message}' 234 Plugin-Mainversion: ${plugin.main.version} 235 JOSM build version: ${coreversion.info.entry.revision} 236 Plugin-Version : ${version.entry.commit.revision} 237 ***** / Properties of published ${plugin.jar} ***** 238 239 Now commiting ${plugin.jar} ... 240 </echo> 241 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 242 <env key="LANG" value="C"/> 243 <arg value="-m '${commit.message}'"/> 244 <arg value="commit"/> 245 <arg value="${plugin.jar}"/> 246 </exec> 247 </target> 248 249 <!-- ** make sure svn is present as a command line tool ** --> 250 <target name="ensure-svn-present"> 251 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code"> 252 <env key="LANG" value="C" /> 253 <arg value="--version" /> 254 </exec> 255 <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system."> 256 <!-- return code not set at all? Most likely svn isn't installed --> 257 <condition> 258 <not> 259 <isset property="svn.exit.code" /> 260 </not> 261 </condition> 262 </fail> 263 <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system."> 264 <!-- error code from SVN? Most likely svn is not what we are looking on this system --> 265 <condition> 266 <isfailure code="${svn.exit.code}" /> 267 </condition> 268 </fail> 269 </target> 270 271 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist"> 272 </target> 273 274 <target name="unjar-test" > 257 275 <!--unjar dest="C:/Workspace_2/geotoolstest/lib/unjartest"> 258 276 <fileset dir="lib"/> 259 277 </unjar--> 260 <jar destfile="C:/Workspace_2/geotoolstest/lib/unjartest/${ant.project.name}.jar" basedir="C:/Workspace_2/geotoolstest/lib/unjartest"> 261 <manifest> 278 279 <jar destfile="C:/Workspace_2/geotoolstest/lib/unjartest/${ant.project.name}.jar" basedir="C:/Workspace_2/geotoolstest/lib/unjartest"> 280 281 <manifest> 262 282 <attribute name="Author" value="Christoph Beekmans, Fabian Kowitz, Anna Robaszkiewicz, Oliver Kuhn, Martin Ulitzny"/> 263 283 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.CoveragePlugin.CoveragePlugin"/> … … 267 287 <attribute name="Plugin-Mainversion" value=".."/> 268 288 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 269 <attribute name="Class-path" value=" . CoveragePlugin/lib/commons-beanutils-1.7.0.jar CoveragePlugin/lib/commons-pool-1.5.3.jar CoveragePlugin/lib/geoapi-2.3-M1.jar CoveragePlugin/lib/geoapi-pending-2.3-M1.jar CoveragePlugin/lib/geoapi.jar CoveragePlugin/lib/gt-api-2.6.0.jar CoveragePlugin/lib/gt-coverage-2.6.0.jar CoveragePlugin/lib/gt-epsg-extension-2.6.0.jar CoveragePlugin/lib/gt-epsg-hsql-2.6.0.jar CoveragePlugin/lib/gt-geotiff-2.6.0.jar CoveragePlugin/lib/gt-main-2.6.0.jar CoveragePlugin/lib/gt-metadata-2.6.0.jar CoveragePlugin/lib/gt-referencing-2.6.0.jar CoveragePlugin/lib/hsqldb-1.8.0.7.jar CoveragePlugin/lib/imageio-ext-tiff-1.0.4.jar CoveragePlugin/lib/imageio-ext-utilities-1.0.4.jar CoveragePlugin/lib/jai_codec-1.1.3.jar CoveragePlugin/lib/jai_core.jar CoveragePlugin/lib/jai_imageio-1.1.jar CoveragePlugin/lib/jdom-1.0.jar CoveragePlugin/lib/jsr-275-1.0-beta-2.jar CoveragePlugin/lib/jts-1.10.jar CoveragePlugin/lib/log4j-1.2.12.jar CoveragePlugin/lib/vecmath-1.3.2.jar"/> 270 </manifest> 271 </jar> 272 </target> 289 <attribute name="Class-path" value=" . CoveragePlugin/lib/commons-beanutils-1.7.0.jar CoveragePlugin/lib/commons-pool-1.5.3.jar CoveragePlugin/lib/geoapi-2.3-M1.jar CoveragePlugin/lib/geoapi-pending-2.3-M1.jar CoveragePlugin/lib/geoapi.jar CoveragePlugin/lib/gt-api-2.6.0.jar CoveragePlugin/lib/gt-coverage-2.6.0.jar CoveragePlugin/lib/gt-epsg-extension-2.6.0.jar CoveragePlugin/lib/gt-epsg-hsql-2.6.0.jar CoveragePlugin/lib/gt-geotiff-2.6.0.jar CoveragePlugin/lib/gt-main-2.6.0.jar CoveragePlugin/lib/gt-metadata-2.6.0.jar CoveragePlugin/lib/gt-referencing-2.6.0.jar CoveragePlugin/lib/hsqldb-1.8.0.7.jar CoveragePlugin/lib/imageio-ext-tiff-1.0.4.jar CoveragePlugin/lib/imageio-ext-utilities-1.0.4.jar CoveragePlugin/lib/jai_codec-1.1.3.jar CoveragePlugin/lib/jai_core.jar CoveragePlugin/lib/jai_imageio-1.1.jar CoveragePlugin/lib/jdom-1.0.jar CoveragePlugin/lib/jsr-275-1.0-beta-2.jar CoveragePlugin/lib/jts-1.10.jar CoveragePlugin/lib/log4j-1.2.12.jar CoveragePlugin/lib/vecmath-1.3.2.jar" /> 290 </manifest> 291 </jar> 292 </target> 293 273 294 </project> -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayer.java
r25934 r26413 4 4 5 5 import java.awt.Component; 6 import java.awt.Color; 6 7 import java.awt.Graphics2D; 7 8 import java.awt.Image; … … 68 69 private CoordinateReferenceSystem sourceRefSys; 69 70 70 71 72 71 /** 73 72 * Constructor … … 82 81 this.image = (BufferedImage) createImage(); 83 82 layericon = new ImageIcon(ImportImagePlugin.pluginClassLoader.getResource("images/layericon.png")); 84 85 83 } 86 84 … … 97 95 try { 98 96 // create a grid coverage from the image 99 coverage = PluginOperations.createGridFromFile(imageFile, null );97 coverage = PluginOperations.createGridFromFile(imageFile, null, true); 100 98 this.sourceRefSys = coverage.getCoordinateReferenceSystem(); 101 99 … … 109 107 if(e.getMessage().contains("No projection file found")) 110 108 { 111 int use DefaultCRS = JOptionPane.showConfirmDialog(Main.parent, "<html>No projection file (.prj) found.<br>Use the default Coordinate Reference System instead?</html>", "Missing projection", JOptionPane.YES_NO_OPTION);112 if (use DefaultCRS == 0)113 {109 int useUnprojected = JOptionPane.showConfirmDialog(Main.parent, "<html>No projection file (.prj) found.<br />Use the image unprojected?</html>", "Missing projection", JOptionPane.YES_NO_OPTION); 110 if (useUnprojected == 0) { // Yes 111 logger.debug("Passing through image un-projected."); 114 112 try { 115 113 // create a grid coverage from the image 116 coverage = PluginOperations.createGridFromFile(imageFile, PluginOperations.defaultSourceCRS);114 coverage = PluginOperations.createGridFromFile(imageFile, null, false); 117 115 this.sourceRefSys = coverage.getCoordinateReferenceSystem(); 118 119 // now reproject grid coverage120 coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(Main.proj.toCode()));121 116 } catch (Exception e1) { 122 117 logger.error("Error while creating GridCoverage:",e1); 123 118 throw new IOException(e1); 124 119 } 125 } 126 else{ 127 logger.debug("Layer creation cancled by user due to missing projection information."); 120 } else { // No 121 logger.debug("No projection and user declined un-projected use"); 128 122 throw new LayerCreationCancledException(); 129 123 } 130 131 124 } 132 125 else … … 140 133 141 134 // TODO 142 upperLeft = new EastNorth(coverage.getEnvelope2D().y, coverage 143 .getEnvelope2D().x 144 + coverage.getEnvelope2D().width); 135 upperLeft = new EastNorth(coverage.getEnvelope2D().x, 136 coverage.getEnvelope2D().y + coverage.getEnvelope2D().height); 145 137 angle = 0; 146 138 bbox = coverage.getEnvelope2D(); … … 163 155 EastNorth center = Main.map.mapView.getCenter(); 164 156 EastNorth leftop = Main.map.mapView.getEastNorth(0, 0); 165 double pixel_per_ lon_degree= (Main.map.mapView.getWidth() / 2.0)157 double pixel_per_east_unit = (Main.map.mapView.getWidth() / 2.0) 166 158 / (center.east() - leftop.east()); 167 double pixel_per_ lat_degree= (Main.map.mapView.getHeight() / 2.0)159 double pixel_per_north_unit = (Main.map.mapView.getHeight() / 2.0) 168 160 / (leftop.north() - center.north()); 169 161 170 162 // This is now the offset in screen pixels 171 double pic_offset_x = ((upperLeft.east() - leftop.east()) * pixel_per_ lon_degree);172 double pic_offset_y = ((leftop.north() - upperLeft.north()) * pixel_per_ lat_degree);163 double pic_offset_x = ((upperLeft.east() - leftop.east()) * pixel_per_east_unit); 164 double pic_offset_y = ((leftop.north() - upperLeft.north()) * pixel_per_north_unit); 173 165 174 166 Graphics2D g = (Graphics2D) g2.create(); … … 187 179 double height = projbounds.maxNorth - projbounds.minNorth; 188 180 189 double ratio_x = (this.bbox.getMax Y() - this.bbox.getMinY())181 double ratio_x = (this.bbox.getMaxX() - this.bbox.getMinX()) 190 182 / width; 191 double ratio_y = (this.bbox.getMax X() - this.bbox.getMinX())183 double ratio_y = (this.bbox.getMaxY() - this.bbox.getMinY()) 192 184 / height; 193 185 … … 199 191 double scaley = pixels4bbox_height / image.getHeight(); 200 192 193 if ((scalex > 10) || (scaley > 10)) { 194 logger.warn("Not drawing image - scale too big"); 195 return; 196 } 201 197 g.scale(scalex, scaley); 202 198 … … 282 278 void resample(CoordinateReferenceSystem refSys) throws IOException, NoSuchAuthorityCodeException, FactoryException 283 279 { 284 285 GridCoverage2D coverage = PluginOperations.createGridFromFile(this.imageFile, refSys );280 logger.debug("resample"); 281 GridCoverage2D coverage = PluginOperations.createGridFromFile(this.imageFile, refSys, true); 286 282 coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(Main.proj.toCode())); 287 283 this.bbox = coverage.getEnvelope2D(); … … 333 329 } 334 330 335 336 337 331 public CoordinateReferenceSystem getSourceRefSys() { 338 332 return sourceRefSys; -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/LoadImageAction.java
r23305 r26413 14 14 import org.openstreetmap.josm.actions.JosmAction; 15 15 import org.openstreetmap.josm.data.Bounds; 16 import org.openstreetmap.josm.data.coor. LatLon;16 import org.openstreetmap.josm.data.coor.EastNorth; 17 17 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 18 18 import org.openstreetmap.josm.plugins.ImportImagePlugin.ImageLayer.LayerCreationCancledException; … … 45 45 ImageLayer layer = null; 46 46 if (result == JFileChooser.APPROVE_OPTION) { 47 logger.info("File choose d:" + fc.getSelectedFile());47 logger.info("File choosen:" + fc.getSelectedFile()); 48 48 try { 49 49 layer = new ImageLayer(fc.getSelectedFile()); … … 51 51 // if user decides that layer should not be created just return. 52 52 return; 53 } catch (Exception e) {53 } catch (Exception e) { 54 54 logger.error("Error while creating image layer: \n" + e.getMessage()); 55 55 JOptionPane.showMessageDialog(null, marktr("Error while creating image layer: " + e.getCause())); … … 60 60 // Add layer: 61 61 Main.main.addLayer(layer); 62 LatLon min = new LatLon(layer.getBbox().getMinX(), layer.getBbox().getMinY());63 LatLon max = new LatLon(layer.getBbox().getMaxX(), layer.getBbox().getMaxY());62 EastNorth min = new EastNorth(layer.getBbox().getMinX(), layer.getBbox().getMinY()); 63 EastNorth max = new EastNorth(layer.getBbox().getMaxX(), layer.getBbox().getMaxY()); 64 64 BoundingXYVisitor boundingXYVisitor = new BoundingXYVisitor(); 65 boundingXYVisitor.visit(new Bounds(min, max)); 65 boundingXYVisitor.visit(min); 66 boundingXYVisitor.visit(max); 66 67 Main.map.mapView.recalculateCenterScale(boundingXYVisitor); 67 Main.map.mapView.zoomTo(new Bounds(min, max));68 68 } 69 69 } -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/PluginOperations.java
r23305 r26413 107 107 * @throws Exception 108 108 */ 109 public static GridCoverage2D createGridFromFile(File file, CoordinateReferenceSystem refSys ) throws IOException{109 public static GridCoverage2D createGridFromFile(File file, CoordinateReferenceSystem refSys, boolean failIfNoPrjFile) throws IOException { 110 110 111 111 GridCoverage2D coverage = null; … … 125 125 126 126 // try to read GeoTIFF: 127 try {127 try { 128 128 coverage = readGeoTiff(file, refSys); 129 129 return coverage; 130 } catch (DataSourceException dse) {131 if (!dse.getMessage().contains("Coordinate Reference System is not available")){130 } catch (DataSourceException dse) { 131 if (!dse.getMessage().contains("Coordinate Reference System is not available")){ 132 132 dse.printStackTrace(); 133 133 } … … 143 143 for (int i = 0; i < postfixes.length; i++) { 144 144 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]); 145 if (prjFile.exists()){145 if (prjFile.exists()){ 146 146 tfwReader = new WorldFileReader(prjFile); 147 147 } 148 148 } 149 if(tfwReader == null){ 149 150 if (tfwReader == null) { 150 151 throw new IOException("No Worldfile found."); 151 152 } 152 153 153 if (refSys == null){154 if (refSys == null) { 154 155 // if no crs is delivered try to read projection file: 155 156 refSys = readPrjFile(file); 156 if(refSys == null) throw new IOException("No projection file found."); 157 if (refSys == null) { 158 if (failIfNoPrjFile) throw new IOException("No projection file found."); 159 logger.debug("no projection given, no projection file found; using unprojected file."); 160 } 157 161 } 158 162 … … 178 182 for (int i = 0; i < postfixes.length; i++) { 179 183 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]); 180 if (prjFile.exists()){184 if (prjFile.exists()){ 181 185 tfwReader = new WorldFileReader(prjFile); 182 186 } 183 187 } 184 if (tfwReader == null) throw new IOException("No Worldfile found.");185 186 if (refSys == null){188 if (tfwReader == null) throw new IOException("No Worldfile found."); 189 190 if (refSys == null) { 187 191 // if no crs is delivered try to read projection file: 188 192 refSys = readPrjFile(file); 189 if(refSys == null) throw new IOException("No projection file found."); 193 if (refSys == null) { 194 if (failIfNoPrjFile) throw new IOException("No projection file found."); 195 logger.debug("no projection given, no projection file found; using unprojected file."); 196 } 190 197 } 191 198 … … 209 216 for (int i = 0; i < postfixes.length; i++) { 210 217 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]); 211 if (prjFile.exists()){218 if (prjFile.exists()){ 212 219 tfwReader = new WorldFileReader(prjFile); 213 220 } 214 221 } 215 if (tfwReader == null) throw new IOException("No Worldfile found.");216 217 if (refSys == null){222 if (tfwReader == null) throw new IOException("No Worldfile found."); 223 224 if (refSys == null) { 218 225 // if no crs is delivered try to read projection file: 219 226 refSys = readPrjFile(file); 220 if(refSys == null) throw new IOException("No projection file found."); 227 if (refSys == null) { 228 if (failIfNoPrjFile) throw new IOException("No projection file found."); 229 logger.debug("no projection given, no projection file found; using unprojected file."); 230 } 221 231 } 222 232 … … 240 250 for (int i = 0; i < postfixes.length; i++) { 241 251 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]); 242 if (prjFile.exists()){252 if (prjFile.exists()){ 243 253 tfwReader = new WorldFileReader(prjFile); 244 254 } … … 246 256 if(tfwReader == null) throw new IOException("No Worldfile found."); 247 257 248 if (refSys == null){258 if (refSys == null) { 249 259 // if no crs is delivered try to read projection file: 250 260 refSys = readPrjFile(file); 251 if(refSys == null) throw new IOException("No projection file found."); 261 if (refSys == null) { 262 if (failIfNoPrjFile) throw new IOException("No projection file found."); 263 logger.debug("no projection given, no projection file found; using unprojected file."); 264 } 252 265 } 253 266 … … 290 303 291 304 File prjFile = new File(prjFilename); 292 if (!prjFile.exists()) throw new IOException("No projection file found (.prj) for image '" + file.getName() + "'");305 if (!prjFile.exists()) return null; 293 306 logger.debug("Loading .prj file: " + prjFile.getAbsolutePath()); 294 307
Note:
See TracChangeset
for help on using the changeset viewer.