-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImagem.cpp
More file actions
95 lines (74 loc) · 2.33 KB
/
Imagem.cpp
File metadata and controls
95 lines (74 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "Imagem.h"
#include <stdio.h>
#include <string.h>
#include <iostream>
using std::cout;
using std::endl;
Imagem::Imagem ( int i, char * s ) {
codigo = i;
strcpy (nome, s);
inicializa ();
}
Imagem::~Imagem ( ) {
}
char * Imagem::getNome () {
return nome;
}
void Imagem::setNome (char * s) {
strcpy (nome, s);
}
int Imagem::getCodigo () {
return codigo;
}
void Imagem::setCodigo (int i) {
codigo = i;
}
void Imagem::inicializa () {
poDataset = (GDALDataset *) GDALOpen (nome, GA_ReadOnly);
if (poDataset == NULL) {
cout << "erro: nao foi possivel abrir a imagem." << endl;
}
double adfGeoTransform[6];
strcpy (driver, poDataset->GetDriver()->GetDescription());
w = poDataset->GetRasterXSize();
h = poDataset->GetRasterYSize();
z = poDataset->GetRasterCount();
if ( poDataset->GetProjectionRef() != NULL ) {
strcpy (srs, poDataset->GetProjectionRef());
}
if ( poDataset->GetGeoTransform( adfGeoTransform ) == CE_None ) {
x0 = adfGeoTransform[0];
y0 = adfGeoTransform[3];
xd = adfGeoTransform[1];
yd = adfGeoTransform[5];
}
}
void Imagem::imprimeInfo () {
cout << "********************************************************" << endl;
cout << "Imagem" << endl;
cout << "Codigo.....: " << codigo << endl;
cout << "Nome.......: " << nome << endl;
cout << "Driver.....: " << driver << endl;
cout << "SRS........: " << srs << endl;
cout << "Origem.....: " << x0 << ", " << y0 << endl;
cout << "Tam. Pixel.: " << xd << ", " << yd << endl;
cout << "********************************************************" << endl;
}
float Imagem::informaIvdn ( float x, float y) {
GDALRasterBand *poBand;
int nBlockXSize, nBlockYSize;
int bGotMin, bGotMax;
double adfMinMax[2];
poBand = poDataset->GetRasterBand( 1 );
poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );
int n1 = (x - x0)/xd;
int n2 = (y - y0)/yd;
float *pafScanline;
int nXSize = poBand->GetXSize();
int nYSize = poBand->GetYSize();
pafScanline = (float *) CPLMalloc(sizeof(float)*nXSize);
poBand->RasterIO( GF_Read, n1, n2, 1, 1,
pafScanline, 1, 1, GDT_Float32,
0, 0 );
return pafScanline[0];
}