Roman Podolski
Roman Podolski

Reputation: 329

How to transform coordinates in local EngineeringCRS to WGS84?

I want to code the transformation of coordinates given in a local right-handed 3D-Cartesian coordinate system to 3D-geographic-coordinates using geotools:gt-referencing.

I have the location and orientation of a sensor in a local, right-handed coordinate system (of a mobile platform). I know the translation and rotation of the local coordinate system relative to WGS84. Mathematically the operation is rather trival as it can be solved by an Helmert-Tranformation. I'd like to use geotools for this task. The geotools-userguide mentions a Class DefaultEngineeringCRS which seems like a good fit for my local coordinate system. Unfortunately I did not find any example code for the usage of this class and how to define its origin and orientation.

I would like to do something like this

CoordinateReferenceSystem worldFrame = DefaultGeographicCRS.WGS84_3D;
CoordinateReferenceSystem bodyFrame = DefaultEngineeringCRS.CARTESIAN_3D;
/* set transformation rules for how to transform coordinates given in bodyFrame to coordinates in worldFrame */
DirectPosition locationOfSensor = DirectPosition3D(bodyFrame, x, y, z);
MathTransform trafo = CRS.findMathTransform(worldFrame, bodyFrame, true);
trafo.transform(locationOfSensor, locationOfSensor);

Upvotes: 2

Views: 843

Answers (1)

Ian Turton
Ian Turton

Reputation: 10976

I'm not sure I can answer this completely but this may help you in the right direction:

You can use a MathTransformFactory to build your transform. You can also query the factory for operations:

System.out.println("operations");
for (OperationMethod op : mtFactory.getAvailableMethods(Operation.class)) {
  System.out.println(op.getName());
}

Which gives a list like:

operations
Geotools:Logarithmic
Geotools:Exponential
OGC:Affine
EPSG:Longitude rotation
EPSG:Geocentric translations (geog2D domain)
EPSG:Position Vector transformation (geog2D domain)
EPSG:Coordinate Frame Rotation (geog2D domain)
OGC:Ellipsoid_To_Geocentric
OGC:Geocentric_To_Ellipsoid
OGC:Molodenski
OGC:Abridged_Molodenski
OGC:NADCON
EPSG:NTv2
EPSG:Similarity transformation
Geotools:WarpPolynomial
Geotools:Earth gravitational model
OGC:Equidistant_Cylindrical
EPSG:Equidistant Cylindrical (Spherical)
ESRI:Plate_Carree
OGC:Mercator_1SP
OGC:Mercator_2SP
EPSG:Popular Visualisation Pseudo Mercator
OGC:Transverse_Mercator
EPSG:Transverse Mercator (South Orientated)
OGC:Oblique_Mercator
ESRI:Hotine_Oblique_Mercator_Two_Point_Center
OGC:Hotine_Oblique_Mercator
ESRI:Hotine_Oblique_Mercator_Two_Point_Natural_Origin
OGC:Albers_Conic_Equal_Area
OGC:Lambert_Conformal_Conic_1SP
OGC:Lambert_Conformal_Conic_2SP
ESRI:Lambert_Conformal_Conic
OGC:Lambert_Conformal_Conic_2SP_Belgium
OGC:Lambert_Azimuthal_Equal_Area
OGC:Orthographic
ESRI:Stereographic
OGC:Oblique_Stereographic
OGC:Polar_Stereographic
EPSG:Polar Stereographic (variant B)
ESRI:Stereographic_North_Pole
ESRI:Stereographic_South_Pole
OGC:New_Zealand_Map_Grid
OGC:Krovak
OGC:Cassini_Soldner
GeoTIFF:CT_Equidistant_Conic
OGC:Polyconic
Geotools:Robinson
ESRI:Winkel_Tripel
ESRI:Aitoff
Geotools:Eckert_IV
Geotools:Mollweide
Geotools:Wagner_IV
Geotools:Wagner_V
OGC:Gnomonic
OGC:World_Van_der_Grinten_I
Geotools:Sinusoidal
AUTO:General_Oblique
AUTO:MeteosatSG
OGC:GEOS
AUTO:Rotated_Pole
OGC:Azimuthal_Equidistant
Geotools:Cylindrical_Equal_Area
Geotools:Behrmann
Geotools:Lambert Cylindrical Equal Area (Spherical)
Geotools:Equal Earth

