Package org.gdal.gdal

Examples of org.gdal.gdal.Dataset


{
    public static void main(String args[])
    {
        gdal.AllRegister();
        Driver memDriver = gdal.GetDriverByName("MEM");
        Dataset ds1 = memDriver.Create("mem", 100, 100);
        ds1.SetGeoTransform(new double[] { 2, 0.01, 0, 49, 0, -0.01 });
        SpatialReference sr1 = new SpatialReference();
        sr1.ImportFromEPSG(4326);

        Dataset ds2 = memDriver.Create("mem2", 100, 100);
        ds2.SetGeoTransform(new double[] { 400000, 1000, 0, 5500000, 0, -1000 });
        SpatialReference sr2 = new SpatialReference();
        sr2.ImportFromEPSG(32631);

        Vector options = new Vector();
        options.add("SRC_SRS=" + sr1.ExportToWkt());
View Full Code Here


        /*
         * Open Input
         */

        Dataset SourceDataset = null;
        Dataset WorkProximityDataset = null;
        Driver WorkProximityDriver = null;

        SourceDataset = gdal.Open(SourceFilename, gdalconstConstants.GA_ReadOnly);

        if (SourceDataset == null) {
            System.err.println("GDALOpen failed - " + gdal.GetLastErrorNo());
            System.err.println(gdal.GetLastErrorMsg());
            System.exit(1);
        }

        /*
         * Open Output
         */

        WorkProximityDriver = gdal.IdentifyDriver(OutputFilename);

        if (WorkProximityDriver != null) {
           
            WorkProximityDataset = gdal.Open(OutputFilename, gdalconstConstants.GA_Update);

            if (WorkProximityDataset == null) {
                System.err.println("GDALOpen failed - " + gdal.GetLastErrorNo());
                System.err.println(gdal.GetLastErrorMsg());
                System.exit(1);
            }
        } else {

            /*
             * Create a new output dataset
             */
         
            WorkProximityDriver = gdal.GetDriverByName(OutputFormat);

            WorkProximityDataset = WorkProximityDriver.Create(OutputFilename,
                    SourceDataset.getRasterXSize(), SourceDataset.getRasterYSize(),
                    SourceDataset.getRasterCount(), gdal.GetDataTypeByName(OutputType),
                    Options.split(";"));

            WorkProximityDataset.SetGeoTransform(SourceDataset.GetGeoTransform());
            WorkProximityDataset.SetProjection(SourceDataset.GetProjectionRef());
        }

        if (WorkProximityDataset == null) {

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

        /*
         * Are we using pixels or georeferenced coordinates for distances?
         */

        if( GeoUnits ) {
            double geoTransform[] = SourceDataset.GetGeoTransform();
           
            if( Math.abs(geoTransform[1]) != Math.abs(geoTransform[5])) {
                System.err.println("Pixels not square, distances will be inaccurate.");
            }

            DistMult = (float) Math.abs(geoTransform[1]);
        }

        long startTime = System.currentTimeMillis();

        /*
         * Calculate Proximity
         */

        Run(SourceDataset.GetRasterBand(SourceBand),
                WorkProximityDataset.GetRasterBand(DestinyBand),
                DistMult,
                MaxDistance,
                Nodata,
                hasBufferValue,
                BufferValue,
                TargetValues);

        /*
         * Clean up
         */

        long stopTime = System.currentTimeMillis();

        SourceDataset.delete();

        WorkProximityDataset.delete();

        gdal.GDALDestroyDriverManager();

        System.out.println("Done in " + ((double) (stopTime - startTime) / 1000.0) + " seconds");
    }
View Full Code Here

        /*
         * 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);

            /*
             * Right to Left
             */

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

            /*
             * Left to Right
             */

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

            /*
             * Final post processing of distances.
             */

            for (int i = 0; i < xSize; i++) {
                if (proximityBuffer[i] < 0.0F) {
                    proximityBuffer[i] = NoData;
                } else if (proximityBuffer[i] > 0.0F) {
                    if (HasBufferValue) {
                        proximityBuffer[i] = BufferValue;
                    } else {
                        proximityBuffer[i] = DistMult * proximityBuffer[i];
                    }
                }
            }

            /*
             * Write to Proximity Band
             */

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

        ProximityBand.FlushCache();

        /*
         * Delete temporary file
         */

        if (WorkProximityDS != null) {
            WorkProximityDS.delete();
            /*
             * Delete virtual file from memory
             */
            gdal.Unlink(tempFilename);
        }
View Full Code Here

   
    public void run()
    {
        for(int i=0;i<100;i++)
        {
            Dataset ds = gdal.Open(_filename);
            ds.GetRasterBand(1).Checksum();
            //ds.delete();
        }
    }
View Full Code Here

{
    public static void main(String args[])
    {
        gdal.AllRegister();
        Driver memDriver = gdal.GetDriverByName("MEM");
        Dataset ds = memDriver.Create("mem", 1, 1);

        ds.SetDescription("RasterAttributeTable");
        if (!ds.GetDescription().equals("RasterAttributeTable"))
            throw new RuntimeException();

        ds.SetMetadataItem("key", "value");
        if (!ds.GetMetadataItem("key").equals("value"))
            throw new RuntimeException();

        Vector v = ds.GetMetadata_List();
        if (!((String)v.elementAt(0)).equals("key=value"))
            throw new RuntimeException();

        Hashtable h = ds.GetMetadata_Dict();
        if (!h.get("key").equals("value"))
            throw new RuntimeException();

        ds.delete();
        ds = memDriver.Create("mem", 1, 1);

        ds.SetMetadata("key=value");
        if (!ds.GetMetadataItem("key").equals("value"))
            throw new RuntimeException();

        ds.delete();
        ds = memDriver.Create("mem", 1, 1);

        h = new Hashtable();
        h.put("key", "value");
        ds.SetMetadata(h);
        if (!ds.GetMetadataItem("key").equals("value"))
            throw new RuntimeException();
        else
            System.out.println("Success");
    }
View Full Code Here

        /*
         * Create target raster file.
         */

        Dataset dstDS = null;
        String[] layerList = layers.split(":");
        int layerCount = layerList.length;
        int bandCount = layerCount;

        if (SQL != null) {
            bandCount++;
        }

        if (sizeX == 0) {
            sizeX = 256;
        }

        if (sizeY == 0) {
            sizeY = 256;
        }

        String[] optionList = createOptions == null ? null : createOptions
                .split(":");

        dstDS = driver.Create(outputFilename, sizeX, sizeY, 1, outputType,
                optionList);

        if (dstDS == null) {

            System.out.println("Unable to create dataset '" + outputFilename);
            System.out.println(gdal.GetLastErrorMsg());
            System.exit(3);
        }

        /*
         * Use terminal progress report
         */
        if (quiet == false) {

            progressCallback = new TermProgressCallback();
        }

        /*
         * Process SQL request.
         */

        if (SQL != null) {

            Layer srcLayer = srcDS.ExecuteSQL(SQL);

            if (srcLayer != null) {

                ProcessLayer(srcLayer, dstDS, clipSrc, sizeX, sizeY, 1,
                        isXExtentSet, isYExtentSet, minX, maxX, minY, maxY,
                        burnAttribute, outputType, algorithmAndOptions, quiet,
                        progressCallback);
            }
        }

        /*
         * Process each layer.
         */

        for (int i = 0; i < layerList.length; i++) {

            Layer srcLayer = srcDS.GetLayerByName(layerList[i]);

            if (srcLayer == null) {

                System.out.println("Unable to find layer '" + layerList[i]);
                continue;
            }

            if (where != null) {

                if (srcLayer.SetAttributeFilter(where) != gdalconstConstants.CE_None) {
                    break;
                }
            }

            if (spatialFilter != null) {

                srcLayer.SetSpatialFilter(spatialFilter);
            }

            if (outputSRS == null) {

                SpatialReference srs = srcLayer.GetSpatialRef();

                if (srs != null) {

                    outputSRS = srs.ExportToWkt();
                }
            }

            ProcessLayer(srcLayer, dstDS, clipSrc, sizeX, sizeY, i + 1
                    + bandCount - layerCount, isXExtentSet, isYExtentSet, minX,
                    maxX, minY, maxY, burnAttribute, outputType,
                    algorithmAndOptions, quiet, progressCallback);
        }

        /*
         * Apply geotransformation matrix.
         */

        double[] geoTransform = new double[6];

        geoTransform[0] = minX[0];
        geoTransform[1] = (maxX[0] - minX[0]) / sizeX;
        geoTransform[2] = 0.0;
        geoTransform[3] = minY[0];
        geoTransform[4] = 0.0;
        geoTransform[5] = (maxY[0] - minY[0]) / sizeY;

        dstDS.SetGeoTransform(geoTransform);

        /*
         * Apply SRS definition if set.
         */

        if (outputSRS != null) {

            dstDS.SetProjection(outputSRS);
        }

        /*
         * Cleanup.
         */

        srcDS.delete();
        dstDS.delete();

        gdal.GDALDestroyDriverManager();
    }
View Full Code Here

        /*
         * Open source raster file.
         */

        Dataset dataset = gdal.Open(sourceFilename,
                gdalconstConstants.GA_ReadOnly);

        if (dataset == null) {
            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];
            } else {
                hasSourceNodata = false;
            }
        }

        /*
         * Try to get a coordinate system from the raster.
         */

        SpatialReference srs = null;

        String wkt = dataset.GetProjection();

        if (wkt.length() > 0) {

            srs = new SpatialReference(wkt);
        }

        /*
         * Create the outputfile.
         */

        DataSource dataSource = null;
        Driver driver = ogr.GetDriverByName(outputFormat);
        FieldDefn field = null;
        Layer layer = null;

        if (driver == null) {

            System.err.println("Unable to find format driver named "
                    + outputFormat);
            System.exit(10);
        }

        dataSource = driver.CreateDataSource(outputFilename);

        if (dataSource == null) {
            System.exit(1);
        }

        if (threeDimension) {
            layer = dataSource.CreateLayer(newLayerName, srs,
                    ogr.wkbLineString25D);
        } else {
            layer = dataSource
                    .CreateLayer(newLayerName, srs, ogr.wkbLineString);
        }

        if (layer == null) {
            System.exit(1);
        }

        field = new FieldDefn("ID", ogr.OFTInteger);
        field.SetWidth(8);

        layer.CreateField(field, 0);
        field.delete();

        if (attributName != null) {

            field = new FieldDefn(attributName, ogr.OFTReal);
            field.SetWidth(12);
            field.SetPrecision(3);

            layer.CreateField(field, 0);
            layer.delete();
        }

        /*
         * Use terminal progress report
         */

        if (quiet == false) {
            progressCallback = new ProgressCallback();
        }

        /*
         * Invoke.
         */

        FeatureDefn feature = layer.GetLayerDefn();
       
        gdal.ContourGenerate(band, contourInterval, offset, fixedLevelsDouble,
                (ignoreNodata ? 1 : 0), sourceNodata, layer, feature.GetFieldIndex("ID"),
                (attributName != null ? feature.GetFieldIndex(attributName) : -1),
                progressCallback);
       
        dataSource.delete();
        dataset.delete();
    }
