Package org.geotools.coverage.grid

Examples of org.geotools.coverage.grid.GridCoverage2D


        GeneralParameterValue[] readParams = JGrassCatalogUtilities.createGridGeometryGeneralParameter(jGrassRegion.getCols(),
                jGrassRegion.getRows(), jGrassRegion.getNorth(), jGrassRegion.getSouth(), jGrassRegion.getWest(),
                jGrassRegion.getEast(), crs);
        AbstractGridFormat format = (AbstractGridFormat) new GrassCoverageFormatFactory().createFormat();
        GridCoverageReader reader = format.getReader(jGrassMapEnvironment.getCELL());
        GridCoverage2D mapCoverage = ((GridCoverage2D) reader.read(readParams));
        return mapCoverage;
    }
View Full Code Here


             currentContext.setStatus(ILayer.WORKING);
             setState( STARTING );
            
             ParameterValue[] parameterValues = group.values().toArray(new ParameterValue[0]);
            GridCoverage2D coverage = (GridCoverage2D) reader.read(parameterValues);
             if(coverage!=null){             
              //setting rendering hints
                 //
              RenderingHints hints = new RenderingHints(new HashMap<RenderingHints.Key,Object>());
              hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED));
              hints.add(new RenderingHints(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE));
              hints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED));
              hints.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED));
              hints.add(new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
              hints.add(new RenderingHints(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE));
              hints.add(new RenderingHints(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF));
              hints.add(new RenderingHints(JAI.KEY_INTERPOLATION,new InterpolationNearest()));
              graphics.addRenderingHints(hints);
             
              // JG: Store title cache on the layer blackboard so it can last between runs.
              //     Performance question: may do better to have a single larger tile cache on the map blackboard?
              //
              final TileCache tempCache=currentContext.getTileCache();
              hints.add(new RenderingHints(JAI.KEY_TILE_CACHE,tempCache));
              //hints.add( new Hints( Hints.RESAMPLE_TOLERANCE, 0.000000000001 ));
               
              if( CRS.getHorizontalCRS(destinationCRS) == null ){
                  destinationCRS = coverage.getCoordinateReferenceSystem2D();
              }
              //
              AffineTransform worldToScreen = null; // we are leting the GridCoverageRenderer sort that out
             
              //draw
              try {
                  Style style = grabStyle();
                  Rule rule = SLDs.getRasterSymbolizerRule(style);
                 
                  final double currentScale = currentContext.getViewportModel().getScaleDenominator();               
                  double minScale = rule.getMinScaleDenominator();
                  double maxScale = rule.getMaxScaleDenominator();
                  if (minScale <= currentScale && currentScale <= maxScale ) {
                      final GridCoverageRenderer paint = new GridCoverageRenderer( destinationCRS, envelope, screenSize,worldToScreen,hints );
                      final RasterSymbolizer rasterSymbolizer = SLD.rasterSymbolizer(style);

                      // check if there is a color to mask
                      Object maskColor = getContext().getLayer().getStyleBlackboard().getString("raster-color-mask"); //$NON-NLS-1$                     
                        if (maskColor instanceof String) {
                            // create a color mask
                            String[] colorSplit = ((String) maskColor).split(":"); //$NON-NLS-1$
                            Color color = new Color(Integer.parseInt(colorSplit[0]), Integer.parseInt(colorSplit[1]),
                                    Integer.parseInt(colorSplit[2]));
                            RenderedImage image = coverage.getRenderedImage();
                            ImageWorker iw = new ImageWorker(image);
                            iw.makeColorTransparent(color);
                            image = iw.getRenderedImage();
                            GridCoverageFactory gcF = CoverageFactoryFinder.getGridCoverageFactory(null);
                            coverage = gcF.create(coverage.getName(), image, coverage.getCoordinateReferenceSystem(), coverage
                                    .getGridGeometry().getGridToCRS(), coverage.getSampleDimensions(), null, null);
                        }
                 
                      //setState( RENDERING );
                      paint.paint( graphics, coverage, rasterSymbolizer );                       
                      setState( DONE );
View Full Code Here

        Point bottomRight = getContext().worldToPixel(
                new Coordinate(envelope.getMaxX(), envelope.getMaxY()));
        Rectangle screenSize = new Rectangle(upperLeft);
        screenSize.add(bottomRight);

        GridCoverage2D coverage = convertImageToGridCoverage(requestBBox, image);

        AffineTransform worldToScreen = RendererUtilities.worldToScreenTransform(envelope, screenSize, destinationCRS);
    GridCoverageRenderer paint = new GridCoverageRenderer( destinationCRS, envelope, screenSize, worldToScreen  );
                    
        RasterSymbolizer symbolizer = CommonFactoryFinder.getStyleFactory(null).createRasterSymbolizer();
View Full Code Here

            throw wrapException(e);
        }

        GridCoverageFactory factory = new GridCoverageFactory();

        GridCoverage2D gc = (GridCoverage2D) factory.create("GridCoverage", image, gtEnv); //$NON-NLS-1$
        return gc;
    }
View Full Code Here

            GridCoverageLoader loader = geoResource.resolve(GridCoverageLoader.class, monitor);
            if( loader == null ){
                // unable to load in memory
                return;
            }
            GridCoverage2D coverage = (GridCoverage2D) loader.load(geom, monitor);

            if(coverage!=null)
      {
             
              //setting rendering hints
              RenderingHints hints = new RenderingHints(Collections.EMPTY_MAP);
              hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED));
              hints.add(new RenderingHints(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE));
              hints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED));
              hints.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED));
              hints.add(new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
              hints.add(new RenderingHints(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE));
              hints.add(new RenderingHints(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF));
              hints.add(new RenderingHints(JAI.KEY_INTERPOLATION,new InterpolationNearest()));
              graphics.addRenderingHints(hints);
             
              final TileCache tempCache=currentContext.getTileCache();
              hints.add(new RenderingHints(JAI.KEY_TILE_CACHE,tempCache));
             
              if( CRS.getHorizontalCRS(destinationCRS) == null ){
                  destinationCRS = coverage.getCoordinateReferenceSystem2D();
              }
              //draw
              try {
                  Style style = grabStyle();
                  Rule rule = SLDs.getRasterSymbolizerRule(style);
                 
                  final double currentScale = currentContext.getViewportModel().getScaleDenominator();               
                  double minScale = rule.getMinScaleDenominator();
                  double maxScale = rule.getMaxScaleDenominator();
                  if (minScale <= currentScale && currentScale <= maxScale ) {
                      final GridCoverageRenderer paint = new GridCoverageRenderer( destinationCRS, envelope, screenSize,null, hints );
                      final RasterSymbolizer rasterSymbolizer = SLD.rasterSymbolizer(style);
                 
                        // check if there is a color to mask
                        Object maskColor = getContext().getLayer().getStyleBlackboard().getString("raster-color-mask"); //$NON-NLS-1$                      
                        if (maskColor instanceof String) {
                            // create a color mask
                            String[] colorSplit = ((String) maskColor).split(":"); //$NON-NLS-1$
                            Color color = new Color(Integer.parseInt(colorSplit[0]), Integer.parseInt(colorSplit[1]),
                                    Integer.parseInt(colorSplit[2]));
                            RenderedImage image = coverage.getRenderedImage();
                            ImageWorker iw = new ImageWorker(image);
                            iw.makeColorTransparent(color);
                            image = iw.getRenderedImage();
                            GridCoverageFactory gcF = CoverageFactoryFinder.getGridCoverageFactory(null);
                            coverage = gcF.create(coverage.getName(), image, coverage.getCoordinateReferenceSystem(), coverage
                                    .getGridGeometry().getGridToCRS(), coverage.getSampleDimensions(), null, null);
                        }
                     
                      //setState( RENDERING );
                      paint.paint( graphics, coverage, rasterSymbolizer );                       
                      setState( DONE );
View Full Code Here

        // create a gridcoverage from the tile image
        Envelope bounds = tile.getBounds();
        GridCoverageFactory factory = new GridCoverageFactory();
        ReferencedEnvelope ref = new ReferencedEnvelope(bounds.getMinX(), bounds.getMaxX(),
                bounds.getMinY(), bounds.getMaxY(), crs);
        GridCoverage2D coverage = (GridCoverage2D) factory.create(
                "GridCoverage", tile.getBufferedImage(), ref); //$NON-NLS-1$       
        Envelope2D coveragebounds = coverage.getEnvelope2D();

        // bounds of tile
        Envelope tilebBounds = new Envelope(coveragebounds.getMinX(), coveragebounds.getMaxX(),
                coveragebounds.getMinY(), coveragebounds.getMaxY());

        // convert bounds to necessary viewport projection
        CoordinateReferenceSystem tileCrs = getContext().getCRS();
        if (!coverage.getCoordinateReferenceSystem().equals(tileCrs)) {
            MathTransform transform = CRS.findMathTransform(
                    coverage.getCoordinateReferenceSystem(), tileCrs);
            tilebBounds = JTS.transform(tilebBounds, transform);
        }

        // determine screen coordinates of tiles
        Point upperLeft = getContext().worldToPixel(
                new Coordinate(tilebBounds.getMinX(), tilebBounds.getMinY()));
        Point bottomRight = getContext().worldToPixel(
                new Coordinate(tilebBounds.getMaxX(), tilebBounds.getMaxY()));
        Rectangle tileSize = new Rectangle(upperLeft);
        tileSize.add(bottomRight);

        // render
        try {
            AffineTransform worldToScreenTransform = RendererUtilities.worldToScreenTransform(
                    tilebBounds, tileSize, tileCrs);
            GridCoverageRenderer paint = new GridCoverageRenderer(tileCrs, tilebBounds, tileSize,
                    worldToScreenTransform);

            paint.paint(graphics, coverage, style);

            if (TESTING) {
                /* for testing draw border around tiles */
                graphics.setColor(Color.BLACK);
                graphics.drawLine((int) tileSize.getMinX(), (int) tileSize.getMinY(),
                        (int) tileSize.getMinX(), (int) tileSize.getMaxY());
                graphics.drawLine((int) tileSize.getMinX(), (int) tileSize.getMinY(),
                        (int) tileSize.getMaxX(), (int) tileSize.getMinY());
                graphics.drawLine((int) tileSize.getMaxX(), (int) tileSize.getMinY(),
                        (int) tileSize.getMaxX(), (int) tileSize.getMaxY());
                graphics.drawLine((int) tileSize.getMinX(), (int) tileSize.getMaxY(),
                        (int) tileSize.getMaxX(), (int) tileSize.getMaxY());
                graphics.drawString("pos: " + tile.getPosition(), ((int) tileSize.getMaxX() - 113),
                        ((int) tileSize.getMaxY() - 113));
            }
        } catch (Throwable t) {
            t.printStackTrace();
            WmsPlugin
                    .log("Error Rendering tile. Painting Tile:" + (coverage != null ? coverage.getName() : ""), t); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
View Full Code Here

      params.parameter("rangesType").setValue(Range.Type.EXCLUDE); //$NON-NLS-1$
      params.parameter("rangeLocalStats").setValue(false); //$NON-NLS-1$
    }
   

    final GridCoverage2D coverage = (GridCoverage2D) op.doOperation(params,null);
    final ZonalStats zstats = (ZonalStats) coverage
        .getProperty(ZonalStatsDescriptor.ZONAL_STATS_PROPERTY);
    double min = zstats.statistic(Statistic.MIN).results().get(0).getValue();
    double max = zstats.statistic(Statistic.MAX).results().get(0).getValue();
    return new double[]{min,max};
  }
View Full Code Here

                AbstractGridCoverage2DReader reader = resource.resolve(AbstractGridCoverage2DReader.class, monitor);

                GridEnvelope range = reader.getOriginalGridRange();
                GeneralEnvelope env = reader.getOriginalEnvelope();
                GridGeometry2D all = new GridGeometry2D(range, env);
                GridCoverage2D coverage2d = (GridCoverage2D) super.load(all, monitor);
                RenderedImage image = coverage2d.view(ViewType.RENDERED).getRenderedImage();

        RasteringsPlugin
            .log("WARNING.  Loading image fully into memory.  It is about " + size(image) + " MB in size decompressed", null); //$NON-NLS-1$//$NON-NLS-2$

                @SuppressWarnings("rawtypes")
                BufferedImage bi = new BufferedImage(image.getColorModel(), (WritableRaster) image
                        .getData(), false, new Hashtable());
                GridCoverageFactory fac = new GridCoverageFactory();

                GridCoverage2D c = fac.create(fileName, bi, env);
                coverage = new SoftReference<GridCoverage>(c);

            } catch (OutOfMemoryError e) {
                updateMemoryLevel();
            } catch (Exception t) {
View Full Code Here

        param.parameter("CoordinateReferenceSystem").setValue(sourceCRS);
        param.parameter("GridGeometry").setValue(scaledGridGeometry);
        param.parameter("InterpolationType")
             .setValue(Interpolation.getInstance(Interpolation.INTERP_NEAREST));

        final GridCoverage2D scaledGridCoverage = (GridCoverage2D) resampleFactory.doOperation(param,
                hints);

        return scaledGridCoverage;
    }
View Full Code Here

        param.parameter("CoordinateReferenceSystem").setValue(coverage.getCoordinateReferenceSystem());
        param.parameter("GridGeometry").setValue(scaledGridGeometry);
        param.parameter("InterpolationType")
             .setValue(Interpolation.getInstance(Interpolation.INTERP_NEAREST));

        final GridCoverage2D scaledGridCoverage = (GridCoverage2D) resampleFactory.doOperation(param,
                hints);

        return scaledGridCoverage;
    }
View Full Code Here

TOP

Related Classes of org.geotools.coverage.grid.GridCoverage2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.