Package org.geotools.coverage.grid.io

Examples of org.geotools.coverage.grid.io.AbstractGridCoverage2DReader


        if ( store == null || !( store instanceof CoverageStoreInfo ) ) {
            throw new IllegalStateException( "Coverage store not set.");
        }
       
        CoverageStoreInfo csinfo = (CoverageStoreInfo) store;
        AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) catalog.getResourcePool().getGridCoverageReader(csinfo, null);
       
        if(reader == null)
            throw new Exception ("Unable to acquire a reader for this coverage with format: " + csinfo.getFormat().getName());
       
        return buildCoverage(reader);
View Full Code Here


        File info = new File(coverageDir, "info.xml");
        info.createNewFile();
       
        // let's grab the necessary metadata
        AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(coverageFile);
        AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) format.getReader(coverageFile);

        // basic info
        FileWriter writer = new FileWriter(info);
        writer.write("<coverage format=\"" + coverage + "\">\n");
        writer.write("<name>" + coverage + "</name>\n");
        writer.write("<label>" + coverage + "</label>\n");
        writer.write("<description>" + coverage + " description</description>\n");
        writer.write("<metadataLink about = \"http://www.remotesensing.org:16080/websites/geotiff/geotiff.html\" metadataType = \"other\" />");
        writer.write("<keywords>WCS," + coverage + " </keywords>\n");
        if(styleName == null)
            styleName = "raster";
        writer.write("<styles default=\"" + styleName + "\"/>\n");
       
        // envelope
        CoordinateReferenceSystem crs = reader.getCrs();
        GeneralEnvelope envelope = reader.getOriginalEnvelope();
        GeneralEnvelope wgs84envelope = CoverageStoreUtils.getWGS84LonLatEnvelope(envelope);
        final String nativeCrsName = CRS.lookupIdentifier(crs, false);
        writer.write("<envelope crs=\"" + crs.toString().replaceAll("\"", "'") + "\" srsName=\"" + nativeCrsName + "\">\n");
        writer.write("<pos>" + wgs84envelope.getMinimum(0) + " " + wgs84envelope.getMinimum(1) + "</pos>\n");
        writer.write("<pos>" + wgs84envelope.getMaximum(0) + " " + wgs84envelope.getMaximum(1) + "</pos>\n");
        writer.write("</envelope>\n");
       
        /**
         * Now reading a fake small GridCoverage just to retrieve meta information:
         * - calculating a new envelope which is 1/20 of the original one
         * - reading the GridCoverage subset
         */

        final ParameterValueGroup readParams = reader.getFormat().getReadParameters();
        final Map parameters = CoverageUtils.getParametersKVP(readParams);
        double[] minCP = envelope.getLowerCorner().getCoordinates();
        double[] maxCP = new double[] {
                minCP[0] + (envelope.getLength(0) / 20.0),
                minCP[1] + (envelope.getLength(1) / 20.0)
            };
        final GeneralEnvelope subEnvelope = new GeneralEnvelope(minCP, maxCP);
        subEnvelope.setCoordinateReferenceSystem(reader.getCrs());

        parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
            new GridGeometry2D(reader.getOriginalGridRange(), subEnvelope));
        GridCoverage2D gc = (GridCoverage2D) reader.read(CoverageUtils.getParameters(readParams, parameters,
                    true));
       
        // grid geometry
        final GridGeometry geometry = gc.getGridGeometry();
        final int dimensions = geometry.getGridRange().getDimension();
