Java Code Examples for org.geotools.geometry.Envelope2D#getMaxY()

The following examples show how to use org.geotools.geometry.Envelope2D#getMaxY() . 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: FeatureUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a {@link Polygon} from an {@link Envelope}.
 * 
 * @param envelope the envelope to convert.
 * @return the created polygon.
 */
public static Polygon envelopeToPolygon( Envelope2D envelope ) {
    double w = envelope.getMinX();
    double e = envelope.getMaxX();
    double s = envelope.getMinY();
    double n = envelope.getMaxY();

    Coordinate[] coords = new Coordinate[5];
    coords[0] = new Coordinate(w, n);
    coords[1] = new Coordinate(e, n);
    coords[2] = new Coordinate(e, s);
    coords[3] = new Coordinate(w, s);
    coords[4] = new Coordinate(w, n);

    GeometryFactory gf = GeometryUtilities.gf();
    LinearRing linearRing = gf.createLinearRing(coords);
    Polygon polygon = gf.createPolygon(linearRing, null);
    return polygon;
}
 
Example 2
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a subcoverage given a template coverage and an envelope.
 * 
 * @param template the template coverage used for the resolution.
 * @param subregion the envelope to extract to the new coverage. This should
 *                  be snapped on the resolution of the coverage, in order to avoid 
 *                  shifts.
 * @param value the value to set the new raster to, if not <code>null</code>. 
 * @param writableRasterHolder an array of length 1 to place the writable raster in, that 
 *                  was can be used to populate the coverage. If <code>null</code>, it is ignored.
 * @return the new coverage.
 */
public static GridCoverage2D createSubCoverageFromTemplate( GridCoverage2D template, Envelope2D subregion, Double value,
        WritableRaster[] writableRasterHolder ) {
    RegionMap regionMap = getRegionParamsFromGridCoverage(template);
    double xRes = regionMap.getXres();
    double yRes = regionMap.getYres();

    double west = subregion.getMinX();
    double south = subregion.getMinY();
    double east = subregion.getMaxX();
    double north = subregion.getMaxY();

    int cols = (int) ((east - west) / xRes);
    int rows = (int) ((north - south) / yRes);
    ComponentSampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, 1, cols, new int[]{0});

    WritableRaster writableRaster = RasterFactory.createWritableRaster(sampleModel, null);
    if (value != null) {
        // autobox only once
        double v = value;
        for( int y = 0; y < rows; y++ ) {
            for( int x = 0; x < cols; x++ ) {
                writableRaster.setSample(x, y, 0, v);
            }
        }
    }
    if (writableRasterHolder != null)
        writableRasterHolder[0] = writableRaster;
    Envelope2D writeEnvelope = new Envelope2D(template.getCoordinateReferenceSystem(), west, south, east - west,
            north - south);
    GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
    GridCoverage2D coverage2D = factory.create("newraster", writableRaster, writeEnvelope);
    return coverage2D;
}
 
Example 3
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a bounds polygon of a {@link GridCoverage2D}.
 * 
 * @param gridCoverage the coverage to use.
 * @return the bounding polygon.
 */
public static Polygon getRegionPolygon( GridCoverage2D gridCoverage ) {
    Envelope2D env = gridCoverage.getEnvelope2D();
    Coordinate[] c = new Coordinate[]{new Coordinate(env.getMinX(), env.getMinY()),
            new Coordinate(env.getMinX(), env.getMaxY()), new Coordinate(env.getMaxX(), env.getMaxY()),
            new Coordinate(env.getMaxX(), env.getMinY()), new Coordinate(env.getMinX(), env.getMinY())};
    GeometryFactory gf = GeometryUtilities.gf();
    LinearRing linearRing = gf.createLinearRing(c);
    Polygon polygon = gf.createPolygon(linearRing, null);
    return polygon;
}
 
Example 4
Source File: JGTProcessingRegion.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance of {@link JGTProcessingRegion} from an {@link Envelope2D}
 * .
 * 
 * @param envelope2D
 *            the envelope2D from which to take the setting from.
 */
public JGTProcessingRegion( Envelope2D envelope2D ) {
    west = envelope2D.getMinX();
    east = envelope2D.getMaxX();
    south = envelope2D.getMinY();
    north = envelope2D.getMaxY();
    we_res = envelope2D.getHeight();
    ns_res = envelope2D.getWidth();

    fixRowsAndCols();
    fixResolution();
}
 
Example 5
Source File: PrintUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public static org.locationtech.jts.geom.Envelope envelope2D2Envelope( Envelope2D envelope2d ) {
    org.locationtech.jts.geom.Envelope jtsEnv = new org.locationtech.jts.geom.Envelope(envelope2d.getMinX(),
            envelope2d.getMaxX(), envelope2d.getMinY(), envelope2d.getMaxY());
    return jtsEnv;
}
 
Example 6
Source File: OmsGeomorphon.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculate a simple line of sight, given two coordinates on a raster.
 * 
 * @param regionMap
 * @param elevIter
 * @param gridGeometry
 * @param startCoordinate
 * @param endCoordinate
 * @return the last visible point, starting from the startCoordinate.
 * @throws TransformException
 */
public static ProfilePoint getLastVisiblePoint( RegionMap regionMap, RandomIter elevIter, GridGeometry2D gridGeometry,
        Coordinate startCoordinate, Coordinate endCoordinate ) throws TransformException {
    Envelope2D envelope2d = gridGeometry.getEnvelope2D();
    ProfilePoint lastVisible = null;
    double minX = envelope2d.getMinX();
    double maxX = envelope2d.getMaxX();
    double minY = envelope2d.getMinY();
    double maxY = envelope2d.getMaxY();

    if (endCoordinate.x >= minX && //
            endCoordinate.x <= maxX && //
            endCoordinate.y >= minY && //
            endCoordinate.y <= maxY//
    ) {
        List<ProfilePoint> profile = CoverageUtilities.doProfile(elevIter, gridGeometry, startCoordinate, endCoordinate);

        ProfilePoint first = profile.get(0);
        double viewerelev = first.getElevation();

        ProfilePoint secondPoint = profile.get(1);
        double lastMax = secondPoint.getElevation() - viewerelev;
        double lastMaxFactor = lastMax / secondPoint.getProgressive();
        lastVisible = secondPoint;

        for( int i = 2; i < profile.size(); i++ ) {
            ProfilePoint currentPoint = profile.get(i);
            double currentElev = currentPoint.getElevation() - viewerelev;
            double currentProg = currentPoint.getProgressive();
            // the maximum value that it can reach. If it is bigger, it is the new max
            double possibleMax = currentProg * lastMaxFactor;
            if (currentElev >= possibleMax) {
                // new max found, recalculate line of sight and set this as last seen point
                lastMax = currentElev;
                lastMaxFactor = lastMax / currentProg;
                lastVisible = currentPoint;
            }
        }
    }

    return lastVisible;
}