OK, so this is what I have found so far:

1) To obtain the correct raster projection from NZMG to NZTM I need to set
the system property and NOT use the OGC URN code
Here's my code snippet:
<pre>
System.setProperty("org.geotools.referencing.forceXY", "true");
File[] filesin = new File[1];
filesin[0] = new File("TestData/heathcote_200_depth.png");
File[] filesout = new File[1];
filesout[0] = new File("TestData/NZTM/heathcote_200_depth.png");
int i = 0;
for (File rasterFile : filesin) {
    WorldImageReader reader = new WorldImageReader(rasterFile, null);
    GridCoverage2D myGridCov = reader.read(null);
    GridCoverage2D reprojected = (GridCoverage2D)
Operations.DEFAULT.resample(myGridCov,     CRS.decode("EPSG:2193"), null,
null);
    WorldImageWriter wiw = new WorldImageWriter(filesout[i], null);
    ParameterValueGroup params = reader.getFormat().getWriteParameters();
   
params.parameter(WorldImageFormat.FORMAT.getName().toString()).setValue("png");
    GeneralParameterValue[] gpv = {
params.parameter(WorldImageFormat.FORMAT.getName().toString()) };
    wiw.write(reprojected, gpv);
    wiw.dispose();
    i++;
}
</pre>

2) There is no problem at all to reproject a ReferencedEnvelope from NZMG to
NZTM
<pre>
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:27200");
ReferencedEnvelope envelope = new ReferencedEnvelope(2823200.0, 2848750.0,
6157410.0, 6174960.0, sourceCRS); 
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:2193");
ReferencedEnvelope newEnv = envelope.transform(targetCRS, false);
</pre>
Yealds a bounding box of 
1913218.3251509198
1938797.0025404787
5595756.03690457
5613329.706339548
All's good here

3) *There is a problem reprojecting the ReferencedEnvelope from NZTM to
NZMG.*

The ReferencedEnvelope reprojection consistently gives the wrong answers,
whether I use the system setting, OSG URN or various combinations of the
above. 

You can see for yourself by trying
<pre>
CoordinateReferenceSystem sourceCRS =
CRS.decode("urn:ogc:def:crs:EPSG::2193");
ReferencedEnvelope envelope = new ReferencedEnvelope(1567451.39, 1570650.34,
5178586.92, 5184734.56, sourceCRS);
CoordinateReferenceSystem targetCRS =
CRS.decode("urn:ogc:def:crs:EPSG::27200");
ReferencedEnvelope newEnv = envelope.transform(targetCRS, false);
System.out.println(newEnv.getMinX());
System.out.println(newEnv.getMaxX());
System.out.println(newEnv.getMinY());
System.out.println(newEnv.getMaxY());
</pre>

The only way I can get this to work is by manually swapping x and y
coordinates :-(
ReferencedEnvelope envelope = new ReferencedEnvelope(5178586.92, 5184734.56,
1567451.39, 1570650.34, sourceCRS);
This, as discussed previously, is not a acceptable solution.

4) Raster reprojection from NZTM to NZMG works OK for the code as above
(with EPSG codes reversed)

So it seems to me, that there is a bug somewhere in the ReferencedEnvelope
reprojection. 
How to proceed?
Gaby







--
View this message in context: 
http://osgeo-org.1560.x6.nabble.com/Need-help-reprojecting-ReferencedEnvelope-tp5069254p5069757.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&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