org.opengis.referencing.crs.ProjectedCRS Java Examples

The following examples show how to use org.opengis.referencing.crs.ProjectedCRS. 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: CrsFactory.java    From geomajas-project-server with GNU Affero General Public License v3.0 7 votes vote down vote up
public static Crs getCrs(String id, CoordinateReferenceSystem base) {
	if (base instanceof CompoundCRS) {
		return new CompoundCrsImpl(id, (CompoundCRS) base);
	}
	if (base instanceof GeographicCRS) {
		return new GeographicCrsImpl(id, (GeographicCRS) base);
	}
	if (base instanceof GeodeticCRS) {
		return new GeodeticCrsImpl(id, (GeodeticCRS) base);
	}
	if (base instanceof ProjectedCRS) {
		return new ProjectedCrsImpl(id, (ProjectedCRS) base);
	}
	if (base instanceof GeneralDerivedCRS) {
		return new GeneralDerivedCrsImpl(id, (GeneralDerivedCRS) base);
	}
	if (base instanceof TemporalCRS) {
		return new TemporalCrsImpl(id, (TemporalCRS) base);
	}
	if (base instanceof SingleCRS) {
		return new SingleCrsImpl(id, (SingleCRS) base);
	}
	return new CrsImpl(id, base);
}
 
Example #2
Source File: CRSTable.java    From sis with Apache License 2.0 6 votes vote down vote up
static Image getIcon(IdentifiedObject obj) {
    Image icon = ICON_UNKNOWN;
    if (obj instanceof GeographicCRS) {
        icon = ICON_GEO;
    } else if (obj instanceof ProjectedCRS) {
        final ProjectedCRS pcrs = (ProjectedCRS) obj;
        final Projection proj = pcrs.getConversionFromBase();

        if (String.valueOf(proj.getName()).toLowerCase().contains("utm")) {
            icon = ICON_UTM;
        } else if (proj instanceof ConicProjection) {
            icon = ICON_CONIC;
        } else if (proj instanceof CylindricalProjection) {
            icon = ICON_SQUARE;
        } else if (proj instanceof PlanarProjection) {
            icon = ICON_STEREO;
        } else {
            icon = ICON_SQUARE;
        }
    } else {
        icon = ICON_SQUARE;
    }
    return icon;
}
 
