Java Code Examples for org.locationtech.jts.geom.Envelope#getWidth()

The following examples show how to use org.locationtech.jts.geom.Envelope#getWidth() . 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: TransformationUtils.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extend an envelope to have the same ratio as the given width and height.
 * 
 * @param original the envelope.
 * @param width the reference width.
 * @param height the reference height.
 * @return the extended envelope, centered on the original one.
 */
public static Envelope expandToFitRatio( Envelope original, double width, double height ) {

    double oh = height * original.getWidth() / width;
    double ow;
    if (oh < original.getHeight()) {
        ow = width * original.getHeight() / height;
        oh = original.getHeight();
    } else {
        ow = original.getWidth();
    }

    double expandX = (ow - original.getWidth()) / 2.0;
    double expandY = (oh - original.getHeight()) / 2.0;

    Envelope newEnv = new Envelope(original);
    newEnv.expandBy(expandX, expandY);

    return newEnv;
}
 
Example 2
Source File: GeoPkgGeomReader.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public Geometry get() throws IOException {
    if (header == null) {
        header = readHeader();
    }

    if (geometry == null) {
        Envelope envelope = header.getEnvelope();
        if (simplificationDistance != null && geometryType != null
                && header.getFlags().getEnvelopeIndicator() != EnvelopeType.NONE
                && envelope.getWidth() < simplificationDistance.doubleValue()
                && envelope.getHeight() < simplificationDistance.doubleValue()) {
            Geometry simplified = getSimplifiedShape(geometryType, envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(),
                    envelope.getMaxY());
            if (simplified != null) {
                geometry = simplified;
            }
        }

        if (geometry == null) {
            geometry = read();
        }
    }
    return geometry;
}
 
Example 3
Source File: MercatorUtils.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the tiles that fit into a given tile at lower zoomlevel.
 * 
 * @param origTx the original tile x.
 * @param origTy the original tile y.
 * @param origZoom the original tile zoom.
 * @param higherZoom the requested zoom.
 * @param tileSize the used tile size.
 * @return the ordered list of tiles.
 */
public static List<int[]> getTilesAtHigherZoom( int origTx, int origTy, int origZoom, int higherZoom, int tileSize ) {
    Envelope boundsLL = tileBounds4326(origTx, origTy, origZoom);

    int delta = higherZoom - origZoom;
    int splits = (int) Math.pow(2, delta);

    double intervalX = boundsLL.getWidth() / splits;
    double intervalY = boundsLL.getHeight() / splits;

    List<int[]> tilesList = new ArrayList<>();
    for( double y = boundsLL.getMaxY() - intervalY / 2.0; y > boundsLL.getMinY(); y = y - intervalY ) {
        for( double x = boundsLL.getMinX() + intervalX / 2.0; x < boundsLL.getMaxX(); x = x + intervalX ) {
            int[] tileNumber = getTileNumber(y, x, higherZoom);
            tilesList.add(tileNumber);
        }
    }
    return tilesList;
}
 
Example 4
Source File: LasInfoController.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private List<Geometry> getCircleGeometries() throws Exception {
    ILasHeader header = lasReader.getHeader();
    CoordinateReferenceSystem crs = header.getCrs();
    if (crs == null) {
        crs = DEFAULT_GENERIC;
    }

    String text = _circlesMinCellCountField.getText();
    int minCellCount = (int) Double.parseDouble(text);

    int w = lastDrawnImage.getWidth();
    int h = lastDrawnImage.getHeight();
    Envelope env = constraints.getFilteredEnvelope();
    Envelope fittingEnvelope = TransformationUtils.expandToFitRatio(env, w, h);
    double xRes = fittingEnvelope.getWidth() / w;
    double yRes = fittingEnvelope.getHeight() / h;
    RegionMap rm = CoverageUtilities.makeRegionParamsMap(fittingEnvelope.getMaxY(), fittingEnvelope.getMinY(),
            fittingEnvelope.getMinX(), fittingEnvelope.getMaxX(), xRes, yRes, w, h);
    GridCoverage2D raster = CoverageUtilities.buildCoverage("slice", lastDrawnImage, rm, crs);
    List<Geometry> circles = findCircles(raster, minCellCount);
    return circles;
}
 
Example 5
Source File: MainController.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private void zoomToSubItems() {
    if (currentFeaturesList != null) {
        int size = currentFeaturesList.size();
        if (currentFeatureIndex < 0) {
            currentFeatureIndex = 0;
        } else if (currentFeatureIndex > size - 1) {
            currentFeatureIndex = size - 1;
        }

        SimpleFeature simpleFeature = currentFeaturesList.get(currentFeatureIndex);
        Envelope env = ((Geometry) simpleFeature.getDefaultGeometry()).getEnvelopeInternal();
        if (env.getWidth() == 0) {
            env.expandBy(0.1);
        } else {
            env.expandBy(env.getWidth() * 0.05);
        }

        mapPane.setDisplayArea(new ReferencedEnvelope(env, simpleFeature.getFeatureType().getCoordinateReferenceSystem()));
    }

}
 
