Search in sources :

Example 11 with DirectPosition2D

use of org.apache.sis.geometry.DirectPosition2D in project sis by apache.

the class LatLonPointRadiusTest method testGetRectangularRegionApproximation.

/**
 * Tests the getRectangularRegionApproximation() method.
 */
@Test
public void testGetRectangularRegionApproximation() {
    LatLonPointRadius pr1 = new LatLonPointRadius(new DirectPosition2D(0.0, 0.0), 25000.0);
    Rectangle2D r1 = pr1.getRectangularRegionApproximation(10);
    assertEquals(0.0, r1.getX(), EPSILON);
    assertEquals(0.0, r1.getY(), EPSILON);
    assertEquals(360.0, r1.getWidth(), EPSILON);
    assertEquals(180.0, r1.getHeight(), EPSILON);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) Test(org.junit.Test)

Example 12 with DirectPosition2D

use of org.apache.sis.geometry.DirectPosition2D in project sis by apache.

the class LatLonPointRadiusTest method testCreateLatLonPointRadius.

/**
 * Tests the LatLonPointRadius constructor.
 */
@Test
public void testCreateLatLonPointRadius() {
    LatLonPointRadius region = new LatLonPointRadius(new DirectPosition2D(0.0, 0.0), 100.0);
    assertNotNull(region);
}
Also used : DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) Test(org.junit.Test)

Example 13 with DirectPosition2D

use of org.apache.sis.geometry.DirectPosition2D in project sis by apache.

the class LatLonPointRadiusTest method testGetCircularRegionApproximation.

/**
 * Tests the getCircularRegionApproximation() method.
 */
@Test
public void testGetCircularRegionApproximation() {
    LatLonPointRadius pr1 = new LatLonPointRadius(new DirectPosition2D(0.0, 0.0), 25000.0);
    DirectPosition2D[] pts1 = pr1.getCircularRegionApproximation(10);
    assertEquals(5, pts1.length);
    assertEquals(-90.0, pts1[0].y, EPSILON);
    assertEquals(-180.0, pts1[0].x, EPSILON);
    assertEquals(90.0, pts1[1].y, EPSILON);
    assertEquals(-180.0, pts1[1].x, EPSILON);
    assertEquals(90.0, pts1[2].y, EPSILON);
    assertEquals(180.0, pts1[2].x, EPSILON);
    assertEquals(-90.0, pts1[3].y, EPSILON);
    assertEquals(180.0, pts1[3].x, EPSILON);
    assertEquals(-90.0, pts1[4].y, EPSILON);
    assertEquals(-180.0, pts1[4].x, EPSILON);
    LatLonPointRadius pr2 = new LatLonPointRadius(new DirectPosition2D(0.0, 0.0), 1000.0);
    DirectPosition2D[] pts2 = pr2.getCircularRegionApproximation(6);
    assertEquals(7, pts2.length);
}
Also used : DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) Test(org.junit.Test)

Example 14 with DirectPosition2D

use of org.apache.sis.geometry.DirectPosition2D in project sis by apache.

the class LocalizationGridBuilder method create.

/**
 * Creates a transform from the source points to the target points.
 * This method assumes that source points are precise and all uncertainty is in the target points.
 * If this transform is close enough to an affine transform, then an instance of {@link LinearTransform} is returned.
 *
 * @param  factory  the factory to use for creating the transform, or {@code null} for the default factory.
 *                  The {@link MathTransformFactory#createAffineTransform(Matrix)} method of that factory
 *                  shall return {@link LinearTransform} instances.
 * @return the transform from source to target points.
 * @throws FactoryException if the transform can not be created,
 *         for example because the target points have not be specified.
 */
@Override
public MathTransform create(final MathTransformFactory factory) throws FactoryException {
    final LinearTransform gridToCoord = linear.create(factory);
    /*
         * Make a first check about whether the result of above LinearTransformBuilder.create() call
         * can be considered a good fit. If true, then we may return the linear transform directly.
         */
    boolean isExact = true;
    boolean isLinear = true;
    for (final double c : linear.correlation()) {
        isExact &= (c == 1);
        if (c < 0.9999) {
            // Empirical threshold (may need to be revisited).
            isLinear = false;
            break;
        }
    }
    if (isExact) {
        return MathTransforms.concatenate(sourceToGrid, gridToCoord);
    }
    final int width = linear.gridSize(0);
    final int height = linear.gridSize(1);
    final int tgtDim = gridToCoord.getTargetDimensions();
    final double[] residual = new double[tgtDim * linear.gridLength];
    final double[] point = new double[tgtDim + 1];
    double gridPrecision = precision;
    try {
        /*
             * If the user specified a precision, we need to convert it from source units to grid units.
             * We convert each dimension separately, then retain the largest magnitude of vector results.
             */
        if (gridPrecision > 0 && !sourceToGrid.isIdentity()) {
            final double[] vector = new double[sourceToGrid.getSourceDimensions()];
            final double[] offset = new double[sourceToGrid.getTargetDimensions()];
            double converted = 0;
            for (int i = 0; i < vector.length; i++) {
                vector[i] = precision;
                sourceToGrid.deltaTransform(vector, 0, offset, 0, 1);
                final double length = MathFunctions.magnitude(offset);
                if (length > converted)
                    converted = length;
                vector[i] = 0;
            }
            gridPrecision = converted;
        }
        /*
             * Compute the residuals, i.e. the differences between the coordinates that we get by a linear
             * transformation and the coordinates that we want to get. If at least one residual is greater
             * than the desired precision,  then the returned MathTransform will need to apply corrections
             * after linear transforms. Those corrections will be done by InterpolatedTransform.
             */
        final MatrixSIS coordToGrid = MatrixSIS.castOrCopy(gridToCoord.inverse().getMatrix());
        final DirectPosition2D src = new DirectPosition2D();
        point[tgtDim] = 1;
        for (int k = 0, y = 0; y < height; y++) {
            src.y = y;
            tmp[1] = y;
            for (int x = 0; x < width; x++) {
                src.x = x;
                tmp[0] = x;
                // Expected position.
                linear.getControlPoint2D(tmp, point);
                // As grid coordinate.
                double[] grid = coordToGrid.multiply(point);
                isLinear &= (residual[k++] = grid[0] - x) <= gridPrecision;
                isLinear &= (residual[k++] = grid[1] - y) <= gridPrecision;
            }
        }
    } catch (TransformException e) {
        // Should never happen.
        throw new FactoryException(e);
    }
    if (isLinear) {
        return MathTransforms.concatenate(sourceToGrid, gridToCoord);
    }
    return InterpolatedTransform.createGeodeticTransformation(nonNull(factory), new ResidualGrid(sourceToGrid, gridToCoord, width, height, tgtDim, residual, (gridPrecision > 0) ? gridPrecision : DEFAULT_PRECISION));
}
Also used : FactoryException(org.opengis.util.FactoryException) NoninvertibleTransformException(org.opengis.referencing.operation.NoninvertibleTransformException) TransformException(org.opengis.referencing.operation.TransformException) LinearTransform(org.apache.sis.referencing.operation.transform.LinearTransform) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) MatrixSIS(org.apache.sis.referencing.operation.matrix.MatrixSIS)

