use of org.opengis.referencing.cs.CartesianCS in project sis by apache.
the class DefaultImageCRSTest method testXML.
/**
* Implementation of {@link #testCartesianXML()} and {@link #testAffineXML()}.
*/
private void testXML(final boolean cartesian) throws JAXBException {
String expected = "<gml:ImageCRS xmlns:gml=\"" + Namespaces.GML + "\">\n" + " <gml:name>An image CRS</gml:name>\n" + " <gml:cartesianCS>\n" + " <gml:CartesianCS gml:id=\"Grid\">\n" + " <gml:name>Grid</gml:name>\n" + " <gml:axis>\n" + " <gml:CoordinateSystemAxis uom=\"urn:ogc:def:uom:EPSG::9201\" gml:id=\"Column\">\n" + " <gml:name>Column</gml:name>\n" + " <gml:axisAbbrev>i</gml:axisAbbrev>\n" + " <gml:axisDirection codeSpace=\"EPSG\">columnPositive</gml:axisDirection>\n" + " </gml:CoordinateSystemAxis>\n" + " </gml:axis>\n" + " <gml:axis>\n" + " <gml:CoordinateSystemAxis uom=\"urn:ogc:def:uom:EPSG::9201\" gml:id=\"Row\">\n" + " <gml:name>Row</gml:name>\n" + " <gml:axisAbbrev>j</gml:axisAbbrev>\n" + " <gml:axisDirection codeSpace=\"EPSG\">rowPositive</gml:axisDirection>\n" + " </gml:CoordinateSystemAxis>\n" + " </gml:axis>\n" + " </gml:CartesianCS>\n" + " </gml:cartesianCS>\n" + " <gml:imageDatum>\n" + " <gml:ImageDatum gml:id=\"C1\">\n" + " <gml:name>C1</gml:name>\n" + " <gml:pixelInCell>cell center</gml:pixelInCell>\n" + " </gml:ImageDatum>\n" + " </gml:imageDatum>\n" + "</gml:ImageCRS>";
if (!cartesian) {
expected = expected.replace("CartesianCS", "AffineCS").replace("cartesianCS", "affineCS");
}
final String xml = marshal(create(cartesian));
assertXmlEquals(expected, xml, "xmlns:*");
final DefaultImageCRS crs = unmarshal(DefaultImageCRS.class, xml);
assertEquals("name", "An image CRS", crs.getName().getCode());
assertEquals("datum.name", "C1", crs.getDatum().getName().getCode());
final CoordinateSystem cs = crs.getCoordinateSystem();
assertInstanceOf("coordinateSystem", cartesian ? CartesianCS.class : AffineCS.class, cs);
assertEquals("cs.isCartesian", cartesian, cs instanceof CartesianCS);
assertEquals("cs.name", "Grid", cs.getName().getCode());
assertEquals("cs.dimension", 2, cs.getDimension());
assertAxisDirectionsEqual("cartesianCS", cs, AxisDirection.COLUMN_POSITIVE, AxisDirection.ROW_POSITIVE);
assertEquals("cs.axis[0].name", "Column", cs.getAxis(0).getName().getCode());
assertEquals("cs.axis[1].name", "Row", cs.getAxis(1).getName().getCode());
assertEquals("cs.axis[0].abbreviation", "i", cs.getAxis(0).getAbbreviation());
assertEquals("cs.axis[1].abbreviation", "j", cs.getAxis(1).getAbbreviation());
}
use of org.opengis.referencing.cs.CartesianCS in project sis by apache.
the class DefaultGeodeticCRS method formatTo.
/**
* Formats this CRS as a <cite>Well Known Text</cite> {@code GeodeticCRS[…]} element.
* More information about the WKT format is documented in subclasses.
*
* @return {@code "GeodeticCRS"} (WKT 2) or {@code "GeogCS"}/{@code "GeocCS"} (WKT 1).
*/
@Override
protected String formatTo(final Formatter formatter) {
WKTUtilities.appendName(this, formatter, null);
CoordinateSystem cs = getCoordinateSystem();
final Convention convention = formatter.getConvention();
final boolean isWKT1 = (convention.majorVersion() == 1);
final boolean isGeographicWKT1 = isWKT1 && (cs instanceof EllipsoidalCS);
if (isGeographicWKT1 && cs.getDimension() == 3) {
/*
* Version 1 of WKT format did not have three-dimensional GeographicCRS. Instead, such CRS were formatted
* as a CompoundCRS made of a two-dimensional GeographicCRS with a VerticalCRS for the ellipsoidal height.
* Note that such compound is illegal in WKT 2 and ISO 19111 standard, as ellipsoidal height shall not be
* separated from the geographic component. So we perform this separation only at WKT 1 formatting time.
*/
SingleCRS first = CRS.getHorizontalComponent(this);
SingleCRS second = CRS.getVerticalComponent(this, true);
if (first != null && second != null) {
// Should not be null, but we are paranoiac.
if (AxisDirection.UP.equals(AxisDirections.absolute(cs.getAxis(0).getDirection()))) {
// It is very unusual to have VerticalCRS first, but our code tries to be robust.
final SingleCRS t = first;
first = second;
second = t;
}
formatter.newLine();
formatter.append(WKTUtilities.toFormattable(first));
formatter.newLine();
formatter.append(WKTUtilities.toFormattable(second));
formatter.newLine();
return WKTKeywords.Compd_CS;
}
}
/*
* Unconditionally format the datum element, followed by the prime meridian.
* The prime meridian is part of datum according ISO 19111, but is formatted
* as a sibling (rather than a child) element in WKT for historical reasons.
*/
// Gives subclasses a chance to override.
final GeodeticDatum datum = getDatum();
formatter.newLine();
formatter.append(WKTUtilities.toFormattable(datum));
formatter.newLine();
final PrimeMeridian pm = datum.getPrimeMeridian();
final Unit<Angle> angularUnit = AxisDirections.getAngularUnit(cs, null);
if (// Really this specific enum, not Convention.isSimplified().
convention != Convention.WKT2_SIMPLIFIED || ReferencingUtilities.getGreenwichLongitude(pm, Units.DEGREE) != 0) {
final Unit<Angle> oldUnit = formatter.addContextualUnit(angularUnit);
formatter.indent(1);
formatter.append(WKTUtilities.toFormattable(pm));
formatter.indent(-1);
formatter.newLine();
formatter.restoreContextualUnit(angularUnit, oldUnit);
}
/*
* Get the coordinate system to format. This will also determine the units to write and the keyword to
* return in WKT 1 format. Note that for the WKT 1 format, we need to replace the coordinate system by
* an instance conform to the legacy conventions.
*
* We can not delegate the work below to subclasses, because XML unmarshalling of a geodetic CRS will
* NOT create an instance of a subclass (because the distinction between geographic and geocentric CRS
* is not anymore in ISO 19111:2007).
*/
final boolean isBaseCRS;
if (isWKT1) {
if (!isGeographicWKT1) {
// If not geographic, then presumed geocentric.
if (cs instanceof CartesianCS) {
cs = Legacy.forGeocentricCRS((CartesianCS) cs, true);
} else {
// SphericalCS was not supported in WKT 1.
formatter.setInvalidWKT(cs, null);
}
}
isBaseCRS = false;
} else {
isBaseCRS = isBaseCRS(formatter);
}
/*
* Format the coordinate system, except if this CRS is the base CRS of an AbstractDerivedCRS in WKT 2 format.
* This is because ISO 19162 omits the coordinate system definition of enclosed base CRS in order to simplify
* the WKT. The 'formatCS(…)' method may write axis unit before or after the axes depending on whether we are
* formatting WKT version 1 or 2 respectively.
*
* Note that even if we do not format the CS, we may still write the units if we are formatting in "simplified"
* mode (as opposed to the more verbose mode). This looks like the opposite of what we would expect, but this is
* because formatting the unit here allow us to avoid repeating the unit in projection parameters when this CRS
* is part of a ProjectedCRS. Note however that in such case, the units to format are the angular units because
* the linear units will be formatted in the enclosing PROJCS[…] element.
*/
if (!isBaseCRS || convention == Convention.INTERNAL) {
// Will also format the axes unit.
formatCS(formatter, cs, ReferencingUtilities.getUnit(cs), isWKT1);
} else if (convention.isSimplified()) {
formatter.append(formatter.toContextualUnit(angularUnit));
}
/*
* For WKT 1, the keyword depends on the subclass: "GeogCS" for GeographicCRS or "GeocCS" for GeocentricCRS.
* However we can not rely on the subclass for choosing the keyword, because after XML unmarhaling we only
* have a GeodeticCRS. We need to make the choice in this base class. The CS type is a sufficient criterion.
*/
if (isWKT1) {
return isGeographicWKT1 ? WKTKeywords.GeogCS : WKTKeywords.GeocCS;
} else {
return isBaseCRS ? WKTKeywords.BaseGeodCRS : formatter.shortOrLong(WKTKeywords.GeodCRS, WKTKeywords.GeodeticCRS);
}
}
use of org.opengis.referencing.cs.CartesianCS in project sis by apache.
the class DefaultProjectedCRS method formatTo.
/**
* Formats the inner part of the <cite>Well Known Text</cite> (WKT) representation of this CRS.
*
* <div class="note"><b>Example:</b> Well-Known Text (version 2)
* of a projected coordinate reference system using the Lambert Conformal method.
*
* {@preformat wkt
* ProjectedCRS[“NTF (Paris) / Lambert zone II”,
* BaseGeodCRS[“NTF (Paris)”,
* Datum[“Nouvelle Triangulation Francaise”,
* Ellipsoid[“NTF”, 6378249.2, 293.4660212936269, LengthUnit[“metre”, 1]]],
* PrimeMeridian[“Paris”, 2.5969213, AngleUnit[“grad”, 0.015707963267948967]]],
* Conversion[“Lambert zone II”,
* Method[“Lambert Conic Conformal (1SP)”, Id[“EPSG”, 9801, Citation[“IOGP”]]],
* Parameter[“Latitude of natural origin”, 52.0, AngleUnit[“grad”, 0.015707963267948967], Id[“EPSG”, 8801]],
* Parameter[“Longitude of natural origin”, 0.0, AngleUnit[“degree”, 0.017453292519943295], Id[“EPSG”, 8802]],
* Parameter[“Scale factor at natural origin”, 0.99987742, ScaleUnit[“unity”, 1], Id[“EPSG”, 8805]],
* Parameter[“False easting”, 600000.0, LengthUnit[“metre”, 1], Id[“EPSG”, 8806]],
* Parameter[“False northing”, 2200000.0, LengthUnit[“metre”, 1], Id[“EPSG”, 8807]]],
* CS[“Cartesian”, 2],
* Axis[“Easting (E)”, east, Order[1]],
* Axis[“Northing (N)”, north, Order[2]],
* LengthUnit[“metre”, 1],
* Id[“EPSG”, 27572, Citation[“IOGP”], URI[“urn:ogc:def:crs:EPSG::27572”]]]
* }
*
* <p>Same coordinate reference system using WKT 1.</p>
*
* {@preformat wkt
* PROJCS[“NTF (Paris) / Lambert zone II”,
* GEOGCS[“NTF (Paris)”,
* DATUM[“Nouvelle Triangulation Francaise”,
* SPHEROID[“NTF”, 6378249.2, 293.4660212936269]],
* PRIMEM[“Paris”, 2.33722917],
* UNIT[“degree”, 0.017453292519943295],
* AXIS[“Longitude”, EAST],
* AXIS[“Latitude”, NORTH]],
* PROJECTION[“Lambert_Conformal_Conic_1SP”, AUTHORITY[“EPSG”, “9801”]],
* PARAMETER[“latitude_of_origin”, 46.8],
* PARAMETER[“central_meridian”, 0.0],
* PARAMETER[“scale_factor”, 0.99987742],
* PARAMETER[“false_easting”, 600000.0],
* PARAMETER[“false_northing”, 2200000.0],
* UNIT[“metre”, 1],
* AXIS[“Easting”, EAST],
* AXIS[“Northing”, NORTH],
* AUTHORITY[“EPSG”, “27572”]]
* }
* </div>
*
* @return {@code "ProjectedCRS"} (WKT 2) or {@code "ProjCS"} (WKT 1).
*
* @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#57">WKT 2 specification §9</a>
*/
@Override
protected String formatTo(final Formatter formatter) {
if (super.getConversionFromBase() == null) {
/*
* Should never happen except temporarily at construction time, or if the user invoked the copy constructor
* with an invalid Conversion. Delegates to the super-class method for avoiding a NullPointerException.
* That method returns 'null', which will cause the WKT to be declared invalid.
*/
return super.formatTo(formatter);
}
WKTUtilities.appendName(this, formatter, null);
final Convention convention = formatter.getConvention();
final boolean isWKT1 = (convention.majorVersion() == 1);
final CartesianCS cs = getCoordinateSystem();
final GeographicCRS baseCRS = getBaseCRS();
final Unit<?> lengthUnit = ReferencingUtilities.getUnit(cs);
final Unit<Angle> angularUnit = AxisDirections.getAngularUnit(baseCRS.getCoordinateSystem(), null);
final Unit<Angle> oldAngle = formatter.addContextualUnit(angularUnit);
final Unit<?> oldLength = formatter.addContextualUnit(lengthUnit);
/*
* Format the enclosing base CRS. Note that WKT 1 formats a full GeographicCRS while WKT 2 formats only
* the datum with the prime meridian (no coordinate system) and uses a different keyword ("BaseGeodCRS"
* instead of "GeodeticCRS"). The DefaultGeodeticCRS.formatTo(Formatter) method detects when the CRS to
* format is part of an enclosing ProjectedCRS and will adapt accordingly.
*/
formatter.newLine();
formatter.append(toFormattable(baseCRS));
formatter.newLine();
final Parameters p = new Parameters(this);
final boolean isBaseCRS;
if (isWKT1) {
// Format outside of any "Conversion" element.
p.append(formatter);
isBaseCRS = false;
} else {
// Format inside a "Conversion" element.
formatter.append(p);
isBaseCRS = isBaseCRS(formatter);
}
/*
* In WKT 2 format, the coordinate system axes are written only if this projected CRS is not the base CRS
* of another derived CRS.
*/
if (!isBaseCRS || convention == Convention.INTERNAL) {
formatCS(formatter, cs, lengthUnit, isWKT1);
}
formatter.restoreContextualUnit(lengthUnit, oldLength);
formatter.restoreContextualUnit(angularUnit, oldAngle);
return isWKT1 ? WKTKeywords.ProjCS : isBaseCRS ? WKTKeywords.BaseProjCRS : formatter.shortOrLong(WKTKeywords.ProjCRS, WKTKeywords.ProjectedCRS);
}
use of org.opengis.referencing.cs.CartesianCS in project sis by apache.
the class Legacy method forGeocentricCRS.
/**
* Returns the axes to use instead of the ones in the given coordinate system.
* If the coordinate system axes should be used as-is, returns {@code cs}.
*
* @param cs the coordinate system for which to compare the axis directions.
* @param toLegacy {@code true} for replacing ISO directions by the legacy ones,
* or {@code false} for the other way around.
* @return the axes to use instead of the ones in the given CS,
* or {@code cs} if the CS axes should be used as-is.
*/
public static CartesianCS forGeocentricCRS(final CartesianCS cs, final boolean toLegacy) {
final CartesianCS check = toLegacy ? standard(null) : LEGACY;
final int dimension = check.getDimension();
if (cs.getDimension() != dimension) {
return cs;
}
for (int i = 0; i < dimension; i++) {
if (!cs.getAxis(i).getDirection().equals(check.getAxis(i).getDirection())) {
return cs;
}
}
final Unit<?> unit = ReferencingUtilities.getUnit(cs);
return toLegacy ? replaceUnit(LEGACY, unit) : standard(unit);
}
use of org.opengis.referencing.cs.CartesianCS in project sis by apache.
the class GeocentricAffine method createParameters.
/**
* Returns the parameters for creating a datum shift operation.
* The operation method will be one of the {@code GeocentricAffine} subclasses,
* unless the specified {@code method} argument is {@link DatumShiftMethod#NONE}.
* If no single operation method can be used, then this method returns {@code null}.
*
* <p>This method does <strong>not</strong> change the coordinate system type.
* The source and target coordinate systems can be both {@code EllipsoidalCS} or both {@code CartesianCS}.
* Any other type or mix of types (e.g. a {@code EllipsoidalCS} source and {@code CartesianCS} target)
* will cause this method to return {@code null}. In such case, it is caller's responsibility to apply
* the datum shift itself in Cartesian geocentric coordinates.</p>
*
* @param sourceCS the source coordinate system. Only the type and number of dimensions is checked.
* @param targetCS the target coordinate system. Only the type and number of dimensions is checked.
* @param datumShift the datum shift as a matrix, or {@code null} if there is no datum shift information.
* @param method the preferred datum shift method. Note that {@code createParameters(…)} may overwrite.
* @return the parameter values, or {@code null} if no single operation method can be found.
*/
public static ParameterValueGroup createParameters(final CoordinateSystem sourceCS, final CoordinateSystem targetCS, final Matrix datumShift, DatumShiftMethod method) {
final boolean isEllipsoidal = (sourceCS instanceof EllipsoidalCS);
if (!(isEllipsoidal ? (targetCS instanceof EllipsoidalCS) : (targetCS instanceof CartesianCS && sourceCS instanceof CartesianCS))) {
// Coordinate systems are not two EllipsoidalCS or two CartesianCS.
return null;
}
@SuppressWarnings("null") int dimension = sourceCS.getDimension();
if (dimension != targetCS.getDimension()) {
// Any value greater than 3 means "mismatched dimensions" for this method.
dimension = 4;
}
if (method == DatumShiftMethod.NONE) {
if (dimension <= 3) {
return Affine.identity(dimension);
} else if (isEllipsoidal) {
final ParameterDescriptorGroup descriptor;
switch(sourceCS.getDimension()) {
case 2:
descriptor = Geographic2Dto3D.PARAMETERS;
break;
case 3:
descriptor = Geographic3Dto2D.PARAMETERS;
break;
default:
return null;
}
return descriptor.createValue();
} else {
return null;
}
}
/*
* Try to convert the matrix into (tX, tY, tZ, rX, rY, rZ, dS) parameters.
* The matrix may not be convertible, in which case we will let the caller
* uses the matrix directly in Cartesian geocentric coordinates.
*/
final BursaWolfParameters parameters = new BursaWolfParameters(null, null);
if (datumShift != null)
try {
parameters.setPositionVectorTransformation(datumShift, BURSAWOLF_TOLERANCE);
} catch (IllegalArgumentException e) {
log(Loggers.COORDINATE_OPERATION, "createParameters", e);
return null;
}
else {
/*
* If there is no datum shift parameters (not to be confused with identity), then those parameters
* are assumed unknown. Using the most accurate methods would give a false impression of accuracy,
* so we use the fastest method instead. Since all parameter values are zero, Apache SIS should use
* the AbridgedMolodenskyTransform2D optimization.
*/
method = DatumShiftMethod.ABRIDGED_MOLODENSKY;
}
final boolean isTranslation = parameters.isTranslation();
final ParameterDescriptorGroup descriptor;
/*
* Following "if" blocks are ordered from most accurate to less accurate datum shift method
* supported by GeocentricAffine subclasses (except NONE which has already been handled).
* Special cases:
*
* - If the datum shift is applied between geocentric CRS, then the Molodensky approximations do not apply
* as they are designed for transformations between geographic CRS only. User preference is then ignored.
*
* - Molodensky methods are approximations for datum shifts having only translation terms in their Bursa-Wolf
* parameters. If there is also a scale or rotation terms, then we can not use Molodensky methods. The user
* preference is then ignored.
*/
if (!isEllipsoidal) {
method = DatumShiftMethod.GEOCENTRIC_DOMAIN;
descriptor = isTranslation ? GeocentricTranslation.PARAMETERS : PositionVector7Param.PARAMETERS;
} else if (!isTranslation) {
method = DatumShiftMethod.GEOCENTRIC_DOMAIN;
descriptor = (dimension >= 3) ? PositionVector7Param3D.PARAMETERS : PositionVector7Param2D.PARAMETERS;
} else
switch(method) {
case GEOCENTRIC_DOMAIN:
{
descriptor = (dimension >= 3) ? GeocentricTranslation3D.PARAMETERS : GeocentricTranslation2D.PARAMETERS;
break;
}
case MOLODENSKY:
{
descriptor = Molodensky.PARAMETERS;
break;
}
case ABRIDGED_MOLODENSKY:
{
descriptor = AbridgedMolodensky.PARAMETERS;
break;
}
default:
throw new AssertionError(method);
}
/*
* Following lines will set all Bursa-Wolf parameter values (scale, translation
* and rotation terms). In the particular case of Molodensky method, we have an
* additional parameter for the number of source and target dimensions (2 or 3).
*/
final Parameters values = createParameters(descriptor, parameters, isTranslation);
switch(method) {
case MOLODENSKY:
case ABRIDGED_MOLODENSKY:
{
if (dimension <= 3) {
values.getOrCreate(Molodensky.DIMENSION).setValue(dimension);
}
break;
}
}
return values;
}
Aggregations