Package org.geotools.coverage.io

Examples of org.geotools.coverage.io.CoverageSource


        throw new UnsupportedOperationException("This operation is not supported on this reader");
    }

    @Override
    public List<DimensionDescriptor> getDimensionDescriptors(String coverageName) throws IOException {
        final CoverageSource source = (CoverageSource) getGridCoverageSource(coverageName);
        return source.getDimensionDescriptors();
    }
View Full Code Here


        final List<Name> names = access.getNames(null);
        final Name coverageName = names.get(0);
        assertEquals(1, names.size());
        assertEquals(TestCoverageSourceDescriptor.TEST_NAME, coverageName);

        final CoverageSource source = access.access(TestCoverageSourceDescriptor.TEST_NAME, null,
                AccessType.READ_ONLY, null, null);
        CoordinateReferenceSystem crs = source.getCoordinateReferenceSystem();
        assertEquals(TestCoverageSourceDescriptor.TEST_NAME, source.getName(null));

        // Test dimensions and descriptors
        assertTrue(source.getAdditionalDomains().isEmpty());
        assertTrue(source.getDimensionDescriptors().isEmpty());
        assertNull(source.getVerticalDomain());
        assertNotNull(source.getTemporalDomain());

        SpatialDomain spatialDomain = source.getSpatialDomain();
        assertNotNull(spatialDomain);
        assertTrue(CRS.equalsIgnoreMetadata(spatialDomain.getCoordinateReferenceSystem2D(), WGS84));
        assertEquals(RasterLayoutTest.testRasterLayout, spatialDomain
                .getRasterElements(false, null).iterator().next());
