public void testCoverageContents() throws Exception {
    final Long processId = issueProcessAndWaitForTermination();

    final String request = RESTLET_PATH + "/" + processId.longValue();

    final MockHttpServletResponse response = getAsServletResponse(request);
    assertEquals(Status.SUCCESS_OK, Status.valueOf(response.getStatus()));
    assertEquals(MediaType.APPLICATION_ZIP, MediaType.valueOf(response.getContentType()));

    final ByteArrayInputStream responseStream = getBinaryInputStream(response);
    File dataDirectoryRoot = super.getTestData().getDataDirectoryRoot();
    File file = new File(dataDirectoryRoot, "testCoverageContents.zip");
    super.getTestData().copyTo(responseStream, file.getName());

    ZipFile zipFile = new ZipFile(file);
    try {
      // TODO: change this expectation once we normalize the raster file name
      String rasterName = RASTER_LAYER.getPrefix() + ":" + RASTER_LAYER.getLocalPart() + ".tiff";
      ZipEntry nextEntry = zipFile.getEntry(rasterName);
      assertNotNull(nextEntry);
      InputStream coverageInputStream = zipFile.getInputStream(nextEntry);
      // Use a file, geotiffreader might not work well reading out of a plain input stream
      File covFile = new File(file.getParentFile(), "coverage.tiff");
      IOUtils.copy(coverageInputStream, covFile);
      GeoTiffReader geoTiffReader = new GeoTiffReader(covFile);
      GridCoverage2D coverage = geoTiffReader.read(null);
      CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem();
      assertEquals(CRS.decode("EPSG:4326", true), crs);
    } finally {
      zipFile.close();
    }
  }
Exemplo n.º 2
0
  @Test
  public void testElevationSecond() throws Exception {
    String request = getWaterTempElevationRequest("100.0");

    MockHttpServletResponse response = postAsServletResponse("wcs", request);
    assertEquals("image/tiff", response.getContentType());

    // save
    File tiffFile = File.createTempFile("wcs", "", new File("target"));
    IOUtils.copy(getBinaryInputStream(response), new FileOutputStream(tiffFile));

    // make sure we can read the coverage back
    GeoTiffReader reader = new GeoTiffReader(tiffFile);
    GridCoverage2D result = reader.read(null);

    /*
     gdallocationinfo NCOM_wattemp_100_20081101T0000000_12.tiff  10 10
     Report:
      Location: (10P,10L)
      Band 1:
      Value: 13.337999683572
    */

    // check a pixel
    double[] pixel = new double[1];
    result.getRenderedImage().getData().getPixel(10, 10, pixel);
    assertEquals(13.337999683572, pixel[0], 1e-6);

    tiffFile.delete();
  }
Exemplo n.º 3
0
  private void checkTimeCurrent(MockHttpServletResponse response)
      throws IOException, FileNotFoundException, DataSourceException {
    // save
    File tiffFile = File.createTempFile("wcs", "", new File("target"));
    IOUtils.copy(getBinaryInputStream(response), new FileOutputStream(tiffFile));

    // make sure we can read the coverage back
    GeoTiffReader reader = new GeoTiffReader(tiffFile);
    GridCoverage2D result = reader.read(null);

    /*
    gdallocationinfo NCOM_wattemp_000_20081101T0000000_12.tiff 10 10
    Report:
        Location: (10P,10L)
        Band 1:
          Value: 18.2849999185419
    */

    // check a pixel
    double[] pixel = new double[1];
    result.getRenderedImage().getData().getPixel(10, 10, pixel);
    assertEquals(18.2849999185419, pixel[0], 1e-6);

    tiffFile.delete();
  }
  @Test
  public void testTransformReprojectedGridCoverage() throws Exception {
    Style style = RendererBaseTest.loadStyle(this, "coverageCenter.sld");

    GeoTiffReader reader = new GeoTiffReader(TestData.copy(this, "geotiff/world.tiff"));

    MapContent mc = new MapContent();
    mc.addLayer(new GridCoverageLayer(reader.read(null), style));

    StreamingRenderer renderer = new StreamingRenderer();
    renderer.setMapContent(mc);

    ReferencedEnvelope reWgs84 =
        new ReferencedEnvelope(-70, 70, -160, 160, CRS.decode("EPSG:4326"));
    ReferencedEnvelope re = reWgs84.transform(CRS.decode("EPSG:3857"), true);

    BufferedImage image =
        RendererBaseTest.showRender("Lines with circle stroke", renderer, TIME, re);
    // if everything worked we are going to have a red dot in the middle of the map
    assertEquals(Color.RED, getPixelColor(image, image.getWidth() / 2, image.getHeight() / 2));
    assertEquals(Color.WHITE, getPixelColor(image, image.getWidth() / 4, image.getHeight() / 2));
    assertEquals(Color.WHITE, getPixelColor(image, image.getWidth() / 2, image.getHeight() / 4));
    assertEquals(Color.WHITE, getPixelColor(image, image.getWidth() / 4, image.getHeight() / 4));
  }
  public boolean extractTiffMetadata(File tifFile, TiffMeta surface)
      throws UnknownCRSException, FactoryException, TransformException, IOException {

    Preconditions.checkArgument(tifFile != null, "File is null.");

    GeoTiffReader gtr = new GeoTiffReader(tifFile);

    try {

      CoordinateReferenceSystem crs = gtr.getCoordinateReferenceSystem();
      surface.setCRS(crs);
      Integer epsgCode = CRS.lookupEpsgCode(crs, true);

      if (epsgCode == null) {
        ReferenceIdentifier name = crs.getName();
        String crsName = "Unknown";
        if (name != null) {
          crsName = name.toString();
        }
        throw new UnknownCRSException(crsName);
      }

      String srid = "EPSG:" + epsgCode;
      surface.setSrid(srid);

      //
      // extremaOp(surface, gtr.read(null));

      /*
       * Build the envelope and set to WGS84
       */
      GeneralEnvelope origEnv = gtr.getOriginalEnvelope();
      DirectPosition ll = origEnv.getLowerCorner();
      DirectPosition ur = origEnv.getUpperCorner();

      Envelope e = new Envelope();
      e.expandToInclude(ll.getOrdinate(0), ll.getOrdinate(1));
      e.expandToInclude(ur.getOrdinate(0), ur.getOrdinate(1));

      Geometry poly = envelopeToWgs84(epsgCode, e);

      if (poly instanceof Polygon) {
        surface.setEnvelope((Polygon) poly);
      }

      /*
       * Figure out the pixel size
       */
      ImageLayout imageLayout = gtr.getImageLayout();
      int imageWidth = imageLayout.getWidth(null);
      int imageHeight = imageLayout.getHeight(null);

      double pixelSizeX = e.getWidth() / imageWidth;
      double pixelSizeY = e.getHeight() / imageHeight;

      surface.setPixelSizeX(pixelSizeX);
      surface.setPixelSizeY(pixelSizeY);

      surface.setMinVal(0d);
      surface.setMaxVal(100d);

      GridCoverage2D gridCoverage2D = gtr.read(null);

      try {
        int nDims = gridCoverage2D.getNumSampleDimensions();
        surface.setNumSampleDimensions(nDims);

        extremaOp(surface, gridCoverage2D);

      } finally {
        gridCoverage2D.dispose(false);
      }

    } finally {

      gtr.dispose();
    }

    return true;
  }