Example 15 with DirectPosition2D

use of org.apache.sis.geometry.DirectPosition2D in project sis by apache.

the class QuadTreeReader method readFromFile.

/**
 * Read the quad tree index from file.
 *
 * @param tree
 *          the quad tree
 * @param parent
 *          the quad tree parent node
 * @param directory
 *          the directory where the index files are located
 * @param filename
 *          the name of the parent node file
 */
private static void readFromFile(final QuadTree tree, final QuadTreeNode parent, final String directory, final String filename) {
    try {
        BufferedReader reader = new BufferedReader(new FileReader(directory + filename));
        String line = "";
        while ((line = reader.readLine()) != null) {
            String[] tokens = line.split(":");
            Quadrant quadrant = Quadrant.getQuadrant(Integer.parseInt(tokens[0]));
            String nodetype = tokens[1];
            int id = Integer.parseInt(tokens[2]);
            if (nodetype.equals("GRAY")) {
                parent.setChild(new QuadTreeNode(NodeType.GRAY, id), quadrant);
                tree.setNodeSize(tree.getNodeSize() + 1);
            } else {
                int capacity = Integer.parseInt(tokens[3]);
                parent.setChild(new QuadTreeNode(id, capacity), quadrant);
                for (int i = 4; i < tokens.length; i++) {
                    String[] dataTokens = tokens[i].split(";");
                    double lat = Double.parseDouble(dataTokens[0]);
                    double lon = Double.parseDouble(dataTokens[1]);
                    parent.getChild(quadrant).addData(new GeoRSSData(dataTokens[2], new DirectPosition2D(lon, lat)));
                    tree.setSize(tree.getSize() + 1);
                }
                tree.setNodeSize(tree.getNodeSize() + 1);
            }
        }
        reader.close();
        if (parent.getChild(Quadrant.NW) != null && parent.getChild(Quadrant.NW).getNodeType() == NodeType.GRAY) {
            readFromFile(tree, parent.getChild(Quadrant.NW), directory, "node_" + parent.getChild(Quadrant.NW).getId() + ".txt");
        }
        if (parent.getChild(Quadrant.NE) != null && parent.getChild(Quadrant.NE).getNodeType() == NodeType.GRAY) {
            readFromFile(tree, parent.getChild(Quadrant.NE), directory, "node_" + parent.getChild(Quadrant.NE).getId() + ".txt");
        }
        if (parent.getChild(Quadrant.SW) != null && parent.getChild(Quadrant.SW).getNodeType() == NodeType.GRAY) {
            readFromFile(tree, parent.getChild(Quadrant.SW), directory, "node_" + parent.getChild(Quadrant.SW).getId() + ".txt");
        }
        if (parent.getChild(Quadrant.SE) != null && parent.getChild(Quadrant.SE).getNodeType() == NodeType.GRAY) {
            readFromFile(tree, parent.getChild(Quadrant.SE), directory, "node_" + parent.getChild(Quadrant.SE).getId() + ".txt");
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (NumberFormatException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Aggregations

DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)25 Test (org.junit.Test)12 DependsOnMethod (org.apache.sis.test.DependsOnMethod)7 DirectPosition (org.opengis.geometry.DirectPosition)4 Rectangle2D (java.awt.geom.Rectangle2D)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Envelope2D (org.apache.sis.geometry.Envelope2D)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 MathTransform (org.opengis.referencing.operation.MathTransform)2 Matrix (org.opengis.referencing.operation.Matrix)2 WireFeed (com.sun.syndication.feed.WireFeed)1 GeoRSSModule (com.sun.syndication.feed.module.georss.GeoRSSModule)1 Channel (com.sun.syndication.feed.rss.Channel)1 Item (com.sun.syndication.feed.rss.Item)1 WireFeedInput (com.sun.syndication.io.WireFeedInput)1 XmlReader (com.sun.syndication.io.XmlReader)1 AffineTransform (java.awt.geom.AffineTransform)1