Package org.geotools.referencing.datum

Examples of org.geotools.referencing.datum.DefaultEllipsoid


     */
    private void refineParameters(final GeographicCRS baseCRS, final ParameterValueGroup parameters)
            throws InvalidParameterValueException, ParameterNotFoundException {
            // set the remaining parameters.
            final GeodeticDatum tempDatum = ((GeodeticDatum) baseCRS.getDatum());
            final DefaultEllipsoid tempEll = (DefaultEllipsoid) tempDatum.getEllipsoid();
            double inverseFlattening = tempEll.getInverseFlattening();
            double semiMajorAxis = tempEll.getSemiMajorAxis();
            // setting missing parameters
            parameters.parameter("semi_minor").setValue(semiMajorAxis * (1 - (1 / inverseFlattening)));
            parameters.parameter("semi_major").setValue(semiMajorAxis);
    }
View Full Code Here


     */
    public static DefaultGeodeticDatum getDefaultGeodeticDatum(
            final String name, final double equatorialRadius,
            final double inverseFlattening, Unit unit) {

        DefaultEllipsoid ellipsoid = DefaultEllipsoid.createFlattenedSphere(name, equatorialRadius, inverseFlattening, unit);
        final ReferenceIdentifier[] identifiers = CRSUtilities.getIdentifiers(name);
        // TODO: Should I change this behavior?
        if (identifiers == null)
            throw new IllegalArgumentException( "Reference Identifier not available");
        final Map<String, Object> properties = new HashMap<String, Object>(4);
View Full Code Here

    return envelope;
    }
   
    public static DefaultGeodeticDatum getDefaultGeodeticDatum(final String name, final double firstParameter,
        final double secondParameter, Unit<Length> unit, final boolean isSecondParameterInverseFlattening) {
        final DefaultEllipsoid ellipsoid;
        if (isSecondParameterInverseFlattening){
            ellipsoid = DefaultEllipsoid.createFlattenedSphere(name, firstParameter, secondParameter, unit);
        }
        else
            ellipsoid = DefaultEllipsoid.createEllipsoid(name, firstParameter, secondParameter, unit);
View Full Code Here

    @Override
    public Measure distance(final double[] coord1, final double[] coord2)
            throws UnsupportedOperationException, MismatchedDimensionException
    {
        final DefaultEllipsoidalCS cs;
        final DefaultEllipsoid e;
        if (!(coordinateSystem instanceof DefaultEllipsoidalCS)) {
            throw new UnsupportedImplementationException(coordinateSystem.getClass());
        }
        final Ellipsoid ellipsoid = ((GeodeticDatum) datum).getEllipsoid();
        if (!(ellipsoid instanceof DefaultEllipsoid)) {
            throw new UnsupportedImplementationException(ellipsoid.getClass());
        }
        cs = (DefaultEllipsoidalCS) coordinateSystem;
        e  = (DefaultEllipsoid)     ellipsoid;
        if (coord1.length!=2 || coord2.length!=2 || cs.getDimension()!=2) {
            /*
             * Not yet implemented (an exception will be thrown later).
             * We should probably revisit the way we compute distances.
             */
            return super.distance(coord1, coord2);
        }
        return new Measure(e.orthodromicDistance(cs.getLongitude(coord1),
                                                 cs.getLatitude (coord1),
                                                 cs.getLongitude(coord2),
                                                 cs.getLatitude (coord2)), e.getAxisUnit());
    }
View Full Code Here

     * error.
     */
    private boolean checkOrthodromicDistance() {
        if (ellipsoid instanceof DefaultEllipsoid) {
            double check;
            final DefaultEllipsoid ellipsoid = (DefaultEllipsoid) this.ellipsoid;
            check = ellipsoid.orthodromicDistance(toDegrees(long1), toDegrees(lat1),
                                                  toDegrees(long2), toDegrees(lat2));
            check = abs(distance - check);
            return check <= (distance+1) * TOLERANCE_CHECK;
        }
        return true;
View Full Code Here

     * @return a properly built Datum.
     */
    public static DefaultGeodeticDatum getDefaultGeodeticDatum(final String name,
            final double equatorialRadius, final double inverseFlattening, Unit unit) {

        DefaultEllipsoid ellipsoid = DefaultEllipsoid.createFlattenedSphere(name, equatorialRadius,
                inverseFlattening, unit);
        final ReferenceIdentifier[] identifiers = Utilities.getIdentifiers(name);
        // TODO: Should I change this behavior?
        if (identifiers == null)
            throw new IllegalArgumentException("Reference Identifier not available");
View Full Code Here

    // was the projection user defined?
    // in such case we need to set the remaining parameters.
    if (projUserDefined) {
      final GeodeticDatum tempDatum = ((GeodeticDatum) gcs.getDatum());
      final DefaultEllipsoid tempEll = (DefaultEllipsoid) tempDatum
          .getEllipsoid();
      double inverseFlattening = tempEll.getInverseFlattening();
      double semiMajorAxis = tempEll.getSemiMajorAxis();
      // setting missing parameters
      parameters.parameter("semi_minor").setValue(
          semiMajorAxis * (1 - (1 / inverseFlattening)));
      parameters.parameter("semi_major").setValue(semiMajorAxis);

View Full Code Here

            157.50975812374,
            168.75993913258,
            180.00, 1000014142
        };
        final double             R          = 20000/Math.PI;
        final DefaultEllipsoid   ellipsoid  = DefaultEllipsoid.createEllipsoid("Test",R,R,SI.KILO(SI.METER));
        final GeodeticCalculator calculator = new GeodeticCalculator(ellipsoid);
        calculator.setStartingGeographicPoint(0, 45);
        for (int i=0; i<DATA.length; i+=3) {
            calculator.setDestinationGeographicPoint(DATA[i], 45);
            final double orthodromic = calculator.getOrthodromicDistance();
//          final double loxodromic  = calculator. getLoxodromicDistance();
            assertEquals("Orthodromic distance", DATA[i+1], orthodromic, 0.75);
//          assertEquals( "Loxodromic distance", DATA[i+2], loxodromic,  0.75);
            /*
             * Test the orthodromic path. We compare its length with the expected length.
             */
            int    count=0;
            double length=0, lastX=Double.NaN, lastY=Double.NaN;
            final Shape        path     = calculator.getGeodeticCurve(1000);
            final PathIterator iterator = path.getPathIterator(null, 0.1);
            final double[]     buffer   = new double[6];
            while (!iterator.isDone()) {
                switch (iterator.currentSegment(buffer)) {
                    case PathIterator.SEG_LINETO: {
                        count++;
                        length += ellipsoid.orthodromicDistance(lastX, lastY, buffer[0], buffer[1]);
                        // Fall through
                    }
                    case PathIterator.SEG_MOVETO: {
                        lastX = buffer[0];
                        lastY = buffer[1];
View Full Code Here

     *                                   Source: Office de la langue française, 1996
     *                                           http://www.granddictionnaire.com
     */
    @Test
    public void testEllipsoid() throws FactoryException {
        final DefaultEllipsoid e = DefaultEllipsoid.WGS84;
        final double          hm = 0.5/60; // Half of a minute of angle, in degrees.
        /*
         * Test the ellipsoidal model.
         */
        assertEquals("Nautical mile at equator",    1842.78, e.orthodromicDistance(0, 00-hm, 0, 00+hm), 0.2);
        assertEquals("Nautical mile at North pole", 1861.67, e.orthodromicDistance(0, 90-2*hm, 090), 0.2);
        assertEquals("Nautical mile at South pole", 1861.67, e.orthodromicDistance(0, 2*hm-90, 0, -90), 0.2);
        assertEquals("International nautical mile", 1852.00, e.orthodromicDistance(0, 45-hm, 0, 45+hm), 0.2);
        for (double i=0.01; i<180; i+=1) {
            final double base = 180*random.nextDouble()-90;
            assertEquals(i+"° rotation", e.getSemiMajorAxis()*Math.toRadians(i),
                                         e.orthodromicDistance(base, 0, base+i, 0), 0.2);
        }
        /*
         * Test the spherical model. The factory method should create
         * a specialized class, which is not the usual Ellipsoid class.
         */
        final double radius = e.getSemiMajorAxis();
        final double circumference = (radius*1.00000001) * (2*Math.PI);
        final DefaultEllipsoid s = DefaultEllipsoid.createEllipsoid("Sphere", radius, radius, e.getAxisUnit());
        assertTrue("Spheroid class", !DefaultEllipsoid.class.equals(s.getClass()));
        for (double i=0; i<=180; i+=1) {
            final double base = 360*random.nextDouble()-180;
            assertEquals(i+"° rotation", s.getSemiMajorAxis()*Math.toRadians(i),
                                         s.orthodromicDistance(base, 0, base+i, 0), 0.001);
        }
        for (double i=-90; i<=+90; i+=1) {
            final double meridian = 360*random.nextDouble()-180;
            assertEquals(i+"° rotation", s.getSemiMajorAxis()*Math.toRadians(Math.abs(i)),
                                         s.orthodromicDistance(meridian, 0, meridian, i), 0.001);
        }
        for (int i=0; i<100; i++) {
            final double y1 =  -90 + 180*random.nextDouble();
            final double y2 =  -90 + 180*random.nextDouble();
            final double x1 = -180 + 360*random.nextDouble();
            final double x2 = -180 + 360*random.nextDouble();
            final double distance = s.orthodromicDistance(x1, y1, x2, y2);
            assertTrue("Range of legal values", distance>=0 && distance<=circumference);
        }
    }
View Full Code Here

    @Test
    public void testGeocentricTransform() throws FactoryException, TransformException {
        /*
         * Gets the math transform from WGS84 to a geocentric transform.
         */
        final DefaultEllipsoid          ellipsoid = DefaultEllipsoid.WGS84;
        final CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84_3D;
        final CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN;
        final CoordinateOperation       operation = opFactory.createOperation(sourceCRS, targetCRS);
        final MathTransform             transform = operation.getMathTransform();
        final int                       dimension = transform.getSourceDimensions();
        assertEquals("Source dimension", 3, dimension);
        assertEquals("Target dimension", 3, transform.getTargetDimensions());
        assertSame("Inverse transform", transform, transform.inverse().inverse());
        assertInterfaced(transform);
        /*
         * Construct an array of 850 random points. The first 8 points
         * are initialized to know values. Other points are left random.
         */
        final double   cartesianDistance[] = new double[4];
        final double orthodromicDistance[] = new double[4];
        final double[]              array0 = new double[900]; // Must be divisible by 3.
        for (int i=0; i<array0.length; i++) {
            final int range;
            switch (i % 3) {
                case 0:  range =   360; break; // Longitude
                case 1:  range =   180; break; // Latitidue
                case 2:  range = 10000; break; // Altitude
                default: range =     0; break; // Should not happen
            }
            array0[i] = range*random.nextDouble()-(range/2);
        }
        array0[0]=35.0; array0[1]=24.0; array0[2]=8000; // 24°N 35°E 8km
        array0[3]=34.8; array0[4]=24.7; array0[5]=5000; // ... about 80 km away
        cartesianDistance  [0] = 80284.00;
        orthodromicDistance[0] = 80302.99; // Not really exact.

        array0[6]0; array0[ 7]=0.0; array0[ 8]=0;
        array0[9]=180; array0[10]=0.0; array0[11]=0; // Antipodes; distance should be 2*6378.137 km
        cartesianDistance  [1] = ellipsoid.getSemiMajorAxis() * 2;
        orthodromicDistance[1] = ellipsoid.getSemiMajorAxis() * Math.PI;

        array0[12]0; array0[13]=-90; array0[14]=0;
        array0[15]=180; array0[16]=+90; array0[17]=0; // Antipodes; distance should be 2*6356.752 km
        cartesianDistance  [2] = ellipsoid.getSemiMinorAxis() * 2;
        orthodromicDistance[2] = 20003931.46;

        array0[18]= 95; array0[19]=-38; array0[20]=0;
        array0[21]=-85; array0[22]=+38; array0[23]=0; // Antipodes
        cartesianDistance  [3] = 12740147.19;
        orthodromicDistance[3] = 20003867.86;
        /*
         * Transform all points, and then inverse transform then. The resulting
         * <code>array2</code> array should be equals to <code>array0</code>
         * except for rounding errors. We tolerate maximal error of 0.1 second
         * in longitude or latitude and 1 cm in height.
         */
        final double[] array1 = new double[array0.length];
        final double[] array2 = new double[array0.length];
        transform          .transform(array0, 0, array1, 0, array0.length/dimension);
        transform.inverse().transform(array1, 0, array2, 0, array1.length/dimension);
        assertPointsEqual("transform(Geographic --> Geocentric --> Geographic)", array0, array2,
                          new double[] {0.1/3600, 0.1/3600, 0.01});
        /*
         * Compare the distances between "special" points with expected distances.
         * This test the ellipsoid orthodromic distance computation as well.
         * We require a precision of 10 centimeters.
         */
        for (int i=0; i<array0.length/6; i++) {
            final int base = i*6;
            final Point3d  pt1 = new Point3d(array1[base+0], array1[base+1], array1[base+2]);
            final Point3d  pt2 = new Point3d(array1[base+3], array1[base+4], array1[base+5]);
            final double cartesian = pt1.distance(pt2);
            if (i < cartesianDistance.length) {
                assertEquals("Cartesian distance["+i+']', cartesianDistance[i], cartesian, 0.1);
            }
            /*
             * Compare with orthodromic distance.  Distance is computed using an ellipsoid
             * at the maximal altitude (i.e. the length of semi-major axis is increased to
             * fit the maximal altitude).
             */
            try {
                final double altitude = Math.max(array0[base+2], array0[base+5]);
                final DefaultEllipsoid ellip = DefaultEllipsoid.createFlattenedSphere("Temporary",
                                               ellipsoid.getSemiMajorAxis()+altitude,
                                               ellipsoid.getInverseFlattening(),
                                               ellipsoid.getAxisUnit());
                double orthodromic = ellip.orthodromicDistance(array0[base+0], array0[base+1],
                                                               array0[base+3], array0[base+4]);
                orthodromic = Math.hypot(orthodromic, array0[base+2] - array0[base+5]);
                if (i < orthodromicDistance.length) {
                    assertEquals("Orthodromic distance["+i+']', orthodromicDistance[i], orthodromic, 0.1);
                }
View Full Code Here

TOP

Related Classes of org.geotools.referencing.datum.DefaultEllipsoid

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.