Package org.geotools.coverage.grid.io

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


        CoveragesConsistencyChecker checker = null;
        for (CoverageBand band : bands) {
            // Refactor this once supporting complex compositions
            final InputCoverageBand inputBand = band.getInputCoverageBands().get(0);
            final String coverageName = inputBand.getCoverageName();
            final GridCoverage2DReader reader = wrap(delegate, coverageName, coverageInfo);

            // Remove this when removing constraints
            if (checker == null) {
                checker = new CoveragesConsistencyChecker(reader);
            } else {
                checker.checkConsistency(reader);
            }

            GridCoverage2D coverage = (GridCoverage2D) reader.read(parameters);
            if (coverage != null) {

                // We may consider revisiting this to use integers instead of String
                // For the moment, let's continue using String
                String selectedBand = inputBand.getBand();
View Full Code Here


    /**
     * Get a {@link GridCoverage2DReader} wrapping the provided delegate reader
     */
    private static GridCoverage2DReader wrap(GridCoverage2DReader delegate, String coverageName,
            CoverageInfo info) {
        GridCoverage2DReader reader = delegate;
        if (coverageName != null) {
            reader = SingleGridCoverage2DReader.wrap(delegate, coverageName);
        }
        if (reader instanceof StructuredGridCoverage2DReader) {
            return new CoverageDimensionCustomizerViewStructuredReader(
View Full Code Here

        } else if (rinfo instanceof CoverageInfo) {
            // the coverage bounds computation path is a bit more linear, the
            // readers always return the bounds and in the proper CRS (afaik)
            CoverageInfo cinfo = (CoverageInfo) rinfo;           
            GridCoverage2DReader reader = null;
            if (data instanceof GridCoverage2DReader) {
                reader = (GridCoverage2DReader) data;
            }
            else {
                reader = (GridCoverage2DReader)
                    cinfo.getGridCoverageReader(null, GeoTools.getDefaultHints());
            }

            // get  bounds
            bounds = new ReferencedEnvelope(reader.getOriginalEnvelope());
          
        } else if(rinfo instanceof WMSLayerInfo) {
            // the logic to compute the native bounds is pretty convoluted,
            // let's rebuild the layer info
            WMSLayerInfo rebuilt = buildWMSLayer(rinfo.getStore(), rinfo.getNativeName());
View Full Code Here

    /**
     * Initialize a coverage object and set any unset info.
     */
    public void initCoverage(CoverageInfo cinfo, final String coverageName) throws Exception {
      CoverageStoreInfo csinfo = (CoverageStoreInfo) store;
        GridCoverage2DReader reader = (GridCoverage2DReader) catalog
              .getResourcePool().getGridCoverageReader(cinfo, GeoTools.getDefaultHints());
        if(coverageName != null) {
            reader = SingleGridCoverage2DReader.wrap(reader, coverageName);
        }
       
        initResourceInfo(cinfo);

        if (reader == null)
            throw new Exception("Unable to acquire a reader for this coverage with format: "
                    + csinfo.getFormat().getName());

        if (cinfo.getNativeCRS() == null) {
          cinfo.setNativeCRS(reader.getCoordinateReferenceSystem());
        }

        CoordinateReferenceSystem nativeCRS = cinfo.getNativeCRS();

        if (cinfo.getSRS() == null) {
          cinfo.setSRS(nativeCRS.getIdentifiers().toArray()[0].toString());
        }

        if (cinfo.getProjectionPolicy() == null) {
            if (nativeCRS != null && !nativeCRS.getIdentifiers().isEmpty()) {
                cinfo.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
            }
            if (nativeCRS == null) {
                cinfo.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);
            }
        }

      if (cinfo.getLatLonBoundingBox() == null
          && cinfo.getNativeBoundingBox() == null) {
        GeneralEnvelope envelope = reader.getOriginalEnvelope();

        cinfo.setNativeBoundingBox(new ReferencedEnvelope(envelope));
        cinfo.setLatLonBoundingBox(new ReferencedEnvelope(CoverageStoreUtils.getWGS84LonLatEnvelope(envelope)));
      } else if (cinfo.getLatLonBoundingBox() == null) {
        setupBounds(cinfo);
      } else if (cinfo.getNativeBoundingBox() == null && cinfo.getNativeCRS() != null) {
        ReferencedEnvelope boundsLatLon = cinfo.getLatLonBoundingBox();
        cinfo.setNativeBoundingBox(boundsLatLon.transform(cinfo.getNativeCRS(), true));
      }

        if (cinfo.getGrid() == null) {
            GridEnvelope originalRange = reader.getOriginalGridRange();
            cinfo.setGrid(new GridGeometry2D(originalRange, reader.getOriginalGridToWorld(PixelInCell.CELL_CENTER), nativeCRS));
        }
    }
View Full Code Here

        if (store == null || !(store instanceof CoverageStoreInfo)) {
            throw new IllegalStateException("Coverage store not set.");
        }

        CoverageStoreInfo csinfo = (CoverageStoreInfo) store;
        GridCoverage2DReader reader = (GridCoverage2DReader) catalog
                .getResourcePool().getGridCoverageReader(csinfo, GeoTools.getDefaultHints());

        if (reader == null)
            throw new Exception("Unable to acquire a reader for this coverage with format: "
                    + csinfo.getFormat().getName());
View Full Code Here

        GridCoverage2D targetCoverage = null;
        try {
            targetCoverage = readerTarget.read(null);

            // checks spatial consistency
            GridCoverage2DReader sourceReader = (GridCoverage2DReader) getCatalog().getCoverageByName(getLayerId(WATTEMP)).getGridCoverageReader(null, null);
            GeneralEnvelope expectedEnvelope  = sourceReader.getOriginalEnvelope();
            assertEnvelopeEquals(expectedEnvelope, 1.0,(GeneralEnvelope) targetCoverage.getEnvelope(), 1.0);
            assertTrue(CRS.equalsIgnoreMetadata(targetCoverage.getCoordinateReferenceSystem(), expectedEnvelope.getCoordinateReferenceSystem()));
           
            // check raster space consistency
            final GridEnvelope gridRange = targetCoverage.getGridGeometry().getGridRange();
            GridEnvelope expectedGridRange = sourceReader.getOriginalGridRange();
            assertEquals(gridRange.getSpan(0), expectedGridRange.getSpan(0));
            assertEquals(gridRange.getSpan(1), expectedGridRange.getSpan(1));
           
            // check the reference pixel
            double[] pixel = new double[1];
View Full Code Here

       
        //initialize the mock by actually building a real one first
        CatalogBuilder cb = new CatalogBuilder(new CatalogImpl());
        cb.setStore(cs);
   
        GridCoverage2DReader reader = cs.getFormat().getReader(cs.getURL());
        if (reader == null) {
            throw new RuntimeException("No reader for " + cs.getURL());
        }
   
        CoverageInfo real = null;
View Full Code Here

        store.setType((imageMosaicFormat.getName()));
        // Addition to the catalog
        getCatalog().add(store);
        builder.setStore(store);
        // Input reader used for reading the mosaic folder
        GridCoverage2DReader reader = null;
        // Reader used for checking if the mosaic has been configured correctly
        StructuredGridCoverage2DReader reader2 = null;

        try {
            // Selection of the reader to use for the mosaic
            reader = (GridCoverage2DReader) imageMosaicFormat.getReader(DataUtilities
                    .fileToURL(mosaic));

            // configure the coverage
            configureCoverageInfo(builder, store, reader);

            // check the coverage is actually there
            CoverageStoreInfo storeInfo = getCatalog().getCoverageStoreByName("watertemp4");
            assertNotNull(storeInfo);
            CoverageInfo ci = getCatalog().getCoverageByName("mosaic");
            assertNotNull(ci);
            assertEquals(storeInfo, ci.getStore());

            // Harvesting of the Mosaic
            URL zipHarvest = getClass().getResource("test-data/harvesting.zip");
            // Extract a Byte array from the zip file
            InputStream is = null;
            byte[] bytes;
            try {
                is = zipHarvest.openStream();
                bytes = IOUtils.toByteArray(is);
            } finally {
                IOUtils.closeQuietly(is);
            }
            // Create the POST request
            MockHttpServletRequest request = createRequest("/rest/workspaces/gs/coveragestores/watertemp4/file.imagemosaic");
            request.setMethod("POST");
            request.setContentType("application/zip");
            request.setBodyContent(bytes);
            request.setHeader("Content-type", "application/zip");
            // Get The response
            MockHttpServletResponse response = dispatch(request);
            // Get the Mosaic Reader
            reader2 = (StructuredGridCoverage2DReader) storeInfo.getGridCoverageReader(null,
                    GeoTools.getDefaultHints());
            // Test if all the TIME DOMAINS are present
            String[] metadataNames = reader2.getMetadataNames();
            assertNotNull(metadataNames);
            assertEquals("true", reader2.getMetadataValue("HAS_TIME_DOMAIN"));
            assertEquals(
                    "2008-10-31T00:00:00.000Z,2008-11-01T00:00:00.000Z,2008-11-02T00:00:00.000Z",
                    reader2.getMetadataValue(metadataNames[0]));
            // Removal of all the data associated to the mosaic
            reader2.delete(true);
        } finally {
            // Reader disposal
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
            if (reader2 != null) {
View Full Code Here

        if ( "none".equalsIgnoreCase( configure ) ) {
            getResponse().setStatus( Status.SUCCESS_CREATED );
            return;
        }
       
        GridCoverage2DReader reader = null;
        try {
            reader =
                (GridCoverage2DReader) ((AbstractGridFormat) coverageFormat).getReader(DataUtilities.fileToURL(uploadedFile));
            if ( reader == null ) {
                throw new RestletException( "Could not aquire reader for coverage.", Status.SERVER_ERROR_INTERNAL);
            }
           
            // coverage read params
            final Map customParameters = new HashMap();
            String useJAIImageReadParam = form.getFirstValue("USE_JAI_IMAGEREAD");
            if (useJAIImageReadParam != null) {
              customParameters.put(AbstractGridFormat.USE_JAI_IMAGEREAD.getName().toString(), Boolean.valueOf(useJAIImageReadParam));
            }
           
            //check if the name of the coverage was specified
            String coverageName = form.getFirstValue("coverageName");
            String[] names = reader.getGridCoverageNames();
           
            if(names.length > 1 && coverageName != null) {
                throw new RestletException("The reader found more than one coverage, " +
                    "coverageName cannot be used in this case (it would generate " +
                    "the same name for all coverages found", Status.CLIENT_ERROR_BAD_REQUEST);
            }
           
            // configure all available coverages, preserving backwards compatibility for the
            // case of single coverage reader
            if(names.length > 1) {
                for (String name : names) {
                    SingleGridCoverage2DReader singleReader = new SingleGridCoverage2DReader(reader, name);
                    configureCoverageInfo(builder, info, add, name, name, singleReader,
                            customParameters);
                }
            } else {
                configureCoverageInfo(builder, info, add, names[0], coverageName, reader,
                        customParameters);
            }
           
           
            //poach the coverage store data format
            DataFormat df = new CoverageStoreResource(getContext(),request,response,catalog).createXMLFormat(request, response);
            response.setEntity(df.toRepresentation(info));
            response.setStatus(Status.SUCCESS_CREATED);
        }
        catch( Exception e ) {
            if(e instanceof RestletException) {
                throw (RestletException) e;
            }
            throw new RestletException( "Error auto-configuring coverage", Status.SERVER_ERROR_INTERNAL, e );
        } finally {
            if(reader != null) {
                try {
                    reader.dispose();
                } catch(IOException e)  {
                    // it's ok, we tried
                }           
            }
        }
View Full Code Here

TOP

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

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.