What is wrong with this code?

Given a BufferedImage , a world file  and a coordinate system I construct
a code coverage as follows:

Rectangle actualDim = new Rectangle(0, 0, bufferedImage.getWidth(),
bufferedImage.getHeight());
                        AffineTransform tempTransform = new
AffineTransform(this.getAffineTransform());
                        tempTransform.translate(-0.5D, -0.5D);
                        GeneralEnvelope envelope;
GridCoverage2D gc;
                        try {
        envelope = CRS.transform(this.getTransform(), new
GeneralEnvelope(actualDim));
        envelope.setCoordinateReferenceSystem(CRS.decode("EPSG:" +
sourceCRSCode));
        gc = (new GridCoverageFactory()).create("", bufferedImage.getRaster(),
envelope);
        if (sourceCRSCode == Configuration.getInstance().getDefaultEPSGCode())
                return gc;
        else
                return (GridCoverage2D) Operations.DEFAULT.resample(gc,
Configuration.getInstance().getDefaultCRS());
                        } catch (TransformException | 
MismatchedDimensionException |
FactoryException e1) {
        return null;
                        }

When my source CRS is 27200 (NZMG) and I need to resample to 2193 I get
the following error:

Nov 19, 2014 5:01:50 PM
org.geotools.referencing.operation.projection.TransverseMercator.Inverse
transform
WARNING: Possible use of "Transverse_Mercator (Inverse transform)"
projection outside its valid area.
Latitude 132°28.1'S is out of range (±90°).
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException:
Angle 
2,834,816,019,771,248,000,000,000,000,000,000,000,000,000,000,000,000,000,0
00,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
,000 is too high.
        at org.geotools.measure.AngleFormat.format(AngleFormat.java:703)
        at org.geotools.measure.AngleFormat.format(AngleFormat.java:940)
        at org.geotools.measure.AngleFormat.format(AngleFormat.java:862)
        at org.geotools.measure.Angle.toString(Angle.java:165)
        at java.text.MessageFormat.subformat(MessageFormat.java:1271)
        at java.text.MessageFormat.format(MessageFormat.java:860)
        at java.text.Format.format(Format.java:157)
        at 
org.geotools.resources.IndexedResourceBundle.getString(IndexedResourceBundl
e.java:491)
        at org.geotools.resources.i18n.Errors.format(Errors.java:77)
        at 
org.geotools.referencing.operation.projection.MapProjection.verifyGeographi
cRanges(MapProjection.java:501)
        at 
org.geotools.referencing.operation.projection.MapProjection.access$000(MapP
rojection.java:87)
        at 
org.geotools.referencing.operation.projection.MapProjection$Inverse.transfo
rm(MapProjection.java:1052)
        at 
org.geotools.referencing.operation.projection.MapProjection$Inverse.transfo
rm(MapProjection.java:1091)
        at 
org.geotools.referencing.operation.transform.ConcatenatedTransformDirect.tr
ansform(ConcatenatedTransformDirect.java:80)
        at 
org.geotools.referencing.operation.transform.ConcatenatedTransformDirect.tr
ansform(ConcatenatedTransformDirect.java:81)
        at 
org.geotools.referencing.operation.transform.WarpBuilder.isWithinTolerance(
WarpBuilder.java:335)
        at 
org.geotools.referencing.operation.transform.WarpBuilder.computeOptimalDept
hs(WarpBuilder.java:267)
        at 
org.geotools.referencing.operation.transform.WarpBuilder.buildWarp(WarpBuil
der.java:137)
        at 
org.geotools.coverage.processing.operation.Resampler2D.createWarp(Resampler
2D.java:988)
        at 
org.geotools.coverage.processing.operation.Resampler2D.reproject(Resampler2
D.java:706)
        at 
org.geotools.coverage.processing.operation.Resample.doOperation(Resample.ja
va:258)
        at 
org.geotools.coverage.processing.CoverageProcessor.doOperation(CoverageProc
essor.java:542)
        at 
org.geotools.coverage.processing.CoverageProcessor.doOperation(CoverageProc
essor.java:564)
        at 
org.geotools.coverage.processing.Operations.doOperation(Operations.java:828
)
        at 
org.geotools.coverage.processing.Operations.resample(Operations.java:408)

Going in the opposite direction the resulting image is way off to the
NorthEast.


I am totally stuck and quite a bit frustrated :-( Obviously I am running
into the problem created by the dreaded 2193 (reversed axis) but I don’t
know how to deal with it in this situation
(in other cases I just manually swap x for y, etc).

Thanx in advance for any help.
Gaby







------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to