Κυρίες Δεσποσύνες και Κύριοι,
καλή σας ώρα :-)
Δείτε
σε C:
/*
RSEx3 - Remote Sensing Lab. - SRSE NTUA
GDAL Getting Dataset Information
Reference: https://www.gdal.org/gdal_tutorial.html
License: https://www.gnu.org/licenses/gpl.txt
*/
#include <stdio.h> /* for printf */
#include <stdlib.h> /* for exit */
#include "gdal/gdal.h"
#include "gdal/cpl_conv.h" /* for CPLMalloc() */
int main(void){
/* Enter your cropped.tif image full path filename here */
char *pszFilename="/home/chiossif/Data/LC08_L1TP_184033_20180622_20180703_01_T1/clipped.tif";
GDALDatasetH hDataset;
GDALAllRegister();
hDataset = GDALOpen( pszFilename, GA_ReadOnly );
if( hDataset == NULL ) {
printf("Unable to open %s file\n", pszFilename);
exit(1);
}
GDALDriverH hDriver;
double adfGeoTransform[6];
hDriver = GDALGetDatasetDriver( hDataset );
printf( "Driver: %s/%s\n",
GDALGetDriverShortName( hDriver ),
GDALGetDriverLongName( hDriver ) );
printf( "Size is %dx%dx%d\n",
GDALGetRasterXSize( hDataset ),
GDALGetRasterYSize( hDataset ),
GDALGetRasterCount( hDataset ) );
if( GDALGetProjectionRef( hDataset ) != NULL )
printf( "Projection is `%s'\n",
GDALGetProjectionRef( hDataset ) );
if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None ){
printf( "Origin = (%.6f,%.6f)\n",
adfGeoTransform[0], adfGeoTransform[3] );
printf( "Pixel Size = (%.6f,%.6f)\n",
adfGeoTransform[1], adfGeoTransform[5] );
}
GDALRasterBandH hBand;
int nBlockXSize, nBlockYSize;
int bGotMin, bGotMax;
double adfMinMax[2];
double myMin, myMax, myMean, myStdD, mySum, mySum2;
float *pafScanline, tmpfloat;
int bands, bandno, myNum;
register int i, r;
bands = GDALGetRasterCount( hDataset );
for (bandno=1;bandno<=bands;bandno++){
printf("Band=%d\n",bandno);
hBand = GDALGetRasterBand( hDataset, bandno );
GDALGetBlockSize( hBand, &nBlockXSize, &nBlockYSize );
printf( "Block=%dx%d Type=%s, ColorInterp=%s\n",
nBlockXSize, nBlockYSize,
GDALGetDataTypeName(GDALGetRasterDataType(hBand)),
GDALGetColorInterpretationName( GDALGetRasterColorInterpretation(hBand)) );
adfMinMax[0] = GDALGetRasterMinimum( hBand, &bGotMin );
adfMinMax[1] = GDALGetRasterMaximum( hBand, &bGotMax );
if( ! (bGotMin && bGotMax) )
GDALComputeRasterMinMax( hBand, TRUE, adfMinMax );
printf( "Min=%.3f, Max=%.3f\n", adfMinMax[0], adfMinMax[1] );
if( GDALGetOverviewCount(hBand) > 0 )
printf( "Band has %d overviews.\n", GDALGetOverviewCount(hBand));
if( GDALGetRasterColorTable( hBand ) != NULL )
printf( "Band has a color table with %d entries.\n",
GDALGetColorEntryCount( GDALGetRasterColorTable( hBand ) ) );
pafScanline = (float *) CPLMalloc(sizeof(float)*nBlockXSize);
if (pafScanline!=NULL){
myMin = 65536.0;
myMax = -65537.0;
mySum = 0.0;
mySum2 = 0.0;
myNum = 0;
for (r=0;r < GDALGetRasterYSize( hDataset );r++){
GDALRasterIO( hBand, GF_Read, 0, r, nBlockXSize, 1, pafScanline, nBlockXSize, 1, GDT_Float32, 0, 0 );
for (i=0;i<nBlockXSize;i++){
myNum++;
tmpfloat = pafScanline[i];
mySum += tmpfloat;
mySum2 += tmpfloat * tmpfloat;
if (tmpfloat > myMax)
myMax = tmpfloat;
if (tmpfloat < myMin)
myMin = tmpfloat;
}
}
myMean = mySum / myNum;
myStdD = sqrt(mySum2 / myNum - myMean * myMean);
printf( "Min=%.3lf, Max=%.3lf, Mean=%.3lf, StdDev=%.3lf\n", myMin, myMax, myMean, myStdD);
CPLFree(pafScanline);
}
}
return 0;
}
/*
Driver: GTiff/GeoTIFF
Size is 2840x1541x7
Projection is `PROJCS["WGS 84 / UTM zone 34N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",21],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32634"]]'
Origin = (498255.000000,4282875.000000)
Pixel Size = (30.000000,-30.000000)
Band=1
Block=2840x1 Type=UInt16, ColorInterp=Gray
Min=9260.000, Max=48540.000
Min=9260.000, Max=48540.000, Mean=11449.392, StdDev=2289.782
Band=2
Block=2840x1 Type=UInt16, ColorInterp=Undefined
Min=8217.000, Max=51117.000
Min=8217.000, Max=51117.000, Mean=10476.116, StdDev=2487.918
Band=3
Block=2840x1 Type=UInt16, ColorInterp=Undefined
Min=6982.000, Max=52368.000
Min=6982.000, Max=52368.000, Mean=9604.907, StdDev=2668.937
Band=4
Block=2840x1 Type=UInt16, ColorInterp=Undefined
Min=6159.000, Max=55830.000
Min=6159.000, Max=55830.000, Mean=8906.102, StdDev=3117.561
Band=5
Block=2840x1 Type=UInt16, ColorInterp=Undefined
Min=5497.000, Max=53726.000
Min=5052.000, Max=63093.000, Mean=15602.425, StdDev=6334.375
Band=6
Block=2840x1 Type=UInt16, ColorInterp=Undefined
Min=5097.000, Max=60158.000
Min=4714.000, Max=63849.000, Mean=12332.979, StdDev=5270.812
Band=7
Block=2840x1 Type=UInt16, ColorInterp=Undefined
Min=4978.000, Max=53259.000
Min=4892.000, Max=65535.000, Mean=9391.264, StdDev=3782.803
*/
...