Java Code Examples for org.opengis.geometry.DirectPosition#getCoordinate()

The following examples show how to use org.opengis.geometry.DirectPosition#getCoordinate() . 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: OmsHoleFiller.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private List<Coordinate> getValidSurroundingPoints( WritableRandomIter outIter, GridGeometry2D gridGeometry, int c, int r )
        throws TransformException {
    List<Coordinate> coords = new ArrayList<>();
    for( int dc = -1; dc <= 1; dc++ ) {
        for( int dr = -1; dr <= 1; dr++ ) {
            if (dc == 0 && dr == 0) {
                continue;
            }
            double value = outIter.getSampleDouble(c + dc, r + dr, 0);
            if (!isNovalue(value)) {
                DirectPosition worldPosition = gridGeometry.gridToWorld(new GridCoordinates2D(c + dc, r + dr));
                double[] coordinate = worldPosition.getCoordinate();
                Coordinate pointCoordinate = new Coordinate(coordinate[0], coordinate[1]);
                pointCoordinate.z = value;
                coords.add(pointCoordinate);
            }

        }
    }
    return coords;
}
 
Example 2
Source File: ImageGenerator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private void expandToIncludeEnvelope( ReferencedEnvelope maxExtent, org.opengis.geometry.Envelope envelope ) {
    ReferencedEnvelope tmpExtent = new ReferencedEnvelope(envelope.getCoordinateReferenceSystem());
    DirectPosition ll = envelope.getLowerCorner();
    double[] coordinate = ll.getCoordinate();
    tmpExtent.expandToInclude(new Coordinate(coordinate[0], coordinate[1]));
    DirectPosition ur = envelope.getUpperCorner();
    coordinate = ur.getCoordinate();
    tmpExtent.expandToInclude(new Coordinate(coordinate[0], coordinate[1]));

    try {
        ReferencedEnvelope transformed = tmpExtent.transform(maxExtent.getCoordinateReferenceSystem(), true);
        maxExtent.expandToInclude(transformed);
    } catch (TransformException | FactoryException e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the array of region parameters covered by the {@link GridCoverage2D coverage}. 
 * 
 * @param gridCoverage the coverage.
 * @return the array of region parameters as [n, s, w, e, xres, yres, cols, rows]
 */
public static double[] getRegionArrayFromGridCoverage( GridCoverage2D gridCoverage ) {
    Envelope envelope = gridCoverage.getEnvelope();
    DirectPosition lowerCorner = envelope.getLowerCorner();
    double[] westSouth = lowerCorner.getCoordinate();
    DirectPosition upperCorner = envelope.getUpperCorner();
    double[] eastNorth = upperCorner.getCoordinate();

    GridGeometry2D gridGeometry = gridCoverage.getGridGeometry();
    GridEnvelope2D gridRange = gridGeometry.getGridRange2D();
    int height = gridRange.height;
    int width = gridRange.width;

    AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS();
    double xRes = XAffineTransform.getScaleX0(gridToCRS);
    double yRes = XAffineTransform.getScaleY0(gridToCRS);

    double[] params = new double[]{eastNorth[1], westSouth[1], westSouth[0], eastNorth[0], xRes, yRes, width, height};

    return params;
}
 
Example 4
Source File: WKTPoint.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new WKT point.
 *
 * @param pt the pt
 */
public WKTPoint(DirectPosition pt) {

    if (pt != null) {
        this.x = pt.getCoordinate()[0];
        this.y = pt.getCoordinate()[1];
    }
}
 
Example 5
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the parameters of the region covered by the {@link GridCoverage2D coverage}. 
 * 
 * @param gridCoverage the coverage.
 * @return the {@link HashMap map} of parameters. ( {@link #NORTH} and the 
 *          other static vars can be used to retrieve them.
 */
public static RegionMap getRegionParamsFromGridCoverage( GridCoverage2D gridCoverage ) {
    RegionMap envelopeParams = new RegionMap();

    Envelope envelope = gridCoverage.getEnvelope();

    DirectPosition lowerCorner = envelope.getLowerCorner();
    double[] westSouth = lowerCorner.getCoordinate();
    DirectPosition upperCorner = envelope.getUpperCorner();
    double[] eastNorth = upperCorner.getCoordinate();

    GridGeometry2D gridGeometry = gridCoverage.getGridGeometry();
    GridEnvelope2D gridRange = gridGeometry.getGridRange2D();
    int height = gridRange.height;
    int width = gridRange.width;

    AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS();
    double xRes = XAffineTransform.getScaleX0(gridToCRS);
    double yRes = XAffineTransform.getScaleY0(gridToCRS);

    envelopeParams.put(NORTH, eastNorth[1]);
    envelopeParams.put(SOUTH, westSouth[1]);
    envelopeParams.put(WEST, westSouth[0]);
    envelopeParams.put(EAST, eastNorth[0]);
    envelopeParams.put(XRES, xRes);
    envelopeParams.put(YRES, yRes);
    envelopeParams.put(ROWS, (double) height);
    envelopeParams.put(COLS, (double) width);

    return envelopeParams;
}
 
Example 6
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the parameters of the region covered by the {@link ImageMosaicReader}. 
 * 
 * @param reader the ImageMosaicReader.
 * @return the {@link HashMap map} of parameters. ( {@link #NORTH} and the 
 *          other static vars can be used to retrieve them.
 */
public static RegionMap getRegionParamsFromImageMosaicReader( ImageMosaicReader reader ) throws IOException {
    RegionMap envelopeParams = new RegionMap();

    Envelope envelope = reader.getOriginalEnvelope();

    DirectPosition lowerCorner = envelope.getLowerCorner();
    double[] westSouth = lowerCorner.getCoordinate();
    DirectPosition upperCorner = envelope.getUpperCorner();
    double[] eastNorth = upperCorner.getCoordinate();

    GridEnvelope2D gridRange = (GridEnvelope2D) reader.getOriginalGridRange();
    int height = gridRange.height;
    int width = gridRange.width;
    double[][] resolutionLevels = reader.getResolutionLevels();
    double xRes = resolutionLevels[0][0];
    double yRes = resolutionLevels[0][1];

    envelopeParams.put(NORTH, eastNorth[1]);
    envelopeParams.put(SOUTH, westSouth[1]);
    envelopeParams.put(WEST, westSouth[0]);
    envelopeParams.put(EAST, eastNorth[0]);
    envelopeParams.put(XRES, xRes);
    envelopeParams.put(YRES, yRes);
    envelopeParams.put(ROWS, (double) height);
    envelopeParams.put(COLS, (double) width);

    return envelopeParams;
}
 
Example 7
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static RegionMap gridGeometry2RegionParamsMap( GridGeometry2D gridGeometry ) {
    RegionMap envelopeParams = new RegionMap();

    Envelope envelope = gridGeometry.getEnvelope2D();
    DirectPosition lowerCorner = envelope.getLowerCorner();
    double[] westSouth = lowerCorner.getCoordinate();
    DirectPosition upperCorner = envelope.getUpperCorner();
    double[] eastNorth = upperCorner.getCoordinate();

    GridEnvelope2D gridRange = gridGeometry.getGridRange2D();
    int height = gridRange.height;
    int width = gridRange.width;

    AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS();
    double xRes = XAffineTransform.getScaleX0(gridToCRS);
    double yRes = XAffineTransform.getScaleY0(gridToCRS);

    envelopeParams.put(NORTH, eastNorth[1]);
    envelopeParams.put(SOUTH, westSouth[1]);
    envelopeParams.put(WEST, westSouth[0]);
    envelopeParams.put(EAST, eastNorth[0]);
    envelopeParams.put(XRES, xRes);
    envelopeParams.put(YRES, yRes);
    envelopeParams.put(ROWS, (double) height);
    envelopeParams.put(COLS, (double) width);

    return envelopeParams;
}
 
Example 8
Source File: PrintUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static String getRegionPrint( GridCoverage2D coverage ) {
    org.opengis.geometry.Envelope envelope = coverage.getEnvelope();

    DirectPosition lowerCorner = envelope.getLowerCorner();
    double[] westSouth = lowerCorner.getCoordinate();
    DirectPosition upperCorner = envelope.getUpperCorner();
    double[] eastNorth = upperCorner.getCoordinate();

    GridGeometry2D gridGeometry = coverage.getGridGeometry();
    GridEnvelope2D gridRange = gridGeometry.getGridRange2D();

    String numberSpace = "                ";
    String numberRest = "                  ";

    StringBuilder sb = new StringBuilder();
    sb.append("        +----------------------   ").append(String.format("%17.8f", eastNorth[1]))
            .append("   ----------------------+").append("\n");
    sb.append("        +                         ").append(String.format("%17.8f", gridRange.getMinY()))
            .append("                         +").append("\n");
    sb.append("        +                         ").append(numberSpace).append("                          +").append("\n");
    sb.append("        +                         ").append(numberSpace).append("                          +").append("\n");
    sb.append(String.format("%17.8f", westSouth[0])).append(numberRest).append(numberSpace).append(numberRest)
            .append(String.format("%17.8f", eastNorth[0])).append("\n");
    sb.append(String.format("%17.8f", gridRange.getMinX())).append(numberRest).append(numberSpace).append(numberRest)
            .append(String.format("%17.8f", gridRange.getMaxX())).append("\n");
    sb.append("        +                         ").append(numberSpace).append("                          +").append("\n");
    sb.append("        +                         ").append(numberSpace).append("                          +").append("\n");
    sb.append("        +                         ").append(String.format("%17.8f", gridRange.getMaxY()))
            .append("                         +").append("\n");
    sb.append("        +----------------------   ").append(String.format("%17.8f", westSouth[1]))
            .append("   ----------------------+").append("\n");

    return sb.toString();
}
 
Example 9
Source File: EllipsoidToCentricTransform.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Computes the derivative at the given location. We need to override this method because
 * we will inverse 3×2 matrices in a special way, with the knowledge that <var>h</var>
 * can be set to 0.
 */
@Override
public Matrix derivative(final DirectPosition point) throws TransformException {
    ArgumentChecks.ensureNonNull("point", point);
    final double[] coordinate = point.getCoordinate();
    ArgumentChecks.ensureDimensionMatches("point", 3, coordinate);
    return this.transform(coordinate, 0, coordinate, 0, true);
}
 
Example 10
Source File: SpecializableTransform.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Inverse transforms the specified {@code ptSrc} and stores the result in {@code ptDst}.
 */
@Override
public final DirectPosition transform(final DirectPosition ptSrc, DirectPosition ptDst) throws TransformException {
    final double[] source = ptSrc.getCoordinate();      // Needs to be first in case ptDst overwrites ptSrc.
    ptDst = global.transform(ptSrc, ptDst);
    final SubArea domain = forward.locate(ptDst);
    if (domain != null) {
        ptDst = domain.inverse.transform(new DirectPositionView.Double(source), ptDst);
    }
    return ptDst;
}
 
Example 11
Source File: OmsHoleFiller.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    checkNull(inRaster);

    ISurfaceInterpolator interpolator;
    if (pMode.equals(IDW)) {
        interpolator = new IDWInterpolator(pBuffer);
    } else {
        interpolator = new TPSInterpolator(pBuffer);
    }

    RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
    int rows = regionMap.getRows();
    int cols = regionMap.getCols();

    WritableRaster outWR = CoverageUtilities.renderedImage2WritableRaster(inRaster.getRenderedImage(), false);
    WritableRandomIter outIter = CoverageUtilities.getWritableRandomIterator(outWR);

    GridGeometry2D gridGeometry = inRaster.getGridGeometry();

    PreparedGeometry preparedRoi = null;
    if (inROI != null) {
        List<Geometry> roiList = FeatureUtilities.featureCollectionToGeometriesList(inROI, false, null);
        GeometryCollection gc = new GeometryCollection(roiList.toArray(GeometryUtilities.TYPE_GEOMETRY), gf);
        preparedRoi = PreparedGeometryFactory.prepare(gc);
    }
    pm.beginTask("Filling holes...", cols - 2);
    for( int r = 1; r < rows - 1; r++ ) {
        for( int c = 1; c < cols - 1; c++ ) {
            if (pm.isCanceled()) {
                return;
            }

            double value = outIter.getSampleDouble(c, r, 0);
            if (isNovalue(value)) {
                DirectPosition worldPosition = gridGeometry.gridToWorld(new GridCoordinates2D(c, r));
                double[] coordinate = worldPosition.getCoordinate();
                Coordinate pointCoordinate = new Coordinate(coordinate[0], coordinate[1]);
                Point point = gf.createPoint(pointCoordinate);
                if (preparedRoi == null || preparedRoi.intersects(point)) {

                    // TODO this could be done considering more points and more far away points.
                    // For now, this works.
                    List<Coordinate> surroundingValids = getValidSurroundingPoints(outIter, gridGeometry, c, r);
                    if (surroundingValids.size() > 3) {
                        double newValue = interpolator.getValue(surroundingValids.toArray(new Coordinate[0]),
                                pointCoordinate);
                        outIter.setSample(c, r, 0, newValue);
                    }
                }
            }
        }
        pm.worked(1);
    }
    pm.done();

    outIter.done();

    outRaster = CoverageUtilities.buildCoverage("nulled", outWR, regionMap, inRaster.getCoordinateReferenceSystem());
}
 
Example 12
Source File: AbstractMathTransform.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}.
 * The default implementation performs the following steps:
 *
 * <ul>
 *   <li>Ensures that the dimension of the given points are consistent with the
 *       {@linkplain #getSourceDimensions() source} and {@linkplain #getTargetDimensions()
 *       target dimensions} of this math transform.</li>
 *   <li>Delegates to the {@link #transform(double[], int, double[], int, boolean)} method.</li>
 * </ul>
 *
 * This method does not update the associated {@link org.opengis.referencing.crs.CoordinateReferenceSystem} value.
 *
 * @param  ptSrc  the coordinate point to be transformed.
 * @param  ptDst  the coordinate point that stores the result of transforming {@code ptSrc}, or {@code null}.
 * @return the coordinate point after transforming {@code ptSrc} and storing the result in {@code ptDst},
 *         or a newly created point if {@code ptDst} was null.
 * @throws MismatchedDimensionException if {@code ptSrc} or {@code ptDst} doesn't have the expected dimension.
 * @throws TransformException if the point can not be transformed.
 */
@Override
public DirectPosition transform(final DirectPosition ptSrc, DirectPosition ptDst) throws TransformException {
    final int dimSource = getSourceDimensions();
    final int dimTarget = getTargetDimensions();
    ensureDimensionMatches("ptSrc", dimSource, ptSrc);
    if (ptDst != null) {
        ensureDimensionMatches("ptDst", dimTarget, ptDst);
        /*
         * Transforms the coordinates using a temporary 'double[]' buffer,
         * and copies the transformation result in the destination position.
         */
        final double[] array;
        if (dimSource >= dimTarget) {
            array = ptSrc.getCoordinate();
        } else {
            array = new double[dimTarget];
            for (int i=dimSource; --i>=0;) {
                array[i] = ptSrc.getOrdinate(i);
            }
        }
        transform(array, 0, array, 0, false);
        for (int i=0; i<dimTarget; i++) {
            ptDst.setOrdinate(i, array[i]);
        }
    } else {
        /*
         * Destination not set. We are going to create the destination here. Since we know that the
         * destination will be the SIS implementation, write directly into the `coordinates` array.
         */
        final GeneralDirectPosition destination = new GeneralDirectPosition(dimTarget);
        final double[] source;
        if (dimSource <= dimTarget) {
            source = destination.coordinates;
            for (int i=0; i<dimSource; i++) {
                source[i] = ptSrc.getOrdinate(i);
            }
        } else {
            source = ptSrc.getCoordinate();
        }
        transform(source, 0, destination.coordinates, 0, false);
        ptDst = destination;
    }
    return ptDst;
}
 
Example 13
Source File: PixelInfoViewModelUpdater.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private void updatePositionValues() {
    final boolean availableInRaster = pixelPosValidInRaster &&
            coordinatesAreInRasterBounds(currentRaster, pixelX, pixelY, rasterLevel);
    final boolean availableInScene = isSampleValueAvailableInScene();
    final double offset = 0.5 + (pixelInfoView.getShowPixelPosOffset1() ? 1.0 : 0.0);
    final double pX = levelZeroRasterX + offset;
    final double pY = levelZeroRasterY + offset;

    String tix, tiy, tsx, tsy, tmx, tmy, tgx, tgy;
    tix = tiy = tsx = tsy = tmx = tmy = tgx = tgy = INVALID_POS_TEXT;
    GeoCoding geoCoding = currentRaster.getGeoCoding();
    if (availableInRaster) {
        if (pixelInfoView.getShowPixelPosDecimal()) {
            tix = String.valueOf(pX);
            tiy = String.valueOf(pY);
        } else {
            tix = String.valueOf((int) Math.floor(pX));
            tiy = String.valueOf((int) Math.floor(pY));
        }
    }
    if (getCurrentProduct().isMultiSize()) {
        if (!availableInScene) {
            tsx = PixelInfoViewModelUpdater.INVALID_POS_TEXT;
            tsy = PixelInfoViewModelUpdater.INVALID_POS_TEXT;
        } else {
            double sX = levelZeroSceneX + offset;
            double sY = levelZeroSceneY + offset;
            if (pixelInfoView.getShowPixelPosDecimal()) {
                tsx = String.valueOf(sX);
                tsy = String.valueOf(sY);
            } else {
                tsx = String.valueOf((int) Math.floor(sX));
                tsy = String.valueOf((int) Math.floor(sY));
            }
        }
    }
    if (availableInRaster && geoCoding != null) {
        PixelPos pixelPos = new PixelPos(pX, pY);
        GeoPos geoPos = geoCoding.getGeoPos(pixelPos, null);
        if (pixelInfoView.getShowGeoPosDecimals()) {
            tgx = String.format("%.6f", geoPos.getLon());
            tgy = String.format("%.6f", geoPos.getLat());
        } else {
            tgx = geoPos.getLonString();
            tgy = geoPos.getLatString();
        }
        if (geoCoding instanceof MapGeoCoding) {
            final MapGeoCoding mapGeoCoding = (MapGeoCoding) geoCoding;
            final MapTransform mapTransform = mapGeoCoding.getMapInfo().getMapProjection().getMapTransform();
            Point2D mapPoint = mapTransform.forward(geoPos, null);
            tmx = String.valueOf(MathUtils.round(mapPoint.getX(), 10000.0));
            tmy = String.valueOf(MathUtils.round(mapPoint.getY(), 10000.0));
        } else if (geoCoding instanceof CrsGeoCoding) {
            MathTransform transform = geoCoding.getImageToMapTransform();
            try {
                DirectPosition position = transform.transform(new DirectPosition2D(pX, pY), null);
                double[] coordinate = position.getCoordinate();
                tmx = String.valueOf(coordinate[0]);
                tmy = String.valueOf(coordinate[1]);
            } catch (TransformException ignore) {
            }
        }
    }
    int rowCount = 0;
    positionModel.updateValue(tix, rowCount++);
    positionModel.updateValue(tiy, rowCount++);
    if (getCurrentProduct().isMultiSize()) {
        positionModel.updateValue(tsx, rowCount++);
        positionModel.updateValue(tsy, rowCount++);
    }
    if (geoCoding != null) {
        positionModel.updateValue(tgx, rowCount++);
        positionModel.updateValue(tgy, rowCount++);
        if (geoCoding instanceof MapGeoCoding || geoCoding instanceof CrsGeoCoding) {
            positionModel.updateValue(tmx, rowCount++);
            positionModel.updateValue(tmy, rowCount);
        }
    }
}
 
Example 14
Source File: LasTriangulation2Dsm.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
private void makeRow( STRtree tree, int newRows, GridGeometry2D newGridGeometry2D, WritableRaster newWR, int c )
        throws TransformException {
    for( int r = 0; r < newRows; r++ ) {
        DirectPosition worldPosition = newGridGeometry2D.gridToWorld(new GridCoordinates2D(c, r));
        double[] wpCoords = worldPosition.getCoordinate();
        Coordinate coordinate = new Coordinate(wpCoords[0], wpCoords[1]);
        Point point = gf.createPoint(coordinate);
        Envelope e = new Envelope(coordinate);
        List interceptedTriangles = tree.query(e);
        if (interceptedTriangles.size() == 0) {
            continue;
        }
        double newElev = -9999.0;
        for( Object object : interceptedTriangles ) {
            if (object instanceof Geometry) {
                Geometry triangle = (Geometry) object;
                if (!triangle.intersects(point)) {
                    continue;
                }
                Coordinate[] triangleCoords = triangle.getCoordinates();
                Coordinate c1 = new Coordinate(coordinate.x, coordinate.y, 1E4);
                Coordinate c2 = new Coordinate(coordinate.x, coordinate.y, -1E4);
                Coordinate intersection = GeometryUtilities.getLineWithPlaneIntersection(c1, c2, triangleCoords[0],
                        triangleCoords[1], triangleCoords[2]);
                double maxZ = max(triangleCoords[0].z, triangleCoords[1].z);
                maxZ = max(maxZ, triangleCoords[2].z);
                if (intersection.z > maxZ) {
                    boolean equals = NumericsUtilities.dEq(intersection.z, maxZ, 0.0001);
                    if (!equals) {
                        pm.errorMessage(triangle.toText());
                        pm.errorMessage(gf.createPoint(intersection).toText());
                        throw new RuntimeException("Intersection can't be  > than the triangle.");
                    }
                }
                if (intersection.z > newElev) {
                    newElev = intersection.z;
                }
            }
        }
        synchronized (newWR) {
            newWR.setSample(c, r, 0, newElev);
        }
    }
}
 
Example 15
Source File: OmsGeomorphon.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculate the geomorphon for a given cell of an elevation map.
 * 
 * @param elevIter the elevation map {@link RandomIter}.
 * @param gridGeometry the {@link GridGeometry2D} of the read map.
 * @param searchRadius the search radius to use.
 * @param angleThreshold the angle threshold to apply.
 * @param diagonalDelta the search radius for diagonal cells (usually radius/sqrt(2.0) )
 * @param c the column of the cell to analyse.
 * @param r the row of the cell to analyse.
 * @return the geomorphon classification for the cell.
 * @throws TransformException
 */
public static double calculateGeomorphon( RandomIter elevIter, GridGeometry2D gridGeometry, double searchRadius,
        double angleThreshold, double diagonalDelta, int c, int r ) throws TransformException {
    int[] plusCount = new int[1];
    int[] minusCount = new int[1];

    double elevation = elevIter.getSampleDouble(c, r, 0);
    if (HMConstants.isNovalue(elevation)) {
        return HMConstants.doubleNovalue;
    }
    DirectPosition worldPosition = gridGeometry.gridToWorld(new GridCoordinates2D(c, r));
    double[] coordinateArray = worldPosition.getCoordinate();
    Coordinate center = new Coordinate(coordinateArray[0], coordinateArray[1]);
    center.z = elevation;

    // calc 8 directions at max distance
    Coordinate c1 = new Coordinate(center.x + searchRadius, center.y, center.z);
    calculateCount(elevIter, gridGeometry, plusCount, minusCount, elevation, center, c1, angleThreshold);

    Coordinate c2 = new Coordinate(center.x + diagonalDelta, center.y + diagonalDelta, center.z);
    calculateCount(elevIter, gridGeometry, plusCount, minusCount, elevation, center, c2, angleThreshold);

    Coordinate c3 = new Coordinate(center.x, center.y + searchRadius, center.z);
    calculateCount(elevIter, gridGeometry, plusCount, minusCount, elevation, center, c3, angleThreshold);

    Coordinate c4 = new Coordinate(center.x - diagonalDelta, center.y + diagonalDelta, center.z);
    calculateCount(elevIter, gridGeometry, plusCount, minusCount, elevation, center, c4, angleThreshold);

    Coordinate c5 = new Coordinate(center.x - searchRadius, center.y, center.z);
    calculateCount(elevIter, gridGeometry, plusCount, minusCount, elevation, center, c5, angleThreshold);

    Coordinate c6 = new Coordinate(center.x - diagonalDelta, center.y - diagonalDelta, center.z);
    calculateCount(elevIter, gridGeometry, plusCount, minusCount, elevation, center, c6, angleThreshold);

    Coordinate c7 = new Coordinate(center.x, center.y - searchRadius, center.z);
    calculateCount(elevIter, gridGeometry, plusCount, minusCount, elevation, center, c7, angleThreshold);

    Coordinate c8 = new Coordinate(center.x + diagonalDelta, center.y - diagonalDelta, center.z);
    calculateCount(elevIter, gridGeometry, plusCount, minusCount, elevation, center, c8, angleThreshold);

    int classification = GeomorphonClassification.getClassification(plusCount[0], minusCount[0]);
    return classification;
}
 
Example 16
Source File: OmsSurfaceInterpolator.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
private void processing( final int cols, final STRtree tree, final WritableRandomIter interpolatedIter, final double[] eval,
        final int row ) {
    try {
        for( int c = 0; c < cols; c++ ) {
            final DirectPosition gridToWorld = gridGeometry.gridToWorld(new GridCoordinates2D(c, row));
            // System.out.println(row + "/" + c);
            boolean doProcess = true;
            if (inMask != null) {
                inMask.evaluate(gridToWorld, eval);
                if (isNovalue(eval[0])) {
                    doProcess = false;
                }
            }

            if (doProcess) {
                final Coordinate currentCoord = new Coordinate();
                final double[] coord = gridToWorld.getCoordinate();
                currentCoord.x = coord[0];
                currentCoord.y = coord[1];

                final Envelope env = new Envelope(currentCoord.x - pBuffer, currentCoord.x + pBuffer,
                        currentCoord.y - pBuffer, currentCoord.y + pBuffer);

                @SuppressWarnings("unchecked")
                final List<Coordinate> result = tree.query(env);
                // System.out.println(row + "/" + c + " = " + result.size());

                // we need at least 3 points
                if (result.size() < 4) {
                    continue;
                }

                final double value = interpolator.getValue(result.toArray(new Coordinate[0]), currentCoord);
                synchronized (interpolatedIter) {
                    interpolatedIter.setSample(c, row, 0, value);
                }
            }

        }
        pm.worked(1);
    } catch (TransformException e) {
        e.printStackTrace();
    }
}
 
Example 17
Source File: GeneralDirectPosition.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a position initialized to the same values than the specified point.
 * This is a copy constructor.
 *
 * @param point  the position to copy.
 */
public GeneralDirectPosition(final DirectPosition point) {
    coordinates = point.getCoordinate();                            // Should already be cloned.
    crs = point.getCoordinateReferenceSystem();
    ensureDimensionMatches("crs", coordinates.length, crs);
}