/** * @param envelope * New envelope for the coverage. */ protected void setEnvelope( Envelope envelope ) { if ( envelope != null && envelope.getCoordinateSystem() != null ) { setCoordinateSystem( envelope.getCoordinateSystem() ); } this.envelope = envelope; }
@Override public String getCRSName() { return value.getCoordinateSystem() == null ? null : value.getCoordinateSystem().getAlias(); }
GeometryHelper( Envelope bbox, int width, AffineTransform worldToScreen ) { this.worldToScreen = worldToScreen; try { if ( bbox.getCoordinateSystem() != null && ( !bbox.getCoordinateSystem().getAlias().equals( "CRS:1" ) ) ) { transformer = new GeometryTransformer( bbox.getCoordinateSystem() ); } } catch ( Throwable e ) { LOG.debug( "Stack trace:", e ); LOG.warn( "Setting up the renderer yielded an exception when setting up internal transformer. This may lead to problems." ); } }
@Override public ICRS getCoordinateSystem() { return tileContainer.getEnvelope().getCoordinateSystem(); }
/** * @param bbox * @return the bbox in the native srs */ private Envelope getTransformedEnvelope( Envelope bbox ) { if ( bbox != null && bbox.getCoordinateSystem() != null && transformer != null ) { try { bbox = transformer.transform( bbox ); } catch ( Exception e ) { LOG.error( "Transformation of bbox failed: " + e.getMessage(), e ); } } return bbox; }
public double getScale() { return calcScaleWMS130( width, height, envelope, envelope.getCoordinateSystem(), pixelSize ); }
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 Envelope getTransformedEnvelope( Envelope env ) throws TransformationException, UnknownCRSException { ICRS inputCRS = env.getCoordinateSystem(); if ( inputCRS != null && outputCRS != null && !inputCRS.equals( outputCRS ) ) { if ( transformer == null ) { throw new UnknownCRSException( outputCRS.getAlias() ); } return geoTransformer.transform( env ); } return env; }
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 ); } }
@Override public void render( RenderContext context ) { ICRS nativeCrs = gdalSettings.getDatasetPool().getCrs( datasets.get( 0 ) ); BufferedImage img = null; if ( bbox.getCoordinateSystem().equals( nativeCrs ) ) { img = extractRegionFromGdalFiles( bbox ); } else { img = extractAndReprojectRegion( nativeCrs ); } if ( img != null ) { context.paintImage( img ); } }
private static void exportSupportedCRSs( XMLStreamWriter writer, WCSCoverage coverage ) throws XMLStreamException { writer.writeStartElement( WCS_100_NS, "supportedCRSs" ); CoverageOptions options = coverage.getCoverageOptions(); for ( String crs : options.getCRSs() ) { writeElement( writer, WCS_100_NS, "requestResponseCRSs", crs ); } String nativeCRS = coverage.getEnvelope().getCoordinateSystem().getAlias(); writeElement( writer, WCS_100_NS, "nativeCRSs", nativeCRS ); writer.writeEndElement(); // supportedCRSs }
/** * @param env * @return a polygon */ public static Polygon envelopeToPolygon( Envelope env ) { GeometryFactory fac = new GeometryFactory(); Point a = env.getMin(); Point b = fac.createPoint( null, a.get0() + env.getSpan0(), a.get1(), env.getCoordinateSystem() ); Point c = env.getMax(); Point d = fac.createPoint( null, a.get0(), a.get1() + env.getSpan1(), env.getCoordinateSystem() ); LinearRing ring = fac.createLinearRing( null, env.getCoordinateSystem(), new PointsArray( a, b, c, d, a ) ); return fac.createPolygon( null, env.getCoordinateSystem(), ring, null ); }
private static void exportGMLEnvelope( XMLStreamWriter writer, Envelope envelope ) throws XMLStreamException { writer.writeStartElement( GML_NS, "Envelope" ); writer.writeNamespace( GML_PREFIX, GML_NS ); writer.writeAttribute( "srsName", envelope.getCoordinateSystem().getAlias() ); exportGMLPos( writer, envelope.getMin().get0(), envelope.getMin().get1() ); exportGMLPos( writer, envelope.getMax().get0(), envelope.getMax().get1() ); writer.writeEndElement(); // Envelope }
@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; }
public Envelope calcClickBox( int radius ) { radius = parameters.get( "RADIUS" ) == null ? radius : parseInt( parameters.get( "RADIUS" ) ); GeometryFactory fac = new GeometryFactory(); double dw = envelope.getSpan0() / width; double dh = envelope.getSpan1() / height; int r2 = radius / 2; r2 = r2 <= 0 ? 1 : r2; return fac.createEnvelope( new double[] { envelope.getMin().get0() + ( x - r2 ) * dw, envelope.getMax().get1() - ( y + r2 ) * dh }, new double[] { envelope.getMin().get0() + ( x + r2 ) * dw, envelope.getMax().get1() - ( y - r2 ) * dh }, envelope.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 ); }
private Envelope copyEnvelope( Envelope envelopeToCopy ) { if ( envelopeToCopy != null ) { Point min = envelopeToCopy.getMin(); Point max = envelopeToCopy.getMax(); ICRS crs = envelopeToCopy.getCoordinateSystem(); return GEOM_FACTORY.createEnvelope( min.get0(), min.get1(), max.get0(), max.get1(), crs ); } return null; }
/** * @return string representation of the envelope */ protected String envelopeString() { String epsg = ""; if ( getEnvelope().getCoordinateSystem() != null ) { epsg = getEnvelope().getCoordinateSystem().getAlias(); } return epsg + " " + getEnvelope().getMin().get0() + " " + getEnvelope().getMin().get1() + " " + getEnvelope().getMax().get0() + " " + getEnvelope().getMax().get1(); }
/** * @param gMif * @param width * @param height */ private CacheInfoFile( GridMetaInfoFile gMif, int width, int height, boolean[][] tilesOnFile, long modificationTime ) { super( gMif.getGeoReference(), gMif.rows(), gMif.columns(), gMif.getTileRasterWidth(), gMif.getTileRasterHeight(), gMif.getDataInfo() ); this.rWidth = width; this.rHeight = height; this.tilesOnFile = tilesOnFile; this.modificationTime = modificationTime; this.envelope = gMif.getGeoReference().getEnvelope( OriginLocation.OUTER, rWidth, rHeight, envelope.getCoordinateSystem() ); }
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 }; }