Example #3
Source File: DefaultProjectedCRSTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests WKT 1 formatting using {@link Convention#WKT1_COMMON_UNITS}.
 *
 * @throws FactoryException if the CRS creation failed.
 */
@Test
@DependsOnMethod("testWKT1")
public void testWKT1_WithCommonUnits() throws FactoryException {
    final ProjectedCRS crs = create(HardCodedCRS.NTF);
    assertWktEquals(Convention.WKT1_COMMON_UNITS,
            "PROJCS[“NTF (Paris) / Lambert zone II”,\n" +
            "  GEOGCS[“NTF (Paris)”,\n" +
            "    DATUM[“Nouvelle Triangulation Francaise”,\n" +
            "      SPHEROID[“NTF”, 6378249.2, 293.4660212936269]],\n" +
            "      PRIMEM[“Paris”, 2.33722917],\n" +                    // Note the conversion from 2.5969213 grads.
            "    UNIT[“grad”, 0.015707963267948967],\n" +
            "    AXIS[“Longitude”, EAST],\n" +
            "    AXIS[“Latitude”, NORTH]],\n" +
            "  PROJECTION[“Lambert_Conformal_Conic_1SP”, AUTHORITY[“EPSG”, “9801”]],\n" +
            "  PARAMETER[“latitude_of_origin”, 46.8],\n" +              // Note the conversion from 52 grads.
            "  PARAMETER[“central_meridian”, 0.0],\n" +
            "  PARAMETER[“scale_factor”, 0.99987742],\n" +
            "  PARAMETER[“false_easting”, 600000.0],\n" +
            "  PARAMETER[“false_northing”, 2200000.0],\n" +
            "  UNIT[“meter”, 1],\n" +
            "  AXIS[“Easting”, EAST],\n" +
            "  AXIS[“Northing”, NORTH],\n" +
            "  AUTHORITY[“EPSG”, “27572”]]",
            crs);
}
 
Example #4
Source File: DefaultProjectedCRSTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests WKT 1 formatting.
 *
 * @throws FactoryException if the CRS creation failed.
 */
@Test
@DependsOnMethod("testConstructor")
public void testWKT1() throws FactoryException {
    final ProjectedCRS crs = create(HardCodedCRS.NTF);
    assertWktEquals(Convention.WKT1,
            "PROJCS[“NTF (Paris) / Lambert zone II”,\n" +
            "  GEOGCS[“NTF (Paris)”,\n" +
            "    DATUM[“Nouvelle Triangulation Francaise”,\n" +
            "      SPHEROID[“NTF”, 6378249.2, 293.4660212936269]],\n" +
            "      PRIMEM[“Paris”, 2.5969213],\n" +
            "    UNIT[“grad”, 0.015707963267948967],\n" +
            "    AXIS[“Longitude”, EAST],\n" +
            "    AXIS[“Latitude”, NORTH]],\n" +
            "  PROJECTION[“Lambert_Conformal_Conic_1SP”, AUTHORITY[“EPSG”, “9801”]],\n" +
            "  PARAMETER[“latitude_of_origin”, 52.0],\n" +          // In grads
            "  PARAMETER[“central_meridian”, 0.0],\n" +
            "  PARAMETER[“scale_factor”, 0.99987742],\n" +
            "  PARAMETER[“false_easting”, 600000.0],\n" +
            "  PARAMETER[“false_northing”, 2200000.0],\n" +
            "  UNIT[“metre”, 1],\n" +
            "  AXIS[“Easting”, EAST],\n" +
            "  AXIS[“Northing”, NORTH],\n" +
            "  AUTHORITY[“EPSG”, “27572”]]",
            crs);
}
 
Example #5
Source File: CommonAuthorityFactory.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Provides a complete set of the known codes provided by this factory.
 * The returned set contains a namespace followed by numeric identifiers
 * like {@code "CRS:84"}, {@code "CRS:27"}, {@code "AUTO2:42001"}, <i>etc</i>.
 *
 * @param  type  the spatial reference objects type.
 * @return the set of authority codes for spatial reference objects of the given type.
 * @throws FactoryException if this method failed to provide the set of codes.
 */
@Override
public Set<String> getAuthorityCodes(final Class<? extends IdentifiedObject> type) throws FactoryException {
    ArgumentChecks.ensureNonNull("type", type);
    if (!type.isAssignableFrom(SingleCRS.class) && !SingleCRS.class.isAssignableFrom(type)) {
        return Collections.emptySet();
    }
    synchronized (codes) {
        if (codes.isEmpty()) {
            add(Constants.CRS1,  EngineeringCRS.class);
            add(Constants.CRS27, GeographicCRS.class);
            add(Constants.CRS83, GeographicCRS.class);
            add(Constants.CRS84, GeographicCRS.class);
            add(Constants.CRS88, VerticalCRS.class);
            for (int code = FIRST_PROJECTION_CODE; code < FIRST_PROJECTION_CODE + PROJECTION_NAMES.length; code++) {
                add(code, ProjectedCRS.class);
            }
        }
    }
    return new FilteredCodes(codes, type).keySet();
}
 
Example #6
Source File: StandardDefinitions.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #7
Source File: EllipsoidalHeightCombiner.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the coordinate system if the given CRS is a two-dimensional geographic or projected CRS,
 * or {@code null} otherwise. The returned coordinate system is either ellipsoidal or Cartesian;
 * no other type is returned.
 */
private static CoordinateSystem getCsIfHorizontal2D(final CoordinateReferenceSystem crs) {
    final boolean isProjected = (crs instanceof ProjectedCRS);
    if (isProjected || crs instanceof GeodeticCRS) {
        final CoordinateSystem cs = crs.getCoordinateSystem();
        if (cs.getDimension() == 2 && (isProjected || cs instanceof EllipsoidalCS)) {
            /*
             * ProjectedCRS are guaranteed to be associated to CartesianCS, so we do not test that.
             * GeodeticCRS may be associated to either CartesianCS or EllipsoidalCS, but this method
             * shall accept only EllipsoidalCS. Actually we should accept only GeographicCRS, but we
             * relax this condition by accepting GeodeticCRS with EllipsoidalCS.
             */
            return cs;
        }
    }
    return null;
}
 
Example #8
Source File: CommonAuthorityFactoryTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the {@code "AUTO:42002"} code.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
@DependsOnMethod("testAuto42001")
public void testAuto42002() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO:42002,-122,10");
    assertSame("Omitting namespace.", crs, factory.createProjectedCRS(" 42002, -122 , 10 "));
    assertSame("With explicit unit.", crs, factory.createProjectedCRS("AUTO2 :  42002, 1, -122 , 10 "));
    assertEquals("name", "Transverse Mercator", crs.getName().getCode());
    assertTrue("Expected no EPSG identifier.", crs.getIdentifiers().isEmpty());

    final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues();
    assertEquals(TransverseMercator.NAME, crs.getConversionFromBase().getMethod().getName().getCode());
    assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
    assertEquals(Constants.CENTRAL_MERIDIAN, -122, p.parameter(Constants.CENTRAL_MERIDIAN)  .doubleValue(), STRICT);
    assertEquals(Constants.LATITUDE_OF_ORIGIN, 10, p.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT);
    assertEquals(Constants.FALSE_NORTHING,      0, p.parameter(Constants.FALSE_NORTHING)    .doubleValue(), STRICT);
}
 
Example #9
Source File: DefaultProjectedCRSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests formatting of “Equidistant Cylindrical (Spherical)” projected CRS. This one is a special case
 * because it is simplified to an affine transform. The referencing module should be able to find the
 * original projection parameters.
 *
 * @throws FactoryException if the CRS creation failed.
 */
