org.opengis.referencing.cs.CartesianCS Java Examples
The following examples show how to use
org.opengis.referencing.cs.CartesianCS.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardDefinitions.java From sis with Apache License 2.0 | 6 votes |
/** * 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 met 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) { throw new IllegalStateException(e); // Should not happen with SIS implementation. } 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); }
Example #2
Source File: CommonAuthorityFactory.java From sis with Apache License 2.0 | 6 votes |
/** * Returns the "Computer display" reference system (CRS:1). This is rarely used. */ private synchronized CoordinateReferenceSystem displayCRS() throws FactoryException { if (displayCRS == null) { final CSFactory csFactory = DefaultFactories.forBuildin(CSFactory.class); final CartesianCS cs = csFactory.createCartesianCS( Collections.singletonMap(CartesianCS.NAME_KEY, "Computer display"), csFactory.createCoordinateSystemAxis(Collections.singletonMap(CartesianCS.NAME_KEY, "i"), "i", AxisDirection.EAST, Units.PIXEL), csFactory.createCoordinateSystemAxis(Collections.singletonMap(CartesianCS.NAME_KEY, "j"), "j", AxisDirection.SOUTH, Units.PIXEL)); final Map<String,Object> properties = new HashMap<>(4); properties.put(EngineeringDatum.NAME_KEY, cs.getName()); properties.put(EngineeringDatum.ANCHOR_POINT_KEY, "Origin is in upper left."); displayCRS = DefaultFactories.forBuildin(CRSFactory.class).createEngineeringCRS(properties, DefaultFactories.forBuildin(DatumFactory.class).createEngineeringDatum(properties), cs); } return displayCRS; }
Example #3
Source File: DefaultGeocentricCRSTest.java From sis with Apache License 2.0 | 6 votes |
/** * Tests WKT 1 formatting using axes in kilometres. The intent of this test is to verify that * the coordinate system replacement documented in {@link #testWKT1()} preserves the axis units. * * @since 0.6 */ @Test @DependsOnMethod("testWKT1") public void testWKT1_kilometres() { DefaultGeocentricCRS crs = HardCodedCRS.GEOCENTRIC; crs = new DefaultGeocentricCRS(IdentifiedObjects.getProperties(crs), crs.getDatum(), Legacy.replaceUnit((CartesianCS) crs.getCoordinateSystem(), Units.KILOMETRE)); assertWktEquals(Convention.WKT1, "GEOCCS[“Geocentric”,\n" + " DATUM[“World Geodetic System 1984”,\n" + " SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" + " PRIMEM[“Greenwich”, 0.0],\n" + " UNIT[“kilometre”, 1000],\n" + " AXIS[“X”, OTHER],\n" + " AXIS[“Y”, EAST],\n" + " AXIS[“Z”, NORTH]]", crs); }
Example #4
Source File: DefaultProjectedCRS.java From sis with Apache License 2.0 | 5 votes |
/** * Returns the coordinate system. */ @Override @XmlElement(name = "cartesianCS", required = true) public final CartesianCS getCoordinateSystem() { /* * See AbstractDerivedCRS.createConversionFromBase(…) for * an explanation about why this method is declared final. */ return (CartesianCS) super.getCoordinateSystem(); }
Example #5
Source File: ProjectionFactory.java From gama with GNU General Public License v3.0 | 5 votes |
void computeTargetCRS(final IScope scope, final CoordinateReferenceSystem crs, final double longitude, final double latitude) { // If we already know in which CRS we project the data in GAMA, no need to recompute it. This information is // normally wiped when an experiment is disposed if (targetCRS != null) { return; } try { if (!GamaPreferences.External.LIB_TARGETED.getValue()) { targetCRS = computeDefaultCRS(scope, GamaPreferences.External.LIB_TARGET_CRS.getValue(), true); } else { if (crs != null && crs instanceof DefaultProjectedCRS) { // Temporary fix of issue 766... a better solution final CartesianCS ccs = ((DefaultProjectedCRS) crs).getCoordinateSystem(); final Unit<?> unitX = ccs.getAxis(0).getUnit(); if (unitX != null && !unitX.equals(SI.METER)) { unitConverter = unitX.getConverterTo(SI.METER); } targetCRS = crs; } else { final int index = (int) (0.5 + (longitude + 186.0) / 6); final boolean north = latitude > 0; final String newCode = EPSGPrefix + (32600 + index + (north ? 0 : 100)); targetCRS = getCRS(scope, newCode); } } } catch (final GamaRuntimeException e) { e.addContext( "The cause could be that you try to re-project already projected data (see Gama > Preferences... > External for turning the option to true)"); throw e; } }
Example #6
Source File: AbstractCRS.java From sis with Apache License 2.0 | 5 votes |
/** * Returns the coordinate system if it is of the given type, or {@code null} otherwise. * This method is invoked by subclasses that can accept more than one CS type. */ @SuppressWarnings("unchecked") final <T extends CoordinateSystem> T getCoordinateSystem(final Class<T> type) { final CoordinateSystem cs = coordinateSystem; if (type.isInstance(cs)) { // Special case for AfficeCS: must ensure that the cs is not the CartesianCS subtype. if (type != AffineCS.class || !(cs instanceof CartesianCS)) { return (T) cs; } } return null; }
Example #7
Source File: Legacy.java From sis with Apache License 2.0 | 5 votes |
/** * 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); }
Example #8
Source File: CoordinateSystemsTest.java From sis with Apache License 2.0 | 5 votes |
/** * Tests {@link CoordinateSystems#getEpsgCode(Class, CoordinateSystemAxis...)} * with an ellipsoidal coordinate system. */ @Test public void testGetEpsgCodeForCartesianCS() { final Class<CartesianCS> type = CartesianCS.class; final CoordinateSystemAxis E = HardCodedAxes.EASTING; final CoordinateSystemAxis W = HardCodedAxes.WESTING; final CoordinateSystemAxis N = HardCodedAxes.NORTHING; assertEquals(Integer.valueOf(4400), CoordinateSystems.getEpsgCode(type, E, N)); assertEquals(Integer.valueOf(4500), CoordinateSystems.getEpsgCode(type, N, E)); assertEquals(Integer.valueOf(4501), CoordinateSystems.getEpsgCode(type, N, W)); assertNull(CoordinateSystems.getEpsgCode(type, HardCodedAxes.GEODETIC_LATITUDE, HardCodedAxes.GEODETIC_LONGITUDE)); }
Example #9
Source File: StandardDefinitionsTest.java From sis with Apache License 2.0 | 5 votes |
/** * Tests {@link StandardDefinitions#createCoordinateSystem(short, boolean)}. * * @since 1.0 */ @Test @DependsOnMethod("testCreateAxis") public void testCreateCoordinateSystem() { CoordinateSystem cs = StandardDefinitions.createCoordinateSystem((short) 4400, true); assertInstanceOf("projected", CartesianCS.class, cs); assertEquals("dimension", 2, cs.getDimension()); assertEquals("unit", Units.METRE, cs.getAxis(0).getUnit()); assertEquals("unit", Units.METRE, cs.getAxis(1).getUnit()); assertEquals("direction", AxisDirection.EAST, cs.getAxis(0).getDirection()); assertEquals("direction", AxisDirection.NORTH, cs.getAxis(1).getDirection()); }
Example #10
Source File: DefaultMathTransformFactory.java From sis with Apache License 2.0 | 5 votes |
/** * Creates a math transform that represent a change of coordinate system. If exactly one argument is * an {@linkplain org.apache.sis.referencing.cs.DefaultEllipsoidalCS ellipsoidal coordinate systems}, * then the {@code ellipsoid} argument is mandatory. In all other cases (including the case where both * coordinate systems are ellipsoidal), the ellipsoid argument is ignored and can be {@code null}. * * <div class="note"><b>Design note:</b> * this method does not accept separated ellipsoid arguments for {@code source} and {@code target} because * this method should not be used for datum shifts. If the two given coordinate systems are ellipsoidal, * then they are assumed to use the same ellipsoid. If different ellipsoids are desired, then a * {@linkplain #createParameterizedTransform parameterized transform} like <cite>"Molodensky"</cite>, * <cite>"Geocentric translations"</cite>, <cite>"Coordinate Frame Rotation"</cite> or * <cite>"Position Vector transformation"</cite> should be used instead.</div> * * @param source the source coordinate system. * @param target the target coordinate system. * @param ellipsoid the ellipsoid of {@code EllipsoidalCS}, or {@code null} if none. * @return a conversion from the given source to the given target coordinate system. * @throws FactoryException if the conversion can not be created. * * @since 0.8 */ public MathTransform createCoordinateSystemChange(final CoordinateSystem source, final CoordinateSystem target, final Ellipsoid ellipsoid) throws FactoryException { ArgumentChecks.ensureNonNull("source", source); ArgumentChecks.ensureNonNull("target", target); if (ellipsoid != null) { final boolean isEllipsoidalSource = (source instanceof EllipsoidalCS); if (isEllipsoidalSource != (target instanceof EllipsoidalCS)) { /* * For now we support only conversion between EllipsoidalCS and CartesianCS. * But future Apache SIS versions could add support for conversions between * EllipsoidalCS and SphericalCS or other coordinate systems. */ if ((isEllipsoidalSource ? target : source) instanceof CartesianCS) { final Context context = new Context(); final EllipsoidalCS cs; final String operation; if (isEllipsoidalSource) { operation = GeographicToGeocentric.NAME; context.setSource(cs = (EllipsoidalCS) source, ellipsoid); context.setTarget(target); } else { operation = GeocentricToGeographic.NAME; context.setSource(source); context.setTarget(cs = (EllipsoidalCS) target, ellipsoid); } final ParameterValueGroup pg = getDefaultParameters(operation); if (cs.getDimension() < 3) pg.parameter("dim").setValue(2); // Apache SIS specific parameter. return createParameterizedTransform(pg, context); } } } return CoordinateSystemTransform.create(this, source, target); // No need to use unique(…) here. }
Example #11
Source File: EPSGFactoryFallbackTest.java From sis with Apache License 2.0 | 5 votes |
/** * Tests {@link EPSGFactoryFallback#getAuthorityCodes(Class)}. * * @throws FactoryException if the set of authority codes can not be fetched. */ @Test public void testGetAuthorityCodes() throws FactoryException { assertSetEquals(Arrays.asList(StandardDefinitions.GREENWICH), EPSGFactoryFallback.INSTANCE.getAuthorityCodes(PrimeMeridian.class)); assertSetEquals(Arrays.asList("7030", "7043", "7019", "7008", "7022", "7048"), EPSGFactoryFallback.INSTANCE.getAuthorityCodes(Ellipsoid.class)); assertSetEquals(Arrays.asList("6326", "6322", "6269", "6267", "6258", "6230", "6019", "6047", "5100", "5103"), EPSGFactoryFallback.INSTANCE.getAuthorityCodes(Datum.class)); assertSetEquals(Arrays.asList("6422", "6423"), EPSGFactoryFallback.INSTANCE.getAuthorityCodes(EllipsoidalCS.class)); assertSetEquals(Arrays.asList("6404"), EPSGFactoryFallback.INSTANCE.getAuthorityCodes(SphericalCS.class)); assertSetEquals(Arrays.asList("6500", "4400", "1026", "1027"), EPSGFactoryFallback.INSTANCE.getAuthorityCodes(CartesianCS.class)); assertSetEquals(Arrays.asList("4978", "4984", "4936"), EPSGFactoryFallback.INSTANCE.getAuthorityCodes(GeocentricCRS.class)); assertSetEquals(Arrays.asList("4326", "4322", "4019", "4047", "4269", "4267", "4258", "4230", "4979", "4985", "4937"), EPSGFactoryFallback.INSTANCE.getAuthorityCodes(GeographicCRS.class)); assertSetEquals(Arrays.asList("5714", "5715", "5703"), EPSGFactoryFallback.INSTANCE.getAuthorityCodes(VerticalCRS.class)); /* * There is too many ProjectedCRS codes for enumerating all of them, so test only a sampling. */ final Set<String> codes = EPSGFactoryFallback.INSTANCE.getAuthorityCodes(ProjectedCRS.class); assertTrue(codes.containsAll(Arrays.asList("5041", "5042", "32601", "32660", "32701", "32760"))); assertTrue(Collections.disjoint(codes, Arrays.asList("7030", "6326", "4326", "4978", "32600", "32700", "5714"))); }
Example #12
Source File: CRSBuilder.java From sis with Apache License 2.0 | 5 votes |
/** * Returns a coordinate system (CS) with the same axis directions than the given CS but potentially different units. * If a coordinate system exists in the EPSG database with the requested characteristics, that CS will be returned * in order to have a richer set of metadata (name, minimal and maximal values, <i>etc</i>). Otherwise an CS with * an arbitrary name will be returned. * * @see CoordinateSystems#replaceLinearUnit(CoordinateSystem, Unit) */ private CartesianCS replaceLinearUnit(final CartesianCS cs, final Unit<Length> unit) throws FactoryException { final Integer epsg = CoordinateSystems.getEpsgCode(unit, CoordinateSystems.getAxisDirections(cs)); if (epsg != null) try { return getCSAuthorityFactory().createCartesianCS(epsg.toString()); } catch (NoSuchAuthorityCodeException e) { reader.owner.warning(null, e); } return (CartesianCS) CoordinateSystems.replaceLinearUnit(cs, unit); }
Example #13
Source File: DefaultImageCRSTest.java From sis with Apache License 2.0 | 4 votes |
/** * 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()); }
Example #14
Source File: DefaultEngineeringCRSTest.java From sis with Apache License 2.0 | 4 votes |
/** * Tests XML (un)marshalling of an engineering CRS using a Cartesian CS. * * @throws JAXBException if an error occurred during (un)marshalling. */ @Test public void testCartesianXML() throws JAXBException { final String xml = marshal(createCartesian()); assertXmlEquals( "<gml:EngineeringCRS xmlns:gml=\"" + Namespaces.GML + "\">\n" + " <gml:name>A construction site CRS</gml:name>\n" + " <gml:cartesianCS gml:id=\"Cartesian2D\">\n" + " <gml:name>Cartesian 2D</gml:name>\n" + " <gml:axis>\n" + " <gml:CoordinateSystemAxis uom=\"urn:ogc:def:uom:EPSG::9001\" gml:id=\"x\">\n" + " <gml:name>x</gml:name>\n" + " <gml:axisAbbrev>x</gml:axisAbbrev>\n" + " <gml:axisDirection codeSpace=\"EPSG\">east</gml:axisDirection>\n" + " </gml:CoordinateSystemAxis>\n" + " </gml:axis>\n" + " <gml:axis>\n" + " <gml:CoordinateSystemAxis uom=\"urn:ogc:def:uom:EPSG::9001\" gml:id=\"y\">\n" + " <gml:name>y</gml:name>\n" + " <gml:axisAbbrev>y</gml:axisAbbrev>\n" + " <gml:axisDirection codeSpace=\"EPSG\">north</gml:axisDirection>\n" + " </gml:CoordinateSystemAxis>\n" + " </gml:axis>\n" + " </gml:cartesianCS>\n" + " <gml:engineeringDatum>\n" + " <gml:EngineeringDatum gml:id=\"P1\">\n" + " <gml:name>P1</gml:name>\n" + " </gml:EngineeringDatum>\n" + " </gml:engineeringDatum>\n" + "</gml:EngineeringCRS>", xml, "xmlns:*"); final DefaultEngineeringCRS crs = unmarshal(DefaultEngineeringCRS.class, xml); assertEquals("name", "A construction site CRS", crs.getName().getCode()); assertEquals("datum.name", "P1", crs.getDatum().getName().getCode()); final CoordinateSystem cs = crs.getCoordinateSystem(); assertInstanceOf("coordinateSystem", CartesianCS.class, cs); assertEquals("cs.name", "Cartesian 2D", cs.getName().getCode()); assertEquals("cs.dimension", 2, cs.getDimension()); assertAxisDirectionsEqual("cartesianCS", cs, AxisDirection.EAST, AxisDirection.NORTH); assertEquals("cs.axis[0].name", "x", cs.getAxis(0).getName().getCode()); assertEquals("cs.axis[1].name", "y", cs.getAxis(1).getName().getCode()); }
Example #15
Source File: GeodeticObjectVerifier.java From sis with Apache License 2.0 | 4 votes |
/** * Asserts that the given coordinate system contains the (easting, northing) axes in metres. * This method verifies the following properties: * * <table class="sis"> * <caption>Verified properties</caption> * <tr><th>Property</th> <th colspan="2">Expected value</th></tr> * <tr><td>{@linkplain CartesianCS#getDimension() Dimension}</td> * <td colspan="2">2</td></tr> * <tr><td>Axes {@linkplain Identifier#getCode() Code} of the {@linkplain GeodeticDatum#getName() name}</td> * <td>{@code "Easting"}</td> * <td>{@code "Northing"}</td></tr> * <tr><td>Axes {@linkplain CoordinateSystemAxis#getAbbreviation() abbreviation}</td> * <td>{@code "E"}</td> * <td>{@code "N"}</td></tr> * <tr><td>Axes {@linkplain CoordinateSystemAxis#getDirection() direction}</td> * <td>{@link AxisDirection#EAST EAST}</td> * <td>{@link AxisDirection#NORTH NORTH}</td></tr> * <tr><td>Axes {@linkplain CoordinateSystemAxis#getUnit() units}</td> * <td>{@link Units#METRE}</td> * <td>{@link Units#METRE}</td></tr> * <tr><td>Axes range</td> * <td>[−∞ … ∞]</td> * <td>[−∞ … ∞]</td></tr> * <tr><td>Axes range meaning</td> * <td>{@code null}</td> * <td>{@code null}</td> * </table> * * @param cs the coordinate system to verify. */ public static void assertIsProjected2D(final CartesianCS cs) { assertEquals("dimension", 2, cs.getDimension()); final CoordinateSystemAxis E = cs.getAxis(0); final CoordinateSystemAxis N = cs.getAxis(1); assertNotNull("axis", E); assertNotNull("axis", N); assertEquals("axis[0].name", AxisNames.EASTING, E.getName().getCode()); assertEquals("axis[1].name", AxisNames.NORTHING, N.getName().getCode()); assertEquals("axis[0].abbreviation", "E", E.getAbbreviation()); assertEquals("axis[1].abbreviation", "N", N.getAbbreviation()); assertEquals("axis[0].direction", AxisDirection.EAST, E.getDirection()); assertEquals("axis[1].direction", AxisDirection.NORTH, N.getDirection()); assertEquals("axis[0].unit", Units.METRE, E.getUnit()); assertEquals("axis[1].unit", Units.METRE, N.getUnit()); verifyRange(E, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, null, true); verifyRange(N, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, null, true); }
Example #16
Source File: CRSTest.java From sis with Apache License 2.0 | 4 votes |
/** * Tests {@link CRS#suggestCommonTarget(GeographicBoundingBox, CoordinateReferenceSystem...)}. * * @since 0.8 */ @Test public void testSuggestCommonTarget() { /* * Prepare 4 CRS with different datum (so we can more easily differentiate them in the assertions) and * different domain of validity. CRS[1] is given a domain large enough for all CRS except the last one. */ final Map<String,Object> properties = new HashMap<>(4); final CartesianCS cs = HardCodedCS.PROJECTED; final ProjectedCRS[] crs = new ProjectedCRS[4]; for (int i=0; i<crs.length; i++) { final CommonCRS baseCRS; final double ymin, ymax; switch (i) { case 0: baseCRS = CommonCRS.WGS84; ymin = 2; ymax = 4; break; case 1: baseCRS = CommonCRS.WGS72; ymin = 1; ymax = 4; break; case 2: baseCRS = CommonCRS.SPHERE; ymin = 2; ymax = 3; break; case 3: baseCRS = CommonCRS.NAD27; ymin = 3; ymax = 5; break; default: throw new AssertionError(i); } properties.put(DefaultProjectedCRS.NAME_KEY, "CRS #" + i); properties.put(DefaultProjectedCRS.DOMAIN_OF_VALIDITY_KEY, new DefaultExtent( null, new DefaultGeographicBoundingBox(-1, +1, ymin, ymax), null, null)); crs[i] = new DefaultProjectedCRS(properties, baseCRS.geographic(), HardCodedConversions.MERCATOR, cs); } final ProjectedCRS[] overlappingCRS = Arrays.copyOf(crs, 3); // Exclude the last CRS only. /* * Test between the 3 overlapping CRS without region of interest. We expect the CRS having a domain * of validity large enough for all CRS; this is the second CRS created in above 'switch' statement. */ assertSame("Expected CRS with widest domain of validity.", crs[1], CRS.suggestCommonTarget(null, overlappingCRS)); /* * If we specify a smaller region of interest, we should get the CRS having the smallest domain of validity that * cover the ROI. Following lines gradually increase the ROI size and verify that we get CRS for larger domain. */ final DefaultGeographicBoundingBox regionOfInterest = new DefaultGeographicBoundingBox(-1, +1, 2.1, 2.9); assertSame("Expected best fit for [2.1 … 2.9]°N", crs[2], CRS.suggestCommonTarget(regionOfInterest, overlappingCRS)); regionOfInterest.setNorthBoundLatitude(3.1); assertSame("Expected best fit for [2.1 … 3.1]°N", crs[0], CRS.suggestCommonTarget(regionOfInterest, overlappingCRS)); regionOfInterest.setSouthBoundLatitude(1.9); assertSame("Expected best fit for [1.9 … 3.1]°N", crs[1], CRS.suggestCommonTarget(regionOfInterest, overlappingCRS)); /* * All above tests returned one of the CRS in the given array. Test now a case where none of those CRS * have a domain of validity wide enough, so suggestCommonTarget(…) need to search among the base CRS. */ assertSame("Expected a GeodeticCRS since none of the ProjectedCRS have a domain of validity wide enough.", crs[0].getBaseCRS(), CRS.suggestCommonTarget(null, crs)); /* * With the same domain of validity than above, suggestCommonTarget(…) should not need to fallback on the * base CRS anymore. */ assertSame("Expected best fit for [1.9 … 3.1]°N", crs[1], CRS.suggestCommonTarget(regionOfInterest, crs)); final ProjectedCRS utm13N = CommonCRS.WGS84.universal(20, 13); final ProjectedCRS utm42S = CommonCRS.WGS84.universal(-2, 42); assertSame("CRS suggestion should fallback on common base geographic system when possible.", CommonCRS.WGS84.geographic(), CRS.suggestCommonTarget(null, utm13N, utm42S)); assertNotNull("Disjoint systems should return a geographic suggestion when possible", CRS.suggestCommonTarget(null, CommonCRS.WGS84.universal(-7, 19), CommonCRS.NAD27.universal(20, -101), CommonCRS.NAD27.universal(18, -20) ) ); }
Example #17
Source File: CS_CartesianCS.java From sis with Apache License 2.0 | 4 votes |
/** * Constructor for the {@link #wrap} method only. */ private CS_CartesianCS(final CartesianCS cs) { super(cs); }
Example #18
Source File: EPSGFactoryFallback.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the list of EPSG codes available. */ @Override public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) { final boolean pm = type.isAssignableFrom(PrimeMeridian.class); final boolean ellipsoid = type.isAssignableFrom(Ellipsoid .class); final boolean datum = type.isAssignableFrom(GeodeticDatum.class); final boolean geographic = type.isAssignableFrom(GeographicCRS.class); final boolean geocentric = type.isAssignableFrom(GeocentricCRS.class); final boolean projected = type.isAssignableFrom(ProjectedCRS .class); final Set<String> codes = new LinkedHashSet<>(); if (pm) codes.add(StandardDefinitions.GREENWICH); for (final CommonCRS crs : CommonCRS.values()) { if (ellipsoid) add(codes, crs.ellipsoid); if (datum) add(codes, crs.datum); if (geocentric) add(codes, crs.geocentric); if (geographic) { add(codes, crs.geographic); add(codes, crs.geo3D); } if (projected) { add(codes, crs.northUPS); add(codes, crs.southUPS); if (crs.northUTM != 0 || crs.southUTM != 0) { for (int zone = crs.firstZone; zone <= crs.lastZone; zone++) { if (crs.northUTM != 0) codes.add(Integer.toString(crs.northUTM + zone)); if (crs.southUTM != 0) codes.add(Integer.toString(crs.southUTM + zone)); } } } } final boolean vertical = type.isAssignableFrom(VerticalCRS .class); final boolean vdatum = type.isAssignableFrom(VerticalDatum.class); if (vertical || vdatum) { for (final CommonCRS.Vertical candidate : CommonCRS.Vertical.values()) { if (candidate.isEPSG) { if (vertical) add(codes, candidate.crs); if (vdatum) add(codes, candidate.datum); } } } if (type.isAssignableFrom(EllipsoidalCS.class)) { add(codes, StandardDefinitions.ELLIPSOIDAL_2D); add(codes, StandardDefinitions.ELLIPSOIDAL_3D); } if (type.isAssignableFrom(SphericalCS.class)) { add(codes, StandardDefinitions.SPHERICAL); } if (type.isAssignableFrom(CartesianCS.class)) { add(codes, StandardDefinitions.EARTH_CENTRED); add(codes, StandardDefinitions.CARTESIAN_2D); add(codes, StandardDefinitions.UPS_NORTH); add(codes, StandardDefinitions.UPS_SOUTH); } if (type.isAssignableFrom(Unit.class)) { add(codes, Constants.EPSG_METRE); add(codes, Constants.EPSG_AXIS_DEGREES); } return codes; }
Example #19
Source File: ProjectedCrsImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
public CartesianCS getCoordinateSystem() { return base.getCoordinateSystem(); }
Example #20
Source File: DefaultProjectedCRS.java From sis with Apache License 2.0 | 4 votes |
/** * Returns a coordinate reference system of the same type than this CRS but with different axes. */ @Override final AbstractCRS createSameType(final Map<String,?> properties, final CoordinateSystem cs) { final Projection conversion = super.getConversionFromBase(); return new DefaultProjectedCRS(properties, (GeographicCRS) conversion.getSourceCRS(), conversion, (CartesianCS) cs); }
Example #21
Source File: GridMapping.java From sis with Apache License 2.0 | 4 votes |
/** * If the netCDF variable defines explicitly the map projection method and its parameters, returns those parameters. * Otherwise returns {@code null}. The given {@code node} argument is typically a dummy variable referenced by value * of the {@value CF#GRID_MAPPING} attribute on the real data variable (as required by CF-conventions), but may also * be something else (the data variable itself, or a group, <i>etc.</i>). That node, together with the attributes to * be parsed, depends on the {@link Convention} instance. * * @see <a href="http://cfconventions.org/cf-conventions/cf-conventions.html#grid-mappings-and-projections">CF-conventions</a> */ private static GridMapping parseProjectionParameters(final Node node) { final Map<String,Object> definition = node.decoder.convention().projection(node); if (definition != null) try { /* * Fetch now numerical values that are not map projection parameters. * This step needs to be done before to try to set parameter values. */ final Object greenwichLongitude = definition.remove(Convention.LONGITUDE_OF_PRIME_MERIDIAN); /* * Prepare the block of projection parameters. The set of legal parameter depends on the map projection. * We assume that all numerical values are map projection parameters; character sequences (assumed to be * component names) are handled later. The CF-conventions use parameter names that are slightly different * than OGC names, but Apache SIS implementations of map projections know how to handle them, including * the redundant parameters like "inverse_flattening" and "earth_radius". */ final DefaultCoordinateOperationFactory opFactory = node.decoder.getCoordinateOperationFactory(); final OperationMethod method = opFactory.getOperationMethod((String) definition.remove(CF.GRID_MAPPING_NAME)); final ParameterValueGroup parameters = method.getParameters().createValue(); for (final Map.Entry<String,Object> entry : definition.entrySet()) { final String name = entry.getKey(); final Object value = entry.getValue(); if (value instanceof Number || value instanceof double[] || value instanceof float[]) try { parameters.parameter(name).setValue(value); } catch (IllegalArgumentException ex) { warning(node, ex, Resources.Keys.CanNotSetProjectionParameter_5, node.decoder.getFilename(), node.getName(), name, value, ex.getLocalizedMessage()); } } /* * In principle, projection parameters do not include the semi-major and semi-minor axis lengths. * But if those information are provided, then we use them for building the geodetic reference frame. * Otherwise a default reference frame will be used. */ final GeographicCRS baseCRS = createBaseCRS(node.decoder, parameters, definition, greenwichLongitude); final MathTransform baseToCRS; final CoordinateReferenceSystem crs; if (method instanceof PseudoPlateCarree) { // Only swap axis order from (latitude, longitude) to (longitude, latitude). baseToCRS = MathTransforms.linear(new Matrix3(0, 1, 0, 1, 0, 0, 0, 0, 1)); crs = baseCRS; } else { Map<String,?> properties = properties(definition, Convention.CONVERSION_NAME, node.getName()); final Conversion conversion = opFactory.createDefiningConversion(properties, method, parameters); final CartesianCS cs = node.decoder.getStandardProjectedCS(); properties = properties(definition, Convention.PROJECTED_CRS_NAME, conversion); final ProjectedCRS p = node.decoder.getCRSFactory().createProjectedCRS(properties, baseCRS, conversion, cs); baseToCRS = p.getConversionFromBase().getMathTransform(); crs = p; } /* * Build the "grid to CRS" if present. This is not defined by CF-convention, * but may be present in some non-CF conventions. */ final MathTransform gridToCRS = node.decoder.convention().gridToCRS(node, baseToCRS); return new GridMapping(crs, gridToCRS, false); } catch (ClassCastException | IllegalArgumentException | FactoryException | TransformException e) { canNotCreate(node, Resources.Keys.CanNotCreateCRS_3, e); } return null; }
Example #22
Source File: CoordinateSystemTransform.java From sis with Apache License 2.0 | 4 votes |
/** * Implementation of {@link DefaultMathTransformFactory#createCoordinateSystemChange(CoordinateSystem, * CoordinateSystem, Ellipsoid)}, defined here for reducing the {@code DefaultMathTransformFactory} * weight in the common case where the conversions handled by this class are not needed. */ static MathTransform create(final MathTransformFactory factory, final CoordinateSystem source, final CoordinateSystem target) throws FactoryException { int passthrough = 0; CoordinateSystemTransform kernel = null; if (source instanceof CartesianCS) { if (target instanceof SphericalCS) { kernel = CartesianToSpherical.INSTANCE; } else if (target instanceof PolarCS) { kernel = CartesianToPolar.INSTANCE; } else if (target instanceof CylindricalCS) { kernel = CartesianToPolar.INSTANCE; passthrough = 1; } } else if (target instanceof CartesianCS) { if (source instanceof SphericalCS) { kernel = SphericalToCartesian.INSTANCE; } else if (source instanceof PolarCS) { kernel = PolarToCartesian.INSTANCE; } else if (source instanceof CylindricalCS) { kernel = PolarToCartesian.INSTANCE; passthrough = 1; } } Exception cause = null; try { if (kernel == null) { return factory.createAffineTransform(CoordinateSystems.swapAndScaleAxes(source, target)); } else if (source.getDimension() == kernel.getSourceDimensions() + passthrough && target.getDimension() == kernel.getTargetDimensions() + passthrough) { final MathTransform tr = (passthrough == 0) ? kernel.completeTransform(factory) : kernel.passthrough(factory); final MathTransform before = factory.createAffineTransform( CoordinateSystems.swapAndScaleAxes(source, CoordinateSystems.replaceAxes(source, AxesConvention.NORMALIZED))); final MathTransform after = factory.createAffineTransform( CoordinateSystems.swapAndScaleAxes( CoordinateSystems.replaceAxes(target, AxesConvention.NORMALIZED), target)); return factory.createConcatenatedTransform(before, factory.createConcatenatedTransform(tr, after)); } } catch (IllegalArgumentException | IncommensurableException e) { cause = e; } throw new OperationNotFoundException(Resources.format(Resources.Keys.CoordinateOperationNotFound_2, WKTUtilities.toType(CoordinateSystem.class, source.getClass()), WKTUtilities.toType(CoordinateSystem.class, target.getClass())), cause); }
Example #23
Source File: MathTransformContext.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the normalization or denormalization matrix. */ @Override @SuppressWarnings("fallthrough") public Matrix getMatrix(final MatrixRole role) throws FactoryException { final CoordinateSystem cs; boolean inverse = false; double rotation; switch (role) { default: throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2, "role", role)); case INVERSE_NORMALIZATION: inverse = true; // Fall through case NORMALIZATION: rotation = sourceMeridian; cs = getSourceCS(); break; case INVERSE_DENORMALIZATION: inverse = true; // Fall through case DENORMALIZATION: inverse = !inverse; rotation = targetMeridian; cs = getTargetCS(); break; } Matrix matrix = super.getMatrix(role); if (rotation != 0) { if (inverse) rotation = -rotation; MatrixSIS cm = MatrixSIS.castOrCopy(matrix); if (cs instanceof CartesianCS) { rotation = Math.toRadians(rotation); final Matrix4 rot = new Matrix4(); rot.m00 = rot.m11 = Math.cos(rotation); rot.m01 = -(rot.m10 = Math.sin(rotation)); if (inverse) { matrix = Matrices.multiply(rot, cm); // Apply the rotation after denormalization. } else { matrix = cm.multiply(rot); // Apply the rotation before normalization. } } else if (cs == null || cs instanceof EllipsoidalCS || cs instanceof SphericalCS) { final Double value = rotation; if (inverse) { cm.convertBefore(0, null, value); // Longitude is the first axis in normalized CS. } else { cm.convertAfter(0, null, value); } matrix = cm; } else { throw new FactoryException(Errors.format(Errors.Keys.UnsupportedCoordinateSystem_1, cs.getName())); } } return matrix; }
Example #24
Source File: SubTypes.java From sis with Apache License 2.0 | 4 votes |
/** * Returns a SIS implementation for the given coordinate reference system. * * @see AbstractCRS#castOrCopy(CoordinateReferenceSystem) */ static AbstractCRS castOrCopy(final CoordinateReferenceSystem object) { if (object instanceof DerivedCRS) { return DefaultDerivedCRS.castOrCopy((DerivedCRS) object); } if (object instanceof ProjectedCRS) { return DefaultProjectedCRS.castOrCopy((ProjectedCRS) object); } if (object instanceof GeodeticCRS) { if (object instanceof GeographicCRS) { return DefaultGeographicCRS.castOrCopy((GeographicCRS) object); } if (object instanceof GeocentricCRS) { return DefaultGeocentricCRS.castOrCopy((GeocentricCRS) object); } /* * The GeographicCRS and GeocentricCRS types are not part of ISO 19111. * ISO uses a single type, GeodeticCRS, for both of them and infer the * geographic or geocentric type from the coordinate system. We do this * check here for instantiating the most appropriate SIS type, but only * if we need to create a new object anyway (see below for rational). */ if (object instanceof DefaultGeodeticCRS) { /* * Result of XML unmarshalling — keep as-is. We avoid creating a new object because it * would break object identities specified in GML document by the xlink:href attribute. * However we may revisit this policy in the future. See SC_CRS.setElement(AbstractCRS). */ return (DefaultGeodeticCRS) object; } final Map<String,?> properties = IdentifiedObjects.getProperties(object); final GeodeticDatum datum = ((GeodeticCRS) object).getDatum(); final CoordinateSystem cs = object.getCoordinateSystem(); if (cs instanceof EllipsoidalCS) { return new DefaultGeographicCRS(properties, datum, (EllipsoidalCS) cs); } if (cs instanceof SphericalCS) { return new DefaultGeocentricCRS(properties, datum, (SphericalCS) cs); } if (cs instanceof CartesianCS) { return new DefaultGeocentricCRS(properties, datum, (CartesianCS) cs); } } if (object instanceof VerticalCRS) { return DefaultVerticalCRS.castOrCopy((VerticalCRS) object); } if (object instanceof TemporalCRS) { return DefaultTemporalCRS.castOrCopy((TemporalCRS) object); } if (object instanceof EngineeringCRS) { return DefaultEngineeringCRS.castOrCopy((EngineeringCRS) object); } if (object instanceof ImageCRS) { return DefaultImageCRS.castOrCopy((ImageCRS) object); } if (object instanceof CompoundCRS) { return DefaultCompoundCRS.castOrCopy((CompoundCRS) object); } /* * Intentionally check for AbstractCRS after the interfaces because user may have defined his own * subclass implementing the interface. If we were checking for AbstractCRS before the interfaces, * the returned instance could have been a user subclass without the JAXB annotations required * for XML marshalling. */ if (object == null || object instanceof AbstractCRS) { return (AbstractCRS) object; } return new AbstractCRS(object); }
Example #25
Source File: CRS.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the first horizontal coordinate reference system found in the given CRS, or {@code null} if there is * none. If the given CRS is already horizontal according {@link #isHorizontalCRS(CoordinateReferenceSystem)}, * then this method returns it as-is. Otherwise if the given CRS is compound, then this method searches for the * first horizontal component in the order of the {@linkplain #getSingleComponents(CoordinateReferenceSystem) * single components list}. * * <p>In the special case where a three-dimensional geographic or projected CRS is found, this method * will create a two-dimensional geographic or projected CRS without the vertical axis.</p> * * @param crs the coordinate reference system, or {@code null}. * @return the first horizontal CRS, or {@code null} if none. * * @category information */ public static SingleCRS getHorizontalComponent(final CoordinateReferenceSystem crs) { switch (horizontalCode(crs)) { /* * If the CRS is already two-dimensional and horizontal, return as-is. * We don't need to check if crs is an instance of SingleCRS since all * CRS accepted by horizontalCode(…) are SingleCRS. */ case 2: { return (SingleCRS) crs; } case 3: { /* * The CRS would be horizontal if we can remove the vertical axis. CoordinateSystems.replaceAxes(…) * will do this task for us. We can verify if the operation has been successful by checking that * the number of dimensions has been reduced by 1 (from 3 to 2). */ final CoordinateSystem cs = CoordinateSystems.replaceAxes(crs.getCoordinateSystem(), new AxisFilter() { @Override public boolean accept(final CoordinateSystemAxis axis) { return !AxisDirections.isVertical(axis.getDirection()); } }); if (cs.getDimension() != 2) break; /* * Most of the time, the CRS to rebuild will be geodetic. In such case we known that the * coordinate system is ellipsoidal because (i.e. the CRS is geographic) because it was * a condition verified by horizontalCode(…). A ClassCastException would be a bug. */ final Map<String, ?> properties = ReferencingUtilities.getPropertiesForModifiedCRS(crs); if (crs instanceof GeodeticCRS) { return new DefaultGeographicCRS(properties, ((GeodeticCRS) crs).getDatum(), (EllipsoidalCS) cs); } /* * In Apache SIS implementation, the Conversion contains the source and target CRS together with * a MathTransform. We need to recreate the same conversion, but without CRS and MathTransform * for letting SIS create or associate new ones, which will be two-dimensional now. */ if (crs instanceof ProjectedCRS) { final ProjectedCRS proj = (ProjectedCRS) crs; final GeographicCRS base = (GeographicCRS) getHorizontalComponent(proj.getBaseCRS()); Conversion fromBase = proj.getConversionFromBase(); fromBase = new DefaultConversion(IdentifiedObjects.getProperties(fromBase), fromBase.getMethod(), null, fromBase.getParameterValues()); return new DefaultProjectedCRS(properties, base, fromBase, (CartesianCS) cs); } /* * If the CRS is neither geographic or projected, then it is engineering. */ return new DefaultEngineeringCRS(properties, ((EngineeringCRS) crs).getDatum(), cs); } } if (crs instanceof CompoundCRS) { final CompoundCRS cp = (CompoundCRS) crs; for (final CoordinateReferenceSystem c : cp.getComponents()) { final SingleCRS candidate = getHorizontalComponent(c); if (candidate != null) { return candidate; } } } return null; }
Example #26
Source File: DefaultGeocentricCRS.java From sis with Apache License 2.0 | 3 votes |
/** * Creates a coordinate reference system from the given properties, datum and coordinate system. * The properties given in argument follow the same rules than for the * {@linkplain AbstractReferenceSystem#AbstractReferenceSystem(Map) super-class constructor}. * The following table is a reminder of main (not all) properties: * * <table class="sis"> * <caption>Recognized properties (non exhaustive list)</caption> * <tr> * <th>Property name</th> * <th>Value type</th> * <th>Returned by</th> * </tr> * <tr> * <td>{@value org.opengis.referencing.IdentifiedObject#NAME_KEY}</td> * <td>{@link org.opengis.referencing.ReferenceIdentifier} or {@link String}</td> * <td>{@link #getName()}</td> * </tr> * <tr> * <td>{@value org.opengis.referencing.IdentifiedObject#ALIAS_KEY}</td> * <td>{@link org.opengis.util.GenericName} or {@link CharSequence} (optionally as array)</td> * <td>{@link #getAlias()}</td> * </tr> * <tr> * <td>{@value org.opengis.referencing.IdentifiedObject#IDENTIFIERS_KEY}</td> * <td>{@link org.opengis.referencing.ReferenceIdentifier} (optionally as array)</td> * <td>{@link #getIdentifiers()}</td> * </tr> * <tr> * <td>{@value org.opengis.referencing.IdentifiedObject#REMARKS_KEY}</td> * <td>{@link org.opengis.util.InternationalString} or {@link String}</td> * <td>{@link #getRemarks()}</td> * </tr> * <tr> * <td>{@value org.opengis.referencing.ReferenceSystem#DOMAIN_OF_VALIDITY_KEY}</td> * <td>{@link org.opengis.metadata.extent.Extent}</td> * <td>{@link #getDomainOfValidity()}</td> * </tr> * <tr> * <td>{@value org.opengis.referencing.ReferenceSystem#SCOPE_KEY}</td> * <td>{@link org.opengis.util.InternationalString} or {@link String}</td> * <td>{@link #getScope()}</td> * </tr> * </table> * * @param properties the properties to be given to the coordinate reference system. * @param datum the datum. * @param cs the coordinate system, which must be three-dimensional. * * @see org.apache.sis.referencing.factory.GeodeticObjectFactory#createGeocentricCRS(Map, GeodeticDatum, CartesianCS) */ public DefaultGeocentricCRS(final Map<String,?> properties, final GeodeticDatum datum, final CartesianCS cs) { super(properties, datum, cs); }
Example #27
Source File: DefaultAffineCS.java From sis with Apache License 2.0 | 3 votes |
/** * Returns a SIS coordinate system implementation with the same values than the given arbitrary implementation. * If the given object is {@code null}, then this method returns {@code null}. * Otherwise if the given object is already a SIS implementation, then the given object is returned unchanged. * Otherwise a new SIS implementation is created and initialized to the attribute values of the given object. * * <p>This method checks for the {@link CartesianCS} sub-interface. If that interface is found, * then this method delegates to the corresponding {@code castOrCopy} static method.</p> * * @param object the object to get as a SIS implementation, or {@code null} if none. * @return a SIS implementation containing the values of the given object (may be the * given object itself), or {@code null} if the argument was null. */ public static DefaultAffineCS castOrCopy(final AffineCS object) { if (object instanceof CartesianCS) { return DefaultCartesianCS.castOrCopy((CartesianCS) object); } return (object == null) || (object instanceof DefaultAffineCS) ? (DefaultAffineCS) object : new DefaultAffineCS(object); }
Example #28
Source File: GeodeticObjectBuilder.java From sis with Apache License 2.0 | 3 votes |
/** * Creates a projected CRS using a conversion built from the values given by the {@code setParameter(…)} calls. * * <div class="note"><b>Example:</b> * The following example creates a projected CRS for the <cite>"NTF (Paris) / Lambert zone II"</cite> projection, * from a base CRS which is presumed to already exists in this example. * * {@preformat java * GeodeticObjectBuilder builder = new GeodeticObjectBuilder(); * GeographicCRS baseCRS = ...; * CartesianCS derivedCS = ...; * ProjectedCRS crs = builder * .setConversionMethod("Lambert Conic Conformal (1SP)") * .setConversionName("Lambert zone II") * .setParameter("Latitude of natural origin", 52, Units.GRAD) * .setParameter("Scale factor at natural origin", 0.99987742, Units.UNITY) * .setParameter("False easting", 600000, Units.METRE) * .setParameter("False northing", 2200000, Units.METRE) * .addName("NTF (Paris) / Lambert zone II") * .createProjectedCRS(baseCRS, derivedCS); * } * </div> * * @param baseCRS coordinate reference system to base the derived CRS on. * @param derivedCS the coordinate system for the derived CRS. * @return the projected CRS. * @throws FactoryException if an error occurred while building the projected CRS. */ public ProjectedCRS createProjectedCRS(final GeographicCRS baseCRS, final CartesianCS derivedCS) throws FactoryException { ensureConversionMethodSet(); onCreate(false); try { /* * Create a conversion with the same properties than the ProjectedCRS properties, * except the aliases and identifiers. The name defaults to the ProjectedCRS name, * but can optionally be different. */ final Object name = (conversionName != null) ? properties.put(Conversion.NAME_KEY, conversionName) : null; final Object alias = properties.put(Conversion.ALIAS_KEY, null); final Object identifier = properties.put(Conversion.IDENTIFIERS_KEY, null); final Conversion conversion = factories.getCoordinateOperationFactory().createDefiningConversion(properties, method, parameters); /* * Restore the original properties and create the final ProjectedCRS. */ properties.put(Conversion.IDENTIFIERS_KEY, identifier); properties.put(Conversion.ALIAS_KEY, alias); if (name != null) { properties.put(Conversion.NAME_KEY, name); } return factories.getCRSFactory().createProjectedCRS(properties, baseCRS, conversion, derivedCS); } finally { onCreate(true); } }
Example #29
Source File: GeographicToGeocentric.java From sis with Apache License 2.0 | 3 votes |
/** * If the user asked for the <cite>"Geographic/geocentric conversions"</cite> operation but the parameter types * suggest that (s)he intended to convert in the opposite direction, return the name of operation method to use. * We need this check because EPSG defines a single operation method for both {@code "Ellipsoid_To_Geocentric"} * and {@code "Geocentric_To_Ellipsoid"} methods. * * <p><b>Note:</b> we do not define similar method in {@link GeocentricToGeographic} class because the only * way to obtain that operation method is to ask explicitly for {@code "Geocentric_To_Ellipsoid"} operation. * The ambiguity that we try to resolve here exists only if the user asked for the EPSG:9602 operation, which * is defined only in this class.</p> * * @return {@code "Geocentric_To_Ellipsoid"} if the user apparently wanted to get the inverse of this * {@code "Ellipsoid_To_Geocentric"} operation, or {@code null} if none. */ @Override public String resolveAmbiguity(final DefaultMathTransformFactory.Context context) { if (context.getSourceCS() instanceof CartesianCS && context.getTargetCS() instanceof EllipsoidalCS) { return GeocentricToGeographic.NAME; } return super.resolveAmbiguity(context); }
Example #30
Source File: DefaultProjectedCRS.java From sis with Apache License 2.0 | 3 votes |
/** * Creates a projected CRS from a defining conversion. * The properties given in argument follow the same rules than for the * {@linkplain AbstractCRS#AbstractCRS(Map, CoordinateSystem) super-class constructor}. * The following table is a reminder of main (not all) properties: * * <table class="sis"> * <caption>Recognized properties (non exhaustive list)</caption> * <tr> * <th>Property name</th> * <th>Value type</th> * <th>Returned by</th> * </tr> * <tr> * <td>{@value org.opengis.referencing.IdentifiedObject#NAME_KEY}</td> * <td>{@link org.opengis.metadata.Identifier} or {@link String}</td> * <td>{@link #getName()}</td> * </tr> * <tr> * <td>{@value org.opengis.referencing.IdentifiedObject#ALIAS_KEY}</td> * <td>{@link org.opengis.util.GenericName} or {@link CharSequence} (optionally as array)</td> * <td>{@link #getAlias()}</td> * </tr> * <tr> * <td>{@value org.opengis.referencing.IdentifiedObject#IDENTIFIERS_KEY}</td> * <td>{@link org.opengis.metadata.Identifier} (optionally as array)</td> * <td>{@link #getIdentifiers()}</td> * </tr> * <tr> * <td>{@value org.opengis.referencing.IdentifiedObject#REMARKS_KEY}</td> * <td>{@link org.opengis.util.InternationalString} or {@link String}</td> * <td>{@link #getRemarks()}</td> * </tr> * <tr> * <td>{@value org.opengis.referencing.ReferenceSystem#DOMAIN_OF_VALIDITY_KEY}</td> * <td>{@link org.opengis.metadata.extent.Extent}</td> * <td>{@link #getDomainOfValidity()}</td> * </tr> * <tr> * <td>{@value org.opengis.referencing.ReferenceSystem#SCOPE_KEY}</td> * <td>{@link org.opengis.util.InternationalString} or {@link String}</td> * <td>{@link #getScope()}</td> * </tr> * </table> * * The supplied {@code conversion} argument shall <strong>not</strong> includes the operation steps * for performing {@linkplain org.apache.sis.referencing.cs.CoordinateSystems#swapAndScaleAxes unit * conversions and change of axis order} since those operations will be inferred by this constructor. * * @param properties the properties to be given to the new derived CRS object. * @param baseCRS coordinate reference system to base the derived CRS on. * @param conversion the defining conversion from a {@linkplain AxesConvention#NORMALIZED normalized} * base to a normalized derived CRS. * @param derivedCS the coordinate system for the derived CRS. The number of axes must match * the target dimension of the {@code baseToDerived} transform. * @throws MismatchedDimensionException if the source and target dimensions of {@code baseToDerived} * do not match the dimensions of {@code base} and {@code derivedCS} respectively. * * @see org.apache.sis.referencing.factory.GeodeticObjectFactory#createProjectedCRS(Map, GeographicCRS, Conversion, CartesianCS) */ public DefaultProjectedCRS(final Map<String,?> properties, final GeographicCRS baseCRS, final Conversion conversion, final CartesianCS derivedCS) throws MismatchedDimensionException { super(properties, baseCRS, conversion, derivedCS); }