Package org.geotools.gce.imagemosaic

Examples of org.geotools.gce.imagemosaic.ImageMosaicReader$ImageMosaicFileCollectionWalker


     * Retrieve the ImageMosaicReader for the requested Level and load if necessary
     * @return ImageMosaicReader for level
   * */
  public ImageMosaicReader getImageMosaicReaderForLevel(Integer imageChoice) throws MalformedURLException, IOException
  {
    ImageMosaicReader reader = readers.get(imageChoice);

        if(reader==null)
        {
              //
          // we must create the underlying mosaic
          //
          final String levelDirName = levelsDirs[imageChoice.intValue()];
          final URL parentUrl = DataUtilities.getParentUrl(sourceURL);
          // look for a shapefile first
          final String extension = new StringBuilder(levelDirName).append("/").append(coverageName).append(".shp").toString();
          final URL shpFileUrl = DataUtilities.extendURL(parentUrl, extension);
          if (shpFileUrl.getProtocol() != null
                  && shpFileUrl.getProtocol().equalsIgnoreCase("file")
                  && !DataUtilities.urlToFile(shpFileUrl).exists())
              reader = new ImageMosaicReader(DataUtilities.extendURL(parentUrl, levelDirName), hints);
          else
              reader = new ImageMosaicReader(shpFileUrl, hints);
          final ImageMosaicReader putByOtherThreadJustNow =readers.putIfAbsent(imageChoice, reader);
          if(putByOtherThreadJustNow!=null){
              // some other thread just did inserted this
              try{
                  reader.dispose();
              } catch (Exception e) {
View Full Code Here


    }

  static ImageMosaicReader getReader(URL testURL,
        final AbstractGridFormat format, Hints hints) {
  //    Get a reader
      final ImageMosaicReader reader = (ImageMosaicReader) format.getReader(testURL, hints);
      Assert.assertNotNull(reader);
      return reader;
    }
View Full Code Here

        .append(inputLocation);
    if (LOGGER.isLoggable(Level.FINE))
      LOGGER.fine(message.toString());
    fireEvent(message.toString(), 0);

    ImageMosaicReader inReader = null;
    try {
      inReader = new ImageMosaicReader(inputLocation, new Hints(Hints.OVERVIEW_POLICY, OverviewPolicy.IGNORE));
    } catch (IOException e) {
      LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
      fireException(e);
      return;
    }

    // /////////////////////////////////////////////////////////////////////
    //
    //
    // Preparing all the params
    //
    //
    // /////////////////////////////////////////////////////////////////////
    // output files' directory
    if (!outputLocation.exists())
      outputLocation.mkdir();

    // getting envelope and other information about dimension
    final GeneralEnvelope envelope = inReader.getOriginalEnvelope();
    message = new StringBuilder("Original envelope is ").append(envelope.toString());
    if (LOGGER.isLoggable(Level.FINE))
      LOGGER.fine(message.toString());
    fireEvent(message.toString(), 0);

    final GridEnvelope range = inReader.getOriginalGridRange();
    message = new StringBuilder("Original range is ").append(range
        .toString());
    if (LOGGER.isLoggable(Level.FINE))
      LOGGER.fine(message.toString());
    fireEvent(message.toString(), 0);

    // new number of rows and columns
    final double newWidth = (range.getSpan(0) * 1.0) / scaleFactor;
    final double newHeight = (range.getSpan(1) * 1.0) / scaleFactor;
    if (tileW > newWidth)
      tileW = newWidth;
    if (tileH > newHeight)
      tileH = newHeight;

    message = new StringBuilder("New dimension is (W,H)==(").append(newWidth).append(",").append(newHeight).append(")");
    if (LOGGER.isLoggable(Level.FINE))
      LOGGER.fine(message.toString());
    fireEvent(message.toString(), 0);

    int newCols = (int) (newWidth / tileW);
    int newRows = (int) (newHeight / tileH);
    final boolean hasRemainingColum = (newWidth % tileW) != 0;
    final boolean hasRemainingRow = (newHeight % tileH) != 0;
    message = new StringBuilder("New matrix dimension is (cols,rows)==(").append(newCols).append(",").append(newRows).append(")");
    if (LOGGER.isLoggable(Level.FINE))
      LOGGER.fine(message.toString());
    fireEvent(message.toString(), 0);

    final double minx = envelope.getMinimum(0);
    final double miny = envelope.getMinimum(1);
    final double maxx = envelope.getMaximum(0);
    final double maxy = envelope.getMaximum(1);

    double _maxx = 0.0;
    double _maxy = 0.0;
    double _minx = 0.0;
    double _miny = 0.0;

   
     
   

    // ///////////////////////////////////////////////////////////////////
    //
    // MAIN LOOP
    //
    //
    // ///////////////////////////////////////////////////////////////////
    newRows += hasRemainingRow ? 1 : 0;
    newCols += hasRemainingColum ? 1 : 0;
    final double totalNumberOfFile = newRows * newCols;

    // getting resolution of each tile
    final double tileGeoWidth = envelope.getSpan(0) / newCols;
    final double tileGeoHeight = envelope.getSpan(1) / newRows;

    final int uppers[] = range.getHigh().getCoordinateValues();
    uppers[0] ++;
    uppers[1] ++;
    final double newRange[] = new double[] { uppers[0] / newCols,uppers[1] / newRows };
    final CoverageProcessor processor = CoverageProcessor.getInstance();
    for (int i = 0; i < newRows; i++)
      for (int j = 0; j < newCols; j++) {

        // //
        //
        // computing the bbox for this tile
        //
        // //
        _maxx = minx + (j + 1) * tileGeoWidth;
        _minx = minx + (j) * tileGeoWidth;
        _maxy = miny + (i + 1) * tileGeoHeight;
        _miny = miny + (i) * tileGeoHeight;
        if (_maxx > maxx)
          _maxx = maxx;
        if (_maxy > maxy)
          _maxy = maxy;

        // //
        //
        // creating the output file
        //
        // //
        final File fileOut = new File(outputLocation, new StringBuilder(
            "mosaic").append("_").append(
            Integer.toString(i * newCols + j)).append(".").append(
            "tiff").toString());
        if (fileOut.exists())
          fileOut.delete();

        message = new StringBuilder("Preparing tile (col,row)==(")
            .append(j)
            .append(",")
            .append(i)
            .append(") to file ")
            .append(fileOut);
        if (LOGGER.isLoggable(Level.FINE))
          LOGGER.fine(message.toString());
        fireEvent(message.toString(), (j + i * newCols)/ totalNumberOfFile);

        // //
        //
        // building gridgeometry for the read operation
        //
        // //
        final ParameterValue<GridGeometry2D> gg =  ImageMosaicFormat.READ_GRIDGEOMETRY2D.createValue();
        final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] { _minx, _miny }, new double[] { _maxx,_maxy });
        cropEnvelope.setCoordinateReferenceSystem(inReader.getCrs());
        //we need to supply the requeste grid range but we use a fake one since we are using the ignore overviews switch
        gg.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0, 800, 800)), cropEnvelope));
        message = new StringBuilder("Reading with grid envelope ").append(cropEnvelope.toString());
        if (LOGGER.isLoggable(Level.FINE))
          LOGGER.fine(message.toString());
        fireEvent(message.toString(), (j + i * newCols)
            / totalNumberOfFile);

        // //
        //
        // read the needed part and then crop to be sure that we have what we need
        //
        // //
        GridCoverage2D gc;
        try {
          gc = (GridCoverage2D) inReader
              .read(new GeneralParameterValue[] { gg });


        } catch (IOException e) {
          LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
          fireEvent(e.getLocalizedMessage(), 0);
          return;
        }

        ParameterValueGroup param = processor.getOperation("CoverageCrop").getParameters();
        param.parameter("Source").setValue(gc);
        param.parameter("Envelope").setValue(cropEnvelope);
        param.parameter("ConserveEnvelope").setValue(Boolean.TRUE);
        final GridCoverage2D cropped = (GridCoverage2D) processor.doOperation(param);

        // //
        //
        // Adjusting the resolution in order to be the same as for all the others coverage
        //
        // //
        final GridEnvelope2D newGridrange = new GridEnvelope2D(new Rectangle2D.Double(0.0, 0.0, newRange[0],newRange[1]).getBounds());
        final GridGeometry2D scaledGridGeometry = new GridGeometry2D(newGridrange, cropEnvelope);
        param = processor.getOperation("Resample").getParameters();
        param.parameter("Source").setValue(cropped);
        param.parameter("CoordinateReferenceSystem").setValue(inReader.getCrs());
        param.parameter("GridGeometry").setValue(scaledGridGeometry);
        param.parameter("InterpolationType").setValue(Interpolation.getInstance(Interpolation.INTERP_NEAREST));
        gc = (GridCoverage2D) processor.doOperation(param);


View Full Code Here

            dir.dispose();
        }

        // have the image mosaic write the property file
        ImageMosaicFormat format = new ImageMosaicFormat();
        ImageMosaicReader reader = format.getReader(mosaic.getFile());
        reader.dispose();
       
        // if we have to add the time, do so now
        if (mosaic.getTimeMode() != TimeMode.NONE) {
            File propertyFile = new File(mosaic.getFile(), mosaic.getName() + ".properties");
            FileInputStream fis = null;
View Full Code Here

TOP

Related Classes of org.geotools.gce.imagemosaic.ImageMosaicReader$ImageMosaicFileCollectionWalker

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.