View Full Code Here

      canvas.setIcon(icon);
    }
  }
 
  public BufferedImage openFile(File f) {
    Dataset poDataset = null;
    try {
      poDataset = (Dataset) gdal.Open(f.getAbsolutePath(),
          gdalconst.GA_ReadOnly);
      if (poDataset == null) {
        System.out.println("The image could not be read.");
        printLastError();
        return null;
      }
    } catch(Exception e) {
      System.err.println("Exception caught.");
      System.err.println(e.getMessage());
      e.printStackTrace();
      return null;
    }
    double[] adfGeoTransform = new double[6];

    System.out.println("Driver: " + poDataset.GetDriver().GetDescription());

    System.out.println("Size is: " + poDataset.getRasterXSize() + "x"
        + poDataset.getRasterYSize() + "  bands:"
        + poDataset.getRasterCount());

    if (poDataset.GetProjectionRef() != null)
      System.out.println("Projection is `" + poDataset.GetProjectionRef()
          + "'");
   
    Hashtable dict = poDataset.GetMetadata_Dict("");
    Enumeration keys = dict.keys();
    System.out.println(dict.size() + " items of metadata found (via Hashtable dict):");
    while(keys.hasMoreElements()) {
      String key = (String)keys.nextElement();
      System.out.println(" :" + key + ":==:" + dict.get(key) + ":");
    }

    Vector list = poDataset.GetMetadata_List("");
    Enumeration enumerate = list.elements();
    System.out.println(list.size() + " items of metadata found (via Vector list):");
    while(enumerate.hasMoreElements()) {
      String s = (String)enumerate.nextElement();
      System.out.println(" " + s);
    }
   
    Vector GCPs = new Vector();
    poDataset.GetGCPs(GCPs);
    System.out.println("Got " + GCPs.size() + " GCPs");
    Enumeration e = GCPs.elements();
    while(e.hasMoreElements()) {
      GCP gcp = (GCP)e.nextElement();
      System.out.println(" x:" + gcp.getGCPX() +
          " y:" + gcp.getGCPY() +
          " z:" + gcp.getGCPZ() +
          " pixel:" + gcp.getGCPPixel() +
          " line:" + gcp.getGCPLine() +
          " line:" + gcp.getInfo());
    }
   

    poDataset.GetGeoTransform(adfGeoTransform);
    {
      System.out.println("Origin = (" + adfGeoTransform[0] + ", "
          + adfGeoTransform[3] + ")");

      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 = "
View Full Code Here

        try
        {
            /* -------------------------------------------------------------------- */
            /*      Open dataset.                                                   */
            /* -------------------------------------------------------------------- */
            Dataset ds = gdal.Open( args[0], gdalconst.GA_Update );
   
            if (ds == null)
            {
                System.out.println("Can't open " + args[0]);
                System.exit(-1);
            }

            System.out.println("Raster dataset parameters:");
            System.out.println("  Projection: " + ds.GetProjectionRef());
            System.out.println("  RasterCount: " + ds.getRasterCount());
            System.out.println("  RasterSize (" + ds.getRasterXSize() + "," + ds.getRasterYSize() + ")");
           
            int[] levels = new int[args.length -2];

            System.out.println(levels.length);
          
            for (int i = 2; i < args.length; i++)
            {
                levels[i-2] = Integer.parseInt(args[i]);
            }
     
            if (ds.BuildOverviews(args[1], levels, new TermProgressCallback()) != gdalconst.CE_None)
            {
                System.out.println("The BuildOverviews operation doesn't work");
                System.exit(-1);
            }
            /* -------------------------------------------------------------------- */
            /*      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();

            System.out.println("Completed.");
            System.out.println("Use:  gdalread " + args[0] + " outfile.png [overview] to extract a particular overview!" );
        }
        catch (Exception e)
View Full Code Here

  /*                                main()                                */
  /************************************************************************/

  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" );
                                    }
                                }
                               
        if( hBand.GetUnitType() != null && hBand.GetUnitType().length() > 0)
        {
             System.out.println( "  Unit Type: " + hBand.GetUnitType() );
        }

                                Vector papszCategories = hBand.GetRasterCategoryNames();
                                if (papszCategories.size() > 0)
                                {
                                    System.out.println( "  Categories:" );
                                    Enumeration eCategories = papszCategories.elements();
                                    i = 0;
            while (eCategories.hasMoreElements()) {
                                            System.out.println("    " + i + ": " + (String) eCategories.nextElement());
                                            i ++;
                                    }
                                }

        hBand.GetOffset(pass1);
        if(pass1[0] != null && pass1[0].doubleValue() != 0) {
          System.out.print("  Offset: " + pass1[0]);
        }
        hBand.GetScale(pass1);
        if(pass1[0] != null && pass1[0].doubleValue() != 1) {
          System.out.println(",   Scale:" + pass1[0]);
        }

        papszMetadata = hBand.GetMetadata_List("");
         if( bShowMetadata && papszMetadata.size() > 0 ) {
            Enumeration keys = papszMetadata.elements();
            System.out.println("  Metadata:");
            while (keys.hasMoreElements()) {
              System.out.println("    " + (String) keys.nextElement());
            }
         }
        if (hBand.GetRasterColorInterpretation() == gdalconstConstants.GCI_PaletteIndex
            && (hTable = hBand.GetRasterColorTable()) != null) {
          int count;

          System.out.println("  Color Table ("
              + gdal.GetPaletteInterpretationName(hTable
                  .GetPaletteInterpretation()) + " with "
              + hTable.GetCount() + " entries)");

                                        if (bShowColorTable)
                                        {
                                            for (count = 0; count < hTable.GetCount(); count++) {
                                                    System.out.println(" " + count + ": "
                                                                    + hTable.GetColorEntry(count));
                                            }
                                        }
        }

                                RasterAttributeTable rat = hBand.GetDefaultRAT();
                                if( bShowRAT && rat != null )
                                {
                                    System.out.print("<GDALRasterAttributeTable ");
                                    double[] pdfRow0Min = new double[1];
                                    double[] pdfBinSize = new double[1];
                                    if (rat.GetLinearBinning(pdfRow0Min, pdfBinSize))
                                    {
                                        System.out.print("Row0Min=\"" + pdfRow0Min[0] + "\" BinSize=\"" + pdfBinSize[0] + "\">");
                                    }
                                    System.out.print("\n");
                                    int colCount = rat.GetColumnCount();
                                    for(int col=0;col<colCount;col++)
                                    {
                                        System.out.println("  <FieldDefn index=\"" + col + "\">");
                                        System.out.println("    <Name>" + rat.GetNameOfCol(col) + "</Name>");
                                        System.out.println("    <Type>" + rat.GetTypeOfCol(col) + "</Type>");
                                        System.out.println("    <Usage>" + rat.GetUsageOfCol(col) + "</Usage>");
                                        System.out.println("  </FieldDefn>");
                                    }
                                    int rowCount = rat.GetRowCount();
                                    for(int row=0;row<rowCount;row++)
                                    {
                                        System.out.println("  <Row index=\"" + row + "\">");
                                        for(int col=0;col<colCount;col++)
                                        {
                                            System.out.println("    <F>" + rat.GetValueAsString(row, col)+ "</F>");
                                        }
                                        System.out.println("  </Row>");
                                    }
                                    System.out.println("</GDALRasterAttributeTable>");
                                }
      }

      hDataset.delete();

                        /* Optional */
      gdal.GDALDestroyDriverManager();

      System.exit(0);
 
View Full Code Here

TOP

Related Classes of org.gdal.gdal.Dataset

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.