SAGA API Version 9.14
Loading...
Searching...
No Matches
map_symbology.h
Go to the documentation of this file.
1
3// //
4// SAGA //
5// //
6// System for Automated Geoscientific Analyses //
7// //
8// Application Programming Interface //
9// //
10// Library: SAGA_API //
11// //
12//-------------------------------------------------------//
13// //
14// map_symbology.h //
15// //
16// Copyright (C) 2026 by //
17// Olaf Conrad //
18// //
19//-------------------------------------------------------//
20// //
21// This file is part of 'SAGA - System for Automated //
22// Geoscientific Analyses'. SAGA is free software; you //
23// can redistribute it and/or modify it under the terms //
24// of the GNU General Public License as published by the //
25// Free Software Foundation, either version 2 of the //
26// License, or (at your option) any later version. //
27// //
28// SAGA is distributed in the hope that it will be //
29// useful, but WITHOUT ANY WARRANTY; without even the //
30// implied warranty of MERCHANTABILITY or FITNESS FOR A //
31// PARTICULAR PURPOSE. See the GNU General Public //
32// License for more details. //
33// //
34// You should have received a copy of the GNU General //
35// Public License along with this program; if not, see //
36// <http://www.gnu.org/licenses/>. //
37// //
38//-------------------------------------------------------//
39// //
40// e-mail: oconrad@saga-gis.org //
41// //
42// contact: Olaf Conrad //
43// Institute of Geography //
44// University of Hamburg //
45// Germany //
46// //
48
49//---------------------------------------------------------
50#ifndef _HEADER_INCLUDED__SAGA_API__Map_Symbology_H
51#define _HEADER_INCLUDED__SAGA_API__Map_Symbology_H
52
53
55// //
56// //
57// //
59
60//---------------------------------------------------------
61#include "../table.h"
62
63
65// //
66// //
67// //
69
70//---------------------------------------------------------
72{
73public:
74 CSG_Map_Symbology(class CSG_Map_Layer *pLayer);
75 virtual ~CSG_Map_Symbology(void);
76
77 bool Update (void);
78
79 bool Set_Mode (int Mode);
80 int Get_Mode (void) const { return( m_Mode ); }
81
82 bool Set_NoData_Color (int Color);
83 int Get_NoData_Color (void) const { return( m_NoData_Color ); }
84
85 bool Set_Single_Color (int Color);
86 int Get_Single_Color (void) const { return( m_Single_Color ); }
87
88
89 //---------------------------------------------------------
90 enum
91 {
92 SINGLE = 0,
98 };
99
100 //---------------------------------------------------------
101 enum
102 {
108 };
109
110 //---------------------------------------------------------
111 enum
112 {
121 };
122
123
125
126 //-----------------------------------------------------
127 bool Set_Class_Count (int Count);
128
129 int Get_Class_Count (void) const
130 {
131 switch( m_Mode )
132 {
133 case SINGLE : default:
134 return( 1 );
135
136 case CLASSIFIED:
137 return( (int)m_pLUT->Get_Count() );
138
139 case DISCRETE :
140 return( m_pColors->Get_Count() );
141
142 case GRADUATED :
143 case COMPOSITE :
144 return( m_Count );
145 }
146 }
147
148 //-----------------------------------------------------
149 int Get_Class (double Value)
150 {
151 switch( m_Mode )
152 {
153 case SINGLE : default:
154 return( 0 );
155
156 case CLASSIFIED:
157 return( _LUT_Get_Class(Value) );
158
159 case DISCRETE :
160 case GRADUATED :
161 case COMPOSITE :
162 return( _METRIC_Get_Class(Value) );
163 }
164 }
165
166 int Get_Class (const CSG_String &Value)
167 {
168 if( m_Mode == CLASSIFIED )
169 {
170 return( _LUT_Get_Class(Value) );
171 }
172
173 return( Get_Class(Value.asDouble()) );
174 }
175
176 //-----------------------------------------------------
177 double Get_Class_Value_Minimum (int Class);
178 double Get_Class_Value_Center (int Class);
179 double Get_Class_Value_Maximum (int Class);
180 wxString Get_Class_Name (int Class);
181 wxString Get_Class_Name_byValue (double Value);
182 wxString Get_Class_Name_byValue (const wxString &Value);
183
184
186
187 //-----------------------------------------------------
188 CSG_Colors Get_Class_Colors (void) const;
189
190 //-----------------------------------------------------
191 bool Get_Class_Color (int Class, int &Color) const
192 {
193 switch( m_Mode )
194 {
195 case SINGLE : default:
196 Color = m_Single_Color;
197 break;
198
199 case CLASSIFIED:
200 if( Class < 0 || Class >= m_pLUT->Get_Count() )
201 {
202 Color = m_NoData_Color;
203
204 return( false );
205 }
206
207 Color = m_pLUT->Get_Record(Class)->asInt(LUT_COLOR);
208 break;
209
210
211 case DISCRETE :
212 Color = m_pColors->Get_Color(Class < 0 ? 0 : Class >= m_pColors->Get_Count() ? m_pColors->Get_Count() - 1 : Class);
213 break;
214
215 case GRADUATED :
216 case COMPOSITE :
217 Get_Class_Color_byValue(m_Stretch.from_Relative(Class / (double)m_Count), Color);
218 break;
219 }
220
221 return( true );
222 }
223
224 //-----------------------------------------------------
225 int Get_Class_Color (int Class) const
226 {
227 int Color; return( Get_Class_Color(Class, Color) ? Color : 0 );
228 }
229
230 //-----------------------------------------------------
231 bool Get_Class_Color_byValue (double Value, int &Color) const
232 {
233 switch( m_Mode )
234 {
235 case SINGLE : default:
236 {
237 return( Get_Class_Color(0, Color) );
238 }
239
240 case CLASSIFIED:
241 {
242 return( Get_Class_Color(_LUT_Get_Class(Value), Color) );
243 }
244
245 case DISCRETE :
246 {
247 return( Get_Class_Color(_METRIC_Get_Class(Value), Color) );
248 }
249
250 case GRADUATED :
251 {
252 Color = m_pColors->Get_Interpolated(m_Stretch.to_Relative(Value) * (m_pColors->Get_Count() - 1));
253
254 return( true );
255 }
256
257 case COMPOSITE :
258 {
259 int c = (int)(255. * m_Stretch.to_Relative(Value)); if( c < 0 ) { c = 0; } else if( c > 255 ) { c = 255; }
260
261 Color = SG_GET_RGB(c, c, c);
262
263 return( true );
264 }
265
266 case RGB :
267 {
268 Color = (int)Value;
269
270 return( true );
271 }
272 }
273 }
274
275 bool Get_Class_Color_byValue (const CSG_String &Value, int &Color) const
276 {
277 if( m_Mode == CLASSIFIED )
278 {
279 return( Get_Class_Color(_LUT_Get_Class(Value), Color) );
280 }
281
282 return( Get_Class_Color_byValue(Value.asDouble(), Color) );
283 }
284
285 //-----------------------------------------------------
286 int Get_Class_Color_byValue (double Value) const
287 {
288 int Color; return( Get_Class_Color_byValue(Value, Color) ? Color : 0 );
289 }
290
291 int Get_Class_Color_byValue (const CSG_String &Value) const
292 {
293 int Color; return( Get_Class_Color_byValue(Value, Color) ? Color : 0 );
294 }
295
296
298
299 //-----------------------------------------------------
300 CSG_Colors & Get_Colors (void) { return( *m_pColors ); }
301 const CSG_Colors & Get_Colors (void) const { return( *m_pColors ); }
302
303 CSG_Scaler & Get_Stretch (void) { return( m_Stretch ); }
304 const CSG_Scaler & Get_Stretch (void) const { return( m_Stretch ); }
305
306 bool Set_Stretch (double Minimum, double Maximum, int Mode = 0, double LogScale = 1.) { return( m_Stretch.Create(Minimum, Maximum, Mode, LogScale) ); }
307
308 double Get_Stretch_Minimum (void) const { return( m_Stretch.Get_Minimum () ); }
309 double Get_Stretch_Maximum (void) const { return( m_Stretch.Get_Maximum () ); }
310 double Get_Stretch_Range (void) const { return( m_Stretch.Get_Range () ); }
311 int Get_Stretch_Mode (void) const { return( m_Stretch.Get_Mode () ); }
312 double Get_Stretch_LogScale (void) const { return( m_Stretch.Get_LogScale() ); }
313
314 double Get_Stretch_to_Relative (double Value) const { return( m_Stretch. to_Relative(Value) ); }
315 double Get_Stretch_from_Relative (double Value) const { return( m_Stretch.from_Relative(Value) ); }
316
317
319
320 //-----------------------------------------------------
321 bool Histogram_Update (void);
322
323 const CSG_Histogram & Histogram_Get (void) const { return( m_Histogram ); }
324
325 const CSG_Simple_Statistics & Statistics_Get (void) const { return( m_Statistics ); }
326
327
328protected:
329
331
333
335
337
339
341
342 class CSG_Map_Layer *m_pLayer = NULL;
343
344
345 //-----------------------------------------------------
346 int _LUT_Cmp_Class (double Value, int Class) const;
347 int _LUT_Get_Class (double Value ) const;
348
349 int _LUT_Cmp_Class (const CSG_String &Value, int Class) const;
350 int _LUT_Get_Class (const CSG_String &Value ) const;
351
352 int _METRIC_Get_Class (double Value) const
353 {
354 if( Value < m_Stretch.Get_Minimum() )
355 {
356 return( -1 );
357 }
358
359 if( Value > m_Stretch.Get_Maximum() )
360 {
361 return( Get_Class_Count() );
362 }
363
364 int Class = (int)(m_Stretch.to_Relative(Value) * Get_Class_Count());
365
366 return( Class < 0 ? 0 : Class < Get_Class_Count() ? Class : Get_Class_Count() - 1 );
367 }
368
369
370 //-----------------------------------------------------
371 bool _Histogram_Update (CSG_Data_Object *pObject);
372 bool _Histogram_Update (CSG_Table *pTable, int Field, int Normalize = -1, double Scale = 1.);
373
374};
375
376
378// //
379// //
380// //
382
383//---------------------------------------------------------
384#endif // #ifndef _HEADER_INCLUDED__SAGA_API__Map_Symbology_H
#define SAGA_API_DLL_EXPORT
Definition api_core.h:94
#define SG_GET_RGB(r, g, b)
Definition api_core.h:1345
int Get_Class_Color_byValue(double Value) const
double Get_Stretch_Range(void) const
int _METRIC_Get_Class(double Value) const
CSG_Colors * m_pColors
double Get_Stretch_Maximum(void) const
double Get_Stretch_LogScale(void) const
bool Get_Class_Color_byValue(double Value, int &Color) const
CSG_Scaler & Get_Stretch(void)
int Get_Class(double Value)
int Get_Single_Color(void) const
const CSG_Simple_Statistics & Statistics_Get(void) const
bool Get_Class_Color_byValue(const CSG_String &Value, int &Color) const
const CSG_Colors & Get_Colors(void) const
int Get_NoData_Color(void) const
int _LUT_Cmp_Class(double Value, int Class) const
CSG_Simple_Statistics m_Statistics
double Get_Stretch_from_Relative(double Value) const
double Get_Stretch_Minimum(void) const
int Get_Class(const CSG_String &Value)
CSG_Map_Symbology(class CSG_Map_Layer *pLayer)
bool Set_Stretch(double Minimum, double Maximum, int Mode=0, double LogScale=1.)
int _LUT_Get_Class(double Value) const
CSG_Histogram m_Histogram
const CSG_Histogram & Histogram_Get(void) const
int Get_Class_Color_byValue(const CSG_String &Value) const
const CSG_Scaler & Get_Stretch(void) const
double Get_Stretch_to_Relative(double Value) const
bool Set_Mode(int Mode)
CSG_Colors & Get_Colors(void)
int Get_Class_Count(void) const
int Get_Stretch_Mode(void) const
bool Get_Class_Color(int Class, int &Color) const
int Get_Class_Color(int Class) const
class CSG_Map_Layer * m_pLayer
int Get_Mode(void) const
bool asDouble(double &Value) const