Example 6
Source File: OrthodromicDistancePartitioner.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
protected void initIndex(final CommonIndexModel indexModel, final double[] distancePerDimension) {

  longDimensionPosition = findLongitude(indexModel);
  latDimensionPosition = findLatitude(indexModel);

  final List<Geometry> geos = getGeometries(new Coordinate(0, 0), distancePerDimension);

  final Envelope envelope = geos.get(0).getEnvelopeInternal();

  // set up the distances based on geometry (orthodromic distance)
  final double[] distancePerDimensionForIndex = new double[distancePerDimension.length];
  for (int i = 0; i < distancePerDimension.length; i++) {
    distancePerDimensionForIndex[i] =
        (i == longDimensionPosition) ? envelope.getWidth() / 2.0
            : (i == latDimensionPosition ? envelope.getHeight() / 2.0 : distancePerDimension[i]);
    LOGGER.info("Dimension size {} is {} ", i, distancePerDimensionForIndex[i]);
  }

  super.initIndex(indexModel, distancePerDimensionForIndex);
}
 
Example 7
Source File: MapRender.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Mouse wheel moved.
 *
 * @param ev the mousewheel event
 */
@Override
public void mouseWheelMoved(MouseWheelEvent ev) {

    int clicks = ev.getWheelRotation();
    // -ve means wheel moved up, +ve means down
    int sign = (clicks < 0 ? -1 : 1);

    Envelope env = mapPane.getDisplayArea();
    double width = env.getWidth();
    double delta = width * CLICK_TO_ZOOM_FACTOR * sign;

    env.expandBy(delta);
    mapPane.setDisplayArea((org.opengis.geometry.Envelope) env);

    switch (geometryType) {
        case RASTER:
            setRasterBounds(env);
            break;
        case POINT:
        case LINE:
        case POLYGON:
            setVectorBounds(env);
            break;
        default:
            break;
    }

    EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues);

    clearLabelCache();

    mapPane.repaint();
}
 
Example 8
Source File: TransformationUtils.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the affine transform that brings from the world envelope to the rectangle. 
 * 
 * @param worldEnvelope the envelope.
 * @param pixelRectangle the destination rectangle.
 * @return the transform.
 */
public static AffineTransform getWorldToPixel( Envelope worldEnvelope, Rectangle pixelRectangle ) {
    double width = pixelRectangle.getWidth();
    double worldWidth = worldEnvelope.getWidth();
    double height = pixelRectangle.getHeight();
    double worldHeight = worldEnvelope.getHeight();

    AffineTransform translate = AffineTransform.getTranslateInstance(-worldEnvelope.getMinX(), -worldEnvelope.getMinY());
    AffineTransform scale = AffineTransform.getScaleInstance(width / worldWidth, height / worldHeight);
    AffineTransform mirror_y = new AffineTransform(1, 0, 0, -1, 0, pixelRectangle.getHeight());
    AffineTransform world2pixel = new AffineTransform(mirror_y);
    world2pixel.concatenate(scale);
    world2pixel.concatenate(translate);
    return world2pixel;
}
 
Example 9
Source File: TransformationUtils.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the affine transform that brings from the world envelope to the rectangle. 
 * 
 * @param worldEnvelope the envelope.
 * @param pixelRectangle the destination rectangle.
 * @return the transform.
 */
public static AffineTransformation getWorldToRectangle( Envelope worldEnvelope, Rectangle pixelRectangle ) {
    int cols = (int) pixelRectangle.getWidth();
    int rows = (int) pixelRectangle.getHeight();
    double worldWidth = worldEnvelope.getWidth();
    double worldHeight = worldEnvelope.getHeight();

    double x = -worldEnvelope.getMinX();
    double y = -worldEnvelope.getMinY();
    AffineTransformation translate = AffineTransformation.translationInstance(x, y);
    double xScale = cols / worldWidth;
    double yScale = rows / worldHeight;
    AffineTransformation scale = AffineTransformation.scaleInstance(xScale, yScale);

    int m00 = 1;
    int m10 = 0;
    int m01 = 0;
    int m11 = -1;
    int m02 = 0;
    int m12 = rows;
    AffineTransformation mirror_y = new AffineTransformation(m00, m01, m02, m10, m11, m12);

    AffineTransformation world2pixel = new AffineTransformation(translate);
    world2pixel.compose(scale);
    world2pixel.compose(mirror_y);
    return world2pixel;
}
 
Example 10
Source File: TransformationUtils.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Scale an envelope to have a given width.
 * 
 * @param original the envelope.
 * @param newWidth the new width to use.
 * @return the scaled envelope placed in the original lower left corner position.
 */
