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

The following examples show how to use org.locationtech.jts.geom.Envelope#centre() . 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: TestUtils.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testTiles2() throws Exception {
    int zoomLevel = 8;
    double tolerance = 0.0000001;

    Coordinate c1 = new Coordinate(1289079.2130195359, 5900910.886700573);
    Coordinate c2 = new Coordinate(1298888.6991376826, 5909656.474824957);
    Envelope env3857 = new Envelope(c1, c2);
    Envelope env4326 = MercatorUtils.convert3857To4326(env3857);

    Coordinate centre = env4326.centre();
    assertTrue(centre.equals2D(new Coordinate(11.62405565150858, 46.77412159831822), tolerance));

    int[] tileNumberFrom3857 = MercatorUtils.getTileNumberFrom3857(env3857.centre(), zoomLevel);
    assertEquals(136, tileNumberFrom3857[1]);
    assertEquals(90, tileNumberFrom3857[2]);
    assertEquals(8, tileNumberFrom3857[0]);

}
 
Example 2
Source File: GeopackageTilesNwwLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public GeopackageTilesNwwLayer( File gpkgFile, String tableName ) throws Exception {
    super(makeLevels(gpkgFile, getTilegenerator(gpkgFile), tableName));
    this.layerName = tableName;
    this.setUseTransparentTextures(true);

    try (GeopackageCommonDb db = new GeopackageDb()) {
        db.open(gpkgFile.getAbsolutePath());

        TileEntry tile = db.tile(tableName);
        Envelope bounds = tile.getBounds();
        Coordinate centre3857 = bounds.centre();
        Coordinate ll = MercatorUtils.convert3857To4326(centre3857);

        centerCoordinate = ll;
    }
}
 
Example 3
Source File: ALasDataManager.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Retrieve all the envelope features that intersect the geometry.
 *
 * <p>an elev attribute is added with the max elev contained in the envelope.
 *
 * @param checkGeom the {@link org.locationtech.jts.geom.Geometry} to use to check.
 * @param doOnlyEnvelope check for the geom envelope instead of a intersection with it.
 * @param minMaxZI an array to be filled with the [minz,maxz, minintensity, maxintensity] to be used as style.
 * @param doPoints if <code>true</code>, create points instead of polygons.
 * @return the features of the envelopes contained in the supplied geometry.
 * @throws Exception
 */
public synchronized SimpleFeatureCollection getEnvelopeFeaturesInGeometry( Geometry checkGeom, boolean doOnlyEnvelope,
        double[] minMaxZI, boolean doPoints ) throws Exception {
    List<Geometry> envelopesInGeometry = getEnvelopesInGeometry(checkGeom, doOnlyEnvelope, null);

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("overview");
    b.setCRS(crs);
    if (!doPoints) {
        b.add("the_geom", Polygon.class);
    } else {
        b.add("the_geom", Point.class);
    }
    b.add("elev", Double.class);
    b.add("intensity", Double.class);

    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    double minZ = Double.POSITIVE_INFINITY;
    double maxZ = Double.NEGATIVE_INFINITY;
    double minI = Double.POSITIVE_INFINITY;
    double maxI = Double.NEGATIVE_INFINITY;

    DefaultFeatureCollection newFeatures = new DefaultFeatureCollection();
    for( int i = 0; i < envelopesInGeometry.size(); i++ ) {
        Geometry geom = envelopesInGeometry.get(i);
        if (doPoints) {
            Envelope envelope = geom.getEnvelopeInternal();
            Coordinate centre = envelope.centre();
            geom = gf.createPoint(centre);
        }

        double elev = -9999.0;
        double intens = -9999.0;
        Object userData = geom.getUserData();
        if (userData instanceof double[]) {
            double[] data = (double[]) userData;
            elev = data[0];
            intens = data[1];
        }

        if (minMaxZI != null) {
            minZ = Math.min(minZ, elev);
            maxZ = Math.max(maxZ, elev);
            minI = Math.min(minI, intens);
            maxI = Math.max(maxI, intens);
        }

        Object[] objs = new Object[]{geom, elev, intens};
        builder.addAll(objs);
        SimpleFeature feature = builder.buildFeature(null);
        newFeatures.add(feature);
    }

    if (minMaxZI != null) {
        minMaxZI[0] = minZ;
        minMaxZI[1] = maxZ;
        minMaxZI[2] = minI;
        minMaxZI[3] = maxI;
    }
    return newFeatures;
}
 
Example 4
Source File: NwwUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public static LatLon getEnvelopeCenter( Envelope bounds ) {
    Coordinate centre = bounds.centre();
    LatLon latLon = new LatLon(Angle.fromDegrees(centre.y), Angle.fromDegrees(centre.x));
    return latLon;
}
 
Example 5
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() {}
  };
}