@Override public Envelope getEnvelope() { return new DefaultEnvelope( null, crs, pm, this, this ); }
@Override public Envelope merge( Envelope other ) { if ( this.getCoordinateSystem() != null && other.getCoordinateSystem() != null ) { if ( !this.getCoordinateSystem().equals( other.getCoordinateSystem() ) ) { synchronized ( this ) { transformer = new GeometryTransformer( this.getCoordinateSystem() ); int coordinateDimension = Math.min( getCoordinateDimension(), other.getCoordinateDimension() ); double[] min = new double[coordinateDimension]; double[] max = new double[coordinateDimension]; Point newMin = new DefaultPoint( null, getCoordinateSystem(), pm, min ); Point newMax = new DefaultPoint( null, getCoordinateSystem(), pm, max ); return new DefaultEnvelope( null, getCoordinateSystem(), pm, newMin, newMax );
@Override public boolean intersects( Geometry other ) { if ( !( other instanceof Envelope ) ) { return super.intersects( other ); } Envelope e = (Envelope) other; double minX1 = this.getMin().get0(); double minY1 = this.getMin().get1(); double maxX1 = this.getMax().get0(); double maxY1 = this.getMax().get1(); double minX2 = e.getMin().get0(); double minY2 = e.getMin().get1(); double maxX2 = e.getMax().get0(); double maxY2 = e.getMax().get1(); return pointInside( minX1, minY1, e ) || pointInside( minX1, maxY1, e ) || pointInside( maxX1, minY1, e ) || pointInside( maxX1, maxY1, e ) || pointInside( minX2, minY2, this ) || pointInside( minX2, maxY2, this ) || pointInside( maxX2, minY2, this ) || pointInside( maxX2, maxY2, this ) || noEdgeOverlap( e, this ) || noEdgeOverlap( this, e ); }
@Override public Point getCentroid() { if ( centroid == null ) { double[] coordinates = new double[max.getAsArray().length]; for ( int i = 0; i < coordinates.length; i++ ) { coordinates[i] = min.getAsArray()[i] + ( max.getAsArray()[i] - min.getAsArray()[i] ) / 2d; } centroid = new DefaultPoint( null, getCoordinateSystem(), getPrecision(), coordinates ); } return centroid; }
private SpatialMetadata createSpatialMetadata( ICRS crs, double resolution, double[] topLeftCorner, BigInteger tileSizeX, BigInteger tileSizeY, BigInteger numTilesX, BigInteger numTilesY ) { double worldWidth = tileSizeX.longValue() * numTilesX.longValue() * resolution; double worldHeight = tileSizeY.longValue() * numTilesY.longValue() * resolution; double min0 = topLeftCorner[0]; double max0 = topLeftCorner[0] + worldWidth; double max1 = topLeftCorner[1]; double min1 = topLeftCorner[1] - worldHeight; Point min = new DefaultPoint( null, crs, null, new double[] { min0, min1 } ); Point max = new DefaultPoint( null, crs, null, new double[] { max0, max1 } ); Envelope bbox = new DefaultEnvelope( null, crs, null, min, max ); return new SpatialMetadata( bbox, singletonList( crs ) ); } }
@Override public Envelope getBBoxAggregateValue( ResultSet rs, int colIdx, ICRS crs ) throws SQLException { Envelope env = null; PGboxbase pgBox = (PGboxbase) rs.getObject( colIdx ); if ( pgBox != null ) { org.deegree.geometry.primitive.Point min = buildPoint( pgBox.getLLB(), crs ); org.deegree.geometry.primitive.Point max = buildPoint( pgBox.getURT(), crs ); env = new DefaultEnvelope( null, crs, null, min, max ); } return env; }
/** * Creates an {@link Envelope}. * * @param min * minimum corner coordinates * @param max * maximum corner coordinates * @param crs * coordinate reference system, may be null * @return created {@link Envelope} */ public Envelope createEnvelope( double[] min, double[] max, ICRS crs ) { return (Envelope) inspect( new DefaultEnvelope( null, crs, pm, new DefaultPoint( null, crs, pm, min ), new DefaultPoint( null, crs, pm, max ) ) ); }
private Envelope readEnvelope() throws UnknownCRSException, IOException { double[] geoTransform = dataset.GetGeoTransform(); int rasterXSize = dataset.getRasterXSize(); int rasterYSize = dataset.getRasterYSize(); double pixelResX = geoTransform[1]; double pixelResY = geoTransform[5]; double minX = geoTransform[0]; double maxX = minX + pixelResX * rasterXSize; double minY = geoTransform[3]; double maxY = minY + pixelResY * rasterYSize; if ( minX > maxX ) { double tmp = maxX; maxX = minX; minX = tmp; } if ( minY > maxY ) { double tmp = maxY; maxY = minY; minY = tmp; } Point min = new DefaultPoint( null, crs, null, new double[] { minX, minY } ); Point max = new DefaultPoint( null, crs, null, new double[] { maxX, maxY } ); return new DefaultEnvelope( null, crs, null, min, max ); }
return new DefaultEnvelope( null, crs, null, min, max );
@Override public Envelope getEnvelope() { if ( env == null ) { com.vividsolutions.jts.geom.Envelope jtsEnvelope = getJTSGeometry().getEnvelopeInternal(); Point min = new DefaultPoint( null, crs, pm, new double[] { jtsEnvelope.getMinX(), jtsEnvelope.getMinY() } ); Point max = new DefaultPoint( null, crs, pm, new double[] { jtsEnvelope.getMaxX(), jtsEnvelope.getMaxY() } ); env = new DefaultEnvelope( null, crs, pm, min, max ); } return env; }
private Envelope transform( Envelope bbox, SpatialReference requestSr, SpatialReference nativeSr ) { double[][] points = getBoundarySamplePointsAndEnsureXyOrder( bbox ); CoordinateTransformation transform = CreateCoordinateTransformation( requestSr, nativeSr ); transform.TransformPoints( points ); transform.delete(); double[] minXY = new double[] { points[0][0], points[0][1] }; double[] maxXY = new double[] { points[0][0], points[0][1] }; for ( double[] point : points ) { if ( point[0] < minXY[0] ) { minXY[0] = point[0]; } if ( point[1] < minXY[1] ) { minXY[1] = point[1]; } if ( point[0] > maxXY[0] ) { maxXY[0] = point[0]; } if ( point[1] > maxXY[1] ) { maxXY[1] = point[1]; } } Point min = new DefaultPoint( null, null, null, minXY ); Point max = new DefaultPoint( null, null, null, maxXY ); return new DefaultEnvelope( min, max ); }
Envelope env = new DefaultEnvelope( null, crs, null, min, max ); return new SpatialMetadata( env, singletonList( env.getCoordinateSystem() ) );
private Polygon calculateClippingArea( final Envelope bbox, final int width ) { double resolution = bbox.getSpan0() / width; double delta = resolution * 100; double[] minCords = new double[] { bbox.getMin().get0() - delta, bbox.getMin().get1() - delta }; double[] maxCords = new double[] { bbox.getMax().get0() + delta, bbox.getMax().get1() + delta }; Point min = new DefaultPoint( null, bbox.getCoordinateSystem(), null, minCords ); Point max = new DefaultPoint( null, bbox.getCoordinateSystem(), null, maxCords ); Envelope enlargedBBox = new DefaultEnvelope( min, max ); return (Polygon) Geometries.getAsGeometry( enlargedBBox ); }
@Override public Tile getTile( long x, long y ) { if ( !isWithinLimits( x, y ) ) { return null; } double tileWidth = metadata.getTileWidth(); double tileHeight = metadata.getTileHeight(); Envelope matrixEnvelope = metadata.getSpatialMetadata().getEnvelope(); double minX = tileWidth * x + matrixEnvelope.getMin().get0(); double maxX = minX + tileWidth; double maxY = matrixEnvelope.getMax().get1() - tileHeight * y; double minY = maxY - tileHeight; ICRS crs = metadata.getSpatialMetadata().getEnvelope().getCoordinateSystem(); Point min = new DefaultPoint( null, crs, null, new double[] { minX, minY } ); Point max = new DefaultPoint( null, crs, null, new double[] { maxX, maxY } ); Envelope tileEnvelope = new DefaultEnvelope( null, crs, null, min, max ); return new GdalTile( file, tileEnvelope, (int) metadata.getTilePixelsX(), (int) metadata.getTilePixelsY(), imageFormat, gdalSettings.getDatasetPool() ); }
private Envelope clip( Envelope region ) { double minX = region.getMin().get0(); double minY = region.getMin().get1(); double maxX = region.getMax().get0(); double maxY = region.getMax().get1(); boolean clipped = false; if ( datasetEnvelope.getMin().get0() > minX ) { minX = datasetEnvelope.getMin().get0(); clipped = true; } if ( datasetEnvelope.getMin().get1() > minY ) { minY = datasetEnvelope.getMin().get1(); clipped = true; } if ( datasetEnvelope.getMax().get0() < maxX ) { maxX = datasetEnvelope.getMax().get0(); clipped = true; } if ( datasetEnvelope.getMax().get1() < maxY ) { maxY = datasetEnvelope.getMax().get1(); clipped = true; } if ( !clipped ) { return region; } Point min = new DefaultPoint( null, null, null, new double[] { minX, minY } ); Point max = new DefaultPoint( null, null, null, new double[] { maxX, maxY } ); return new DefaultEnvelope( min, max ); }