use of org.opengis.referencing.operation.OperationMethod in project sis by apache.
the class ParameterFormat method format.
/**
* Formats the given object to the given stream of buffer.
* The object may be an instance of any of the following types:
*
* <ul>
* <li>{@link ParameterValueGroup}</li>
* <li>{@link ParameterDescriptorGroup}</li>
* <li>{@link OperationMethod}</li>
* <li><code>{@linkplain IdentifiedObject}[]</code> — accepted only for {@link ContentLevel#NAME_SUMMARY}.</li>
* </ul>
*
* @throws IOException if an error occurred while writing to the given appendable.
*/
@Override
public void format(final Object object, final Appendable toAppendTo) throws IOException {
ArgumentChecks.ensureNonNull("object", object);
ArgumentChecks.ensureNonNull("toAppendTo", toAppendTo);
final boolean isSummary = contentLevel == ContentLevel.NAME_SUMMARY;
final ParameterDescriptorGroup descriptor;
final ParameterValueGroup values;
final Identifier name;
if (object instanceof ParameterValueGroup) {
values = (ParameterValueGroup) object;
descriptor = values.getDescriptor();
name = descriptor.getName();
} else if (object instanceof ParameterDescriptorGroup) {
descriptor = (ParameterDescriptorGroup) object;
values = null;
name = descriptor.getName();
} else if (object instanceof OperationMethod) {
final OperationMethod operation = (OperationMethod) object;
descriptor = operation.getParameters();
values = null;
name = operation.getName();
} else if (isSummary && object instanceof IdentifiedObject[]) {
formatSummary((IdentifiedObject[]) object, toAppendTo);
return;
} else {
throw new IllegalArgumentException(Errors.getResources(displayLocale).getString(Errors.Keys.UnsupportedType_1, object.getClass()));
}
if (isSummary) {
final List<GeneralParameterDescriptor> parameters = descriptor.descriptors();
formatSummary(parameters.toArray(new IdentifiedObject[parameters.size()]), toAppendTo);
} else {
format(name.getCode(), descriptor, values, toAppendTo);
}
}
use of org.opengis.referencing.operation.OperationMethod in project sis by apache.
the class DefaultMathTransformFactoryTest method testGetOperationMethod.
/**
* Tests the {@link DefaultMathTransformFactory#getOperationMethod(String)} method.
*
* @throws NoSuchIdentifierException if the operation was not found.
*/
@Test
public void testGetOperationMethod() throws NoSuchIdentifierException {
final DefaultMathTransformFactory factory = factory();
final OperationMethod affine = factory.getOperationMethod(Constants.AFFINE);
final OperationMethod mercator = factory.getOperationMethod("Mercator (variant A)");
assertInstanceOf("Affine", Affine.class, affine);
assertInstanceOf("Mercator (variant A)", Mercator1SP.class, mercator);
// Same than above, using EPSG code and alias.
assertSame("EPSG:9624", affine, factory.getOperationMethod("EPSG:9624"));
assertSame("EPSG:9804", mercator, factory.getOperationMethod("EPSG:9804"));
assertSame("Mercator_1SP", mercator, factory.getOperationMethod("Mercator_1SP"));
}
use of org.opengis.referencing.operation.OperationMethod in project sis by apache.
the class StandardDefinitions method createUniversal.
/**
* Creates a Universal Transverse Mercator (UTM) or a Universal Polar Stereographic (UPS) projected CRS
* using the Apache SIS factory implementation. This method restricts the factory to SIS implementation
* instead than arbitrary factory in order to meet the contract saying that {@link CommonCRS} methods
* should never fail.
*
* @param code the EPSG code, or 0 if none.
* @param baseCRS the geographic CRS on which the projected CRS is based.
* @param isUTM {@code true} for UTM or {@code false} for UPS. Note: redundant with the given latitude.
* @param latitude a latitude in the zone of the desired projection, to be snapped to 0°, 90°S or 90°N.
* @param longitude a longitude in the zone of the desired projection, to be snapped to UTM central meridian.
* @param derivedCS the projected coordinate system.
*/
static ProjectedCRS createUniversal(final int code, final GeographicCRS baseCRS, final boolean isUTM, final double latitude, final double longitude, final CartesianCS derivedCS) {
final OperationMethod method;
try {
method = DefaultFactories.forBuildin(MathTransformFactory.class, DefaultMathTransformFactory.class).getOperationMethod(isUTM ? TransverseMercator.NAME : PolarStereographicA.NAME);
} catch (NoSuchIdentifierException e) {
// Should not happen with SIS implementation.
throw new IllegalStateException(e);
}
final ParameterValueGroup parameters = method.getParameters().createValue();
String name = isUTM ? TransverseMercator.Zoner.UTM.setParameters(parameters, latitude, longitude) : PolarStereographicA.setParameters(parameters, latitude >= 0);
final DefaultConversion conversion = new DefaultConversion(properties(0, name, null, false), method, null, parameters);
name = baseCRS.getName().getCode() + " / " + name;
return new DefaultProjectedCRS(properties(code, name, null, false), baseCRS, conversion, derivedCS);
}
use of org.opengis.referencing.operation.OperationMethod in project sis by apache.
the class GeoKeysTest method verifyParameterNames.
/**
* Verifies that parameter names registered in the {@link org.apache.sis.internal.referencing.provider} package
* match the name of fields listed in {@link GeoKeys}.
*/
@Test
@DependsOnMethod("testName")
public void verifyParameterNames() {
final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class);
for (final OperationMethod method : factory.getAvailableMethods(SingleOperation.class)) {
for (final GeneralParameterDescriptor param : method.getParameters().descriptors()) {
final Identifier identifier = IdentifiedObjects.getIdentifier(param, Citations.GEOTIFF);
final Set<String> names = IdentifiedObjects.getNames(param, Citations.GEOTIFF);
/*
* If there is no GeoTIFF identifiers, we should have no GeoTIFF name neither.
*/
assertEquals(param.getName().getCode(), identifier == null, names.isEmpty());
if (identifier != null) {
final int code = Short.parseShort(identifier.getCode());
for (final String name : names) {
assertEquals(name, code(name), code);
}
}
}
}
}
use of org.opengis.referencing.operation.OperationMethod in project sis by apache.
the class AbstractCoordinateOperation method formatTo.
/**
* Formats this coordinate operation in Well Known Text (WKT) version 2 format.
*
* @param formatter the formatter to use.
* @return {@code "CoordinateOperation"}.
*
* @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#113">WKT 2 specification §17</a>
*/
@Override
protected String formatTo(final Formatter formatter) {
super.formatTo(formatter);
formatter.newLine();
/*
* If the WKT is a component of a ConcatenatedOperation, do not format the source CRS since it is identical
* to the target CRS of the previous step, or to the source CRS of the enclosing "ConcatenatedOperation" if
* this step is the first step.
*
* This decision is SIS-specific since the WKT 2 specification does not define concatenated operations.
* This choice may change in any future SIS version.
*/
final FormattableObject enclosing = formatter.getEnclosingElement(1);
final boolean isSubOperation = (enclosing instanceof PassThroughOperation);
final boolean isComponent = (enclosing instanceof ConcatenatedOperation);
if (!isSubOperation && !isComponent) {
append(formatter, getSourceCRS(), WKTKeywords.SourceCRS);
append(formatter, getTargetCRS(), WKTKeywords.TargetCRS);
}
final OperationMethod method = getMethod();
if (method != null) {
formatter.append(DefaultOperationMethod.castOrCopy(method));
ParameterValueGroup parameters;
try {
parameters = getParameterValues();
} catch (UnsupportedOperationException e) {
final IdentifiedObject c = getParameterDescriptors();
formatter.setInvalidWKT(c != null ? c : this, e);
parameters = null;
}
if (parameters != null) {
/*
* Format the parameter values. Apache SIS uses the EPSG geodetic dataset as the main source of
* parameter definitions. When a parameter is defined by both OGC and EPSG with different names,
* the Formatter class is responsible for choosing an appropriate name. But when the difference
* is more fundamental, we may have duplication. For example in the "Molodensky" operation, OGC
* uses source and target axis lengths while EPSG uses only difference between those lengths.
* In this case, OGC and EPSG parameters are defined separately and are redundant. To simplify
* the CoordinateOperation WKT, we omit non-EPSG parameters when we have determined that we are
* about to describe an EPSG operation. We could generalize this filtering to any authority, but
* we don't because few authorities are as complete as EPSG, so other authorities are more likely
* to mix EPSG or someone else components with their own. Note also that we don't apply filtering
* on MathTransform WKT neither for more reliable debugging.
*/
final boolean filter = // NOT method.getName()
WKTUtilities.isEPSG(parameters.getDescriptor(), false) && Constants.EPSG.equalsIgnoreCase(Citations.getCodeSpace(formatter.getNameAuthority()));
formatter.newLine();
formatter.indent(+1);
for (final GeneralParameterValue param : parameters.values()) {
if (!filter || WKTUtilities.isEPSG(param.getDescriptor(), true)) {
WKTUtilities.append(param, formatter);
}
}
formatter.indent(-1);
}
}
if (!isSubOperation && !(this instanceof ConcatenatedOperation)) {
append(formatter, getInterpolationCRS(), WKTKeywords.InterpolationCRS);
final double accuracy = getLinearAccuracy();
if (accuracy > 0) {
formatter.append(new FormattableObject() {
@Override
protected String formatTo(final Formatter formatter) {
formatter.append(accuracy);
return WKTKeywords.OperationAccuracy;
}
});
}
}
if (formatter.getConvention().majorVersion() == 1) {
formatter.setInvalidWKT(this, null);
}
if (isComponent) {
formatter.setInvalidWKT(this, null);
return "CoordinateOperationStep";
}
return WKTKeywords.CoordinateOperation;
}
Aggregations