@Test
@DependsOnMethod("testWKT2_Simplified")
public void testWKT2_ForEquirectangular() throws FactoryException {
    final ProjectedCRS crs = new GeodeticObjectBuilder()
            .setConversionMethod("Equirectangular")
            .setConversionName("Equidistant Cylindrical (Spherical)")
            .setParameter("False easting",  1000, Units.METRE)
            .setParameter("False northing", 2000, Units.METRE)
            .addName("Equidistant Cylindrical (Spherical)")
            .createProjectedCRS(HardCodedCRS.WGS84, HardCodedCS.PROJECTED);

    assertWktEquals(Convention.WKT2_SIMPLIFIED,
            "ProjectedCRS[“Equidistant Cylindrical (Spherical)”,\n" +
            "  BaseGeodCRS[“WGS 84”,\n" +
            "    Datum[“World Geodetic System 1984”,\n" +
            "      Ellipsoid[“WGS84”, 6378137.0, 298.257223563]],\n" +
            "    Unit[“degree”, 0.017453292519943295]],\n" +
            "  Conversion[“Equidistant Cylindrical (Spherical)”,\n" +
            "    Method[“Equidistant Cylindrical (Spherical)”],\n" +
            "    Parameter[“Latitude of 1st standard parallel”, 0.0],\n" +
            "    Parameter[“Longitude of natural origin”, 0.0],\n" +
            "    Parameter[“False easting”, 1000.0],\n" +
            "    Parameter[“False northing”, 2000.0]],\n" +
            "  CS[Cartesian, 2],\n" +
            "    Axis[“Easting (E)”, east],\n" +
            "    Axis[“Northing (N)”, north],\n" +
            "    Unit[“metre”, 1]]",
            crs);
}
 
Example #10
Source File: TransformTestCase.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests conversions of an envelope or rectangle which is <strong>not</strong> over a pole,
 * but was wrongly considered as over a pole before SIS-329 fix.
 *
 * @throws FactoryException if an error occurred while creating the operation.
 * @throws TransformException if an error occurred while transforming the envelope.
 *
 * @see <a href="https://issues.apache.org/jira/browse/SIS-329">SIS-329</a>
 */
@Test
@DependsOnMethod("testTransform")
public final void testTransformNotOverPole() throws FactoryException, TransformException {
    final ProjectedCRS  sourceCRS  = CommonCRS.WGS84.universal(10, -3.5);
    final GeographicCRS targetCRS  = sourceCRS.getBaseCRS();
    final Conversion    conversion = inverse(sourceCRS.getConversionFromBase());
    final G rectangle = createFromExtremums(sourceCRS, 199980, 4490220, 309780, 4600020);
    final G expected  = createFromExtremums(targetCRS,
            40.50846282536367, -6.594124551832373,          // Computed by SIS (not validated by external authority).
            41.52923550023067, -5.246186118392847);
    final G actual = transform(conversion, rectangle);
    assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE);
}
 
