Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to display a GeoTiff image with no projection but where the geographical extent (bounding box) is known:

reader= format.getReader(new File(sImageName));
GridCoverage2D gridCoverage= reader.getGridCoverage2D(null);
ReferencedEnvelope referencedEnvelope= new ReferencedEnvelope(-106,
-105,55,56, CRS.decode('EPSG:4326', true));
MapContext map= new DefaultMapContext();
map.setCoordinateReferenceSystem(CRS.decode('EPSG:4326', true));
map.setAreaOfInterest(referencedEnvelope, CRS.decode('EPSG:4326', true));
map.addLayer(reader, rasterStyle);
JMapPane pane= new JMapPane();
pane.setMapContext(map);

It does not work (with GeoTools 2.7.5), I get

java.lang.NullPointerException at org.geotools.swing.JMapPane.setTransforms(JMapPane.java:1114) at org.geotools.swing.JMapPane.doSetDisplayArea(JMapPane.java:607) at org.geotools.swing.JMapPane.doSetMapContext(JMapPane.java:505) at org.geotools.swing.JMapPane.setMapContext(JMapPane.java:472)

It used to work in an earlier version of GeoTools (2.7.2) with a simpler version of the code:

reader= format.getReader(new File(sImageName));
GridCoverage2D gridCoverage= reader.getGridCoverage2D(null);
MapContext map= new DefaultMapContext();
map.addLayer(reader, rasterStyle);
JMapPane pane= new JMapPane();
pane.setMapContext(map);
map.setCoordinateReferenceSystem(CRS.decode('EPSG:4326', true));
share|improve this question
    
I'd break CRS.decode(...) out to a variable and check it isn't null before using it. Root problem is probably a missing epsg jar. –  iant Sep 12 '12 at 8:25

1 Answer 1

Ok, the problem seems that the library gt-swing-2.7.5.jar is unsupported and therefore does not work properly anymore. The best is to take the corresponding code in GeoTools 8.0 which seems to be the development branch and adapt it for GeoTools 2.7.5.

share|improve this answer
    
The best bet is probably to upgrade to the latest stable release rather than back porting bits and peices. –  iant Sep 28 '12 at 13:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.