openModeller
Version 1.5.0
Main Page
Modules
Classes
Files
File List
File Members
Header.cpp
Go to the documentation of this file.
1
29
#include <
openmodeller/env_io/Header.hh
>
30
31
#include <
openmodeller/Log.hh
>
32
33
using
std::string;
34
using
std::pair;
35
using
std::make_pair;
36
37
/****************************************************************/
38
/***************************** Header ***************************/
39
40
/******************/
41
/*** construtor ***/
42
43
Header::Header
(
int
xd,
int
yd,
Coord
xm,
Coord
ym,
44
Coord
xM,
Coord
yM,
Scalar
nv,
int
nb,
int
gd ) :
45
xdim( xd ),
46
ydim( yd ),
47
xmin( xm ),
48
ymin( ym ),
49
xmax( xM ),
50
ymax( yM ),
51
xcel( 0 ),
52
ycel( 0 ),
53
noval( nv ),
54
nband( nb ),
55
grid( gd ),
56
categ( 0 ),
57
minmax( 0 ),
58
vmin( 0.0 ),
59
vmax( 0.0 ),
60
proj()
61
{
62
calculateCell
();
63
64
// Given the information provided in this constructor,
65
// We pretty much have to assume this is the geotransform.
66
67
gt
[0] =
xmin
;
68
gt
[1] =
xcel
;
69
gt
[2] = 0.0;
70
gt
[3] =
ymax
;
71
gt
[4] = 0.0;
72
gt
[5] = -1.0*
ycel
;
73
}
74
75
Header::Header
(
const
Header
&h )
76
{
77
operator=
( h );
78
}
79
80
81
/*****************/
82
/*** destrutor ***/
83
84
Header::~Header
()
85
{
86
}
87
88
89
/******************/
90
/*** operator = ***/
91
Header
&
92
Header::operator=
(
const
Header
&h )
93
{
94
xdim
= h.
xdim
;
95
ydim
= h.
ydim
;
96
97
xmin
= h.
xmin
;
98
ymin
= h.
ymin
;
99
xmax
= h.
xmax
;
100
ymax
= h.
ymax
;
101
102
xcel
= h.
xcel
;
103
ycel
= h.
ycel
;
104
105
gt
[0] = h.
gt
[0];
106
gt
[1] = h.
gt
[1];
107
gt
[2] = h.
gt
[2];
108
gt
[3] = h.
gt
[3];
109
gt
[4] = h.
gt
[4];
110
gt
[5] = h.
gt
[5];
111
112
noval
= h.
noval
;
113
nband
= h.
nband
;
114
grid
= h.
grid
;
115
categ
= h.
categ
;
116
117
minmax
= h.
minmax
;
118
vmin
= h.
vmin
;
119
vmax
= h.
vmax
;
120
121
proj
= h.
proj
;
122
123
return
*
this
;
124
}
125
126
127
/**********************/
128
/*** calculate Cell ***/
129
void
130
Header::calculateCell
()
131
{
132
// todo: verify if it is true for "grid" and "pixel".
133
134
xcel
= (
xmax
-
xmin
) /
xdim
;
135
ycel
= (
ymax
-
ymin
) /
ydim
;
136
}
137
138
139
/****************/
140
/*** set Proj ***/
141
void
142
Header::setProj
(
const
string
& projection )
143
{
144
proj
= projection;
145
}
146
147
// Does not support rotations.
148
pair<Coord,Coord>
149
Header::convertXY2LonLat
(
int
x,
int
y )
const
150
{
151
// Get the coordinates associated with the center of the cell
152
Coord
lon =
gt
[1]*(x+0.5) +
gt
[0];
153
Coord
lat =
gt
[5]*(y+0.5) +
gt
[3];
154
155
return
make_pair(lon,lat);
156
}
157
158
// Does not support rotations.
159
pair<int,int>
160
Header::convertLonLat2XY
(
Coord
lon,
Coord
lat )
const
161
{
162
int
x =
static_cast<
int
>
((lon -
gt
[0]) /
gt
[1]);
163
int
y =
static_cast<
int
>
((lat -
gt
[3]) /
gt
[5]);
164
165
return
make_pair(x,y);
166
}
167
168
/*************/
169
/*** print ***/
170
void
171
Header::printHeader
(
const
std::string& msg )
const
172
{
173
Log::instance
()->
info
(
"%s\n"
, msg.c_str() );
174
175
Log::instance
()->
info
(
"xdim: %d\n"
,
xdim
);
176
Log::instance
()->
info
(
"ydim: %d\n"
,
ydim
);
177
Log::instance
()->
info
(
"xmin: %.4f\n"
,
xmin
);
178
Log::instance
()->
info
(
"ymin: %.4f\n"
,
ymin
);
179
Log::instance
()->
info
(
"xmax: %.4f\n"
,
xmax
);
180
Log::instance
()->
info
(
"ymax: %.4f\n"
,
ymax
);
181
Log::instance
()->
info
(
"xcel: %.4f\n"
,
xcel
);
182
Log::instance
()->
info
(
"ycel: %.4f\n"
,
ycel
);
183
Log::instance
()->
info
(
"noval: %.4f\n"
,
noval
);
184
Log::instance
()->
info
(
"band: %d\n"
,
nband
);
185
Log::instance
()->
info
(
"grid: %d\n"
,
grid
);
186
Log::instance
()->
info
(
"var : %s\n"
,
categ
?
"categorical"
:
"continuous"
);
187
188
if
(
minmax
)
189
{
190
Log::instance
()->
info
(
"min: %f\n"
,
vmin
);
191
Log::instance
()->
info
(
"max: %f\n"
,
vmax
);
192
}
193
else
194
Log::instance
()->
info
(
"No minimum or maximum available.\n"
);
195
196
for
(
int
i=0;i<6; i++ ) {
197
Log::instance
()->
info
(
"GT[%d] = %f\n"
,i,
gt
[i] );
198
}
199
200
Log::instance
()->
info
(
"proj: %s\n"
,
proj
.c_str() );
201
}
Header::xcel
Coord xcel
Definition:
Header.hh:78
Header::categ
int categ
Definition:
Header.hh:93
Header::ycel
Coord ycel
Definition:
Header.hh:79
Header::vmin
Scalar vmin
Definition:
Header.hh:101
Header::xdim
int xdim
Definition:
Header.hh:72
Header::vmax
Scalar vmax
Definition:
Header.hh:102
Scalar
double Scalar
Type of map values.
Definition:
om_defs.hh:39
Header::calculateCell
void calculateCell()
Definition:
Header.cpp:130
Header::ydim
int ydim
Definition:
Header.hh:73
Header::~Header
~Header()
Definition:
Header.cpp:84
Header::nband
int nband
Definition:
Header.hh:83
Header::xmin
Coord xmin
Definition:
Header.hh:74
Header::xmax
Coord xmax
Definition:
Header.hh:76
Log::instance
static Log * instance()
Returns the instance pointer, creating the object on the first call.
Definition:
Log.cpp:45
Header::printHeader
void printHeader(const std::string &msg="") const
Definition:
Header.cpp:171
Header::convertLonLat2XY
std::pair< int, int > convertLonLat2XY(Coord lon, Coord lat) const
Definition:
Header.cpp:160
Header::noval
Scalar noval
Definition:
Header.hh:82
Header::Header
Header()
Definition:
Header.hh:49
Header
Definition:
Header.hh:45
Header::convertXY2LonLat
std::pair< Coord, Coord > convertXY2LonLat(int x, int y) const
Definition:
Header.cpp:149
Header::proj
std::string proj
Definition:
Header.hh:104
Header::gt
Coord gt[6]
Definition:
Header.hh:80
Header::ymin
Coord ymin
Definition:
Header.hh:75
Header::grid
int grid
Definition:
Header.hh:86
Header::ymax
Coord ymax
Definition:
Header.hh:77
Header::minmax
int minmax
Definition:
Header.hh:99
Log::info
void info(const char *format,...)
'Info' level.
Definition:
Log.cpp:256
Header::operator=
Header & operator=(const Header &h)
Definition:
Header.cpp:92
Header.hh
Coord
double Coord
Type of map coordinates.
Definition:
om_defs.hh:38
Log.hh
Header::setProj
void setProj(const std::string &projection)
Definition:
Header.cpp:142
src
openmodeller
env_io
Header.cpp
Generated on Thu Jan 8 2015 17:05:09 for openModeller by
1.8.6