Or by Projection:

System.out.println("projections");
for (OperationMethod op : mtFactory.getAvailableMethods(Projection.class)) {
  System.out.println(op.getName());
}

which gives

projections
OGC:Equidistant_Cylindrical
EPSG:Equidistant Cylindrical (Spherical)
ESRI:Plate_Carree
OGC:Mercator_1SP
OGC:Mercator_2SP
EPSG:Popular Visualisation Pseudo Mercator
OGC:Transverse_Mercator
EPSG:Transverse Mercator (South Orientated)
OGC:Oblique_Mercator
ESRI:Hotine_Oblique_Mercator_Two_Point_Center
OGC:Hotine_Oblique_Mercator
ESRI:Hotine_Oblique_Mercator_Two_Point_Natural_Origin
OGC:Albers_Conic_Equal_Area
OGC:Lambert_Conformal_Conic_1SP
OGC:Lambert_Conformal_Conic_2SP
ESRI:Lambert_Conformal_Conic
OGC:Lambert_Conformal_Conic_2SP_Belgium
OGC:Lambert_Azimuthal_Equal_Area
OGC:Orthographic
ESRI:Stereographic
OGC:Oblique_Stereographic
OGC:Polar_Stereographic
EPSG:Polar Stereographic (variant B)
ESRI:Stereographic_North_Pole
ESRI:Stereographic_South_Pole
OGC:New_Zealand_Map_Grid
OGC:Krovak
OGC:Cassini_Soldner
GeoTIFF:CT_Equidistant_Conic
OGC:Polyconic
Geotools:Robinson
ESRI:Winkel_Tripel
ESRI:Aitoff
Geotools:Eckert_IV
Geotools:Mollweide
Geotools:Wagner_IV
Geotools:Wagner_V
OGC:Gnomonic
OGC:World_Van_der_Grinten_I
Geotools:Sinusoidal
AUTO:General_Oblique
AUTO:MeteosatSG
OGC:GEOS
AUTO:Rotated_Pole
OGC:Azimuthal_Equidistant
Geotools:Cylindrical_Equal_Area
Geotools:Behrmann
Geotools:Lambert Cylindrical Equal Area (Spherical)
Geotools:Equal Earth

You can then determine the parameters you need for an Operation or Projection using:

mtFactory.getDefaultParameters("EPSG:Coordinate Frame Rotation (geog2D domain)")

which gives:

Coordinate Frame Rotation (geog2D domain) : dx  = 0.0
                                            dy  = 0.0
                                            dz  = 0.0
                                            ex  = 0.0
                                            ey  = 0.0
                                            ez  = 0.0
                                            ppm = 0.0

At which point you should be able to define a new projection:

try {

  ParameterValueGroup parameters = mtFactory.getDefaultParameters("EPSG:Coordinate Frame Rotation (geog2D domain)");
  parameters.parameter("dx").setValue(1.0);
  parameters.parameter("dy").setValue(-1.0);
  parameters.parameter("dz").setValue(0.0);
  parameters.parameter("ex").setValue(1.0);
  parameters.parameter("ey").setValue(-1.0);
  parameters.parameter("ez").setValue(0.0);
  Conversion conversion = new DefiningConversion("Frame Rot", parameters);

  GeographicCRS worldFrame = org.geotools.referencing.crs.DefaultGeographicCRS.WGS84;
  CartesianCS bodyFrame = org.geotools.referencing.cs.DefaultCartesianCS.GENERIC_2D;
  Map<String, ?> properties = Collections.singletonMap("name", "My Proj");
  projCRS = crsFactory.createProjectedCRS(properties, worldFrame, conversion, bodyFrame);
} catch (FactoryException e1) {
  // TODO Auto-generated catch block
  e1.printStackTrace();
}

But I get a dimension mismatch here, but if you have a better idea of the transformation you may do better.

Upvotes: 1

Related Questions