Example #11
Source File: WraparoundAdjustment.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * If the coordinate reference system is a projected CRS, replaces it by another CRS where wraparound axes can
 * be identified. The wraparound axes are identifiable in base geographic CRS. If such replacement is applied,
 * remember that we may need to transform the result later.
 *
 * @return whether the replacement has been done. If {@code true}, then {@link #geographicToAOI} is non-null.
 */
private boolean replaceCRS() {
    if (crs instanceof ProjectedCRS) {
        final ProjectedCRS p = (ProjectedCRS) crs;
        crs = p.getBaseCRS();                                          // Geographic, so a wraparound axis certainly exists.
        geographicToAOI = p.getConversionFromBase().getMathTransform();
        return true;
    } else {
        return false;
    }
}
 
Example #12
Source File: GeodeticObjectBuilder.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a projected CRS with base CRS on the specified datum and with default axes.
 * The base CRS uses the ellipsoid specified by {@link #setFlattenedSphere(String, double, double, Unit)}.
 *
 * @return the projected CRS.
 * @throws FactoryException if an error occurred while building the projected CRS.
 */
public ProjectedCRS createProjectedCRS() throws FactoryException {
    GeographicCRS crs = CommonCRS.WGS84.geographic();
    if (datum != null) {
        crs = factories.getCRSFactory().createGeographicCRS(name(datum), datum, crs.getCoordinateSystem());
    }
    return createProjectedCRS(crs, factories.getStandardProjectedCS());
}
 
Example #13
Source File: DefaultProjectedCRSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link DefaultProjectedCRS#equals(Object, ComparisonMode)}.
 * In particular, we want to test the ability to ignore axis order of the base CRS in "ignore metadata" mode.
 *
 * @throws FactoryException if the CRS creation failed.
 *
 * @since 0.7
 */
@Test
public void testEquals() throws FactoryException {
    final ProjectedCRS standard   = create(CommonCRS.WGS84.geographic());
    final ProjectedCRS normalized = create(CommonCRS.WGS84.normalizedGeographic());
    assertFalse("STRICT",          ((LenientComparable) standard).equals(normalized, ComparisonMode.STRICT));
    assertFalse("BY_CONTRACT",     ((LenientComparable) standard).equals(normalized, ComparisonMode.BY_CONTRACT));
    assertTrue ("IGNORE_METADATA", ((LenientComparable) standard).equals(normalized, ComparisonMode.IGNORE_METADATA));
    assertTrue ("APPROXIMATE",     ((LenientComparable) standard).equals(normalized, ComparisonMode.APPROXIMATE));
    assertTrue ("ALLOW_VARIANT",   ((LenientComparable) standard).equals(normalized, ComparisonMode.ALLOW_VARIANT));
}
 
Example #14
Source File: StandardDefinitionsTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link StandardDefinitions#createUniversal(int, GeographicCRS, boolean, double, double, CartesianCS)}
 * for a Universal Transverse Mercator (UTM) projection.
 *
 * @since 0.7
 */
@Test
@DependsOnMethod("testCreateGeographicCRS")
public void testCreateUTM() {
    final ProjectedCRS crs = StandardDefinitions.createUniversal(32610, HardCodedCRS.WGS84, true, 15, -122, HardCodedCS.PROJECTED);
    assertEquals("name", "WGS 84 / UTM zone 10N", crs.getName().getCode());
    final ParameterValueGroup pg = crs.getConversionFromBase().getParameterValues();
    assertEquals(Constants.LATITUDE_OF_ORIGIN,    0, pg.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT);
    assertEquals(Constants.CENTRAL_MERIDIAN,   -123, pg.parameter(Constants.CENTRAL_MERIDIAN)  .doubleValue(), STRICT);
    assertEquals(Constants.SCALE_FACTOR,     0.9996, pg.parameter(Constants.SCALE_FACTOR)      .doubleValue(), STRICT);
    assertEquals(Constants.FALSE_EASTING,    500000, pg.parameter(Constants.FALSE_EASTING)     .doubleValue(), STRICT);
    assertEquals(Constants.FALSE_NORTHING,        0, pg.parameter(Constants.FALSE_NORTHING)    .doubleValue(), STRICT);
}
 
Example #15
Source File: TransformTestCase.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests transform of an envelope over the ±180° limit. The Mercator projection used in this test
 * is not expected to wrap the longitude around Earth when using only the {@code MathTransform}.
 * However when the target CRS is known, then "wrap around" should be applied.
 *
 * @throws TransformException if an error occurred while transforming the envelope.
 *
 * @since 0.8
 */
@Test
@DependsOnMethod("testTransform")
public final void testTransformOverAntiMeridian() throws TransformException {
    final ProjectedCRS  sourceCRS  = HardCodedConversions.mercator();
    final GeographicCRS targetCRS  = sourceCRS.getBaseCRS();
    final Conversion    conversion = inverse(sourceCRS.getConversionFromBase());
    final G expected  = createFromExtremums(targetCRS, 179, 40, 181, 50);
    final G rectangle = createFromExtremums(sourceCRS,
            19926188.852, 4838471.398,                      // Computed by SIS (not validated by external authority).
            20148827.834, 6413524.594);
    final G actual = transform(conversion, rectangle);
    assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE);
}
 
Example #16
Source File: MilitaryGridReferenceSystemTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Encodes random coordinates, decodes them and verifies that the results are approximately equal
 * to the original coordinates.
 *
 * @throws TransformException if an error occurred while computing the coordinate.
 */
@Test
@DependsOnMethod({
    "testEncodeUTM", "testDecodeUTM",
    "testEncodeUPS", "testDecodeUPS"
})
public void verifyConsistency() throws TransformException {
    final Random random = TestUtilities.createRandomNumberGenerator();
    final MilitaryGridReferenceSystem.Coder coder = coder();
    final DirectPosition2D expected = new DirectPosition2D();
    final DirectPosition2D position = new DirectPosition2D(CommonCRS.WGS84.geographic());
    for (int i=0; i<100; i++) {
        position.x = random.nextDouble() * 180 -  90;       // Latitude  (despite the 'x' field name)
        position.y = random.nextDouble() * 358 - 179;       // Longitude (despite the 'y' field name)
        final String reference = coder.encode(position);
        final DirectPosition r = decode(coder, reference);
        final ProjectedCRS crs = (ProjectedCRS) r.getCoordinateReferenceSystem();
        assertSame(expected, crs.getConversionFromBase().getMathTransform().transform(position, expected));
        final double distance = expected.distance(r.getOrdinate(0), r.getOrdinate(1));
        if (!(distance < 1.5)) {    // Use '!' for catching NaN.
            final String lineSeparator = System.lineSeparator();
            fail("Consistency check failed for φ = " + position.x + " and λ = " + position.y + lineSeparator
               + "MGRS reference = " + reference + lineSeparator
               + "Parsing result = " + r         + lineSeparator
               + "Projected φ, λ = " + expected  + lineSeparator
               + "Distance (m)   = " + distance  + lineSeparator);
        }
    }
}
 
Example #17
Source File: EllipsoidalHeightCombinerTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link EllipsoidalHeightCombiner#createCompoundCRS EllipsoidalHeightCombiner.createCompoundCRS(…)}
 * with a projected CRS.
 *
 * @throws FactoryException if a CRS can not be created.
 */
@Test
@DependsOnMethod("testGeographicCRS")
public void testProjectedCRS() throws FactoryException {
    final EllipsoidalHeightCombiner services = create();
    final GeodeticObjectFactory factory = new GeodeticObjectFactory();
    final Map<String,String> properties = Collections.singletonMap(CoordinateReferenceSystem.NAME_KEY, "World Mercator (4D)");
    final ProjectedCRS horizontal = factory.createProjectedCRS(properties, HardCodedCRS.WGS84,    HardCodedConversions.MERCATOR, HardCodedCS.PROJECTED);
    final ProjectedCRS volumetric = factory.createProjectedCRS(properties, HardCodedCRS.WGS84_3D, HardCodedConversions.MERCATOR, HardCodedCS.PROJECTED_3D);
    final VerticalCRS  vertical   = HardCodedCRS.ELLIPSOIDAL_HEIGHT;
    final TemporalCRS  temporal   = HardCodedCRS.TIME;
    final VerticalCRS  geoidal    = HardCodedCRS.GRAVITY_RELATED_HEIGHT;
    /*
     * createCompoundCRS(…) should not combine ProjectedCRS with non-ellipsoidal height.
     */
    CoordinateReferenceSystem compound = services.createCompoundCRS(properties, horizontal, geoidal, temporal);
    assertArrayEqualsIgnoreMetadata(new SingleCRS[] {horizontal, geoidal, temporal}, CRS.getSingleComponents(compound).toArray());
    /*
     * createCompoundCRS(…) should combine ProjectedCRS with ellipsoidal height.
     */
    compound = services.createCompoundCRS(properties, horizontal, vertical);
    assertArrayEqualsIgnoreMetadata(new SingleCRS[] {volumetric}, CRS.getSingleComponents(compound).toArray());
    /*
     * createCompoundCRS(…) should combine ProjectedCRS with ellipsoidal height and keep time.
     */
    compound = services.createCompoundCRS(properties, horizontal, vertical, temporal);
    assertArrayEqualsIgnoreMetadata(new SingleCRS[] {volumetric, temporal}, CRS.getSingleComponents(compound).toArray());
    /*
     * Non-standard feature: accept (VerticalCRS + ProjectedCRS) order.
     */
    compound = services.createCompoundCRS(properties, temporal, vertical, horizontal);
    final Object[] components = CRS.getSingleComponents(compound).toArray();
    assertEquals(2, components.length);
    assertEqualsIgnoreMetadata(temporal, components[0]);
    assertInstanceOf("Shall be a three-dimensional projected CRS.", ProjectedCRS.class, components[1]);
    assertAxisDirectionsEqual("Shall be a three-dimensional projected CRS.",
            ((CoordinateReferenceSystem) components[1]).getCoordinateSystem(),
            AxisDirection.UP, AxisDirection.EAST, AxisDirection.NORTH);
}
 
Example #18
Source File: CRSBuilder.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies if the user-defined CRS created from GeoTIFF values
 * matches the given CRS created from the EPSG geodetic dataset.
 * This method does not verify the EPSG code of the given CRS.
 *
 * @param  crs  the CRS created from the EPSG geodetic dataset.
 */
private void verify(final ProjectedCRS crs) throws FactoryException {
    final Unit<Length> linearUnit  = createUnit(GeoKeys.LinearUnits,  GeoKeys.LinearUnitSize, Length.class, Units.METRE);
    final Unit<Angle>  angularUnit = createUnit(GeoKeys.AngularUnits, GeoKeys.AngularUnitSize, Angle.class, Units.DEGREE);
    final GeographicCRS baseCRS = crs.getBaseCRS();
    verifyIdentifier(crs, baseCRS, GeoKeys.GeographicType);
    verify(baseCRS, angularUnit);
    final Conversion projection = crs.getConversionFromBase();
    verifyIdentifier(crs, projection, GeoKeys.Projection);
    verify(projection, angularUnit, linearUnit);
}
 
Example #19
Source File: DefaultProjectedCRSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests WKT formatting in "internal" mode.
 * This mode is similar to WKT 2 but shall include the axes of the base CRS and more parameter identifiers.
 *
 * @throws FactoryException if the CRS creation failed.
 */
@Test
@DependsOnMethod("testWKT1")
public void testInternal() throws FactoryException {
    ProjectedCRS crs = create(HardCodedCRS.NTF);
    assertWktEquals(Convention.INTERNAL,
            "ProjectedCRS[“NTF (Paris) / Lambert zone II”,\n" +
            "  BaseGeodCRS[“NTF (Paris)”,\n" +
            "    Datum[“Nouvelle Triangulation Française”,\n" +
            "      Ellipsoid[“NTF”, 6378249.2, 293.4660212936269],\n" +
            "      Scope[“Topographic mapping.”],\n" +
            "      Id[“EPSG”, 6807]],\n" +
            "      PrimeMeridian[“Paris”, 2.5969213, Id[“EPSG”, 8903]],\n" +
            "    CS[ellipsoidal, 2],\n" +
            "      Axis[“Longitude (λ)”, east],\n" +
            "      Axis[“Latitude (φ)”, north],\n" +
            "      Unit[“grad”, 0.015707963267948967, Id[“EPSG”, 9105]]],\n" +
            "  Conversion[“Lambert zone II”,\n" +
            "    Method[“Lambert Conic Conformal (1SP)”, Id[“EPSG”, 9801], Id[“GeoTIFF”, 9]],\n" +
            "    Parameter[“Latitude of natural origin”, 52.0, Id[“EPSG”, 8801], Id[“GeoTIFF”, 3081]],\n" +
            "    Parameter[“Longitude of natural origin”, 0.0, Id[“EPSG”, 8802], Id[“GeoTIFF”, 3080]],\n" +
            "    Parameter[“Scale factor at natural origin”, 0.99987742, Id[“EPSG”, 8805], Id[“GeoTIFF”, 3092]],\n" +
            "    Parameter[“False easting”, 600000.0, Id[“EPSG”, 8806], Id[“GeoTIFF”, 3082]],\n" +
            "    Parameter[“False northing”, 2200000.0, Id[“EPSG”, 8807], Id[“GeoTIFF”, 3083]]],\n" +
            "  CS[Cartesian, 2],\n" +
            "    Axis[“Easting (E)”, east],\n" +
            "    Axis[“Northing (N)”, north],\n" +
            "    Unit[“metre”, 1, Id[“EPSG”, 9001]],\n" +
            "  Id[“EPSG”, 27572]]",
            crs);
}
 
Example #20
Source File: DefaultProjectedCRSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests WKT 1 formatting of a pseudo-projection with explicit {@code "semi-major"} and {@code "semi-minor"}
 * parameter values. This was a way to define the Google pseudo-projection using standard projection method
 * name before EPSG introduced the <cite>"Popular Visualisation Pseudo Mercator"</cite> projection method.
 * The approach tested in this method is now deprecated at least for the Google projection (while it may
 * still be useful for other projections), but we still test it for compatibility reasons.
 *
 * @throws FactoryException if the CRS creation failed.
 */
@Test
@DependsOnMethod("testWKT1")
public void testWKT1_WithExplicitAxisLength() throws FactoryException {
    final ProjectedCRS crs = new GeodeticObjectBuilder()
            .setConversionMethod("Mercator (variant A)")
            .setConversionName("Popular Visualisation Pseudo-Mercator")
            .setParameter("semi-major", 6378137, Units.METRE)
            .setParameter("semi-minor", 6378137, Units.METRE)
            .addName("WGS 84 / Pseudo-Mercator")
            .createProjectedCRS(HardCodedCRS.WGS84, HardCodedCS.PROJECTED);

    assertWktEquals(Convention.WKT1,
            "PROJCS[“WGS 84 / Pseudo-Mercator”,\n" +
            "  GEOGCS[“WGS 84”,\n" +
            "    DATUM[“World Geodetic System 1984”,\n" +
            "      SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
            "      PRIMEM[“Greenwich”, 0.0],\n" +
            "    UNIT[“degree”, 0.017453292519943295],\n" +
            "    AXIS[“Longitude”, EAST],\n" +
            "    AXIS[“Latitude”, NORTH]],\n" +
            "  PROJECTION[“Mercator_1SP”, AUTHORITY[“EPSG”, “9804”]],\n" +
            "  PARAMETER[“semi_minor”, 6378137.0],\n" +     // Non-standard: appears because its value is different than the ellipsoid value.
            "  PARAMETER[“latitude_of_origin”, 0.0],\n" +
            "  PARAMETER[“central_meridian”, 0.0],\n" +
            "  PARAMETER[“scale_factor”, 1.0],\n" +
            "  PARAMETER[“false_easting”, 0.0],\n" +
            "  PARAMETER[“false_northing”, 0.0],\n" +
            "  UNIT[“metre”, 1],\n" +
            "  AXIS[“Easting”, EAST],\n" +
            "  AXIS[“Northing”, NORTH]]",
            crs);

    loggings.assertNextLogContains("semi_minor", "WGS84");
    loggings.assertNoUnexpectedLog();
}
 
Example #21
Source File: CRSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests getting the horizontal and vertical components of a three-dimensional projected CRS.
 *
 * @since 0.8
 */
@Test
public void testComponentsOfProjectedCRS() {
    final ProjectedCRS volumetric = HardCodedConversions.mercator3D();
    assertFalse("isHorizontalCRS", CRS.isHorizontalCRS(volumetric));
    assertNull("getTemporalComponent", CRS.getTemporalComponent(volumetric));
    assertNull("getVerticalComponent", CRS.getVerticalComponent(volumetric, false));
    assertEqualsIgnoreMetadata(HardCodedCRS.ELLIPSOIDAL_HEIGHT, CRS.getVerticalComponent(volumetric, true));
    final SingleCRS horizontal = CRS.getHorizontalComponent(volumetric);
    assertInstanceOf("getHorizontalComponent", ProjectedCRS.class, horizontal);
    assertEquals("dimension", 2, horizontal.getCoordinateSystem().getDimension());
    assertTrue("isHorizontalCRS", CRS.isHorizontalCRS(horizontal));
}
 
Example #22
Source File: CommonAuthorityFactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link CommonAuthorityFactory#getAuthorityCodes(Class)}.
 *
 * @throws FactoryException if an error occurred while fetching the set of codes.
 */
@Test
public void testGetAuthorityCodes() throws FactoryException {
    assertTrue("getAuthorityCodes(Datum.class)",
            factory.getAuthorityCodes(Datum.class).isEmpty());
    assertSetEquals(Arrays.asList("CRS:1", "CRS:27", "CRS:83", "CRS:84", "CRS:88",
                                  "AUTO2:42001", "AUTO2:42002", "AUTO2:42003", "AUTO2:42004", "AUTO2:42005"),
            factory.getAuthorityCodes(CoordinateReferenceSystem.class));
    assertSetEquals(Arrays.asList("AUTO2:42001", "AUTO2:42002", "AUTO2:42003", "AUTO2:42004", "AUTO2:42005"),
            factory.getAuthorityCodes(ProjectedCRS.class));
    assertSetEquals(Arrays.asList("CRS:27", "CRS:83", "CRS:84"),
            factory.getAuthorityCodes(GeographicCRS.class));
    assertSetEquals(Arrays.asList("CRS:88"),
            factory.getAuthorityCodes(VerticalCRS.class));
    assertSetEquals(Arrays.asList("CRS:1"),
            factory.getAuthorityCodes(EngineeringCRS.class));

    final Set<String> codes = factory.getAuthorityCodes(GeographicCRS.class);
    assertFalse("CRS:1",      codes.contains("CRS:1"));
    assertTrue ("CRS:27",     codes.contains("CRS:27"));
    assertTrue ("CRS:83",     codes.contains("CRS:83"));
    assertTrue ("CRS:84",     codes.contains("CRS:84"));
    assertFalse("CRS:88",     codes.contains("CRS:88"));
    assertTrue ("0084",       codes.contains("0084"));
    assertFalse("0088",       codes.contains("0088"));
    assertTrue ("OGC:CRS084", codes.contains("OGC:CRS084"));
}
 
Example #23
Source File: CommonAuthorityFactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the {@code "AUTO:42001"} code.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
public void testAuto42001() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO:42001,-123,0");
    assertSame("With other coord.",   crs, factory.createProjectedCRS("AUTO : 42001, -122, 10 "));
    assertSame("Omitting namespace.", crs, factory.createProjectedCRS(" 42001, -122 , 10 "));
    assertSame("With explicit unit.", crs, factory.createProjectedCRS("AUTO2 :  42001, 1, -122 , 10 "));
    assertSame("With explicit unit.", crs, factory.createProjectedCRS("AUTO1 :  42001, 9001, -122 , 10 "));
    assertSame("Legacy namespace.",   crs, factory.createProjectedCRS("AUTO:42001,9001,-122,10"));
    assertSame("When the given parameters match exactly the UTM central meridian and latitude of origin,"
            + " the CRS created by AUTO:42002 should be the same than the CRS created by AUTO:42001.",
            crs, factory.createProjectedCRS("AUTO2:42002,1,-123,0"));

    assertEpsgNameAndIdentifierEqual("WGS 84 / UTM zone 10N", 32610, crs);
    final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues();
    assertEquals(TransverseMercator.NAME, crs.getConversionFromBase().getMethod().getName().getCode());
    assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
    assertEquals(Constants.CENTRAL_MERIDIAN, -123, p.parameter(Constants.CENTRAL_MERIDIAN)  .doubleValue(), STRICT);
    assertEquals(Constants.LATITUDE_OF_ORIGIN,  0, p.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT);
    assertEquals(Constants.FALSE_NORTHING,      0, p.parameter(Constants.FALSE_NORTHING)    .doubleValue(), STRICT);
    assertEquals("axis[0].unit", Units.METRE, crs.getCoordinateSystem().getAxis(0).getUnit());
    try {
        factory.createObject("AUTO:42001");
        fail("Should not have accepted incomplete code.");
    } catch (NoSuchAuthorityCodeException e) {
        assertEquals("42001", e.getAuthorityCode());
    }
}
 
