Skip to content

Commit

Permalink
[josm_importimageplugin] add a unit test for geotiff reading
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.openstreetmap.org/applications/editors/josm/plugins@31746 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
  • Loading branch information
don-vip committed Nov 15, 2015
1 parent 7447baf commit d5c3483
Show file tree
Hide file tree
Showing 46 changed files with 961 additions and 47 deletions.
2 changes: 2 additions & 0 deletions ImportImagePlugin/.classpath
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test/unit"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM-GeoTools"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM-jts"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM-log4j"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions ImportImagePlugin/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//test/report=UTF-8
31 changes: 6 additions & 25 deletions ImportImagePlugin/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,10 @@
<!-- ** include targets that all plugins have in common ** -->
<import file="../build-common.xml"/>

<!--
**********************************************************
** compile - complies the source tree
**********************************************************
-->
<target name="compile" depends="init">
<echo message="compiling sources for ${plugin.jar} ... "/>
<javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}" includeantruntime="false">
<classpath>
<pathelement location="${josm}"/>
<fileset dir="../log4j/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"/>
</javac>
</target>

<fileset id="plugin.requires.jars" dir="${plugin.dist.dir}">
<include name="log4j.jar"/>
<include name="jts.jar"/>
<include name="geotools.jar"/>
</fileset>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private Image createImage() throws IOException {
int val = ex.getValue();
if (val == 3) {
logger.debug("No projection and user declined un-projected use");
throw new LayerCreationCancledException();
throw new LayerCreationCanceledException();
}
CoordinateReferenceSystem src = null;
try {
Expand Down Expand Up @@ -326,15 +326,12 @@ public void actionPerformed(ActionEvent arg0) {
layerProps.setLocation(Main.parent.getWidth() / 4 , Main.parent.getHeight() / 4);
layerProps.setVisible(true);
}

}

/**
* Exception which represents that the layer creation has been cancled by the
* user.
*
* Exception which represents that the layer creation has been canceled by the user.
*/
class LayerCreationCancledException extends IOException{
class LayerCreationCanceledException extends IOException{
}

public CoordinateReferenceSystem getSourceRefSys() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.openstreetmap.josm.gui.progress.ProgressMonitor;
import org.openstreetmap.josm.io.IllegalDataException;
import org.openstreetmap.josm.io.FileImporter;
import org.openstreetmap.josm.plugins.ImportImagePlugin.ImageLayer.LayerCreationCancledException;
import org.openstreetmap.josm.plugins.ImportImagePlugin.ImageLayer.LayerCreationCanceledException;

/**
* Calss to open georeferened image with standard file open dialog
Expand Down Expand Up @@ -46,7 +46,7 @@ public void importData(List<File> files, ProgressMonitor progressMonitor) throws
logger.info("File choosen:" + file);
try {
layer = new ImageLayer(file);
} catch (LayerCreationCancledException e) {
} catch (LayerCreationCanceledException e) {
// if user decides that layer should not be created just return.
continue;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ public ImportImagePlugin(PluginInformation info){
// create new Action for menu entry
loadFileAction = new LoadImageAction();
loadFileAction.setEnabled(true);
MainMenu.add(Main.main.menu.imagerySubMenu, loadFileAction);

// add menu entries
//Main.main.menu.fileMenu.insert(loadFileAction, 8);

//Main.main.menu.fileMenu.insertSeparator(9);
if (Main.main != null) {
MainMenu.add(Main.main.menu.imagerySubMenu, loadFileAction);

// add menu entries
//Main.main.menu.fileMenu.insert(loadFileAction, 8);
//Main.main.menu.fileMenu.insertSeparator(9);
}

ExtensionFileFilter.importers.add(new ImportImageFileImporter());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.openstreetmap.josm.Main;
import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
import org.openstreetmap.josm.plugins.ImportImagePlugin.ImageLayer.LayerCreationCancledException;
import org.openstreetmap.josm.plugins.ImportImagePlugin.ImageLayer.LayerCreationCanceledException;


/**
Expand Down Expand Up @@ -45,7 +45,7 @@ public void actionPerformed(ActionEvent arg0) {
logger.info("File choosen:" + fc.getSelectedFile());
try {
layer = new ImageLayer(fc.getSelectedFile());
} catch (LayerCreationCancledException e) {
} catch (LayerCreationCanceledException e) {
// if user decides that layer should not be created just return.
return;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public static GridCoverage2D createGridFromFile(File file, CoordinateReferenceSy
}

BufferedImage img = ImageIO.read(file);
if (img == null) {
throw new IOException("Cannot read image file " + file.getAbsolutePath());
}

// create Envelope
double width = img.getWidth() * tfwReader.getXPixelSize();
Expand Down Expand Up @@ -335,14 +338,13 @@ public static GridCoverage2D createGridCoverage(BufferedImage img, Envelope2D bb
public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException, FactoryException
{
GridCoverage2D coverage = null;
Hints hints = new Hints();
Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true);
if(refSys != null)
{
hints.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, refSys);

}
// dont't use the EPSG-Factory because of wrong behaviour
hints.put(Hints.CRS_AUTHORITY_FACTORY, CRS.getAuthorityFactory(true));
// don't use the EPSG-Factory because of wrong behaviour
//hints.put(Hints.CRS_AUTHORITY_FACTORY, CRS.getAuthorityFactory(true));

GeoTiffReader reader = new GeoTiffReader(file, hints);

Expand All @@ -351,9 +353,8 @@ public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem re
return coverage;
}


/**
* Loads CRS data from an EPSG database and creates descrptions for each one.
* Loads CRS data from an EPSG database and creates descriptions for each one.
*
* @param pluginProps
* @throws Exception
Expand Down
23 changes: 23 additions & 0 deletions ImportImagePlugin/test/data/geotiff/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
GeoTIFF Samples
===============

The following directories contain GeoTIFF samples from a variety of
sources. Just because a file is in this tree does not imply that
it follows the standard correctly, or should be considered an
example of good practice. However, a reader that aims for flexibility
would be well advised to try and handle virtually all these files
gracefully.

Most of the TIFF files have an .lgo file associated with them. This
is the output of listgeo for that file. This includes the normalized
form of the underlying projection and when possible the corners
reprojected into lat/long. The reprojection output of listgeo should
not be considered authoritative. If you believe that the reprojected
results for any of the files is wrong, please contact me.

Over time I intend to prepare a set of samples which can be considered
``best practice'', and which can be used as authoritative examples.
Any assistance in this task would be appreciated.

If you have additional samples you would like to submit to this archive
please contact me at [email protected] (or [email protected]).
42 changes: 42 additions & 0 deletions ImportImagePlugin/test/data/geotiff/spot/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
The following images are GeoTIFF samples. These are SPOT Imagery
data of downtown Chicago, IL (USA) at 10 meter resolution.
There are two GeoTIFF images as follows:

SP27GTIF TIF 652094 bytes
UTM2GTIF TIF 650463 bytes

One is in State Plane NAD 1927 projected coordinate systems.
The Other is in Universal Transverse Mercator proj coord system.

These were constructed using the following GeoTIFF parser metadata files:

SP27GTIF TXT 732 bytes
UTM2GTIF TXT 729 bytes

These TXT files are in the format compliant with Niles Ritter's
"LibGeoTIFF" parsing software.

For your reference, I included two of the SPOT "GeoSPOT" format
header files to provide more information about these images.
This is all ASCII readable and provided just for reference, in
case you need to see what we intended the GeoTIFF images to contain.

These images have been enhanced by contrast optimization and a light
Laplace spatial filter. So, you should be able to see them immediately
without further processing, in your display environment. If you can't
see them right away, it's not because they need stretching or brightening
but probably there is a problem with the display software.

Please contact me if you have questions about these images or
their attributes. My name is Mike Ruth, and the following
contact information may be used:

-------------
Mike Ruth [[email protected]]
SPOT Image Corporation
Manager, Product Development
voice: 703) 715-3146
fax: 703) 648-1813
------------

Thanks for your interest in GeoTIFF. ... 6 OCT 95
43 changes: 43 additions & 0 deletions ImportImagePlugin/test/data/geotiff/spot/SP27GTIF.hdr
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
!
! GIS-GEOSPOT Header File
!
! Image Information
!
DELTA_X_ORIGIN 0.0 FT
DELTA_Y_ORIGIN 0.0 FT
MAPUNITS FEET
ULXMAP 681451.44 FT
ULYMAP 1913050.20 FT
XDIM 32.8 FT
YDIM 32.8 FT
NCOLS 700
NROWS 930
NBANDS 1
!
! Frame Corner Support
!
NW_X_PIXEL 1
NW_Y_PIXEL 6
NE_X_PIXEL 692
NE_Y_PIXEL 1
SW_X_PIXEL 8
SW_Y_PIXEL 930
SE_X_PIXEL 700
SE_Y_PIXEL 926
!
! File Encoding
!
NBITS 8
BYTEORDER I
SKIPBYTES 0
RECORDSKIPBYTES 0
BANDROWBYTES 700
TOTALROWBYTES 700
LAYOUT BIL
BAND_RGB 1 1 1
!
! Process Information
!
PRE_PROCESSING_LEVEL "2b"
!
! End of File
91 changes: 91 additions & 0 deletions ImportImagePlugin/test/data/geotiff/spot/SP27GTIF.rep
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
!
! GIS-GEOSPOT Report File
!
! Product Identification
!
MAP_NUMBER "St27pan5"
PRODUCTION_DATE 1995-09-06
MAP_NAME "Chicago Loop"
LOCATION "Chicago, IL"
!
! Geospot Structure
!
GEOSPOT_N_FILES 8
!
FILE_NAME_001 SPCS27.REP
FILE_FORMAT_001 GEOSPOT 4.0
FILE_THEME_001 "Geospot report file"
!
FILE_NAME_002 COPYRITE.T01
FILE_FORMAT_002 TEXT 1.0
FILE_THEME_002 "Copyright file"
!
FILE_NAME_003 SPCS27.HDR
FILE_FORMAT_003 GEOSPOT 4.0
FILE_THEME_003 "Image header file"
!
FILE_NAME_004 SPCS27.BIL
FILE_FORMAT_004 GEOSPOT 4.0
FILE_THEME_004 "Image file"
!
FILE_NAME_005 SPCS27.STX
FILE_FORMAT_005 GEOSPOT 4.0
FILE_THEME_005 "Image statistics file"
!
FILE_NAME_006 SPCS27.CLR
FILE_FORMAT_006 GEOSPOT 4.0
FILE_THEME_006 "Image palette file"
!
FILE_NAME_007 SPCS27.RSC
FILE_FORMAT_007 GEOSPOT 4.0
FILE_THEME_007 "Image source file"
!
FILE_NAME_008 QCK_LOOK.TIF
FILE_FORMAT_008 TIFF 6.0
FILE_THEME_008 "Quick-look file"
!
!
! Cartographic Parameters
!
PROJ_ID "State Plane Coordinate System 1927"
PROJ_ZONE 1201
PROJ_CODE 2 USGS
HORIZ_DATUM "North American 1927"
SPHEROID_NAME "Clarke 1866"
SPHEROID_MAJ_AXIS 6378206.4 M
SPHEROID_FLAT 294.9786982
!
! Framing Information
!
SHEET_RECT_TYPE SINGLE
SHEET_RECT_ELEVATION 50.0 M
EASTING_SIZE 0.083333 DEG
NORTHING_SIZE 0.083333 DEG
NW_LON -87.666667 DEG
NW_LAT 41.916667 DEG
NE_LON -87.583333 DEG
NE_LAT 41.916667 DEG
SW_LON -87.666667 DEG
SW_LAT 41.833333 DEG
SE_LON -87.583333 DEG
SE_LAT 41.833333 DEG
NW_X_COORD 681451.53 FT
NW_Y_COORD 1912895.78 FT
NE_X_COORD 704132.98 FT
NE_Y_COORD 1913083.12 FT
SW_X_COORD 681687.39 FT
SW_Y_COORD 1882529.60 FT
SE_X_COORD 704398.33 FT
SE_Y_COORD 1882716.88 FT
GRID_DECLINATION -0.4728 DEG
!
! Raster Frame Information
!
PIXEL_ROTATION_SIN 0.0
PIXEL_ROTATION_COS 1.0
RASTER_X_ORIGIN 681451.44 FT
RASTER_Y_ORIGIN 1913050.20 FT
RASTER_X_SIZE 22965.6 FT
RASTER_Y_SIZE 30511.4 FT
!
! End of File
Binary file not shown.
Loading

0 comments on commit d5c3483

Please sign in to comment.