Skip to content

Commit

Permalink
[josm_importimage] Major refactoring/update of COTS in order to rely …
Browse files Browse the repository at this point in the history
…on GeoTools plugin

git-svn-id: http://svn.openstreetmap.org/applications/editors/josm/plugins@28954 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
  • Loading branch information
don-vip committed Nov 18, 2012
1 parent a686246 commit 1181d6f
Show file tree
Hide file tree
Showing 33 changed files with 82 additions and 156 deletions.
62 changes: 31 additions & 31 deletions ImportImagePlugin/.classpath
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/commons-beanutils-1.7.0.jar"/>
<classpathentry kind="lib" path="lib/commons-pool-1.5.3.jar"/>
<classpathentry kind="lib" path="lib/geoapi-2.3-M1.jar"/>
<classpathentry kind="lib" path="lib/geoapi-pending-2.3-M1.jar"/>
<classpathentry kind="lib" path="lib/geoapi.jar"/>
<classpathentry kind="lib" path="lib/gt-api-2.6.0.jar"/>
<classpathentry kind="lib" path="lib/gt-coverage-2.6.0.jar"/>
<classpathentry kind="lib" path="lib/gt-epsg-extension-2.6.0.jar"/>
<classpathentry kind="lib" path="lib/gt-epsg-hsql-2.6.0.jar"/>
<classpathentry kind="lib" path="lib/gt-geotiff-2.6.0.jar"/>
<classpathentry kind="lib" path="lib/gt-main-2.6.0.jar"/>
<classpathentry kind="lib" path="lib/gt-metadata-2.6.0.jar"/>
<classpathentry kind="lib" path="lib/gt-referencing-2.6.0.jar"/>
<classpathentry kind="lib" path="lib/hsqldb-1.8.0.7.jar"/>
<classpathentry kind="lib" path="lib/imageio-ext-tiff-1.0.4.jar"/>
<classpathentry kind="lib" path="lib/imageio-ext-utilities-1.0.4.jar"/>
<classpathentry kind="lib" path="lib/jai_codec-1.1.3.jar"/>
<classpathentry kind="lib" path="lib/jai_core.jar"/>
<classpathentry kind="lib" path="lib/jai_imageio-1.1.jar"/>
<classpathentry kind="lib" path="lib/jdom-1.0.jar"/>
<classpathentry kind="lib" path="lib/jsr-275-1.0-beta-2.jar"/>
<classpathentry kind="lib" path="lib/jts-1.10.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.12.jar"/>
<classpathentry kind="lib" path="lib/vecmath-1.3.2.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM-GeoTools"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM-jts"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/commons-beanutils-1.7.0.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/commons-pool-1.5.4.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/hsqldb-1.8.0.7.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/jai_codec-1.1.3.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/jai_core-1.1.3.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/jai_imageio-1.1.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/jdom-1.0.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/jsr-275-1.0-beta-2.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/vecmath-1.3.2.jar"/>
<classpathentry kind="lib" path="/JOSM-jts/lib/jts-1.12.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/gt-api-8.3.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/gt-coverage-8.3.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/gt-epsg-extension-8.3.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/gt-epsg-hsql-8.3.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/gt-geotiff-8.3.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/gt-main-8.3.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/gt-metadata-8.3.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/gt-referencing-8.3.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/imageio-ext-tiff-1.1.5.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/imageio-ext-utilities-1.1.5.jar"/>
<classpathentry kind="lib" path="/JOSM-GeoTools/lib/gt-opengis-8.3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
34 changes: 17 additions & 17 deletions ImportImagePlugin/.project
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ImportImagePlugin</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>JOSM-ImportImage</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions ImportImagePlugin/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
40 changes: 10 additions & 30 deletions ImportImagePlugin/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<property name="plugin.src.dir" value="src"/>
<!-- this is the directory where the plugin jar is copied to -->
<property name="plugin.dist.dir" value="../../dist"/>
<property name="ant.build.javac.target" value="1.5"/>
<property name="ant.build.javac.target" value="1.6"/>
<property name="plugin.dist.dir" value="../../dist"/>
<property name="plugin.jar" value="${plugin.dist.dir}/${ant.project.name}.jar"/>

Expand All @@ -64,12 +64,18 @@
-->
<target name="compile" depends="init">
<echo message="compiling sources for ${plugin.jar} ... "/>
<javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}">
<javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}" includeantruntime="false">
<classpath>
<pathelement location="${josm}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="../jts/lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="../geotools/lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
<compilerarg value="-Xlint:deprecation"/>
<compilerarg value="-Xlint:unchecked"/>
Expand All @@ -84,14 +90,7 @@
<target name="dist" depends="compile,revision">
<echo message="creating ${ant.project.name}.jar ... "/>