View Full Code Here

    }

    @Override
    protected IGeoResourceInfo createInfo( IProgressMonitor monitor ) throws IOException {
        try {
            AbstractGridCoverage2DReader reader = getReader(monitor);
            ServiceInfo serviceInfo = reader.getInfo();

            String name = serviceInfo.getTitle();
            String title = serviceInfo.getTitle();
            String description = serviceInfo.getDescription();
            URI schema = serviceInfo.getSchema();
            String[] keywords = serviceInfo.getKeywords().toArray(
                    new String[serviceInfo.getKeywords().size()]);

            GeneralEnvelope env = reader.getOriginalEnvelope();
            Envelope bounds = new Envelope(env.getMinimum(0), env.getMaximum(0), env.getMinimum(1),
                    env.getMaximum(1));
            CoordinateReferenceSystem crs = reader.getCrs();
            ImageDescriptor icon = null;
            IGeoResourceInfo rasterInfo = new IGeoResourceInfo(title, name, description, schema,
                    bounds, crs, keywords, icon);
            return rasterInfo;
        } catch (Exception e) {
View Full Code Here

        // if (adaptee.isAssignableFrom(GridCoverage.class)) {
        // return adaptee.cast(createInfo(monitor));
        // }
        if (adaptee.isAssignableFrom(AbstractGridCoverage2DReader.class)) {
            AbstractGridCoverage2DReader reader = getReader(monitor);
            status = Status.CONNECTED;
            return adaptee.cast(reader);
        }

        return super.resolve(adaptee, monitor);
View Full Code Here

    private AbstractGridCoverage2DReader getReader( IProgressMonitor monitor ) {
        String source = getCoverageURL();
        ArcSDERasterFormatFactory formatFactory = new ArcSDERasterFormatFactory();
        ArcSDERasterFormat format = formatFactory.createFormat();
        AbstractGridCoverage2DReader reader;
        reader = format.getReader(source);
        return reader;
    }
View Full Code Here

        || lowFileName.endsWith(".jpeg")
        || lowFileName.endsWith(".png") || lowFileName.endsWith(".gif")
        || lowFileName.endsWith(".tif")
        || lowFileName.endsWith(".tiff")) {
      // Raster
      AbstractGridCoverage2DReader reader = GridCoverage2DReaderFactory
          .getGridCoverage2DReaderFromFile(file);
      Style style = getRasterLayerStyle(styleSource, reader);
      MapLayer mapLayer = new DefaultMapLayer(reader, style);
      layer = new RasterLayer();
      layer.setMapLayer(mapLayer);
View Full Code Here

public class GridCoverage2DReaderFactory {
  public static AbstractGridCoverage2DReader getGridCoverage2DReaderFromFile(File file) throws Exception{
    // For raster data files
    AbstractGridFormat format = GridFormatFinder.findFormat(file);
    AbstractGridCoverage2DReader reader = format.getReader(file);
    return reader;
 
View Full Code Here

    @Override
    public final synchronized List<? extends Layer> getLayers(final MfClientHttpRequestFactory httpRequestFactory,
                                                 final MapfishMapContext mapContext,
                                                 final boolean isFirstLayer) throws Exception {
        AbstractGridCoverage2DReader coverage2DReader = this.coverage2DReaderSupplier.apply(httpRequestFactory);
        Style style = this.styleSupplier.load(httpRequestFactory, coverage2DReader, mapContext);
        return Collections.singletonList(new GridReaderLayer(coverage2DReader, style));
    }
View Full Code Here

        LOG.info("Loading population from raster file {}", sourceFilename);
        try {
            File rasterFile = new File(sourceFilename);
            // determine file format and CRS, then load raster
            AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile);
            AbstractGridCoverage2DReader reader = format.getReader(rasterFile);
            GridCoverage2D coverage = reader.read(null);
            this.coverageCRS = coverage.getCoordinateReferenceSystem();
            GridGeometry2D gridGeometry = coverage.getGridGeometry();
            GridEnvelope2D gridEnvelope = gridGeometry.getGridRange2D();
            gridGeometry.getGridToCRS();
            // because we may want to produce an empty raster rather than loading one, alongside the coverage we
View Full Code Here

    public void testFullResolutionNull() throws Exception {
        // this one has null native resolutions
        final GridCoverage2D coverage = new GridCoverageFactory().create("test",
                new float[200][100], new ReferencedEnvelope(-180, 180, -90, 90,
                        DefaultGeographicCRS.WGS84));
        GridCoverage2DReader reader = new AbstractGridCoverage2DReader() {
           
            {
                this.crs = DefaultGeographicCRS.WGS84;
                this.originalEnvelope = new GeneralEnvelope((BoundingBox) coverage.getEnvelope2D());
                this.originalGridRange = coverage.getGridGeometry().getGridRange();
            }

            @Override
            public Format getFormat() {
                return null;
            }
           
            @Override
            public GridCoverage2D read(GeneralParameterValue[] parameters) throws IllegalArgumentException,
                    IOException {
                // return fake coveage
                return coverage;
            }
        };
        CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true);
        ReferencedEnvelope mapExtent = new ReferencedEnvelope(-20000000, 20000000, -20000000,
                20000000, crs);

        GridCoverageReaderHelper helper = new GridCoverageReaderHelper(reader, new Rectangle(400,
                200), mapExtent, Interpolation.getInstance(Interpolation.INTERP_NEAREST));

        // read, we should get back a coverage, not a exception
        ProjectionHandler handler = ProjectionHandlerFinder.getHandler(mapExtent,
                reader.getCoordinateReferenceSystem(), true);
        List<GridCoverage2D> coverages = helper.readCoverages(null, handler);
        assertEquals(1, coverages.size());
       
       
    }
View Full Code Here

TOP

Related Classes of org.geotools.coverage.grid.io.AbstractGridCoverage2DReader

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.