Example #24
Source File: CommonAuthorityFactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the same {@code "AUTO:42001"} code
 * than {@link #testAuto42001()} except that axes are feet.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
@DependsOnMethod("testAuto42001")
public void testAuto42001_foot() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO2:42001, 0.3048, -123, 0");
    assertSame("Legacy namespace.", crs, factory.createProjectedCRS("AUTO:42001,9002,-123,0"));
    assertEquals("name", "WGS 84 / UTM zone 10N", crs.getName().getCode());
    assertTrue("Expected no EPSG identifier because the axes are not in metres.", crs.getIdentifiers().isEmpty());
    assertEquals("axis[0].unit", Units.FOOT, crs.getCoordinateSystem().getAxis(0).getUnit());
}
 
Example #25
Source File: CommonAuthorityFactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the {@code "AUTO:42003"} code.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
@DependsOnMethod("testAuto42001")
@Ignore("Pending the port of Orthographic projection.")
public void testAuto42003() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO:42003,9001,10,45");
    final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues();
    assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
    assertEquals(Constants.CENTRAL_MERIDIAN,   10, p.parameter(Constants.CENTRAL_MERIDIAN)  .doubleValue(), STRICT);
    assertEquals(Constants.LATITUDE_OF_ORIGIN, 45, p.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT);
}
 