<copy todir="${plugin.build.dir}/lib">
<fileset dir="lib">
<not>
<filename name="log4j-1.2.12.jar"/>
</not>
</fileset>
</copy>
<unjar src="lib/log4j-1.2.12.jar" dest="${plugin.build.dir}"/>
<unjar src="lib/log4j-1.2.17.jar" dest="${plugin.build.dir}"/>
<copy todir="${plugin.build.dir}/images">
<fileset dir="images"/>
</copy>
Expand Down Expand Up @@ -123,6 +122,7 @@
<attribute name="Plugin-Icon" value="images/layericon.png"/>
<attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/ImportImagePlugin"/>
<attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
<attribute name="Plugin-Requires" value="geotools"/>
<attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
</manifest>
</jar>
Expand Down Expand Up @@ -272,24 +272,4 @@
<target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">
</target>

<target name="unjar-test" >
<!--unjar dest="C:/Workspace_2/geotoolstest/lib/unjartest">
<fileset dir="lib"/>
</unjar-->

<jar destfile="C:/Workspace_2/geotoolstest/lib/unjartest/${ant.project.name}.jar" basedir="C:/Workspace_2/geotoolstest/lib/unjartest">

<manifest>
<attribute name="Author" value="Christoph Beekmans, Fabian Kowitz, Anna Robaszkiewicz, Oliver Kuhn, Martin Ulitzny"/>
<attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.CoveragePlugin.CoveragePlugin"/>
<attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
<attribute name="Plugin-Description" value="Plugin for importing spatial referenced images"/>
<attribute name="Plugin-Link" value="..."/>
<attribute name="Plugin-Mainversion" value=".."/>
<attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
<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" />
</manifest>
</jar>
</target>

</project>
Binary file removed ImportImagePlugin/lib/commons-beanutils-1.7.0.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/commons-pool-1.5.3.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/geoapi-2.3-M1.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/geoapi-pending-2.3-M1.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/geoapi.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/gt-api-2.6.0.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/gt-coverage-2.6.0.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/gt-epsg-extension-2.6.0.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/gt-epsg-hsql-2.6.0.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/gt-geotiff-2.6.0.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/gt-main-2.6.0.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/gt-metadata-2.6.0.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/gt-referencing-2.6.0.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/hsqldb-1.8.0.7.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/imageio-ext-tiff-1.0.4.jar
Binary file not shown.
Binary file not shown.
Binary file removed ImportImagePlugin/lib/jai_codec-1.1.3.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/jai_core.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/jai_imageio-1.1.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/jdom-1.0.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/jsr-275-1.0-beta-2.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/jts-1.10.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/log4j-1.2.12.jar
Binary file not shown.
Binary file added ImportImagePlugin/lib/log4j-1.2.17.jar
Binary file not shown.
Binary file removed ImportImagePlugin/lib/vecmath-1.3.2.jar
Binary file not shown.
1 change: 0 additions & 1 deletion ImportImagePlugin/resources/pluginProperties.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
default_crs_srid=EPSG\:31467
default_crs_eastingfirst=true
libraries=commons-beanutils-1.7.0.jar,commons-pool-1.5.3.jar,geoapi-2.3-M1.jar,geoapi-pending-2.3-M1.jar,gt-api-2.6.0.jar,gt-coverage-2.6.0.jar,gt-epsg-hsql-2.6.0.jar,gt-geotiff-2.6.0.jar,gt-main-2.6.0.jar,gt-metadata-2.6.0.jar,gt-referencing-2.6.0.jar,hsqldb-1.8.0.7.jar,imageio-ext-tiff-1.0.4.jar,imageio-ext-utilities-1.0.4.jar,jai_codec-1.1.3.jar,jai_core.jar,jai_imageio-1.1.jar,jdom-1.0.jar,jsr-275-1.0-beta-2.jar,jts-1.10.jar,vecmath-1.3.2.jar
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import java.io.IOException;

import javax.media.jai.PlanarImage;
import javax.swing.Action;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;

