private double[] getGeoTransform( Envelope bbox, int pixelsX, int pixelsY ) { if ( isXy( bbox.getCoordinateSystem() ) ) { double originX = bbox.getMin().get0(); double pixelSizeX = bbox.getSpan0() / pixelsX; double originY = bbox.getMax().get1(); double pixelSizeY = -bbox.getSpan1() / pixelsY; return new double[] { originX, pixelSizeX, 0.0, originY, 0.0, pixelSizeY }; } double originX = bbox.getMin().get1(); double pixelSizeX = bbox.getSpan1() / pixelsX; double originY = bbox.getMax().get0(); double pixelSizeY = -bbox.getSpan0() / pixelsY; return new double[] { originX, pixelSizeX, 0.0, originY, 0.0, pixelSizeY }; }
@Override public Envelope getEnvelope() { if ( env == null ) { // TODO NullEnvelope for emtpy aggregates? or throw an exception? env = get( 0 ).getEnvelope(); for ( Geometry geom : this ) { env = env.merge( geom.getEnvelope() ); } if ( env.getCoordinateSystem() == null ) { env.setCoordinateSystem( crs ); } } return env; }
boolean intersects( Envelope env/* float minX2, float minY2, float maxX2, float maxY2 */) { // float minX1 = this.minX; // float minY1 = this.minY; // float maxX1 = this.maxX; // float maxY1 = this.maxY; // // // special case: this node is completely inside the region of the tilefile // if ( minX1 >= minX2 && maxX1 <= maxX2 && minY1 >= minY2 && maxY1 <= maxY2 ) { // return true; // } // // // left or right border of the tilefile lays inside the y-band of this node // if ( ( minX2 >= minX1 && minX2 <= maxX1 ) || ( maxX2 <= maxX1 && maxX2 >= minX1 ) ) { // if ( minY2 <= maxY1 && maxY2 >= minY1 ) { // return true; // } // } // // // top or bottom border of the tilefile lays inside the x-band of this node // if ( ( minY2 >= minY1 && minY2 <= maxY1 ) || ( maxY2 <= maxY1 && maxY2 >= minY1 ) ) { // if ( minX2 <= maxX1 && maxX2 >= minX1 ) { // return true; // } // } return this.env.intersects( env ); }
private Envelope mergeEnvelope( final Envelope existing, final Envelope additional ) { if ( existing == null ) { return additional; } if ( additional == null || additional.getCoordinateDimension() < 2 ) { return existing; } return existing.merge( additional ); }
private static void exportBbox( AdHocQuery query, Map<String, String> kvp ) { Envelope bbox = ( (BBoxQuery) query ).getBBox(); if ( bbox != null ) { StringBuilder sb = new StringBuilder(); sb.append( DECIMAL_FORMAT.format( bbox.getMin().get0() ) ).append( "," ); sb.append( DECIMAL_FORMAT.format( bbox.getMin().get1() ) ).append( "," ); sb.append( DECIMAL_FORMAT.format( bbox.getMax().get0() ) ).append( "," ); sb.append( DECIMAL_FORMAT.format( bbox.getMax().get1() ) ); if ( bbox.getCoordinateSystem() != null ) sb.append( ',' ).append( bbox.getCoordinateSystem().getName() ); kvp.put( "BBOX", sb.toString() ); } }
private void writeEnvelope( DataOutputStream out, Envelope env ) throws IOException { double[] min = env.getMin().getAsArray(); double[] max = env.getMax().getAsArray(); out.writeDouble( min[0] ); out.writeDouble( min[1] ); out.writeDouble( min[2] ); out.writeDouble( max[0] ); out.writeDouble( max[1] ); out.writeDouble( max[2] ); }
/** * @param envelope * New envelope for the coverage. */ protected void setEnvelope( Envelope envelope ) { if ( envelope != null && envelope.getCoordinateSystem() != null ) { setCoordinateSystem( envelope.getCoordinateSystem() ); } this.envelope = envelope; }
private boolean isDefaultBBox() { Envelope env = getDefaultBBox(); return ( Math.abs( bbox.getSpan0() - env.getSpan0() ) < 1E-11 ) && ( Math.abs( bbox.getSpan1() - env.getSpan1() ) < 1E-11 ) && ( Math.abs( bbox.getMin().get0() - env.getMin().get0() ) < 1E-11 ) && ( Math.abs( bbox.getMin().get1() - env.getMin().get1() ) < 1E-11 ) && ( Math.abs( bbox.getMin().get2() - env.getMin().get2() ) < 1E-11 ); }
private static double getEnvDepth( Envelope env ) { double result = Double.NaN; if ( env.getCoordinateDimension() == 3 ) { result = env.getMax().get2() - env.getMin().get2(); } return result; }
private void enforceCrs( ICRS crs, Envelope boundingBox ) { boundingBox.getMin().setCoordinateSystem( crs ); boundingBox.getMax().setCoordinateSystem( crs ); boundingBox.setCoordinateSystem( crs ); }
/** * @param bbox * the bbox to set */ public final void setBbox( Envelope bbox ) { if ( bbox == null ) { throw new NullPointerException( "Bbox may not be null" ); } this.bbox = bbox; Point p = bbox.getCentroid(); double[] min = bbox.getMin().getAsArray(); double[] max = bbox.getMax().getAsArray(); position = new float[] { (float) p.get0(), (float) p.get1(), (float) ( ( p.getCoordinateDimension() == 3 ) ? p.get2() : 0 ) }; if ( bbox.getMin().getCoordinateDimension() == 2 ) { min = new double[] { min[0], min[1], 0 }; } if ( bbox.getMax().getCoordinateDimension() == 2 ) { max = new double[] { max[0], max[1], 0 }; } this.error = (float) Vectors3d.length( Vectors3d.sub( max, min ) ); this.height = (float) bbox.getSpan1(); this.groundLevel = (float) min[2]; }
public GetMap( List<Pair<String, String>> layers, int width, int height, Envelope boundingBox, String format, boolean transparent ) throws OWSException { for ( Pair<String, String> layer : layers ) { this.layers.add( new LayerRef( layer.first ) ); this.styles.add( layer.second != null ? new StyleRef( layer.second ) : null ); } this.width = width; this.height = height; this.bbox = boundingBox; this.crs = boundingBox.getCoordinateSystem(); this.bgcolor = white; this.format = format; this.transparent = transparent; try { scale = RenderHelper.calcScaleWMS130( width, height, bbox, crs, pixelSize ); LOG.debug( "GetMap request has a WMS 1.3.0/SLD scale of '{}' (adapted to pixel size of {}).", scale, pixelSize ); resolution = max( bbox.getSpan0() / width, bbox.getSpan1() / height ); LOG.debug( "Resolution per pixel is {}.", resolution ); } catch ( ReferenceResolvingException e ) { LOG.trace( "Stack trace:", e ); throw new OWSException( e.getLocalizedMessage(), "InvalidParameterValue" ); } }
/** * Calculates the envelope for a tile at a given position in the grid. * * @param columnId * column id, must be in the range [0 ... #columns - 1] * @param rowId * row id, must be in the range [0 ... #rows - 1] * @return the tile's envelope */ protected Envelope getTileEnvelope( int rowId, int columnId ) { double xOffset = columnId * tileWidth; double yOffset = ( rows - rowId - 1 ) * tileHeight; double minX = envelope.getMin().get0() + xOffset; double minY = envelope.getMin().get1() + yOffset; double maxX = minX + tileWidth; double maxY = minY + tileHeight; return geomFac.createEnvelope( minX, minY, maxX, maxY, envelope.getCoordinateSystem() ); }
if ( bbox.getCoordinateSystem() != null && !bbox.getCoordinateSystem().equals( storageSrs ) ) { GeometryTransformer transformer = new GeometryTransformer( storageSrs ); bbox = transformer.transform( bbox ); bbox = oldBBox.merge( bbox );
/** * Extend the envelope of the coverage. * * The new envelope of the coverage will contain the old and the given envelope. * * @param envelope * Envelope to add. */ protected void extendEnvelope( Envelope envelope ) { if ( this.envelope == null ) { this.envelope = envelope; } else { this.envelope = this.envelope.merge( envelope ); } }
Envelope rEnv = coverageReq.getRequestEnvelope(); if ( rEnv != null ) { ICRS crs = rEnv.getCoordinateSystem(); boolean intersects = true; if ( crs == null ) { intersects = rEnv.intersects( coverage.getEnvelope() ); } else { Iterator<Envelope> it = coverage.responseEnvelopes.iterator(); Envelope e = it.next(); if ( e != null ) { ICRS eCRS = e.getCoordinateSystem(); if ( crs.equals( eCRS ) ) { defEnv = e; defEnv = coverage.getEnvelope(); intersects = rEnv.intersects( defEnv );
private Envelope transform( Envelope bbox, ICRS targetCrs ) throws IllegalArgumentException, TransformationException, UnknownCRSException { if ( targetCrs.equals( bbox.getEnvelope().getCoordinateSystem() ) ) { return bbox; } GeometryTransformer transformer = new GeometryTransformer( targetCrs ); return transformer.transform( bbox ); } }
/** * Create a Gird for the given pixel resolution and output envelope * * @param resx * resolution of a pixel (ie. the width of each grid cell in CRS units) * @param resy * resolution of a pixel (ie. the height of each grid cell in CRS units) * @param resz * resolution of a pixel (ie. the depth of each grid cell in CRS units) * @param targetEnvelope * the envelope of the output grid * @return a new grid */ public static Grid fromRes( double resx, double resy, double resz, Envelope targetEnvelope ) { int width = (int) Math.round( targetEnvelope.getSpan0() / resx ); int height = (int) Math.round( targetEnvelope.getSpan1() / resy ); int depth = Integer.MIN_VALUE; if ( !Double.isNaN( resz ) ) { if ( targetEnvelope.getCoordinateDimension() == 3 ) { double envDepth = getEnvDepth( targetEnvelope ); depth = (int) Math.round( envDepth / resz ); } } return new Grid( width, height, depth, targetEnvelope ); }