Example #26
Source File: CommonAuthorityFactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the {@code "AUTO:42004"} code.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
@DependsOnMethod("testAuto42001")
public void testAuto42004() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO2:42004,1,10,45");
    final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues();
    assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
    assertEquals(Constants.CENTRAL_MERIDIAN,   10, p.parameter(Constants.CENTRAL_MERIDIAN)   .doubleValue(), STRICT);
    assertEquals(Constants.LATITUDE_OF_ORIGIN, 45, p.parameter(Constants.STANDARD_PARALLEL_1).doubleValue(), STRICT);
    assertInstanceOf("Opportunistic check: in the special case of Equirectangular projection, "
            + "SIS should have optimized the MathTransform as an affine transform.",
            LinearTransform.class, crs.getConversionFromBase().getMathTransform());
}
 
Example #27
Source File: CommonAuthorityFactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the {@code "AUTO:42005"} code.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
@DependsOnMethod("testAuto42001")
@Ignore("Pending implementation of Mollweide projection.")
public void testAuto42005() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO:42005,9001,10,45");
    final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues();
    assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
    assertEquals(Constants.CENTRAL_MERIDIAN,   10, p.parameter(Constants.CENTRAL_MERIDIAN)  .doubleValue(), STRICT);
}
 
Example #28
Source File: DefaultProjectedCRSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a projected CRS and verifies its parameters.
 * Verifies also that the constructor does not accept invalid base CRS.
 *
 * @throws FactoryException if the CRS creation failed.
 */
