Examples of GeneralMatrix


Examples of org.geotools.referencing.operation.matrix.GeneralMatrix

     */
    public void testTransformCoordinate() throws FactoryException, TransformException {
        Coordinate   coord = new Coordinate(10, 10);
        AffineTransform at = AffineTransform.getScaleInstance(0.5, 1);
        MathTransform2D  t = (MathTransform2D) ReferencingFactoryFinder.getMathTransformFactory(null)
                                            .createAffineTransform(new GeneralMatrix(at));
        coord = JTS.transform(coord, coord, t);
        assertEquals(new Coordinate(5, 10), coord);
        coord = JTS.transform(coord, coord, t.inverse());
        assertEquals(new Coordinate(10, 10), coord);
       
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.GeneralMatrix

     */
    public void testTransformEnvelopeMathTransform() throws FactoryException, TransformException {
        Envelope envelope  = new Envelope(0, 10, 0, 10);
        AffineTransform at = AffineTransform.getScaleInstance(0.5, 1);
        MathTransform2D t  = (MathTransform2D) ReferencingFactoryFinder.getMathTransformFactory(null)
                                            .createAffineTransform(new GeneralMatrix(at));
        envelope = JTS.transform(envelope, t);
        assertEquals(new Envelope(0, 5, 0, 10), envelope);
        envelope = JTS.transform(envelope, t.inverse());
        assertEquals(new Envelope(0, 10, 0, 10), envelope);
       
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.GeneralMatrix

  }

  private void initTransform() {
    if (transform == null) {
      // building the transform
      final GeneralMatrix gm = new GeneralMatrix(3);

      // compute an "offset and scale" matrix
      gm.setElement(0, 0, xPixelSize);
      gm.setElement(1, 1, yPixelSize);
      gm.setElement(0, 1, rotationX);
      gm.setElement(1, 0, rotationY);

      gm.setElement(0, 2, xULC);
      gm.setElement(1, 2, yULC);

      // make it a LinearTransform
      transform = gm;
    }
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.GeneralMatrix

    public void testMatrix2() {
        final Matrix2 m = new Matrix2();
        assertTrue(m.isAffine());
        assertTrue(m.isIdentity());
        final Random random = new Random(8447482612423035360L);
        final GeneralMatrix identity = new GeneralMatrix(2);
        for (int i=0; i<100; i++) {
            m.setElement(0,0, 100*random.nextDouble());
            m.setElement(0,1, 100*random.nextDouble());
            m.setElement(1,0, 100*random.nextDouble());
            m.setElement(1,1, 100*random.nextDouble());
            final Matrix2 original = m.clone();
            final GeneralMatrix check = new GeneralMatrix(m);
            m.invert();
            check.invert();
            assertTrue(check.equals(m, 1E-9));
            m.multiply(original);
            assertTrue(identity.equals(m, 1E-9));
        }
    }
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.GeneralMatrix

     */
    @Test
    public void testAxisSwapping() {
        AxisDirection[] srcAxis = {NORTH, EAST, UP};
        AxisDirection[] dstAxis = {NORTH, EAST, UP};
        GeneralMatrix   matrix  = new GeneralMatrix(srcAxis, dstAxis);
        assertTrue(matrix.isAffine  ());
        assertTrue(matrix.isIdentity());
        dstAxis = new AxisDirection[] {WEST, UP, SOUTH};
        matrix  = new GeneralMatrix(srcAxis, dstAxis);
        assertTrue (matrix.isAffine  ());
        assertFalse(matrix.isIdentity());
        assertEquals(new GeneralMatrix(new double[][] {
            { 0,-1, 0, 0},
            { 0, 0, 1, 0},
            {-1, 0, 0, 0},
            { 0, 0, 0, 1}
        }), matrix);
        dstAxis = new AxisDirection[] {DOWN, NORTH};
        matrix  = new GeneralMatrix(srcAxis, dstAxis);
        assertFalse(matrix.isIdentity());
        assertEquals(new GeneralMatrix(new double[][] {
            {0, 0,-1, 0},
            {1, 0, 0, 0},
            {0, 0, 0, 1}
        }), matrix);
        dstAxis = new AxisDirection[] {DOWN, DOWN};
        matrix  = new GeneralMatrix(srcAxis, dstAxis);
        assertFalse(matrix.isIdentity());
        assertEquals(new GeneralMatrix(new double[][] {
            {0, 0,-1, 0},
            {0, 0,-1, 0},
            {0, 0, 0, 1}
        }), matrix);
        dstAxis = new AxisDirection[] {DOWN, GEOCENTRIC_X};
        try {
            matrix = new GeneralMatrix(srcAxis, dstAxis);
            fail();
        } catch (IllegalArgumentException exception) {
            // This is the expected exception (axis not in source).
        }
        srcAxis = dstAxis;
        dstAxis = new AxisDirection[] {NORTH, EAST, UP, WEST};
        try {
            matrix = new GeneralMatrix(srcAxis, dstAxis);
            fail();
        } catch (IllegalArgumentException exception) {
            // This is the expected exception (colinear axis).
        }
    }
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.GeneralMatrix

        final AbstractCS cs = new DefaultCartesianCS("Test",
              new DefaultCoordinateSystemAxis("y", SOUTH, cm),
              new DefaultCoordinateSystemAxis("x", EAST,  mm));
        Matrix matrix;
        matrix = AbstractCS.swapAndScaleAxis(DefaultCartesianCS.GENERIC_2D, cs);
        assertEquals(new GeneralMatrix(new double[][] {
            {0,  -100,    0},
            {10000,    0},
            {0,     0,    1}
        }), matrix);
        matrix = AbstractCS.swapAndScaleAxis(DefaultCartesianCS.GENERIC_3D, cs);
        assertEquals(new GeneralMatrix(new double[][] {
            {0,  -100,   0,   0},
            {10000,   0,   0},
            {0,     0,   0,   1}
        }), matrix);
    }
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.GeneralMatrix

    {
        final Matrix matrix = AbstractCS.swapAndScaleAxis(cs1, cs2);
        final int numRow = matrix.getNumRow();
        final int numCol = matrix.getNumCol();
        assertEquals(expected.length, numRow*numCol);
        final Matrix em = new GeneralMatrix(numRow, numCol, expected);
        assertEquals(em, matrix);
    }
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.GeneralMatrix

            dx[1] = channel == Channel.PORT ? -cosAlpha * yDim : cosAlpha * yDim;

            dy[0] = cosAlpha * xDim;
            dy[1] = channel == Channel.PORT ? sinAlpha * yDim : sinAlpha * -yDim;
           
            GeneralMatrix gm = new GeneralMatrix(3);
            gm.setElement(0, 0, dx[0]);
            gm.setElement(0, 1, dx[1]);
            gm.setElement(1, 0, dy[0]);
            gm.setElement(1, 1, dy[1]);
            gm.setElement(0, 2, easting);
            gm.setElement(1, 2, northing);
            gt = gm.toAffineTransform2D();
           
            this.raster2Model = ProjectiveTransform.create(gt);
            MathTransform tempTransform = PixelTranslation.translate(
                    raster2Model, PixelInCell.CELL_CENTER,
                    PixelInCell.CELL_CORNER);
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.GeneralMatrix

      if (coefficients.length == 6) {
        final double[] geotCoeff = new double[6];
        for (int i = 0; i < 6; i++) {
          geotCoeff[i] = Double.parseDouble(coefficients[i]);
        }
        final GeneralMatrix gm = new GeneralMatrix(3);

        // //
        //
        // The proj_to_image_affine is defined as follows:
        //
        // Image row = affine[0]*y + affine[2]*x + affine[4]
        // Image col = affine[1]+y + affine[3]*x + affine[5]
        //
        // As stated in the earth_location_notes, Y and X
        // are kilometers north and east of projection
        // origin
        //
        // //
        gm.setElement(0, 0, geotCoeff[3] / 1000);
        gm.setElement(1, 1, geotCoeff[0] / 1000);
        gm.setElement(0, 1, geotCoeff[2] / 1000);
        gm.setElement(1, 0, geotCoeff[1] / 1000);
        gm.setElement(0, 2, geotCoeff[5]);
        gm.setElement(1, 2, geotCoeff[4]);

        try {
          final MathTransform inverseTransformation = ProjectiveTransform.create(gm).inverse();
          final AffineTransform tempTransform = new AffineTransform((AffineTransform) inverseTransformation);
          at = tempTransform;
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.GeneralMatrix

     * each transformation parameter (sx, sy, sxy, phi, tx,ty). The rows are derivations of fx and fy.
     *
     * @return A matrix
     */
    protected GeneralMatrix getA() {
        GeneralMatrix A = new GeneralMatrix(2 * this.getMappedPositions().size(), 6);

        double cosphix = Math.cos(phix);
        double sinphix = Math.sin(phix);
       
        double cosphiy = Math.cos(phiy);
        double sinphiy = Math.sin(phiy);

        /**
         * Each row is calculated with values of proper GCPs
         */
        for (int j = 0; j < (A.getNumRow() / 2); j++) {
            double x = getSourcePoints()[j].getOrdinate(0);
            double y = getSourcePoints()[j].getOrdinate(1);

            /*************************
             *
             * Derivation X
             *
             **************************/
            double dxsx = cosphix*x;
                      
            double dxsy = - sinphiy * y;
                
            double dxphix = -sx*sinphix* x;
           
            double dxphiy = -sy*cosphiy* y ;
           
            double dxtx = 1;
           
            double dxty = 0;

            /*************************
             *
             * Derivation Y
             *
             ***********************/
            double dysx = sinphix * x;
                      
            double dysy = cosphiy * y;
                
            double dyphix =  sx*cosphix*x;
           
            double dyphiy = -sy*sinphiy* y ;
           
            double dytx = 0;
           
            double dyty = 1;
        
            A.setRow(j,                   new double[] { dxsx, dxsy, dxphix, dxphiy, dxtx, dxty });
            A.setRow(A.getNumRow()/2 + j, new double[] { dysx, dysy, dyphix, dyphiy, dytx, dyty });
        }

        return A;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.