Hi all,
I have an application where I want a user to be able to enter a set of
bounds and a CRS and then the code will reproject their input into a
default CRS for further processing. A fairly simple operation:
public ReferencedEnvelope getEnvelope(
double minEast, double maxEast,
double minNorth, double maxNorth,
CoordinateReferenceSystem crs) throws TransformException,
FactoryException {
Envelope envelope = new Envelope(minEast, maxEast, minNorth, maxNorth);
ReferencedEnvelope refEnv = ReferencedEnvelope.create(envelope, crs);
return refEnv.transform(DEFAULT_CRS, true);
}
Except for NZTM. Thanks to LINZ, NZTM is has an axis order y/x. The
above code falls over.
Following this (admittedly quite old) thread:
http://osgeo-org.1560.x6.nabble.com/Need-help-reprojecting-ReferencedEnvelope-td5069254.html
to the suggested resolution seems to be to "Make a special case for
NZTM". Extending this to "make a special case for any y/x CRS" means my
code now looks like:
public ReferencedEnvelope getEnvelope(
double minEast, double maxEast,
double minNorth, double maxNorth,
CoordinateReferenceSystem crs) throws TransformException,
FactoryException {
AxisDirection axisDir =
crs.getCoordinateSystem().getAxis(0).getDirection();
Envelope envelope = axisDir == AxisDirection.NORTH ?
new Envelope(minNorth, maxNorth, minEast, maxEast) :
new Envelope(minEast, maxEast, minNorth, maxNorth);
ReferencedEnvelope refEnv = ReferencedEnvelope.create(envelope, crs);
return refEnv.transform(DEFAULT_CRS, true);
}
which seems like a lot of faff for what should be an easy operation.
But we haven't even started yet because I am pretty sure this code is
incomplete. I _think_ the real question is not are we x/y or y/x it is
are we right handed (x/y) or left handed (y/x). So my code above would
actually have to handle not just NORTH/EAST (right) and EAST/NORTH
(left) but also NORTH/WEST (right) or NORTHEAST/SOUTHEAST (left) etc etc
and so on through all the permutations of AxisDirection.
So ... the only sensible resolution I can see without writing an entire
novel of if/elses for all the possible pairs of AxisDirections is to use
forceXY, but referring back to the discussion mentioned above, Ben
strongly discourages this.
Does anyone have any suggestions how this can be handled in a generic
non-complex way without forcing x/y axis ordering? Hopefully someone can
help.
If not can I suggest a method
ReferencedEnvelope.create(Envelope env, CoordinateReferenceSystem crs,
boolean envelopeIsGeometric)
which (if arg2 is true) treats the envelope as x/y and does any
necessary axis conversion internally so that this piece of code can be
written once and doesn't need to be written by anyone and everyone who
might need NZTM in their app?
Would anyone else find this useful?
Thanks
Iain
--
Sent from my ZX80
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users