Expand All @@ -28,7 +28,6 @@
import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.ProjectionBounds;
import org.openstreetmap.josm.data.coor.EastNorth;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
import org.openstreetmap.josm.gui.ExtendedDialog;
import org.openstreetmap.josm.gui.MapView;
Expand Down Expand Up @@ -207,7 +206,12 @@ public void paint(Graphics2D g2, MapView mv, Bounds bounds) {
g.scale(scalex, scaley);

// Draw picture
g.drawImage(image, 0, 0, null);
try {
g.drawImage(image, 0, 0, null);
} catch (ArrayIndexOutOfBoundsException e) {
// TODO: prevents this to happen when displaying GeoTIFF images (see #7902)
e.printStackTrace();
}

} else {
logger.error("Error while dawing image: image == null or Graphics == null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,6 @@ public ImportImagePlugin(PluginInformation info){
logger.debug("Plugin properties loaded");
}

/* Change class path:
* Use java reflection methods to add URLs to the class-path.
* Changes take effect when calling methods of other plugin classes
* (new threads)
* */
URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
String[] libraryNames = pluginProps.getProperty("libraries").split(",");
Class<URLClassLoader> sysclass = URLClassLoader.class;
Method method = sysclass.getDeclaredMethod("addURL", new Class[]{URL.class});
method.setAccessible(true);
for (int i = 0; i < libraryNames.length; i++) {
File library = new File(PLUGINLIBRARIES_DIR + "/" + libraryNames[i]);
method.invoke(sysLoader, new Object[]{library.toURI().toURL()});
}


// load information about supported reference systems
PluginOperations.loadCRSData(pluginProps);

Expand All @@ -113,7 +97,6 @@ public ImportImagePlugin(PluginInformation info){
Main.main.menu.fileMenu.insert(loadFileAction, 8);
Main.main.menu.fileMenu.insertSeparator(9);


} catch (Exception e) {
logger.fatal("Error while loading plugin", e);
try {
Expand All @@ -124,7 +107,6 @@ public ImportImagePlugin(PluginInformation info){
}

logger.info("Plugin successfully loaded.");

}

/**
Expand All @@ -135,7 +117,6 @@ public ImportImagePlugin(PluginInformation info){
*/
private void checkInstallation() throws IOException
{

// check plugin resource state
boolean isInstalled = true;
if(!new File(PLUGINPROPERTIES_PATH).exists()
Expand Down Expand Up @@ -185,42 +166,6 @@ private void checkInstallation() throws IOException
logger.debug("Logging properties created");
}


// Copy all needed JAR files to $PLUGIN_DIR$/lib/
String[] libStrings = pluginProps.getProperty("libraries").split(",");

for (int i = 0; i < libStrings.length; i++) {

URL url = pluginClassLoader.getResource("lib/" + libStrings[i]);

FileOutputStream out = null;

try{
out = new FileOutputStream(new File(libDir, libStrings[i]));
} catch (FileNotFoundException e) {
break;
}

BufferedInputStream in = null;
try
{
in = new BufferedInputStream(url.openStream());

byte[] buffer = new byte[1024];
while (true)
{
int count = in.read(buffer);
if (count == -1)
break;
out.write(buffer, 0, count);
}
}
finally
{
if (in != null)
in.close();
}
}
logger.debug("Plugin successfully installed");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,20 @@
import org.apache.log4j.Logger;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridCoverageFactory;
import org.geotools.coverage.processing.DefaultProcessor;
import org.geotools.coverage.processing.CoverageProcessor;
import org.geotools.data.DataSourceException;
import org.geotools.data.WorldFileReader;
import org.geotools.factory.Hints;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.geometry.Envelope2D;
import org.geotools.image.jai.Registry;
import org.geotools.referencing.CRS;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.metadata.content.ImageDescription;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CRSAuthorityFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.opengis.util.InternationalString;



/**
* Class provides methods for resampling operations, IO and stores important data.
*
Expand Down Expand Up @@ -83,14 +77,12 @@ public static GridCoverage2D reprojectCoverage(GridCoverage2D coverage,

GridCoverage2D destination = null;

DefaultProcessor processor = new DefaultProcessor(null);
ParameterValueGroup resampleParams = processor.getOperation("Resample")
.getParameters();
CoverageProcessor processor = new CoverageProcessor();
ParameterValueGroup resampleParams = processor.getOperation("Resample").getParameters();

// set parameters
resampleParams.parameter("Source").setValue(coverage);
resampleParams.parameter("CoordinateReferenceSystem").setValue(
targetCrs);
resampleParams.parameter("CoordinateReferenceSystem").setValue(targetCrs);

// resample coverage with given parameters
destination = (GridCoverage2D) processor.doOperation(resampleParams);
Expand Down Expand Up @@ -379,29 +371,24 @@ public static void loadCRSData(Properties pluginProps)
Set<String> supportedCodes = CRS.getSupportedCodes("EPSG");
CRSAuthorityFactory fac = CRS.getAuthorityFactory(false);

for (Iterator iterator = supportedCodes.iterator(); iterator.hasNext();) {
for (Iterator<String> iterator = supportedCodes.iterator(); iterator.hasNext();) {
String string = (String) iterator.next();
try {
if ("WGS84(DD)".equals(string)) {
continue;
}
InternationalString desc = fac.getDescriptionText("EPSG:" + string);

String description = desc.toString() + " [-EPSG:" + string + "-]";

crsDescriptions.add(description);

if(defaultcrsString != null && defaultcrsString.equalsIgnoreCase("EPSG:" + string)){
boolean isEastingFirst = Boolean.valueOf(pluginProps.getProperty("default_crs_eastingfirst"));
defaultSourceCRS = CRS.decode("EPSG:" + string, isEastingFirst);
defaultSourceCRSDescription = description;
}
} catch (NoSuchAuthorityCodeException e) {
logger.error("Error while loading EPSG data: " + e.getMessage());

} catch (FactoryException e) {
logger.error("Error while loading EPSG data: " + e.getMessage());
}
}
}

}

0 comments on commit 1181d6f

Please sign in to comment.