Пример #1
0
  private File localReproject(
      WcsReaderRequest request, File containingDirectory, String baseFilename)
      throws NoSuchAuthorityCodeException, FactoryException, IOException {
    InputStream input = null;
    File tmpFile = null;
    try {
      BoundWcsRequest geotiffRequest = request.bind(_wcsUrl).withFormat("geotiff");
      BoundWcsRequest requestNativeFormat =
          geotiffRequest.withCRS(geotiffRequest.getNativeCRSs().iterator().next());
      requestNativeFormat.assertLegalSize(_maxCoverageExtractionSize);

      input = requestNativeFormat.getCoverage();

      File file = null;
      file = new File(containingDirectory, baseFilename + "." + request.fileExtension());
      LOG.debug("Writing GridCoverage obtained from " + _wcsUrl + " to file " + file);

      tmpFile = File.createTempFile(baseFilename, ".tif");
      writeToFile(tmpFile, input);

      transformCoverage(tmpFile, file, request, requestNativeFormat, true);
      return file;
    } finally {
      if (tmpFile != null) FileUtils.delete(tmpFile);

      if (input != null) IOUtils.closeQuietly(input);
    }
  }
Пример #2
0
  /* ------------------- Support methods for readToFile ------------------- */
  private File remoteReproject(
      WcsReaderRequest request, File containingDirectory, String baseFilename)
      throws NoSuchAuthorityCodeException, FactoryException, IOException {
    InputStream input = null;
    try {
      BoundWcsRequest requestNegotiatedFormat = negotiateFormat(request.bind(_wcsUrl));
      BoundWcsRequest requestNegotiatedFormatCrs = negotiateRequestCRS(requestNegotiatedFormat);
      BoundWcsRequest requestNegotiatedFormatCrs2 =
          negotiateResponseCRS(requestNegotiatedFormatCrs);
      requestNegotiatedFormatCrs2.assertLegalSize(_maxCoverageExtractionSize);

      input = requestNegotiatedFormatCrs2.getCoverage();

      // file = new File (new File("/tmp/"),
      // baseFilename+"."+request.fileExtension());
      File file = null;
      file = new File(containingDirectory, baseFilename + "." + request.fileExtension());
      LOG.debug("Writing GridCoverage obtained from " + _wcsUrl + " to file " + file);

      convertFormat(baseFilename, input, file, request, requestNegotiatedFormatCrs2);

      transformCoverage(file, file, request, requestNegotiatedFormatCrs2, false);

      return file;
    } finally {
      if (input != null) IOUtils.closeQuietly(input);
    }
  }
  @Test
  public void BoundWcsRequestTest() throws Throwable {
    WcsReaderRequest rq =
        new WcsReaderRequestFactory()
            .create(
                "1.0",
                "myCov",
                0,
                0,
                1,
                1,
                CRS.decode("EPSG:4326"),
                CRS.decode("EPSG:2154"),
                1,
                "GeoTiff",
                true,
                true,
                true,
                "scott",
                "tiger");

    BoundWcsRequest bwr = new BoundWcsRequest(new URL("http://localhost/"), rq);

    HttpClient mockClient = getMockHttpClient();
    bwr.setHttpClient(mockClient);

    // DescribeCoverage related tests
    setOutputDocument(describeCoverageSample);
    bwr.getCoverage();

    // supported formats
    Set<String> fmts = bwr.getSupportedFormats();
    String[] expectedFmts = {"jpg", "geotiff", "tif", "jpeg", "png", "gif", "tiff"};
    assertArrayEquals(expectedFmts, fmts.toArray());

    // supported response CRS
    Set<String> supportedResponseCrs = bwr.getSupportedResponseCRSs();
    String[] expectedResponseCrs = {"EPSG:4326"};
    assertArrayEquals(expectedResponseCrs, supportedResponseCrs.toArray());

    // num bands
    int numBands = bwr.numBands();
    assertEquals(numBands, 1);

    // supported request CRS
    Set<String> supportedRequestCrs = bwr.getSupportedRequestCRSs();
    String[] expectedRequestCrs = {"EPSG:4326"};
    assertArrayEquals(expectedRequestCrs, supportedRequestCrs.toArray());

    // Native CRS
    Set<String> nativeCRSs = bwr.getNativeCRSs();
    String[] expectedNativeCRSs = {"EPSG:4326"};
    assertArrayEquals(expectedNativeCRSs, nativeCRSs.toArray());

    // just to recall getDescribeCoverage(), should be defined as for now
    assertTrue(bwr.getDescribeCoverage() instanceof String);

    // Same
    assertTrue(bwr.getSupportedFormats() instanceof Set<?>);
    assertTrue(bwr.getSupportedResponseCRSs() instanceof Set<?>);
    assertTrue(bwr.numBands() == 1);
    assertTrue(bwr.getSupportedRequestCRSs() instanceof Set<?>);
    assertTrue(bwr.getNativeCRSs() instanceof Set<?>);

    // GetCapabilities related tests
    setOutputDocument(getCapabilitiesSample);

    String getCap = bwr.getCapabilities();
    assertTrue(getCap instanceof String);
    // another time
    assertTrue(bwr.getCapabilities() instanceof String);
  }