public static Envelope scaleToWidth( Envelope original, double newWidth ) {
    double width = original.getWidth();
    double factor = newWidth / width;

    double newHeight = original.getHeight() * factor;

    return new Envelope(original.getMinX(), original.getMinX() + newWidth, original.getMinY(),
            original.getMinY() + newHeight);
}
 
Example 11
Source File: TransformationUtils.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Scale an envelope to have a given height.
 * 
 * @param original the envelope.
 * @param newHeight the new height to use.
 * @return the scaled envelope placed in the original lower left corner position.
 */
public static Envelope scaleToHeight( Envelope original, double newHeight ) {
    double height = original.getHeight();
    double factor = newHeight / height;

    double newWidth = original.getWidth() * factor;

    return new Envelope(original.getMinX(), original.getMinX() + newWidth, original.getMinY(),
            original.getMinY() + newHeight);
}
 
Example 12
Source File: HMModelIM.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
protected void addSource( File imageMosaicSource ) throws Exception {

        URL imageMosaicUrl = imageMosaicSource.toURI().toURL();
        final AbstractGridFormat imageMosaicFormat = (AbstractGridFormat) GridFormatFinder.findFormat(imageMosaicUrl);
        final ImageMosaicReader imReader = (ImageMosaicReader) imageMosaicFormat.getReader(imageMosaicUrl);
        // ImageMosaicReader imReader = new ImageMosaicReader(imageMosaicSource);

        if (readers.size() == 0) {
            File propertiesFile = FileUtilities.substituteExtention(imageMosaicSource, "properties");
            HashMap<String, String> propertiesMap = FileUtilities.readFileToHashMap(propertiesFile.getAbsolutePath(), null,
                    false);

            String xyREs = propertiesMap.get("Levels");
            String[] split = xyREs.split(",");
            xRes = Double.parseDouble(split[0]);
            yRes = Double.parseDouble(split[1]);

            locationField = propertiesMap.get("LocationAttribute");
            crs = imReader.getCoordinateReferenceSystem();

            GeneralEnvelope originalEnvelope = imReader.getOriginalEnvelope();
            llCorner = originalEnvelope.getLowerCorner().getCoordinate();
            urCorner = originalEnvelope.getUpperCorner().getCoordinate();

            SimpleFeatureCollection vectorBounds = OmsVectorReader.readVector(imageMosaicSource.getAbsolutePath());
            boundsGeometries = FeatureUtilities.featureCollectionToGeometriesList(vectorBounds, true, locationField);

            Envelope singleTileEnv = boundsGeometries.get(0).getEnvelopeInternal();
            Envelope allTilesEnv = new Envelope();
            for( Geometry boundsGeometry : boundsGeometries ) {
                allTilesEnv.expandToInclude(boundsGeometry.getEnvelopeInternal());
            }
            if (allTilesEnv.getWidth() > singleTileEnv.getWidth()) {
                isSingleInX = false;
            }
            if (allTilesEnv.getHeight() > singleTileEnv.getHeight()) {
                isSingleInY = false;
            }

        }
        readers.add(imReader);
    }
 
Example 13
Source File: GeometryGenerator.java    From geowave with Apache License 2.0 4 votes vote down vote up
/**
 * @param count
 * @param distanceactors
 * @param distortationFn
 * @param delta
 * @param env
 * @return
 */
public static Iterator<Geometry> generate(
    final int count,
    final List<Double> distanceactors,
    final DistortationFn distortationFn,
    final double delta,
    final Envelope env) {
  // Create the star-ellipses for intersections later on
  return new Iterator<Geometry>() {
    int currentCount = 0;
    GeometryFactory geometryFactory = new GeometryFactory();

    @Override
    public boolean hasNext() {
      return currentCount < count;
    }

    @Override
    public Geometry next() {
      // Thanks to Chris Bennight for the foundations of this code.
      currentCount++;
      final double cx = env.centre().x * distortationFn.distort();
      final double cy = env.centre().y * distortationFn.distort();

      final double dx = env.getWidth() * distortationFn.distort();
      final double dy = env.getHeight() * distortationFn.distort();

      // We will use a coordinate list to build the linear ring
      final CoordinateList clist = new CoordinateList();
      double angle = 0.0;
      for (int i = 0; angle < 360; angle += (delta * distortationFn.distort()) + delta, i++) {
        final double a =
            distanceactors.get(i % distanceactors.size()) * dx * distortationFn.distort();
        // double b = distanceactors.get(i % distanceactors.size())
        // * dy * distortationFn.distort();
        clist.add(
            new Coordinate(
                cx + (a * Math.sin(Math.toRadians(angle))),
                cy + (a * Math.cos(Math.toRadians(angle)))));
      }

      clist.add(clist.get(0));
      return geometryFactory.createPolygon(clist.toCoordinateArray());
    }

    @Override
    public void remove() {}
  };
}