@Test
public void testConstructor() throws FactoryException {
    final ProjectedCRS crs = create(HardCodedCRS.NTF);
    verifyParameters(crs.getConversionFromBase().getParameterValues());
    try {
        create(HardCodedCRS.WGS84_3D);
        fail("Should not accept a three-dimensional base geodetic CRS.");
    } catch (InvalidGeodeticParameterException e) {
        final String message = e.getMessage();
        assertTrue(message, message.contains("Lambert Conic Conformal (1SP)"));
    }
}
 
Example #29
Source File: DefaultProjectedCRSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the "NTF (Paris) / Lambert zone II" CRS. The prime meridian is always in grads,
 * but the axes can be in degrees or in grads depending if the {@code baseCRS} argument is
 * {@link HardCodedCRS#NTF_NORMALIZED_AXES} or {@link HardCodedCRS#NTF} respectively.
 *
 * @see HardCodedCRS#NTF
 */
private static ProjectedCRS create(final GeographicCRS baseCRS) throws FactoryException {
    return new GeodeticObjectBuilder()
            .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)
            .setCodeSpace(Citations.EPSG, Constants.EPSG)
            .addName("NTF (Paris) / Lambert zone II")
            .addIdentifier("27572")
            .createProjectedCRS(baseCRS, HardCodedCS.PROJECTED);
}
 
