Package org.gdal.gdal

Examples of org.gdal.gdal.Band


        /*
         * Create working band
         */

        Band WorkProximityBand = ProximityBand;
        Dataset WorkProximityDS = null;

        int ProxType = ProximityBand.getDataType();

        String tempFilename = null;

        if (ProxType == gdalconstConstants.GDT_Byte
                || ProxType == gdalconstConstants.GDT_UInt16
                || ProxType == gdalconstConstants.GDT_UInt32) {
            tempFilename = "/vsimem/proximity_" + String.valueOf(System.currentTimeMillis()) + ".tif";
            WorkProximityDS = gdal.GetDriverByName("GTiff").Create(tempFilename,
                    ProximityBand.getXSize(), ProximityBand.getYSize(), 1,
                    gdalconstConstants.GDT_Float32);
            WorkProximityBand = WorkProximityDS.GetRasterBand(1);
        }

        int xSize = WorkProximityBand.getXSize();
        int ySize = WorkProximityBand.getYSize();

        /*
         * Allocate buffers
         */

        short nearXBuffer[] = new short[xSize];
        short nearYBuffer[] = new short[xSize];
        int scanline[] = new int[xSize];
        float proximityBuffer[] = new float[xSize];

        /*
         * Loop from top to bottom of the image
         */

        for (int i = 0; i < xSize; i++) {
            nearXBuffer[i] = -1;
            nearYBuffer[i] = -1;
        }

        for (int iLine = 0; iLine < ySize; iLine++) {

            SrcBand.ReadRaster(0, iLine, xSize, 1, xSize, 1,
                    gdalconstConstants.GDT_Int32, scanline);

            for (int i = 0; i < xSize; i++) {
                proximityBuffer[i] = -1F;
            }

            /*
             * Left to Right
             */

            ProcessProximityLine(scanline, nearXBuffer, nearYBuffer,
                    true, iLine, xSize, MaxDistance, proximityBuffer,
                    TargetValues);

            /*
             * Right to Left
             */

            ProcessProximityLine(scanline, nearXBuffer, nearYBuffer,
                    false, iLine, xSize, MaxDistance, proximityBuffer,
                    TargetValues);

            /*
             * Write to Proximity Band
             */

            WorkProximityBand.WriteRaster(0, iLine, xSize, 1, xSize, 1,
                    gdalconstConstants.GDT_Float32, proximityBuffer);
        }

        /*
         * Loop from bottom to top of the image
         */

        for (int i = 0; i < xSize; i++) {
            nearXBuffer[i] = -1;
            nearYBuffer[i] = -1;
        }

        for (int iLine = ySize - 1; iLine >= 0; iLine--) {

            WorkProximityBand.ReadRaster(0, iLine, xSize, 1, xSize, 1,
                    gdalconstConstants.GDT_Float32, proximityBuffer);

            SrcBand.ReadRaster(0, iLine, xSize, 1, xSize, 1,
                    gdalconstConstants.GDT_Int32, scanline);

View Full Code Here


                    + ").");
            System.out.println("Source point count = " + X.size() + " .");
            PrintAlgorithmAndOptions(algorithmAndOptions);
        }

        Band band = dstDS.GetRasterBand(bandIndex);

        if (X.size() == 0) {

            Double val[] = new Double[1];

            band.GetNoDataValue(val);

            if (val[0] != null) {
                band.Fill(val[0]);
            } else {
                band.Fill(0.0);
            }

            return;
        }

        int offsetX = 0;
        int offsetY = 0;
        int[] blockXSize = new int[1];
        int[] blockYSize = new int[1];

        band.GetBlockSize(blockXSize, blockYSize);

        int bufferSize = blockXSize[0] * blockYSize[0]
                * gdal.GetDataTypeSize(type) / 8;

        ByteBuffer data = ByteBuffer.allocateDirect(bufferSize);

        int blockIndex = 0;
        int blockCount = ((sizeX + blockXSize[0] - 1) / blockXSize[0])
                * ((sizeY + blockYSize[0] - 1) / blockYSize[0]);

        GDALGridScaledProgress griddingProgress = null;

        for (offsetY = 0; offsetY < sizeY; offsetY += blockYSize[0]) {

            for (offsetX = 0; offsetX < sizeX; offsetX += blockXSize[0]) {

                int requestX = blockXSize[0];

                if (offsetX + requestX > sizeX) {

                    requestX = sizeX - offsetX;
                }

                int requestY = blockYSize[0];

                if (offsetY + requestY > sizeY) {

                    requestY = sizeY - offsetY;
                }

               
                /*
                 * Reformat arguments
                 */

                double[][] points = new double[X.size()][3];
                for (int i = 0; i < X.size(); i++)
                    points[i][0] = X.get(i);
                for (int i = 0; i < Y.size(); i++)
                    points[i][1] = Y.get(i);
                for (int i = 0; i < Z.size(); i++)
                    points[i][2] = Z.get(i);

                /*
                 * Create Scaled progress report
                 */

                if (quiet == false) {
                    griddingProgress = new GDALGridScaledProgress(
                            blockIndex * 1.0 / blockCount,
                            (blockIndex + 1) * 1.0 / blockCount,
                            progressCallback);
                }

                /*
                 * Create Grid
                 */
                               
                gdal.GridCreate(algorithmAndOptions, points, minX[0] + deltaX
                        * offsetX, minX[0] + deltaX * (offsetX + requestX), minY[0]
                        + deltaY * offsetY, minY[0] + deltaY
                        * (offsetY + requestY), requestX, requestY, type, data,
                        griddingProgress);

                /*
                 * Write grid to raster output
                 */

                band.WriteRaster_Direct(offsetX, offsetY, requestX, requestY,
                        requestX, requestY, type, data);

                if (quiet == false) {
                    griddingProgress.delete();
                }
View Full Code Here

            System.err.println("GDALOpen failed - " + gdal.GetLastErrorNo());
            System.err.println(gdal.GetLastErrorMsg());
            System.exit(2);
        }

        Band band = dataset.GetRasterBand(sourceBand);

        if (band == null) {
            System.err.println("Band does not exist on dataset");
            System.err.println("GDALOpen failed - " + gdal.GetLastErrorNo());
            System.err.println(gdal.GetLastErrorMsg());
            System.exit(3);
        }

        if (!hasSourceNodata && !ignoreNodata) {

            Double val[] = new Double[1];

            band.GetNoDataValue(val);

            hasSourceNodata = true;

            if (val[0] != null) {
                sourceNodata = val[0];
View Full Code Here

      System.out.println("Pixel Size = (" + adfGeoTransform[1] + ", "
          + adfGeoTransform[5] + ")");
    }

    Band poBand = null;
    double[] adfMinMax = new double[2];
    Double[] max = new Double[1];
    Double[] min = new Double[1];
   
    int bandCount = poDataset.getRasterCount();
    ByteBuffer[] bands = new ByteBuffer[bandCount];
    int[] banks = new int[bandCount];
    int[] offsets = new int[bandCount];
   
    int xsize = 1024;//poDataset.getRasterXSize();
    int ysize = 1024;//poDataset.getRasterYSize();
    int pixels = xsize * ysize;
    int buf_type = 0, buf_size = 0;

    for(int band = 0; band < bandCount; band++) {
      /* Bands are not 0-base indexed, so we must add 1 */
      poBand = poDataset.GetRasterBand(band+1);
     
      buf_type = poBand.getDataType();
      buf_size = pixels * gdal.GetDataTypeSize(buf_type) / 8;

      System.out.println(" Data Type = "
          + gdal.GetDataTypeName(poBand.getDataType()));
      System.out.println(" ColorInterp = "
          + gdal.GetColorInterpretationName(poBand
              .GetRasterColorInterpretation()));
     
      System.out.println("Band size is: " + poBand.getXSize() + "x"
          + poBand.getYSize());
 
      poBand.GetMinimum(min);
      poBand.GetMaximum(max);
      if(min[0] != null || max[0] != null) {
        System.out.println("  Min=" + min[0] + " Max="
            + max[0]);
      } else {
        System.out.println("  No Min/Max values stored in raster.");
      }
 
      if (poBand.GetOverviewCount() > 0) {
        System.out.println("Band has " + poBand.GetOverviewCount()
            + " overviews.");
      }
 
      if (poBand.GetRasterColorTable() != null) {
        System.out.println("Band has a color table with "
            + poBand.GetRasterColorTable().GetCount() + " entries.");
        for(int i = 0; i < poBand.GetRasterColorTable().GetCount(); i++) {
          System.out.println(" " + i + ": " +
              poBand.GetRasterColorTable().GetColorEntry(i));
        }
      }
     
      System.out.println("Allocating ByteBuffer of size: " + buf_size);

      ByteBuffer data = ByteBuffer.allocateDirect(buf_size);
      data.order(ByteOrder.nativeOrder());

      int returnVal = 0;
      try {
        returnVal = poBand.ReadRaster_Direct(0, 0, poBand.getXSize(),
            poBand.getYSize(), xsize, ysize,
            buf_type, data);
      } catch(Exception ex) {
        System.err.println("Could not read raster data.");
        System.err.println(ex.getMessage());
        ex.printStackTrace();
        return null;
      }
      if(returnVal == gdalconstConstants.CE_None) {
        bands[band] = data;
      } else {
        printLastError();
      }
      banks[band] = band;
      offsets[band] = 0;
    }

    DataBuffer imgBuffer = null;
    SampleModel sampleModel = null;
    int data_type = 0, buffer_type = 0;
   
    if(buf_type == gdalconstConstants.GDT_Byte) {
      byte[][] bytes = new byte[bandCount][];
      for(int i = 0; i < bandCount; i++) {       
        bytes[i] = new byte[pixels];
        bands[i].get(bytes[i]);
      }
      imgBuffer = new DataBufferByte(bytes, pixels);
      buffer_type = DataBuffer.TYPE_BYTE;
      sampleModel = new BandedSampleModel(buffer_type,
          xsize, ysize, xsize, banks, offsets);
      data_type = (poBand.GetRasterColorInterpretation() ==
        gdalconstConstants.GCI_PaletteIndex)?
        BufferedImage.TYPE_BYTE_INDEXED : BufferedImage.TYPE_BYTE_GRAY;
    } else if(buf_type == gdalconstConstants.GDT_Int16) {
      short[][] shorts = new short[bandCount][];
      for(int i = 0; i < bandCount; i++) {       
        shorts[i] = new short[pixels];
        bands[i].asShortBuffer().get(shorts[i]);
      }
      imgBuffer = new DataBufferShort(shorts, pixels);
      buffer_type = DataBuffer.TYPE_USHORT;
      sampleModel = new BandedSampleModel(buffer_type,
          xsize, ysize, xsize, banks, offsets);
      data_type = BufferedImage.TYPE_USHORT_GRAY;
    } else if(buf_type == gdalconstConstants.GDT_Int32) {
      int[][] ints = new int[bandCount][];
      for(int i = 0; i < bandCount; i++) {       
        ints[i] = new int[pixels];
        bands[i].asIntBuffer().get(ints[i]);
      }
      imgBuffer = new DataBufferInt(ints, pixels);
      buffer_type = DataBuffer.TYPE_INT;
      sampleModel = new BandedSampleModel(buffer_type,
          xsize, ysize, xsize, banks, offsets);
      data_type = BufferedImage.TYPE_CUSTOM;
    }

    WritableRaster raster = Raster.createWritableRaster(sampleModel, imgBuffer, null);
    BufferedImage img = null;
    ColorModel cm = null;

    if(poBand.GetRasterColorInterpretation() ==
      gdalconstConstants.GCI_PaletteIndex) {
      data_type = BufferedImage.TYPE_BYTE_INDEXED;
      cm = poBand.GetRasterColorTable().getIndexColorModel(
                gdal.GetDataTypeSize(buf_type));
      img = new BufferedImage(cm, raster, false, null);
    } else {
      ColorSpace cs = null;
      if(bandCount > 2){
View Full Code Here

            /* -------------------------------------------------------------------- */
            /*      Displaying the raster parameters                                */
            /* -------------------------------------------------------------------- */
            for (int iBand = 1; iBand <= ds.getRasterCount(); iBand++)
            {
                Band band = ds.GetRasterBand(iBand);
                System.out.println("Band " + iBand + " :");
                System.out.println("   DataType: " + band.getDataType());
                System.out.println("   Size (" + band.getXSize() + "," + band.getYSize() + ")");
                System.out.println("   PaletteInterp: " + gdal.GetColorInterpretationName(band.GetRasterColorInterpretation()));

                for (int iOver = 0; iOver < band.GetOverviewCount(); iOver++)
                {
                    Band over = band.GetOverview(iOver);
                    System.out.println("      OverView " + iOver + " :");
                    System.out.println("         DataType: " + over.getDataType());
                    System.out.println("         Size (" + over.getXSize() + "," + over.getYSize() + ")");
                    System.out.println("         PaletteInterp: " + gdal.GetColorInterpretationName(over.GetRasterColorInterpretation()));
                }
            }

            /* explicit closing of dataset */
            ds.delete();
View Full Code Here

  /************************************************************************/

  public static void main(String[] args) {
    {
      Dataset hDataset;
      Band hBand;
      int i, iBand;
      double[] adfGeoTransform = new double[6];
      Driver hDriver;
      Vector papszMetadata;
      boolean bComputeMinMax = false, bSample = false;
      boolean bShowGCPs = true, bShowMetadata = true;
      boolean bStats = false, bApproxStats = true;
                        boolean bShowColorTable = true, bComputeChecksum = false;
                        boolean bReportHistograms = false;
                        boolean bShowRAT = true;
      String pszFilename = null;
                        Vector papszFileList;
                        Vector papszExtraMDDomains = new Vector();

      gdal.AllRegister();

                        args = gdal.GeneralCmdLineProcessor(args);

      if (args.length < 1) {
        Usage();
        System.exit(0);
      }
      /* -------------------------------------------------------------------- */
      /*      Parse arguments.                                                */
      /* -------------------------------------------------------------------- */
      for (i = 0; i < args.length; i++) {
        if (args[i].equals("-mm"))
          bComputeMinMax = true;
                                else if (args[i].equals("-hist"))
          bReportHistograms = true;
        else if (args[i].equals("-stats"))
                                {
          bStats = true;
                                        bApproxStats = false;
                                }
        else if (args[i].equals("-approx_stats"))
        {
          bStats = true;
                                        bApproxStats = true;
                                }
        else if (args[i].equals("-nogcp"))
          bShowGCPs = false;
                                else if( args[i].equals("-noct"))
                                        bShowColorTable = false;
        else if (args[i].equals("-nomd"))
          bShowMetadata = false;
                                else if (args[i].equals("-norat"))
          bShowRAT = false;
                                else if (args[i].equals("-checksum"))
          bComputeChecksum = true;
                                else if (args[i].equals("-mdd") && i + 1 < args.length)
          papszExtraMDDomains.addElement(args[++i]);
        else if (args[i].startsWith("-"))
          Usage();
        else if (pszFilename == null)
          pszFilename = args[i];
        else
          Usage();
      }
      if (pszFilename == null)
        Usage();

      /* -------------------------------------------------------------------- */
      /*      Open dataset.                                                   */
      /* -------------------------------------------------------------------- */
      hDataset = gdal.Open(pszFilename, gdalconstConstants.GA_ReadOnly);

      if (hDataset == null) {
        System.err
            .println("GDALOpen failed - " + gdal.GetLastErrorNo());
        System.err.println(gdal.GetLastErrorMsg());

        //gdal.DumpOpenDatasets( stderr );

        //gdal.DestroyDriverManager();

        //gdal.DumpSharedList( null );

        System.exit(1);
      }

      /* -------------------------------------------------------------------- */
      /*      Report general info.                                            */
      /* -------------------------------------------------------------------- */
      hDriver = hDataset.GetDriver();
      System.out.println("Driver: " + hDriver.getShortName() + "/"
          + hDriver.getLongName());

                        papszFileList = hDataset.GetFileList( );
                        if( papszFileList.size() == 0 )
                        {
                            System.out.println( "Files: none associated" );
                        }
                        else
                        {
                            Enumeration e = papszFileList.elements();
                            System.out.println( "Files: " + (String)e.nextElement() );
                            while(e.hasMoreElements())
                                System.out.println( "       " (String)e.nextElement() );
                        }

      System.out.println("Size is " + hDataset.getRasterXSize() + ", "
          + hDataset.getRasterYSize());

      /* -------------------------------------------------------------------- */
      /*      Report projection.                                              */
      /* -------------------------------------------------------------------- */
      if (hDataset.GetProjectionRef() != null) {
        SpatialReference hSRS;
        String pszProjection;

        pszProjection = hDataset.GetProjectionRef();

        hSRS = new SpatialReference(pszProjection);
        if (hSRS != null && pszProjection.length() != 0) {
          String[] pszPrettyWkt = new String[1];

          hSRS.ExportToPrettyWkt(pszPrettyWkt, 0);
          System.out.println("Coordinate System is:");
          System.out.println(pszPrettyWkt[0]);
          //gdal.CPLFree( pszPrettyWkt );
        } else
          System.out.println("Coordinate System is `"
              + hDataset.GetProjectionRef() + "'");

        hSRS.delete();
      }

      /* -------------------------------------------------------------------- */
      /*      Report Geotransform.                                            */
      /* -------------------------------------------------------------------- */
      hDataset.GetGeoTransform(adfGeoTransform);
      {
        if (adfGeoTransform[2] == 0.0 && adfGeoTransform[4] == 0.0) {
          System.out.println("Origin = (" + adfGeoTransform[0] + ","
              + adfGeoTransform[3] + ")");

          System.out.println("Pixel Size = (" + adfGeoTransform[1]
              + "," + adfGeoTransform[5] + ")");
        } else {
          System.out.println("GeoTransform =");
                                        System.out.println("  " + adfGeoTransform[0] + ", "
                                                        + adfGeoTransform[1] + ", " + adfGeoTransform[2]);
                                        System.out.println("  " + adfGeoTransform[3] + ", "
                                                        + adfGeoTransform[4] + ", " + adfGeoTransform[5]);
                                }
      }

      /* -------------------------------------------------------------------- */
      /*      Report GCPs.                                                    */
      /* -------------------------------------------------------------------- */
      if (bShowGCPs && hDataset.GetGCPCount() > 0) {
        System.out.println("GCP Projection = "
            + hDataset.GetGCPProjection());

        int count = 0;
        Vector GCPs = new Vector();
        hDataset.GetGCPs(GCPs);

        Enumeration e = GCPs.elements();
        while (e.hasMoreElements()) {
          GCP gcp = (GCP) e.nextElement();
          System.out.println("GCP[" + (count++) + "]: Id="
              + gcp.getId() + ", Info=" + gcp.getInfo());
          System.out.println("    (" + gcp.getGCPPixel() + ","
              + gcp.getGCPLine() + ") (" + gcp.getGCPX() + ","
              + gcp.getGCPY() + "," + gcp.getGCPZ() + ")");
        }

      }

      /* -------------------------------------------------------------------- */
      /*      Report metadata.                                                */
      /* -------------------------------------------------------------------- */
      papszMetadata = hDataset.GetMetadata_List("");
      if (bShowMetadata && papszMetadata.size() > 0) {
        Enumeration keys = papszMetadata.elements();
        System.out.println("Metadata:");
        while (keys.hasMoreElements()) {
          System.out.println("  " + (String) keys.nextElement());
        }
      }
                       
                        Enumeration eExtraMDDDomains = papszExtraMDDomains.elements();
                        while(eExtraMDDDomains.hasMoreElements())
                        {
                            String pszDomain = (String)eExtraMDDDomains.nextElement();
                            papszMetadata = hDataset.GetMetadata_List(pszDomain);
                            if( bShowMetadata && papszMetadata.size() > 0 )
                            {
                                Enumeration keys = papszMetadata.elements();
                                System.out.println("Metadata (" + pszDomain + "):");
                                while (keys.hasMoreElements()) {
          System.out.println("  " + (String) keys.nextElement());
        }
                            }
                        }
                        /* -------------------------------------------------------------------- */
                        /*      Report "IMAGE_STRUCTURE" metadata.                              */
                        /* -------------------------------------------------------------------- */
                        papszMetadata = hDataset.GetMetadata_List("IMAGE_STRUCTURE" );
                        if( bShowMetadata && papszMetadata.size() > 0) {
        Enumeration keys = papszMetadata.elements();
        System.out.println("Image Structure Metadata:");
        while (keys.hasMoreElements()) {
          System.out.println("  " + (String) keys.nextElement());
        }
      }
      /* -------------------------------------------------------------------- */
      /*      Report subdatasets.                                             */
      /* -------------------------------------------------------------------- */
      papszMetadata = hDataset.GetMetadata_List("SUBDATASETS");
      if (papszMetadata.size() > 0) {
        System.out.println("Subdatasets:");
        Enumeration keys = papszMetadata.elements();
        while (keys.hasMoreElements()) {
          System.out.println("  " + (String) keys.nextElement());
        }
      }
                   
                    /* -------------------------------------------------------------------- */
                    /*      Report geolocation.                                             */
                    /* -------------------------------------------------------------------- */
                        papszMetadata = hDataset.GetMetadata_List("GEOLOCATION" );
                        if (papszMetadata.size() > 0) {
                            System.out.println( "Geolocation:" );
                            Enumeration keys = papszMetadata.elements();
                            while (keys.hasMoreElements()) {
                                    System.out.println("  " + (String) keys.nextElement());
                            }
                        }
                   
                    /* -------------------------------------------------------------------- */
                    /*      Report RPCs                                                     */
                    /* -------------------------------------------------------------------- */
                        papszMetadata = hDataset.GetMetadata_List("RPC" );
                        if (papszMetadata.size() > 0) {
                            System.out.println( "RPC Metadata:" );
                            Enumeration keys = papszMetadata.elements();
                            while (keys.hasMoreElements()) {
                                    System.out.println("  " + (String) keys.nextElement());
                            }
                        }

      /* -------------------------------------------------------------------- */
      /*      Report corners.                                                 */
      /* -------------------------------------------------------------------- */
      System.out.println("Corner Coordinates:");
      GDALInfoReportCorner(hDataset, "Upper Left ", 0.0, 0.0);
      GDALInfoReportCorner(hDataset, "Lower Left ", 0.0, hDataset
          .getRasterYSize());
      GDALInfoReportCorner(hDataset, "Upper Right", hDataset
          .getRasterXSize(), 0.0);
      GDALInfoReportCorner(hDataset, "Lower Right", hDataset
          .getRasterXSize(), hDataset.getRasterYSize());
      GDALInfoReportCorner(hDataset, "Center     ",
          hDataset.getRasterXSize() / 2.0,
          hDataset.getRasterYSize() / 2.0);

      /* ==================================================================== */
      /*      Loop over bands.                                                */
      /* ==================================================================== */
      for (iBand = 0; iBand < hDataset.getRasterCount(); iBand++) {
        Double[] pass1 = new Double[1], pass2 = new Double[1];
        double[] adfCMinMax = new double[2];
        ColorTable hTable;

        hBand = hDataset.GetRasterBand(iBand + 1);

        /*if( bSample )
         {
         float[] afSample = new float[10000];
         int   nCount;

         nCount = hBand.GetRandomRasterSample( 10000, afSample );
         System.out.println( "Got " + nCount + " samples." );
         }*/

                                int[] blockXSize = new int[1];
                                int[] blockYSize = new int[1];
                                hBand.GetBlockSize(blockXSize, blockYSize);
        System.out.println("Band "
            + (iBand+1)
                                                + " Block="
                                                + blockXSize[0] + "x" + blockYSize[0]
            + " Type="
            + gdal.GetDataTypeName(hBand.getDataType())
            + ", ColorInterp="
            + gdal.GetColorInterpretationName(hBand
                .GetRasterColorInterpretation()));

        String hBandDesc = hBand.GetDescription();
        if (hBandDesc != null && hBandDesc.length() > 0)
          System.out.println("  Description = " + hBandDesc);

        hBand.GetMinimum(pass1);
        hBand.GetMaximum(pass2);
        if(pass1[0] != null || pass2[0] != null || bComputeMinMax) {
                                    System.out.print( "  " );
                                    if( pass1[0] != null )
                                        System.out.print( "Min=" + pass1[0] + " ");
                                    if( pass2[0] != null )
                                        System.out.print( "Max=" + pass2[0] + " ");
                               
                                    if( bComputeMinMax )
                                    {
                                        hBand.ComputeRasterMinMax(adfCMinMax, 0);
                                        System.out.print( "  Computed Min/Max=" + adfCMinMax[0]
              + "," + adfCMinMax[1]);
                                    }
                       
                                    System.out.print( "\n" );
        }

                                double dfMin[] = new double[1];
                                double dfMax[] = new double[1];
                                double dfMean[] = new double[1];
                                double dfStdDev[] = new double[1];
        if( hBand.GetStatistics( bApproxStats, bStats,
                                                         dfMin, dfMax, dfMean, dfStdDev ) == gdalconstConstants.CE_None )
        {
            System.out.println( "  Minimum=" + dfMin[0] + ", Maximum=" + dfMax[0] +
                                                        ", Mean=" + dfMean[0] + ", StdDev=" + dfStdDev[0] );
        }

                                if( bReportHistograms )
                                {
                                    int[][] panHistogram = new int[1][];
                                    int eErr = hBand.GetDefaultHistogram(dfMin, dfMax, panHistogram, true, new TermProgressCallback());
                                    if( eErr == gdalconstConstants.CE_None )
                                    {
                                        int iBucket;
                                        int nBucketCount = panHistogram[0].length;
                                        System.out.print( "  " + nBucketCount + " buckets from " +
                                                           dfMin[0] + " to " + dfMax[0] + ":\n  " );
                                        for( iBucket = 0; iBucket < nBucketCount; iBucket++ )
                                            System.out.print( panHistogram[0][iBucket] + " ");
                                        System.out.print( "\n" );
                                    }
                                }

                                if ( bComputeChecksum)
                                {
                                    System.out.println( "  Checksum=" + hBand.Checksum());
                                }

        hBand.GetNoDataValue(pass1);
        if(pass1[0] != null)
        {
          System.out.println("  NoData Value=" + pass1[0]);
        }

        if (hBand.GetOverviewCount() > 0) {
          int iOverview;

          System.out.print("  Overviews: ");
          for (iOverview = 0; iOverview < hBand.GetOverviewCount(); iOverview++) {
            Band hOverview;

            if (iOverview != 0)
              System.out.print(", ");

            hOverview = hBand.GetOverview(iOverview);
            System.out.print(hOverview.getXSize() + "x"
                + hOverview.getYSize());
          }
          System.out.print("\n");

                                        if ( bComputeChecksum)
                                        {
                                            System.out.print( "  Overviews checksum: " );
                                            for( iOverview = 0;
                                                iOverview < hBand.GetOverviewCount();
                                                iOverview++ )
                                            {
                                                Band  hOverview;
                           
                                                if( iOverview != 0 )
                                                    System.out.print( ", " );
                           
                                                hOverview = hBand.GetOverview(iOverview);
                                                System.out.print( hOverview.Checksum());
                                            }
                                            System.out.print( "\n" );
                                        }
        }

        if( hBand.HasArbitraryOverviews() )
        {
            System.out.println( "  Overviews: arbitrary" );
        }


                                int nMaskFlags = hBand.GetMaskFlags(  );
                                if( (nMaskFlags & (gdalconstConstants.GMF_NODATA|gdalconstConstants.GMF_ALL_VALID)) == 0 )
                                {
                                    Band hMaskBand = hBand.GetMaskBand() ;
                       
                                    System.out.print( "  Mask Flags: " );
                                    if( (nMaskFlags & gdalconstConstants.GMF_PER_DATASET) != 0 )
                                        System.out.print( "PER_DATASET " );
                                    if( (nMaskFlags & gdalconstConstants.GMF_ALPHA) != 0 )
                                        System.out.print( "ALPHA " );
                                    if( (nMaskFlags & gdalconstConstants.GMF_NODATA) != 0 )
                                        System.out.print( "NODATA " );
                                    if( (nMaskFlags & gdalconstConstants.GMF_ALL_VALID) != 0 )
                                        System.out.print( "ALL_VALID " );
                                    System.out.print( "\n" );
                       
                                    if( hMaskBand != null &&
                                        hMaskBand.GetOverviewCount() > 0 )
                                    {
                                        int    iOverview;
                       
                                        System.out.print( "  Overviews of mask band: " );
                                        for( iOverview = 0;
                                            iOverview < hMaskBand.GetOverviewCount();
                                            iOverview++ )
                                        {
                                            Band  hOverview;
                       
                                            if( iOverview != 0 )
                                                System.out.print( ", " );
                       
                                            hOverview = hMaskBand.GetOverview( iOverview );
                                            System.out.print(
                                                    hOverview.getXSize() + "x" +
                                                    hOverview.getYSize() );
                                        }
                                        System.out.print( "\n" );
                                    }
                                }
                               
View Full Code Here

   
    public void run()
    {
        Dataset dataset = null;
        Driver driver = null;
        Band band = null;
       
        int xsize = 4000;
        int ysize = 400;

        synchronized(notifier)
        {
            nReady ++;
            notifier.notify();
        }

        synchronized(waiter)
        {
            while( bWait )
            {
                try
                {
                    waiter.wait();
                }
                catch(InterruptedException ie)
                {
                }
            }
        }

        driver = gdal.GetDriverByName("GTiff");
           
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * xsize);
        byteBuffer.order(ByteOrder.nativeOrder());
        FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
        int[] intArray = new int[xsize];
        float[] floatArray = new float[xsize];
       
        dataset = driver.Create(filename, xsize, ysize, 1, gdalconst.GDT_Float32);
        band = dataset.GetRasterBand(1);
       
        for(int iter = 0; iter < nbIters; iter++)
        {
            if (method == METHOD_DBB)
            {
                for( int i = 0; i < ysize; i++) {
                    for( int j = 0; j < xsize; j++) {
                        floatBuffer.put(j, (float) (i + j));
                    }
                    band.WriteRaster_Direct(0, i, xsize, 1, gdalconst.GDT_Float32, byteBuffer);
                }
            }
            else
            {
                for( int i = 0; i < ysize; i++) {
                    for( int j = 0; j < xsize; j++) {
                        floatArray[j] = (float) (i + j);
                    }
                    band.WriteRaster(0, i, xsize, 1, floatArray);
                }
            }
        }
       
        dataset.delete();
       
        /* Open the file to check the values */
        dataset = gdal.Open(filename);
        band = dataset.GetRasterBand(1);
       
        for(int iter = 0; iter < nbIters; iter++)
        {
            if (method == METHOD_DBB)
            {
                for( int i = 0; i < ysize; i++) {
                    band.ReadRaster_Direct(0, i, xsize, 1, xsize, 1, gdalconst.GDT_Int32, byteBuffer);
                    for( int j = 0; j < xsize; j++) {
                        int val = byteBuffer.getInt(j*4);
                        if (val != (i + j))
                            throw new RuntimeException("Bad value for (" + j + "," + i + ") : " + val);
                    }
                }
            }
            else
            {
                for( int i = 0; i < ysize; i++) {
                    band.ReadRaster(0, i, xsize, 1, intArray);
                    for( int j = 0; j < xsize; j++) {
                        int val = intArray[j];
                        if (val != (i + j))
                            throw new RuntimeException("Bad value for (" + j + "," + i + ") : " + val);
                    }
View Full Code Here

TOP

Related Classes of org.gdal.gdal.Band

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.