| | | | Browse by category |
Question
How to retrieve WGS84 coordinates from an USRP map?
Answer
One of the differences between USRP and ASRP is that USRP uses UTM projection.
If you want to transform an USRP map from UTM to WGS84 coordinates, you need to use an IlvProjectionTransform which will allow you to transform projected cartographic coordinates to and from ellipsoidal coordinates systems.
The sample code below illustrates how to retrieve WGS84 coordinates from an USRP map loaded by an IlvRasterUSRPReader.
Note: the code below can be inserted in USRPLoadAction, makeReader(String) method of the mapbuilderextension sample provided with JViews Maps distribution.
IlvRasterAbstractReader reader = (IlvRasterAbstractReader) USRPDefLess.newIlvRasterUSRPReader();
USRPDefLess.addMap(reader, fileName);
// USRP file uses UTM projection
IlvProjectionTransform projection = (IlvProjectionTransform)reader.getInternalTransformation(0);
IlvCoordinate lr = reader.getLowerRightCorner();
IlvCoordinate uf = reader.getUpperLeftCorner();
System.out.print("UTM Coordinates:\n");
System.out.println("lr :: " + lr);
System.out.println("uf :: " + uf);
try {
projection.getInverse().transform(lr, lr);
projection.getInverse().transform(uf, uf);
System.out.print("WGS84 in radian:\n");
System.out.println("lr :: " + lr);
System.out.println("uf :: " + uf);
} catch (IlvCoordinateTransformationException e) {
e.printStackTrace();
}
// Convert radian to degrees:
lr.x *= (180/Math.PI);
lr.y *= (180/Math.PI);
uf.x *= (180/Math.PI);
uf.y *= (180/Math.PI);
System.out.print("WGS84 in degrees:\n");
System.out.println("lr :: " + lr);
System.out.println("uf :: " + uf);