Package org.geotools.geometry

Examples of org.geotools.geometry.DirectPosition2D


    GridCoverage2DReader reader = format.getReader(file);
    // exampleGridCoverageDirect start
    GridCoverage2D coverage = reader.read(null);
   
    // direct access
    DirectPosition position = new DirectPosition2D( crs, x, y);
   
    double[] sample = (double[]) coverage.evaluate( position ); // assume double
   
    // resample with the same array
    sample = coverage.evaluate( position, sample );
View Full Code Here


                    MapProjection.AbstractProvider.FALSE_EASTING.getName().getCode());
            double originX = fe.doubleValue();
            ParameterValue<?> fn = ps.getParameterValues().parameter(
                    MapProjection.AbstractProvider.FALSE_NORTHING.getName().getCode());
            double originY = fn.doubleValue();
            DirectPosition2D origin = new DirectPosition2D(originX, originY);
            if (generalEnvelope.contains(origin)) {
                if (targetCRS instanceof GeographicCRS) {
                    DirectPosition lowerCorner = transformed.getLowerCorner();
                    if (getAxisOrder(targetCRS) == AxisOrder.NORTH_EAST) {
                        lowerCorner.setOrdinate(1, -180);
View Full Code Here

    private static void expandEnvelopeByLongitude(double longitude, DirectPosition input,
            GeneralEnvelope transformed, CoordinateReferenceSystem sourceCRS) {
        try {
            MathTransform mt = findMathTransform(sourceCRS,
                    DefaultGeographicCRS.WGS84);
            DirectPosition2D pos = new DirectPosition2D(sourceCRS);
            mt.transform(input, pos);
            pos.setOrdinate(0, longitude);
            mt.inverse().transform(pos, pos);
            transformed.add(pos);
        } catch (Exception e) {
            LOGGER.log(Level.FINER, "Tried to expand target envelope to include longitude "
                    + longitude + " but failed. This is not necesseraly and issue, "
View Full Code Here

            + (nearestOne.getTarget().getCoordinate()[0]
            - nearestOne.getSource().getCoordinate()[0]);
        double dstY = x.getCoordinate()[1]
            + (nearestOne.getTarget().getCoordinate()[1]
            - nearestOne.getSource().getCoordinate()[1]);
        DirectPosition dst = new DirectPosition2D(nearestOne.getTarget()
                                                            .getCoordinateReferenceSystem(),
                dstX, dstY);

        return new MappedPosition(x, dst);
    }
View Full Code Here

     *
     * @return the MappedPosition to the x Coordinate.
     */
    protected MappedPosition nearestMappedCoordinate(DirectPosition dp,
        List <MappedPosition> vertices) {
        DirectPosition2D x = new DirectPosition2D(dp);

        // Assert.isTrue(vectors.size() > 0);
        MappedPosition nearestOne = (MappedPosition) vertices.get(0);

        for (Iterator <MappedPosition> i = vertices.iterator(); i.hasNext();) {
            MappedPosition candidate = (MappedPosition) i.next();

            if (((DirectPosition2D) candidate.getSource()).distance(
                        x.toPoint2D()) < ((DirectPosition2D) nearestOne
                    .getSource()).distance(x.toPoint2D())) {
                nearestOne = candidate;
            }
        }

        return nearestOne;
View Full Code Here

    public final DirectPosition gridToWorld(final GridCoordinates2D point)
            throws TransformException {

        if (getGridRange2D().contains(point)) {
            Point2D trPoint = getGridToCRS2D().transform(point, null);
            return new DirectPosition2D(getCoordinateReferenceSystem2D(),
                    trPoint.getX(), trPoint.getY());

        } else {
            throw new IllegalArgumentException(
                    Errors.format(ErrorKeys.POINT_OUTSIDE_COVERAGE_$1, point));
View Full Code Here

            GridCoordinates2D high = gridEnv.getHigh();
            Point2D trHigh = mt.transform(new Point2D.Double(high.x + 0.5, high.y + 0.5), null);

            return new Envelope2D(
                    new DirectPosition2D(crs2D, trLow.getX(), trLow.getY()),
                    new DirectPosition2D(crs2D, trHigh.getX(), trHigh.getY()));

        } else {
            throw new IllegalArgumentException(
                    Errors.format(ErrorKeys.POINT_OUTSIDE_COVERAGE_$1, gridEnv));
        }
View Full Code Here

     * {@linkplain #getTarget target} position of the specified dimension.
     * The initial coordinate values are 0.
     */
    public MappedPosition(final int dimension) {
        if (dimension == 2) {
            source = new DirectPosition2D();
            target = new DirectPosition2D();
        } else {
            source = new GeneralDirectPosition(dimension);
            target = new GeneralDirectPosition(dimension);
        }
    }
View Full Code Here

          .doubleValue();
      if(!Double.isNaN(xPeriod)&&!Double.isNaN(yPeriod)){

        // build the new one that spans over the requested area
        // NOTE:
        final DirectPosition2D LLC = new DirectPosition2D(crs, envelope.x,
            envelope.y);
        LLC.setCoordinateReferenceSystem(crs);
        final DirectPosition2D URC = new DirectPosition2D(crs, envelope.x
            + xPeriod, envelope.y + yPeriod);
        URC.setCoordinateReferenceSystem(crs);
        final Envelope2D shrinkedEnvelope = new Envelope2D(LLC, URC);
 
        // transform back into raster space
        final Rectangle2D transformedEnv = CRS.transform(
            worldToGridTransform, shrinkedEnvelope).toRectangle2D();
View Full Code Here

        final GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
        GridCoverage2D coverage = factory.create("translated", ti, new Envelope2D(wgs84LatLon, 3, 5, 6, 8));
       
        // verify we're good
        int[] pixel = new int[3];
        coverage.evaluate((DirectPosition) new DirectPosition2D(4, 6), pixel);
        assertEquals(0, pixel[0]);
        assertEquals(255, pixel[1]);
        assertEquals(0, pixel[2]);
       
        // now reproject flipping the axis
        CoordinateReferenceSystem wgs84LonLat = CRS.decode("EPSG:4326", true);
        GridGeometry gg = new GridGeometry2D(new GridEnvelope2D(-10, -10, 5, 5), (Envelope) new Envelope2D(wgs84LonLat, 5, 3, 8, 6));
        GridCoverage2D flipped = (GridCoverage2D) Operations.DEFAULT.resample(coverage, wgs84LonLat, 
                gg, Interpolation.getInstance(Interpolation.INTERP_NEAREST));

        // before the fix the pixel would have been black
        flipped.evaluate((DirectPosition) new DirectPosition2D(6, 4), pixel);
        assertEquals(0, pixel[0]);
        assertEquals(255, pixel[1]);
        assertEquals(0, pixel[2]);
    }
View Full Code Here

TOP

Related Classes of org.geotools.geometry.DirectPosition2D

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.