View Full Code Here

                }
                // get the names
                final List<Name> names = access.getNames(null);
                for (Name name : names) {
                    // get a source
                    final CoverageSource gridSource = access.access(name, null, AccessType.READ_ONLY, null, null);
                    if (gridSource == null) {
                        throw new IOException("Unable to access");
                    }
                    LOGGER.info("Connected to coverage: " + name.toString());

                    // TEMPORAL DOMAIN
                    final TemporalDomain temporalDomain = gridSource.getTemporalDomain();
                    if (temporalDomain == null) {
                        LOGGER.info("Temporal domain is null");
                    } else {
                        // temporal crs
                        LOGGER.info("TemporalCRS: " + temporalDomain.getCoordinateReferenceSystem());

                        // print the temporal domain elements
                        for (DateRange tg : temporalDomain.getTemporalElements(true, null)) {
                            LOGGER.info("Global Temporal Domain: " + tg.toString());
                        }

                        // print the temporal domain elements with overall = true
                        StringBuilder overallTemporal = new StringBuilder("Temporal domain element (overall = true):\n");
                        for (DateRange tg : temporalDomain.getTemporalElements(false, null)) {
                            overallTemporal.append(tg.toString()).append("\n");
                        }
                        LOGGER.info(overallTemporal.toString());
                    }

                    // VERTICAL DOMAIN
                    final VerticalDomain verticalDomain = gridSource.getVerticalDomain();
                    if (verticalDomain == null) {
                        LOGGER.info("Vertical domain is null");
                    } else {
                        // vertical crs
                        LOGGER.info("VerticalCRS: " + verticalDomain.getCoordinateReferenceSystem());

                        // print the Vertical domain elements
                        for (NumberRange<Double> vg : verticalDomain.getVerticalElements(true, null)) {
                            LOGGER.info("Vertical domain element: " + vg.toString());
                        }

                        // print the Vertical domain elements with overall = true
                        StringBuilder overallVertical = new StringBuilder("Vertical domain element (overall = true):\n");
                        for (NumberRange<Double> vg : verticalDomain.getVerticalElements(false, null)) {
                            overallVertical.append(vg.toString()).append("\n");
                        }
                        LOGGER.info(overallVertical.toString());
                    }

                    // HORIZONTAL DOMAIN
                    final SpatialDomain spatialDomain = gridSource.getSpatialDomain();
                    if (spatialDomain == null) {
                        LOGGER.info("Horizontal domain is null");
                    } else {
                        // print the horizontal domain elements
                        final CoordinateReferenceSystem crs2D = spatialDomain.getCoordinateReferenceSystem2D();
                        assert crs2D != null;
                        final MathTransform2D g2w = spatialDomain.getGridToWorldTransform(null);
                        assert g2w != null;
                        final Set<? extends BoundingBox> spatialElements = spatialDomain.getSpatialElements(true, null);
                        assert spatialElements != null && !spatialElements.isEmpty();

                        final StringBuilder buf = new StringBuilder();
                        buf.append("Horizontal domain is as follows:\n");
                        buf.append("G2W:").append("\t").append(g2w).append("\n");
                        buf.append("CRS2D:").append("\t").append(crs2D).append("\n");
                        for (BoundingBox bbox : spatialElements) {
                            buf.append("BBOX:").append("\t").append(bbox).append("\n");
                        }
                        LOGGER.info(buf.toString());
                    }

                    CoverageReadRequest readRequest = new CoverageReadRequest();
                    // //
                    //
                    // Setting up a limited range for the request.
                    //
                    // //

                    LinkedHashSet<NumberRange<Double>> requestedVerticalSubset = new LinkedHashSet<NumberRange<Double>>();
                    SortedSet<? extends NumberRange<Double>> verticalElements = verticalDomain
                            .getVerticalElements(false, null);
                    final int numLevels = verticalElements.size();
                    final Iterator<? extends NumberRange<Double>> iterator = verticalElements.iterator();
                    for (int i = 0; i < numLevels; i++) {
                        NumberRange<Double> level = iterator.next();
                        if (i % (numLevels / 5) == 1) {
                            requestedVerticalSubset.add(level);
                        }
                    }
                    readRequest.setVerticalSubset(requestedVerticalSubset);

                    SortedSet<DateRange> requestedTemporalSubset = new DateRangeTreeSet();
                    SortedSet<? extends DateRange> temporalElements = temporalDomain.getTemporalElements(false, null);
                    final int numTimes = temporalElements.size();
                    Iterator<? extends DateRange> iteratorT = temporalElements.iterator();
                    for (int i = 0; i < numTimes; i++) {
                        DateRange time = iteratorT.next();
                        if (i % (numTimes / 5) == 1) {
                            requestedTemporalSubset.add(time);
                        }
                    }
                    readRequest.setTemporalSubset(requestedTemporalSubset);

                    CoverageResponse response = gridSource.read(readRequest, null);
                    if (response == null || response.getStatus() != Status.SUCCESS || !response.getExceptions().isEmpty()) {
                        throw new IOException("Unable to read");
                    }

                    final Collection<? extends Coverage> results = response.getResults(null);
                    int index = 0;
                    for (Coverage c : results) {
                        GridCoverageResponse resp = (GridCoverageResponse) c;
                        GridCoverage2D coverage = resp.getGridCoverage2D();
                        String title = coverage.getSampleDimension(0).getDescription().toString();
                        // Crs and envelope
                        if (isInteractiveTest) {
                            // ImageIOUtilities.visualize(coverage.getRenderedImage(), "tt",true);
                            coverage.show(title + " " + index++);
                        } else {
                            PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
                        }

                        final StringBuilder buffer = new StringBuilder();
                        buffer.append("GridCoverage CRS: ")
                                .append(coverage.getCoordinateReferenceSystem2D().toWKT())
                                .append("\n");
                        buffer.append("GridCoverage GG: ")
                                .append(coverage.getGridGeometry().toString()).append("\n");
                        LOGGER.info(buffer.toString());
                    }
                    gridSource.dispose();
                }
            } catch (Throwable t) {
                if (LOGGER.isLoggable(Level.WARNING)) {
                    LOGGER.log(Level.WARNING, t.getLocalizedMessage(), t);
                }
View Full Code Here

 
              // get the names
              final List<Name> names = access.getNames(null);
              for (Name name : names) {
                  // get a source
                  final CoverageSource gridSource = access.access(name, null,AccessType.READ_ONLY, null, null);
                  if (gridSource == null)
                      throw new IOException("Unable to access");                 
                  LOGGER.info("Connected to coverage: "+name.toString());
 
                  // TEMPORAL DOMAIN
                  final TemporalDomain temporalDomain = gridSource.getTemporalDomain();
                  if(temporalDomain==null)
                    LOGGER.info("Temporal domain is null");
                  else{
                    // temporal crs
                    LOGGER.info("TemporalCRS: "+temporalDomain.getCoordinateReferenceSystem());
                   
                    // print the temporal domain elements
                    for(TemporalGeometricPrimitive tg:temporalDomain.getTemporalElements(null)){
                      LOGGER.info("TemporalGeometricPrimitive: "+tg.toString());
                    }
                  }
                 
                  // VERTICAL DOMAIN
                  final VerticalDomain verticalDomain= gridSource.getVerticalDomain();
                  if(verticalDomain==null || verticalDomain.getVerticalElements(true, null).isEmpty())
                    LOGGER.info("Vertical domain is null");
                  else{
                    // vertical  crs
                    LOGGER.info("VerticalCRS: "+verticalDomain.getCoordinateReferenceSystem());
                   
                    // print the temporal domain elements
                    for(NumberRange<Double> vg:verticalDomain.getVerticalElements(true, null)){
                      LOGGER.info("Vertical domain element: "+vg.toString());
                    }
                  }
                 
                 
                  // HORIZONTAL DOMAIN
                  final HorizontalDomain horizontalDomain= gridSource.getHorizontalDomain();
                  if(horizontalDomain==null)
                    LOGGER.info("Horizontal domain is null");
                  else{
                    // print the horizontal domain elements
                    final CoordinateReferenceSystem crs2D=horizontalDomain.getCoordinateReferenceSystem2D();
                    assert crs2D!=null;
                    final MathTransform2D g2w=horizontalDomain.getGridToWorldTransform(null);
                    assert g2w !=null;
                    final Set<? extends BoundingBox> spatialElements = horizontalDomain.getSpatialElements(true,null);
                    assert spatialElements!=null&& !spatialElements.isEmpty();
                   
                    final StringBuilder buf= new StringBuilder();
                    buf.append("Horizontal domain is as follows:\n");
                    buf.append("G2W:").append("\t").append(g2w).append("\n");
                    buf.append("CRS2D:").append("\t").append(crs2D).append("\n");
                    for(BoundingBox bbox:spatialElements)
                      buf.append("BBOX:").append("\t").append(bbox).append("\n");
                    LOGGER.info(buf.toString());
                  }
                 
                 
                  // RANGE TYPE
                  RangeType range = gridSource.getRangeType(null);
  //
                  CoverageReadRequest readRequest = new CoverageReadRequest();
                  // //
                  //
                  // Setting up a limited range for the request.
                  //
                  // //
                  Iterator<FieldType> ftIterator = range.getFieldTypes().iterator();
                  HashSet<FieldType> fieldSet = new HashSet<FieldType>();
                  FieldType ft = null;
                  while (ftIterator.hasNext()) {
                      ft = ftIterator.next();
                      if (ft != null) {
                          fieldSet.add(ft);
                      }
                      break;
                  }
                  RangeType rangeSubset = new DefaultRangeType(range.getName(), range.getDescription(), fieldSet);
                  readRequest.setRangeSubset(rangeSubset);
  //                LinkedHashSet<Envelope> requestedVerticalSubset = new LinkedHashSet<Envelope>();
  //                final int numLevels = verticalDomain.size();
  //                final Iterator<Envelope> iterator = verticalDomain.iterator();
  //                if (!isExtensiveTest) {
  //                    for (int i = 0; i < numLevels; i++) {
  //                        Envelope level = iterator.next();
  //                        if (i % (numLevels / 5) == 1)
  //                            requestedVerticalSubset.add(level);
  //                    }
  //                    readRequest.setVerticalSubset(requestedVerticalSubset);
  //                }
                  CoverageResponse response = gridSource.read(readRequest, null);
                  if (response == null || response.getStatus() != Status.SUCCESS || !response.getExceptions().isEmpty())
                      throw new IOException("Unable to read");
 
                  final Collection<? extends Coverage> results = response.getResults(null);
                  for (Coverage c : results) {
View Full Code Here

                // get the names
                List<Name> names = access.getNames(null);
                for (Name name : names) {
                    // get a source
                    CoverageSource gridSource = access.access(name, null,
                            AccessType.READ_ONLY, null, null);
                    if (gridSource == null)
                        throw new IOException("");
                    // create a request
                    // reading the coverage
                    CoverageResponse response = gridSource.read(
                            new DefaultCoverageReadRequest(), null);
                    if (response == null
                            || response.getStatus() != Status.SUCCESS
                            || !response.getExceptions().isEmpty())
                        throw new IOException("");

                    Collection<? extends Coverage> results = response
                            .getResults(null);
                    for (Coverage c : results) {
                        GridCoverage2D coverage = (GridCoverage2D) c;
                        // Crs and envelope
                        if (TestData.isInteractiveTest()) {
                            buffer.append("CRS: ").append(
                                    coverage.getCoordinateReferenceSystem2D()
                                            .toWKT()).append("\n");
                            buffer.append("GG: ").append(
                                    coverage.getGridGeometry().toString())
                                    .append("\n");
                        }

                        // create an update request
                        final DefaultCoverageUpdateRequest request = new DefaultCoverageUpdateRequest();
                        request.setData(Collections.singletonList(coverage));

                        // create access

                        final File writeFile = new File(writedir, coverage
                                .getName().toString()
                                + ".tiff");
                        final GeoTiffAccess storeAccess =
                          (GeoTiffAccess) factory.process(
                              DriverOperation.CREATE,
                              writeFile.toURI().toURL(),
                              null,
                              null,
                              null);
                        final CoverageStore gridStore = (CoverageStore) storeAccess
                                .create(name, null, null, null);

                        // write it down
                        gridStore.update(request, null);

                        // getting access to the file
                        access = factory.process(DriverOperation.CONNECT,writeFile.toURI().toURL(),null, null, null);
                        if (access == null)
                            throw new IOException("");

                        //get the names
                        names = access.getNames(null);
                        gridSource = access.access(names.iterator().next(),
                                null, AccessType.READ_ONLY, null, null);
                        if (gridSource == null)
                            throw new IOException("");
                        //create a request
                        // reading the coverage
                        response = gridSource.read(
                                new DefaultCoverageReadRequest(), null);
                        if (response == null
                                || response.getStatus() != Status.SUCCESS
                                || !response.getExceptions().isEmpty())
                            throw new IOException("");
View Full Code Here

                .getProgress());

            for (Name name : names) {
              // get a source
              watch = new TestProgress();
              final CoverageSource gridSource = access.access(
                  name, null, AccessType.READ_ONLY, null,
                  watch);
              assertEquals("access progress", 1.0f, watch
                  .getProgress());

              if (gridSource == null)
                throw new IOException("");
              // create a request
              // reading the coverage
              watch = new TestProgress();
              CoverageResponse response = gridSource.read(
                  new DefaultCoverageReadRequest(), watch);
              assertEquals("read progress", 1.0f, watch
                  .getProgress());

              assertNotNull("response is null", response);
View Full Code Here

TOP

Related Classes of org.geotools.coverage.io.CoverageSource

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.