use of org.apache.sis.io.wkt.WKTFormat in project sis by apache.
the class CoordinateOperationFinderTest method createFactory.
/**
* Creates a new {@link DefaultCoordinateOperationFactory} to use for testing purpose.
* The same factory will be used for all tests in this class.
*
* @throws ParseException if an error occurred while preparing the WKT parser.
*/
@BeforeClass
public static void createFactory() throws ParseException {
factory = new DefaultCoordinateOperationFactory();
parser = new WKTFormat(null, null);
/*
* The fist keyword in WKT below should be "GeodeticCRS" in WKT 2, but we use the WKT 1 keyword ("GEOGCS")
* for allowing inclusion in ProjectedCRS. SIS is okay with mixed WKT versions, but this is of course not
* something to recommend in production.
*/
parser.addFragment("Sphere", "GEOGCS[“Sphere”,\n" + " Datum[“Sphere”, Ellipsoid[“Sphere”, 6370997, 0]],\n" + " CS[ellipsoidal, 2],\n" + // Use of non-ASCII letters is departure from WKT 2.
" Axis[“Longitude (λ)”, EAST],\n" + " Axis[“Latitude (φ)”, NORTH],\n" + " Unit[“degree”, 0.017453292519943295]]");
/*
* Nouvelle Triangulation Française (Datum of EPSG:4807 CRS).
* Use non-Greenwich prime meridian grad units (0.9 grad = 1°).
* We use the WKT 1 format because TOWGS84[…] is not a legal WKT 2 element.
*/
parser.addFragment("NTF", "DATUM[“Nouvelle Triangulation Française”,\n" + " SPHEROID[“Clarke 1880 (IGN)”, 6378249.2, 293.466021293627],\n" + " TOWGS84[-168, -60, 320]]");
}
use of org.apache.sis.io.wkt.WKTFormat in project sis by apache.
the class ConsistencyTest method testCoordinateReferenceSystems.
/**
* Verifies the WKT consistency of all CRS instances.
*
* @throws FactoryException if an error other than "unsupported operation method" occurred.
*/
@Test
public void testCoordinateReferenceSystems() throws FactoryException {
assumeTrue(RUN_EXTENSIVE_TESTS);
final WKTFormat v1 = new WKTFormat(null, null);
final WKTFormat v1c = new WKTFormat(null, null);
final WKTFormat v2 = new WKTFormat(null, null);
final WKTFormat v2s = new WKTFormat(null, null);
v1.setConvention(Convention.WKT1);
v1c.setConvention(Convention.WKT1_COMMON_UNITS);
v2.setConvention(Convention.WKT2);
v2s.setConvention(Convention.WKT2_SIMPLIFIED);
for (final String code : CRS.getAuthorityFactory(null).getAuthorityCodes(CoordinateReferenceSystem.class)) {
if (!EXCLUDES.contains(code)) {
final CoordinateReferenceSystem crs;
try {
crs = CRS.forCode(code);
} catch (UnavailableFactoryException | NoSuchIdentifierException | FactoryDataException e) {
print(code, "WARNING", e.getLocalizedMessage());
continue;
}
lookup(parseAndFormat(v2, code, crs), crs);
lookup(parseAndFormat(v2s, code, crs), crs);
/*
* There is more information lost in WKT 1 than in WKT 2, so we can not test everything.
* For example we can not format fully three-dimensional geographic CRS because the unit
* is not the same for all axes. We can not format neither some axis directions.
*/
try {
parseAndFormat(v1, code, crs);
} catch (UnformattableObjectException e) {
print(code, "WARNING", e.getLocalizedMessage());
continue;
}
parseAndFormat(v1c, code, crs);
}
}
}
use of org.apache.sis.io.wkt.WKTFormat in project sis by apache.
the class MTFactory method createFromWKT.
/**
* Parses the given Well Known Text (version 1) into a math transform.
*/
@Override
public synchronized MathTransform createFromWKT(final String wkt) throws FactoryException {
ArgumentChecks.ensureNonEmpty("wkt", wkt);
if (parser == null) {
parser = new WKTFormat(null, null);
parser.setFactory(CRSAuthorityFactory.class, this);
parser.setFactory(MathTransformFactory.class, this);
parser.setFactory(CoordinateOperationFactory.class, this);
}
try {
return (MathTransform) parser.parseObject(wkt);
} catch (ParseException | ClassCastException e) {
throw new FactoryException(e);
}
}
use of org.apache.sis.io.wkt.WKTFormat in project sis by apache.
the class TransformCommand method printDetails.
/**
* Prints the coordinate operation or math transform in Well Known Text format.
* This information is printed only if the {@code --verbose} option was specified.
*/
private void printDetails() throws IOException {
final boolean debug = options.containsKey(Option.DEBUG);
final WKTFormat f = new WKTFormat(locale, timezone);
if (colors)
f.setColors(Colors.DEFAULT);
f.setConvention(convention);
CharSequence[] lines = CharSequences.splitOnEOL(f.format(debug ? operation.getMathTransform() : operation));
for (int i = 0; i < lines.length; i++) {
if (i == 0) {
printHeader(Vocabulary.Keys.Details);
} else {
printCommentLinePrefix();
outHeader.nextColumn();
}
outHeader.append(lines[i]);
outHeader.nextLine();
}
final Warnings warnings = f.getWarnings();
if (warnings != null) {
lines = CharSequences.splitOnEOL(warnings.toString());
if (lines.length != 0) {
// Paranoiac check.
printHeader(Vocabulary.Keys.Note);
outHeader.append(lines[0]);
outHeader.nextLine();
}
}
}
use of org.apache.sis.io.wkt.WKTFormat in project sis by apache.
the class CoordinateOperationRegistryTest method createFactory.
/**
* Creates a new {@link DefaultCoordinateOperationFactory} to use for testing purpose.
* The same factory will be used for all tests in this class.
*
* @throws ParseException if an error occurred while preparing the WKT parser.
*/
@BeforeClass
public static void createFactory() throws ParseException {
factory = new DefaultCoordinateOperationFactory();
parser = new WKTFormat(null, null);
parser.addFragment("NTF", "Datum[“Nouvelle Triangulation Française (Paris)”,\n" + " Ellipsoid[“Clarke 1880 (IGN)”, 6378249.2, 293.4660212936269]]");
}
Aggregations