Example #30
Source File: DefaultProjectedCRSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests WKT 1 formatting with a somewhat convolved case where the units of the prime meridian is not
 * the same than the unit of axes. Since the axis units is what we write in the {@code UNIT[…]} element,
 * the WKT formatter need to convert the unit of prime meridian and all parameter angular values.
 *
 * @throws FactoryException if the CRS creation failed.
 */
@Test
@DependsOnMethod("testWKT1_WithCommonUnits")
public void testWKT1_WithMixedUnits() throws FactoryException {
    final ProjectedCRS crs = create(HardCodedCRS.NTF_NORMALIZED_AXES);
    Validators.validate(crs);   // Opportunist check.
    assertWktEquals(Convention.WKT1,
            "PROJCS[“NTF (Paris) / Lambert zone II”,\n" +
            "  GEOGCS[“NTF (Paris)”,\n" +
            "    DATUM[“Nouvelle Triangulation Francaise”,\n" +
            "      SPHEROID[“NTF”, 6378249.2, 293.4660212936269]],\n" +
            "      PRIMEM[“Paris”, 2.33722917],\n" +                    // Note the conversion from 2.5969213 grads.
            "    UNIT[“degree”, 0.017453292519943295],\n" +
            "    AXIS[“Longitude”, EAST],\n" +
            "    AXIS[“Latitude”, NORTH]],\n" +
            "  PROJECTION[“Lambert_Conformal_Conic_1SP”, AUTHORITY[“EPSG”, “9801”]],\n" +
            "  PARAMETER[“latitude_of_origin”, 46.8],\n" +              // Note the conversion from 52 grads.
            "  PARAMETER[“central_meridian”, 0.0],\n" +
            "  PARAMETER[“scale_factor”, 0.99987742],\n" +
            "  PARAMETER[“false_easting”, 600000.0],\n" +
            "  PARAMETER[“false_northing”, 2200000.0],\n" +
            "  UNIT[“metre”, 1],\n" +
            "  AXIS[“Easting”, EAST],\n" +
            "  AXIS[“Northing”, NORTH],\n" +
            "  AUTHORITY[“EPSG”, “27572”]]",
            crs);
}