SAGA API v9.10
Loading...
Searching...
No Matches
grid.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// grid.h //
15// //
16// Copyright (C) 2005 by Olaf Conrad //
17// //
18//-------------------------------------------------------//
19// //
20// This file is part of 'SAGA - System for Automated //
21// Geoscientific Analyses'. //
22// //
23// This library is free software; you can redistribute //
24// it and/or modify it under the terms of the GNU Lesser //
25// General Public License as published by the Free //
26// Software Foundation, either version 2.1 of the //
27// License, or (at your option) any later version. //
28// //
29// This library is distributed in the hope that it will //
30// be useful, but WITHOUT ANY WARRANTY; without even the //
31// implied warranty of MERCHANTABILITY or FITNESS FOR A //
32// PARTICULAR PURPOSE. See the GNU Lesser General Public //
33// License for more details. //
34// //
35// You should have received a copy of the GNU Lesser //
36// General Public License along with this program; if //
37// not, see <http://www.gnu.org/licenses/>. //
38// //
39//-------------------------------------------------------//
40// //
41// contact: Olaf Conrad //
42// Institute of Geography //
43// University of Hamburg //
44// Germany //
45// //
46// e-mail: oconrad@saga-gis.org //
47// //
49
50//---------------------------------------------------------
51#ifndef HEADER_INCLUDED__SAGA_API__grid_H
52#define HEADER_INCLUDED__SAGA_API__grid_H
53
54
56// //
57// //
58// //
60
61//---------------------------------------------------------
68
69
71// //
72// //
73// //
75
76//---------------------------------------------------------
77#include "table.h"
78#include "grid_pyramid.h"
79
80
82// //
83// Grid File //
84// //
86
87//---------------------------------------------------------
98
99//---------------------------------------------------------
121
122//---------------------------------------------------------
124{
125 SG_T("NAME"),
126 SG_T("DESCRIPTION"),
127 SG_T("UNIT"),
128 SG_T("DATAFILE_NAME"),
129 SG_T("DATAFILE_OFFSET"),
130 SG_T("DATAFORMAT"),
131 SG_T("BYTEORDER_BIG"),
132 SG_T("POSITION_XMIN"),
133 SG_T("POSITION_YMIN"),
134 SG_T("CELLCOUNT_X"),
135 SG_T("CELLCOUNT_Y"),
136 SG_T("CELLSIZE"),
137 SG_T("Z_FACTOR"),
138 SG_T("Z_OFFSET"),
139 SG_T("NODATA_VALUE"),
140 SG_T("TOPTOBOTTOM")
141};
142
143//---------------------------------------------------------
144#define GRID_FILE_KEY_TRUE SG_T("TRUE")
145#define GRID_FILE_KEY_FALSE SG_T("FALSE")
146
147
149// //
150// //
151// //
153
154//---------------------------------------------------------
177
178// deprecated, for backward compatibility only >>
179#define GRID_RESAMPLING_NearestNeighbour CSG_Grid_Resampling::NearestNeighbour
180#define GRID_RESAMPLING_Bilinear CSG_Grid_Resampling::Bilinear
181#define GRID_RESAMPLING_BicubicSpline CSG_Grid_Resampling::Bicubic_1
182#define GRID_RESAMPLING_BSpline CSG_Grid_Resampling::Bicubic_2
183#define GRID_RESAMPLING_Mean_Nodes CSG_Grid_Resampling::Mean_Nodes
184#define GRID_RESAMPLING_Mean_Cells CSG_Grid_Resampling::Mean_Cells
185#define GRID_RESAMPLING_Minimum CSG_Grid_Resampling::Minimum
186#define GRID_RESAMPLING_Maximum CSG_Grid_Resampling::Maximum
187#define GRID_RESAMPLING_Majority CSG_Grid_Resampling::Majority
188#define GRID_RESAMPLING_Undefined CSG_Grid_Resampling::Undefined
189#define TSG_Grid_Resampling CSG_Grid_Resampling
190// << deprecated, for backward compatibility only
191
192//---------------------------------------------------------
201
202
204// //
205// CSG_Grid_System //
206// //
208
209//---------------------------------------------------------
218//---------------------------------------------------------
220{
221public:
222 CSG_Grid_System(void);
223
224 CSG_Grid_System (const CSG_Grid_System &System, int Precision = -1);
225 bool Create (const CSG_Grid_System &System, int Precision = -1);
226
227 CSG_Grid_System (double Cellsize, const CSG_Rect &Extent, int Precision = -1);
228 bool Create (double Cellsize, const CSG_Rect &Extent, int Precision = -1);
229
230 CSG_Grid_System (double Cellsize, double xMin, double yMin, double xMax, double yMax, int Precision = -1);
231 bool Create (double Cellsize, double xMin, double yMin, double xMax, double yMax, int Precision = -1);
232
233 CSG_Grid_System (double Cellsize, double xMin, double yMin, int NX, int NY, int Precision = -1);
234 bool Create (double Cellsize, double xMin, double yMin, int NX, int NY, int Precision = -1);
235
236 CSG_Grid_System (const CSG_String &System, int Precision = -1);
237 bool Create (const CSG_String &System, int Precision = -1);
238
239 ~CSG_Grid_System(void);
240
241 bool Destroy (void);
242
243 //-----------------------------------------------------
244 bool Assign (const CSG_Grid_System &System);
245 bool Assign (double Cellsize, const CSG_Rect &Extent);
246 bool Assign (double Cellsize, double xMin, double yMin, double xMax, double yMax);
247 bool Assign (double Cellsize, double xMin, double yMin, int NX, int NY);
248
249 //-----------------------------------------------------
250 bool is_Valid (void) const;
251
252 const SG_Char * Get_Name (bool bShort = true);
253 const SG_Char * asString (void);
254
255 double Get_Cellsize (void) const { return( m_Cellsize ); }
256 double Get_Cellarea (void) const { return( m_Cellarea ); }
257
258 int Get_NX (void) const { return( m_NX ); }
259 int Get_NY (void) const { return( m_NY ); }
260 sLong Get_NCells (void) const { return( m_NCells ); }
261
262 const CSG_Rect & Get_Extent (bool bCells = false) const { return( bCells ? m_Extent_Cells : m_Extent ); }
263
264 double Get_XMin (bool bCells = false) const { return( bCells ? m_Extent_Cells.Get_XMin () : m_Extent.Get_XMin () ); }
265 double Get_XMax (bool bCells = false) const { return( bCells ? m_Extent_Cells.Get_XMax () : m_Extent.Get_XMax () ); }
266 double Get_XRange (bool bCells = false) const { return( bCells ? m_Extent_Cells.Get_XRange() : m_Extent.Get_XRange() ); }
267
268 double Get_YMin (bool bCells = false) const { return( bCells ? m_Extent_Cells.Get_YMin () : m_Extent.Get_YMin () ); }
269 double Get_YMax (bool bCells = false) const { return( bCells ? m_Extent_Cells.Get_YMax () : m_Extent.Get_YMax () ); }
270 double Get_YRange (bool bCells = false) const { return( bCells ? m_Extent_Cells.Get_YRange() : m_Extent.Get_YRange() ); }
271
272
273 //-----------------------------------------------------
274 CSG_Grid_System & operator = (const CSG_Grid_System &System);
275
276 bool operator == (const CSG_Grid_System *pSystem) const;
277 bool operator != (const CSG_Grid_System *pSystem) const;
278 bool operator == (const CSG_Grid_System &System) const;
279 bool operator != (const CSG_Grid_System &System) const;
280
281 bool is_Equal (const CSG_Grid_System &System) const;
282 bool is_Equal (double Cellsize, const TSG_Rect &Extent) const;
283
284
285 //-----------------------------------------------------
287 double Fit_xto_Grid_System (double x) const { return( Get_XMin() + m_Cellsize * Get_xWorld_to_Grid(x) ); }
288
290 double Fit_yto_Grid_System (double y) const { return( Get_YMin() + m_Cellsize * Get_yWorld_to_Grid(y) ); }
291
294 {
295 ptWorld.x = Fit_xto_Grid_System(ptWorld.x);
296 ptWorld.y = Fit_yto_Grid_System(ptWorld.y);
297
298 return( ptWorld );
299 }
300
301
302 //-----------------------------------------------------
303 double Get_xGrid_to_World (int xGrid) const { return( Get_XMin() + xGrid * m_Cellsize ); }
304 double Get_yGrid_to_World (int yGrid) const { return( Get_YMin() + yGrid * m_Cellsize ); }
305
306 TSG_Point Get_Grid_to_World (int xGrid, int yGrid) const
307 {
308 TSG_Point pt;
309
310 pt.x = Get_xGrid_to_World(xGrid);
311 pt.y = Get_yGrid_to_World(yGrid);
312
313 return( pt );
314 }
315
316
317 //-----------------------------------------------------
318 int Get_xWorld_to_Grid (double xWorld) const { return( (int)floor(0.5 + (xWorld - Get_XMin()) / m_Cellsize) ); }
319 int Get_yWorld_to_Grid (double yWorld) const { return( (int)floor(0.5 + (yWorld - Get_YMin()) / m_Cellsize) ); }
320
321 bool Get_World_to_Grid (int &xGrid, int &yGrid, double xWorld, double yWorld) const
322 {
323 return( is_InGrid(xGrid = Get_xWorld_to_Grid(xWorld), yGrid = Get_yWorld_to_Grid(yWorld)) );
324 }
325
326 bool Get_World_to_Grid (int &xGrid, int &yGrid, TSG_Point ptWorld) const
327 {
328 return( is_InGrid(xGrid = Get_xWorld_to_Grid(ptWorld.x), yGrid = Get_yWorld_to_Grid(ptWorld.y)) );
329 }
330
331
332 //-----------------------------------------------------
333 bool Get_Neighbor_Pos (int Direction, int x, int y, int &xPos, int &yPos) const
334 {
335 return( is_InGrid(xPos = Get_xTo(Direction, x), yPos = Get_yTo(Direction, y)) );
336 }
337
338 static int Get_xTo (int Direction, int x = 0)
339 {
340 static int ix[8] = { 0, 1, 1, 1, 0,-1,-1,-1 };
341
342 Direction %= 8;
343
344 if( Direction < 0 )
345 {
346 Direction += 8;
347 }
348
349 return( x + ix[Direction] );
350 }
351
352 static int Get_yTo (int Direction, int y = 0)
353 {
354 static int iy[8] = { 1, 1, 0,-1,-1,-1, 0, 1 };
355
356 Direction %= 8;
357
358 if( Direction < 0 )
359 {
360 Direction += 8;
361 }
362
363 return( y + iy[Direction] );
364 }
365
366 static int Get_xFrom (int Direction, int x = 0) { return( Get_xTo(Direction + 4, x) ); }
367 static int Get_yFrom (int Direction, int y = 0) { return( Get_yTo(Direction + 4, y) ); }
368
369 int Get_xToSave (int Direction, int x) const { return( (x = Get_xTo (Direction, x)) < 0 ? 0 : (x >= m_NX ? m_NX - 1 : x) ); }
370 int Get_yToSave (int Direction, int y) const { return( (y = Get_yTo (Direction, y)) < 0 ? 0 : (y >= m_NY ? m_NY - 1 : y) ); }
371 int Get_xFromSave (int Direction, int x) const { return( (x = Get_xFrom(Direction, x)) < 0 ? 0 : (x >= m_NX ? m_NX - 1 : x) ); }
372 int Get_yFromSave (int Direction, int y) const { return( (y = Get_yFrom(Direction, y)) < 0 ? 0 : (y >= m_NY ? m_NY - 1 : y) ); }
373
374 bool is_InGrid (int x, int y) const { return( x >= 0 && x < m_NX && y >= 0 && y < m_NY ); }
375 bool is_InGrid (int x, int y, int Rand) const { return( x >= Rand && x < m_NX - Rand && y >= Rand && y < m_NY - Rand ); }
376
377 double Get_Length (int Direction) const { return( Direction % 2 ? m_Diagonal : m_Cellsize ); }
378 static double Get_UnitLength (int Direction) { return( Direction % 2 ? sqrt(2.) : 1. ); }
379
380 static int Set_Precision (int Decimals);
381 static int Get_Precision (void);
382
383 sLong Get_IndexFromRowCol (int x, int y) const
384 {
385 if( m_NX > 0 )
386 {
387 return( (sLong)y * m_NX + x );
388 }
389
390 return( -1 );
391 }
392
393 bool Get_RowColFromIndex (int &x, int &y, sLong i) const
394 {
395 if( m_NX > 0 )
396 {
397 x = (int)(i % m_NX);
398 y = (int)(i / m_NX);
399
400 return( true );
401 }
402
403 return( false );
404 }
405
406
407private:
408
409 int m_NX, m_NY;
410
411 sLong m_NCells;
412
413 double m_Cellsize, m_Cellarea, m_Diagonal;
414
415 CSG_Rect m_Extent, m_Extent_Cells;
416
417 CSG_String m_Name;
418
419 static int m_Precision;
420
421};
422
423
425// //
426// CSG_Grid //
427// //
429
430//---------------------------------------------------------
434//---------------------------------------------------------
436{
437//---------------------------------------------------------
438public:
439
440 //-----------------------------------------------------
441 CSG_Grid_File_Info(void);
442
444 bool Create (const CSG_Grid_File_Info &Info);
445
446 CSG_Grid_File_Info (const CSG_String &File);
447 bool Create (const CSG_String &File);
448
450 bool Create (CSG_File &Stream);
451
452 CSG_Grid_File_Info (const CSG_Grid &Grid);
453 bool Create (const CSG_Grid &Grid);
454
455 bool Save (const CSG_String &File , bool bBinary = true);
456 bool Save (const CSG_File &Stream, bool bBinary = true);
457
458 static bool Save (const CSG_String &File , const CSG_Grid &Grid, bool bBinary = true);
459 static bool Save (const CSG_File &Stream, const CSG_Grid &Grid, bool bBinary = true);
460
461 bool Save_AUX_XML (const CSG_String &File);
462 bool Save_AUX_XML (CSG_File &Stream);
463
464 //-----------------------------------------------------
466
468
470
472
474
476
478
479
480private:
481
482 void _On_Construction (void);
483
484 int _Get_Key (CSG_File &Stream, CSG_String &Line);
485
486};
487
488
490// //
491// CSG_Grid //
492// //
494
495//---------------------------------------------------------
499//---------------------------------------------------------
501{
502//---------------------------------------------------------
503public:
504
505 //-----------------------------------------------------
506 CSG_Grid(void);
507
508 CSG_Grid (const CSG_Grid &Grid);
509 bool Create (const CSG_Grid &Grid);
510
511 CSG_Grid (const CSG_String &File , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false, bool bLoadData = true);
512 bool Create (const CSG_String &File , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false, bool bLoadData = true);
513 CSG_Grid (const char *File , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false, bool bLoadData = true);
514 bool Create (const char *File , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false, bool bLoadData = true);
515 CSG_Grid (const wchar_t *File , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false, bool bLoadData = true);
516 bool Create (const wchar_t *File , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false, bool bLoadData = true);
517
518 CSG_Grid (CSG_Grid *pGrid , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false);
519 bool Create (CSG_Grid *pGrid , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false);
520
521 CSG_Grid (const CSG_Grid_System &System, TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false);
522 bool Create (const CSG_Grid_System &System, TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false);
523
524 CSG_Grid (TSG_Data_Type Type, int NX, int NY, double Cellsize = 1., double xMin = 0., double yMin = 0., bool bCached = false);
525 bool Create (TSG_Data_Type Type, int NX, int NY, double Cellsize = 1., double xMin = 0., double yMin = 0., bool bCached = false);
526
527
528 //-----------------------------------------------------
529 virtual ~CSG_Grid(void);
530
531 virtual bool Destroy (void);
532
533
534 //-----------------------------------------------------
535 virtual bool Save (const char *File, int Format = 0) { return( Save(CSG_String(File), Format) ); }
536 virtual bool Save (const wchar_t *File, int Format = 0) { return( Save(CSG_String(File), Format) ); }
537 virtual bool Save (const CSG_String &File, int Format = 0);
538
539 //-----------------------------------------------------
543
544 //-----------------------------------------------------
545 // Data-Info...
546
547 TSG_Data_Type Get_Type (void) const { return( m_Type ); }
548
549 int Get_nValueBytes (void) const { return( (int)m_nBytes_Value ); }
550 int Get_nLineBytes (void) const { return( (int)m_nBytes_Line ); }
551
552 void Set_Unit (const CSG_String &Unit);
553 const CSG_String & Get_Unit (void) const { return( m_Unit ); }
554
555
556 //-----------------------------------------------------
557 // Georeference...
558
559 const CSG_Grid_System & Get_System (void) const { return( m_System ); }
560
561 virtual const CSG_Rect & Get_Extent (void) { return( m_System.Get_Extent() ); }
562
563 int Get_NX (void) const { return( m_System.Get_NX() ); }
564 int Get_NY (void) const { return( m_System.Get_NY() ); }
565 sLong Get_NCells (void) const { return( m_System.Get_NCells() ); }
566
567 double Get_Cellsize (void) const { return( m_System.Get_Cellsize() ); }
568 double Get_Cellarea (void) const { return( m_System.Get_Cellarea() ); }
569
570 const CSG_Rect & Get_Extent (bool bCells = false) const { return( m_System.Get_Extent(bCells) ); }
571
572 double Get_XMin (bool bCells = false) const { return( m_System.Get_XMin (bCells) ); }
573 double Get_XMax (bool bCells = false) const { return( m_System.Get_XMax (bCells) ); }
574 double Get_XRange (bool bCells = false) const { return( m_System.Get_XRange(bCells) ); }
575
576 double Get_YMin (bool bCells = false) const { return( m_System.Get_YMin (bCells) ); }
577 double Get_YMax (bool bCells = false) const { return( m_System.Get_YMax (bCells) ); }
578 double Get_YRange (bool bCells = false) const { return( m_System.Get_YRange(bCells) ); }
579
580
581 //-----------------------------------------------------
582 // Values...
583
584 void Set_Scaling (double Scale = 1., double Offset = 0.);
585 double Get_Scaling (void) const;
586 double Get_Offset (void) const;
587 bool is_Scaled (void) const { return( m_zScale != 1. || m_zOffset != 0. ); }
588
589 double Get_Mean (void);
590 double Get_Min (void);
591 double Get_Max (void);
592 double Get_Range (void);
593 double Get_StdDev (void);
594 double Get_Variance (void);
595 double Get_Quantile (double Quantile, bool bFromHistogram = true);
596 double Get_Percentile (double Percentile, bool bFromHistogram = true);
597
598 const CSG_Simple_Statistics & Get_Statistics (void);
599 bool Get_Statistics (const CSG_Rect &rWorld, CSG_Simple_Statistics &Statistics, bool bHoldValues = false) const;
600
601 const CSG_Histogram & Get_Histogram (size_t nClasses = 0);
602 bool Get_Histogram (const CSG_Rect &rWorld, CSG_Histogram &Histogram, size_t nClasses = 0) const;
603
604 sLong Get_Data_Count (void);
605 sLong Get_NoData_Count (void);
606
607
608 //-----------------------------------------------------
609 // Checks...
610
611 virtual bool is_Valid (void) const;
612
613 TSG_Intersection is_Intersecting (const CSG_Rect &Extent) const;
614 TSG_Intersection is_Intersecting (const TSG_Rect &Extent) const;
615 TSG_Intersection is_Intersecting (double xMin, double yMin, double xMax, double yMax) const;
616
617 bool is_Compatible (CSG_Grid *pGrid) const;
618 bool is_Compatible (const CSG_Grid_System &System) const;
619 bool is_Compatible (int NX, int NY, double Cellsize, double xMin, double yMin) const;
620
621 bool is_InGrid (int x, int y, bool bCheckNoData = true) const { return( m_System.is_InGrid(x, y) && (!bCheckNoData || !is_NoData(x, y)) ); }
622 bool is_InGrid_byPos (double x, double y, bool bCheckNoData = true) const { return( Get_Extent(true).Contains(x, y) && (!bCheckNoData || !is_NoData(m_System.Get_xWorld_to_Grid(x), m_System.Get_yWorld_to_Grid(y))) ); }
623 bool is_InGrid_byPos (const TSG_Point &p, bool bCheckNoData = true) const { return( is_InGrid_byPos(p.x, p.y, bCheckNoData) ); }
624
625
626 //-----------------------------------------------------
627 // Memory...
628
629 sLong Get_Memory_Size (void) const { return( Get_NCells() * Get_nValueBytes() ); }
630 double Get_Memory_Size_MB (void) const { return( (double)Get_Memory_Size() / N_MEGABYTE_BYTES ); }
631
632 bool Set_Cache (bool bOn);
633 bool is_Cached (void) const { return( m_Cache_Stream != NULL ); }
634
635
636 //-----------------------------------------------------
637 // Operations...
638
639 bool Assign_NoData (void);
640
641 virtual bool Assign (double Value = 0.);
642 virtual bool Assign (CSG_Data_Object *pObject , bool bProgress = false);
643 virtual bool Assign (CSG_Grid *pGrid, CSG_Grid_Resampling Method, bool bProgress = false);
644
645 void Flip (void);
646 void Mirror (void);
647 void Invert (void);
648
649 bool Normalise (void);
650 bool DeNormalise (double Minimum, double Maximum);
651
652 bool Standardise (void);
653 bool DeStandardise (double Mean, double StdDev);
654
655 int Get_Gradient_NeighborDir (int x, int y, bool bDown = true, bool bNoEdges = true) const;
656 bool Get_Gradient (int x, int y , double &Slope, double &Aspect) const;
657 bool Get_Gradient (double x, double y, double &Slope, double &Aspect, CSG_Grid_Resampling Interpolation) const;
658 bool Get_Gradient (const TSG_Point &p, double &Slope, double &Aspect, CSG_Grid_Resampling Interpolation) const;
659
660
661 //-----------------------------------------------------
662 // Set update flag when modified...
663
664 virtual void Set_Modified (bool bModified = true)
665 {
667
668 if( bModified )
669 {
671 }
672 }
673
674
675 //-----------------------------------------------------
676 // Index...
677
678 bool Set_Index (bool bOn = true)
679 {
680 if( !bOn )
681 {
682 SG_FREE_SAFE(m_Index);
683
684 return( true );
685 }
686
687 return( _Get_Index() );
688 }
689
690 sLong Get_Sorted (sLong Position, bool bDown = true, bool bCheckNoData = true)
691 {
692 if( Position >= 0 && Position < Get_NCells() && _Get_Index() )
693 {
694 Position = m_Index[bDown ? Get_NCells() - Position - 1 : Position];
695
696 if( !bCheckNoData || !is_NoData(Position) )
697 {
698 return( Position );
699 }
700 }
701
702 return( -1 );
703 }
704
705 bool Get_Sorted (sLong Position, sLong &i, bool bDown = true, bool bCheckNoData = true)
706 {
707 return( (i = Get_Sorted(Position, bDown, bCheckNoData)) >= 0 );
708 }
709
710 bool Get_Sorted (sLong Position, int &x, int &y, bool bDown = true, bool bCheckNoData = true)
711 {
712 if( (Position = Get_Sorted(Position, bDown, bCheckNoData)) >= 0 )
713 {
714 x = (int)(Position % Get_NX());
715 y = (int)(Position / Get_NX());
716
717 return( true );
718 }
719
720 return( false );
721 }
722
723
724 //-----------------------------------------------------
725 // No Data Value...
726
727 virtual bool is_NoData (int x, int y) const { return( is_NoData_Value(asDouble(x, y, false)) ); }
728 virtual bool is_NoData (sLong i) const { return( is_NoData_Value(asDouble( i, false)) ); }
729
730 virtual void Set_NoData (int x, int y) { Set_Value(x, y, Get_NoData_Value(), false); }
731 virtual void Set_NoData (sLong i) { Set_Value( i, Get_NoData_Value(), false); }
732
733
734 //-----------------------------------------------------
735 // Operators...
736
737 virtual CSG_Grid & operator = (const CSG_Grid &Grid);
738 virtual CSG_Grid & operator = (double Value);
739
740 virtual CSG_Grid operator + (const CSG_Grid &Grid) const;
741 virtual CSG_Grid operator + (double Value) const;
742 virtual CSG_Grid & operator += (const CSG_Grid &Grid);
743 virtual CSG_Grid & operator += (double Value);
744 virtual CSG_Grid & Add (const CSG_Grid &Grid);
745 virtual CSG_Grid & Add (double Value);
746
747 virtual CSG_Grid operator - (const CSG_Grid &Grid) const;
748 virtual CSG_Grid operator - (double Value) const;
749 virtual CSG_Grid & operator -= (const CSG_Grid &Grid);
750 virtual CSG_Grid & operator -= (double Value);
751 virtual CSG_Grid & Subtract (const CSG_Grid &Grid);
752 virtual CSG_Grid & Subtract (double Value);
753
754 virtual CSG_Grid operator * (const CSG_Grid &Grid) const;
755 virtual CSG_Grid operator * (double Value) const;
756 virtual CSG_Grid & operator *= (const CSG_Grid &Grid);
757 virtual CSG_Grid & operator *= (double Value);
758 virtual CSG_Grid & Multiply (const CSG_Grid &Grid);
759 virtual CSG_Grid & Multiply (double Value);
760
761 virtual CSG_Grid operator / (const CSG_Grid &Grid) const;
762 virtual CSG_Grid operator / (double Value) const;
763 virtual CSG_Grid & operator /= (const CSG_Grid &Grid);
764 virtual CSG_Grid & operator /= (double Value);
765 virtual CSG_Grid & Divide (const CSG_Grid &Grid);
766 virtual CSG_Grid & Divide (double Value);
767
768 virtual double operator () (int x, int y) const { return( asDouble(x, y) ); }
769
770
771 //-----------------------------------------------------
772 // Get Value...
773
774 double Get_Value (double x, double y, CSG_Grid_Resampling Resampling = CSG_Grid_Resampling::Bicubic_2 , bool bByteWise = false) const;
775 double Get_Value (const TSG_Point &p, CSG_Grid_Resampling Resampling = CSG_Grid_Resampling::Bicubic_2 , bool bByteWise = false) const;
776 bool Get_Value (double x, double y, double &Value, CSG_Grid_Resampling Resampling = CSG_Grid_Resampling::Bicubic_2, bool bNoData = false, bool bByteWise = false) const;
777 bool Get_Value (const TSG_Point &p, double &Value, CSG_Grid_Resampling Resampling = CSG_Grid_Resampling::Bicubic_2, bool bNoData = false, bool bByteWise = false) const;
778
779 virtual BYTE asByte (int x, int y, bool bScaled = true) const { return( SG_ROUND_TO_BYTE (asDouble(x, y, bScaled)) ); }
780 virtual BYTE asByte ( sLong i, bool bScaled = true) const { return( SG_ROUND_TO_BYTE (asDouble( i, bScaled)) ); }
781 virtual char asChar (int x, int y, bool bScaled = true) const { return( SG_ROUND_TO_CHAR (asDouble(x, y, bScaled)) ); }
782 virtual char asChar ( sLong i, bool bScaled = true) const { return( SG_ROUND_TO_CHAR (asDouble( i, bScaled)) ); }
783 virtual short asShort (int x, int y, bool bScaled = true) const { return( SG_ROUND_TO_SHORT(asDouble(x, y, bScaled)) ); }
784 virtual short asShort ( sLong i, bool bScaled = true) const { return( SG_ROUND_TO_SHORT(asDouble( i, bScaled)) ); }
785 virtual int asInt (int x, int y, bool bScaled = true) const { return( SG_ROUND_TO_INT (asDouble(x, y, bScaled)) ); }
786 virtual int asInt ( sLong i, bool bScaled = true) const { return( SG_ROUND_TO_INT (asDouble( i, bScaled)) ); }
787 virtual sLong asLong (int x, int y, bool bScaled = true) const { return( SG_ROUND_TO_SLONG(asDouble(x, y, bScaled)) ); }
788 virtual sLong asLong ( sLong i, bool bScaled = true) const { return( SG_ROUND_TO_SLONG(asDouble( i, bScaled)) ); }
789 virtual float asFloat (int x, int y, bool bScaled = true) const { return( (float) (asDouble(x, y, bScaled)) ); }
790 virtual float asFloat ( sLong i, bool bScaled = true) const { return( (float) (asDouble( i, bScaled)) ); }
791
792 //-----------------------------------------------------
793 virtual double asDouble( sLong i, bool bScaled = true) const
794 {
795 return( asDouble((int)(i % Get_NX()), (int)(i / Get_NX()), bScaled) );
796 }
797
798 virtual double asDouble(int x, int y, bool bScaled = true) const
799 {
800 double Value;
801
802 if( is_Cached() )
803 {
804 Value = _Cache_Get_Value(x, y);
805 }
806 else switch( m_Type )
807 {
808 case SG_DATATYPE_Float : Value = (double)((float **)m_Values)[y][x]; break;
809 case SG_DATATYPE_Double: Value = (double)((double **)m_Values)[y][x]; break;
810 case SG_DATATYPE_Byte : Value = (double)((BYTE **)m_Values)[y][x]; break;
811 case SG_DATATYPE_Char : Value = (double)((char **)m_Values)[y][x]; break;
812 case SG_DATATYPE_Word : Value = (double)((WORD **)m_Values)[y][x]; break;
813 case SG_DATATYPE_Short : Value = (double)((short **)m_Values)[y][x]; break;
814 case SG_DATATYPE_DWord : Value = (double)((DWORD **)m_Values)[y][x]; break;
815 case SG_DATATYPE_Int : Value = (double)((int **)m_Values)[y][x]; break;
816 case SG_DATATYPE_Long : Value = (double)((sLong **)m_Values)[y][x]; break;
817 case SG_DATATYPE_ULong : Value = (double)((uLong **)m_Values)[y][x]; break;
818 case SG_DATATYPE_Bit : Value = (double)(((BYTE **)m_Values)[y][x / 8] & m_Bitmask[x % 8]) == 0 ? 0. : 1.; break;
819
820 default:
821 return( 0. );
822 }
823
824 if( bScaled && is_Scaled() )
825 {
826 Value = m_zOffset + m_zScale * Value;
827 }
828
829 return( Value );
830 }
831
832
833 //-----------------------------------------------------
834 // Set Value...
835
836 virtual void Add_Value(int x, int y, double Value) { Set_Value(x, y, asDouble(x, y) + Value ); }
837 virtual void Add_Value(sLong i, double Value) { Set_Value( i, asDouble( i) + Value ); }
838
839 virtual void Mul_Value(int x, int y, double Value) { Set_Value(x, y, asDouble(x, y) * Value ); }
840 virtual void Mul_Value(sLong i, double Value) { Set_Value( i, asDouble( i) * Value ); }
841
842 //-----------------------------------------------------
843 virtual void Set_Value(sLong i, double Value, bool bScaled = true)
844 {
845 Set_Value((int)(i % Get_NX()), (int)(i / Get_NX()), Value, bScaled);
846 }
847
848 virtual void Set_Value(int x, int y, double Value, bool bScaled = true)
849 {
850 if( bScaled && is_Scaled() )
851 {
852 Value = (Value - m_zOffset) / m_zScale;
853 }
854
855 if( is_Cached() )
856 {
857 _Cache_Set_Value(x, y, Value);
858 }
859 else switch( m_Type )
860 {
861 case SG_DATATYPE_Float : ((float **)m_Values)[y][x] = (float )(Value); break;
862 case SG_DATATYPE_Double: ((double **)m_Values)[y][x] = (double )(Value); break;
863 case SG_DATATYPE_Byte : ((BYTE **)m_Values)[y][x] = SG_ROUND_TO_BYTE (Value); break;
864 case SG_DATATYPE_Char : ((char **)m_Values)[y][x] = SG_ROUND_TO_CHAR (Value); break;
865 case SG_DATATYPE_Word : ((WORD **)m_Values)[y][x] = SG_ROUND_TO_WORD (Value); break;
866 case SG_DATATYPE_Short : ((short **)m_Values)[y][x] = SG_ROUND_TO_SHORT(Value); break;
867 case SG_DATATYPE_DWord : ((DWORD **)m_Values)[y][x] = SG_ROUND_TO_DWORD(Value); break;
868 case SG_DATATYPE_Int : ((int **)m_Values)[y][x] = SG_ROUND_TO_INT (Value); break;
869 case SG_DATATYPE_Long : ((sLong **)m_Values)[y][x] = SG_ROUND_TO_SLONG(Value); break;
870 case SG_DATATYPE_ULong : ((uLong **)m_Values)[y][x] = SG_ROUND_TO_ULONG(Value); break;
871 case SG_DATATYPE_Bit : ((BYTE **)m_Values)[y][x / 8] = Value != 0.
872 ? ((BYTE **)m_Values)[y][x / 8] | m_Bitmask[x % 8]
873 : ((BYTE **)m_Values)[y][x / 8] & (~m_Bitmask[x % 8]);
874 break;
875
876 default:
877 return;
878 }
879
880 Set_Modified();
881 }
882
883 //-----------------------------------------------------
884 CSG_Vector Get_Row (int y) const;
885 bool Set_Row (int y, const CSG_Vector &Values);
886
887
888//---------------------------------------------------------
889protected:
890
891 virtual bool On_Update (void);
892 virtual bool On_Reload (void);
893 virtual bool On_Delete (void);
894
895
896//---------------------------------------------------------
897private:
898
899 void **m_Values;
900
901 bool m_Cache_bTemp, m_Cache_bSwap, m_Cache_bFlip;
902
903 size_t m_nBytes_Value, m_nBytes_Line;
904
905 sLong *m_Index, m_Cache_Offset;
906
907 double m_zOffset, m_zScale;
908
909 FILE *m_Cache_Stream;
910
911 TSG_Data_Type m_Type;
912
913 CSG_String m_Unit, m_Cache_File;
914
915 CSG_Simple_Statistics m_Statistics;
916
917 CSG_Histogram m_Histogram;
918
919 CSG_Grid_System m_System;
920
921
922 //-----------------------------------------------------
923 static BYTE m_Bitmask[8];
924
925
926 //-----------------------------------------------------
927 void _On_Construction (void);
928
929 bool _Set_Index (void);
930 bool _Get_Index (void)
931 {
932 if( Get_Update_Flag() )
933 {
934 Update();
935 }
936
937 return( m_Index || _Set_Index() );
938 }
939
940
941 //-----------------------------------------------------
942 // Memory handling...
943
944 bool _Memory_Create (bool bCached);
945 void _Memory_Destroy (void);
946
947 bool _Array_Create (void);
948 void _Array_Destroy (void);
949
950 bool _Cache_Check (void);
951 bool _Cache_Create (const CSG_String &File, TSG_Data_Type Data_Type, sLong Offset, bool bSwap, bool bFlip);
952 bool _Cache_Create (void);
953 bool _Cache_Destroy (bool bMemory_Restore);
954 void _Cache_Set_Value (int x, int y, double Value);
955 double _Cache_Get_Value (int x, int y) const;
956
957
958 //-----------------------------------------------------
959 // File access...
960
961 void _Swap_Bytes (char *Bytes, int nBytes) const;
962
963 bool _Load_External (const CSG_String &File, bool bCached, bool bLoadData);
964 bool _Load_PGSQL (const CSG_String &File, bool bCached, bool bLoadData);
965
966 bool _Load_Native (const CSG_String &File, bool bCached, bool bLoadData);
967 bool _Save_Native (const CSG_String &File, TSG_Grid_File_Format Format);
968
969 bool _Load_Compressed (const CSG_String &File, bool bCached, bool bLoadData);
970 bool _Save_Compressed (const CSG_String &File);
971
972 bool _Load_Binary (CSG_File &Stream, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes);
973 bool _Save_Binary (CSG_File &Stream, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes);
974 bool _Load_ASCII (CSG_File &Stream, bool bCached, bool bFlip = false);
975 bool _Save_ASCII (CSG_File &Stream, bool bFlip = false);
976
977 bool _Load_Surfer (const CSG_String &File, bool bCached, bool bLoadData);
978
979
980 //-----------------------------------------------------
981 CSG_Grid & _Operation_Arithmetic (const CSG_Grid &Grid, TSG_Grid_Operation Operation);
982 CSG_Grid & _Operation_Arithmetic (double Value , TSG_Grid_Operation Operation);
983
984 bool _Assign_Interpolated (CSG_Grid *pSource, CSG_Grid_Resampling Interpolation, bool bProgress);
985 bool _Assign_MeanValue (CSG_Grid *pSource, bool bAreaProportional , bool bProgress);
986 bool _Assign_ExtremeValue (CSG_Grid *pSource, bool bMaximum , bool bProgress);
987 bool _Assign_Majority (CSG_Grid *pSource , bool bProgress);
988
989
990 //-----------------------------------------------------
991 // Interpolation subroutines...
992
993 bool _Get_ValAtPos_NearestNeighbour (double &Value, int x, int y, double dx, double dy ) const;
994 bool _Get_ValAtPos_BiLinear (double &Value, int x, int y, double dx, double dy, bool bByteWise) const;
995 bool _Get_ValAtPos_BiCubic_1 (double &Value, int x, int y, double dx, double dy, bool bByteWise) const;
996 bool _Get_ValAtPos_BiCubic_2 (double &Value, int x, int y, double dx, double dy, bool bByteWise) const;
997
998 double _Get_ValAtPos_BiCubic_1 (double dx, double dy, double z_xy[4][4]) const;
999 double _Get_ValAtPos_BiCubic_2 (double dx, double dy, double z_xy[4][4]) const;
1000
1001 bool _Get_ValAtPos_Fill4x4Submatrix (int x, int y, double z_xy[4][4] ) const;
1002 bool _Get_ValAtPos_Fill4x4Submatrix (int x, int y, double z_xy[4][4][4]) const;
1003
1004};
1005
1006
1008// //
1009// Functions //
1010// //
1012
1013//---------------------------------------------------------
1014#define SG_GRID_PTR_SAFE_SET_NODATA(g, x, y) { if( g && g->is_InGrid(x, y, false) ) { g->Set_NoData(x, y ); } }
1015#define SG_GRID_PTR_SAFE_SET_VALUE(g, x, y, z) { if( g && g->is_InGrid(x, y, false) ) { g->Set_Value (x, y, z); } }
1016
1017//---------------------------------------------------------
1020
1023
1025SAGA_API_DLL_EXPORT CSG_Grid * SG_Create_Grid (const char *File , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false, bool bLoadData = true);
1027SAGA_API_DLL_EXPORT CSG_Grid * SG_Create_Grid (const wchar_t *File , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false, bool bLoadData = true);
1029SAGA_API_DLL_EXPORT CSG_Grid * SG_Create_Grid (const CSG_String &File , TSG_Data_Type Type = SG_DATATYPE_Undefined, bool bCached = false, bool bLoadData = true);
1030
1033
1036
1038SAGA_API_DLL_EXPORT CSG_Grid * SG_Create_Grid (TSG_Data_Type Type, int NX, int NY, double Cellsize = 0., double xMin = 0., double yMin = 0., bool bCached = false);
1039
1040//---------------------------------------------------------
1043
1046
1049
1054
1055//---------------------------------------------------------
1059
1060
1062// //
1063// //
1064// //
1066
1067//---------------------------------------------------------
1069{
1070public:
1072
1073 //-----------------------------------------------------
1074 const TSG_Point_Int & operator [] (size_t i) const { return( *((TSG_Point_Int *)Get_Record(i)) ); }
1075
1076 //-----------------------------------------------------
1077 virtual bool Push (int x, int y)
1078 {
1080
1081 if( pPoint )
1082 {
1083 pPoint->x = x;
1084 pPoint->y = y;
1085
1086 return( true );
1087 }
1088
1089 return( false );
1090 }
1091
1092 //-----------------------------------------------------
1093 virtual bool Pop (int &x, int &y)
1094 {
1096
1097 if( pPoint )
1098 {
1099 x = pPoint->x;
1100 y = pPoint->y;
1101
1102 return( true );
1103 }
1104
1105 return( false );
1106 }
1107
1108};
1109
1110
1112// //
1113// //
1114// //
1116
1117//---------------------------------------------------------
1118#define SG_GRIDCELLADDR_PARM_SQUARE 0x01
1119#define SG_GRIDCELLADDR_PARM_CIRCLE 0x02
1120#define SG_GRIDCELLADDR_PARM_ANNULUS 0x04
1121#define SG_GRIDCELLADDR_PARM_SECTOR 0x08
1122#define SG_GRIDCELLADDR_PARM_SIZEDBL 0x10
1123#define SG_GRIDCELLADDR_PARM_MAPUNIT 0x20
1124#define SG_GRIDCELLADDR_PARM_WEIGHTING 0x40
1125#define SG_GRIDCELLADDR_PARM_DEFAULT (SG_GRIDCELLADDR_PARM_SQUARE|SG_GRIDCELLADDR_PARM_CIRCLE)
1126
1127//---------------------------------------------------------
1129{
1130public:
1132
1133 bool Destroy (void);
1134
1135 static bool Enable_Parameters (class CSG_Parameters &Parameters);
1136 static bool Add_Parameters (class CSG_Parameters &Parameters, const CSG_String &Parent = "", int Style = SG_GRIDCELLADDR_PARM_DEFAULT);
1137 bool Set_Parameters (class CSG_Parameters &Parameters, int Type = 0);
1138
1139 bool Set_Square (class CSG_Parameters &Parameters);
1140 bool Set_Circle (class CSG_Parameters &Parameters);
1141 bool Set_Annulus (class CSG_Parameters &Parameters);
1142 bool Set_Sector (class CSG_Parameters &Parameters);
1143
1144 CSG_Distance_Weighting & Get_Weighting (void) { return( m_Weighting ); }
1145
1146 bool is_Square (void) const { return( m_Type == 0 ); }
1147 bool is_Circle (void) const { return( m_Type == 1 ); }
1148 bool is_Annulus (void) const { return( m_Type == 2 ); }
1149 bool is_Sector (void) const { return( m_Type == 3 ); }
1150
1151 bool Set_Radius (double Radius, bool bSquare = false);
1152 bool Set_Square (double Radius);
1153 bool Set_Circle (double Radius);
1154 bool Set_Annulus (double Radius_Inner, double Radius_Outer);
1155 bool Set_Sector (double Radius, double Direction, double Tolerance);
1156
1157 double Get_Radius (bool bOuter = true) const { return( bOuter ? m_Radius : m_Radius_0 ); }
1158 double Get_Radius_Inner (void) const { return( m_Radius_0 ); }
1159 double Get_Radius_Outer (void) const { return( m_Radius ); }
1160 double Get_Direction (void) const { return( m_Direction ); }
1161 double Get_Tolerance (void) const { return( m_Tolerance ); }
1162
1163 int Get_Count (void) const { return( (int)m_Kernel.Get_Count() ); }
1164 int Get_X (int Index, int Offset = 0) const { return( Index >= 0 && Index < m_Kernel.Get_Count() ? m_Kernel[Index].asInt (0) + Offset : Offset ); }
1165 int Get_Y (int Index, int Offset = 0) const { return( Index >= 0 && Index < m_Kernel.Get_Count() ? m_Kernel[Index].asInt (1) + Offset : Offset ); }
1166 double Get_Distance (int Index ) const { return( Index >= 0 && Index < m_Kernel.Get_Count() ? m_Kernel[Index].asDouble(2) : -1. ); }
1167 double Get_Weight (int Index ) const { return( Index >= 0 && Index < m_Kernel.Get_Count() ? m_Kernel[Index].asDouble(3) : 0. ); }
1168 bool Get_Values (int Index, int &x, int &y, double &Distance, double &Weight, bool bOffset = false) const
1169 {
1170 if( Index >= 0 && Index < m_Kernel.Get_Count() )
1171 {
1172 CSG_Table_Record &Cell = m_Kernel[Index];
1173
1174 x = bOffset ? x + Cell.asInt(0) : Cell.asInt(0);
1175 y = bOffset ? y + Cell.asInt(1) : Cell.asInt(1);
1176 Distance = Cell.asDouble(2);
1177 Weight = Cell.asDouble(3);
1178
1179 return( true );
1180 }
1181
1182 return( false );
1183 }
1184
1185
1186private:
1187
1188 int m_Type;
1189
1190 double m_Radius, m_Radius_0, m_Direction, m_Tolerance;
1191
1192 CSG_Distance_Weighting m_Weighting;
1193
1194 CSG_Table m_Kernel;
1195
1196
1197 bool _Set_Kernel (int Type, double Radius, double Radius_Inner, double Direction, double Tolerance);
1198
1199};
1200
1201
1203// //
1204// //
1205// //
1207
1208//---------------------------------------------------------
1209#endif // #ifndef HEADER_INCLUDED__SAGA_API__grid_H
unsigned long long uLong
Definition api_core.h:159
signed long long sLong
Definition api_core.h:158
#define SG_T(s)
Definition api_core.h:537
#define SAGA_API_DLL_EXPORT
Definition api_core.h:94
#define SG_FREE_SAFE(PTR)
Definition api_core.h:205
TSG_Data_Type
Definition api_core.h:997
@ SG_DATATYPE_Long
Definition api_core.h:1006
@ SG_DATATYPE_Byte
Definition api_core.h:999
@ SG_DATATYPE_Bit
Definition api_core.h:998
@ SG_DATATYPE_Short
Definition api_core.h:1002
@ SG_DATATYPE_Word
Definition api_core.h:1001
@ SG_DATATYPE_ULong
Definition api_core.h:1005
@ SG_DATATYPE_Float
Definition api_core.h:1007
@ SG_DATATYPE_Undefined
Definition api_core.h:1013
@ SG_DATATYPE_Double
Definition api_core.h:1008
@ SG_DATATYPE_Int
Definition api_core.h:1004
@ SG_DATATYPE_Char
Definition api_core.h:1000
@ SG_DATATYPE_DWord
Definition api_core.h:1003
#define SG_Char
Definition api_core.h:536
SAGA_API_DLL_EXPORT CSG_String operator+(const char *A, const CSG_String &B)
bool is_NoData_Value(double Value) const
Definition dataobject.h:255
void Set_Update_Flag(bool bOn=true)
Definition dataobject.h:285
double Get_NoData_Value(bool bUpper=false) const
Definition dataobject.h:253
virtual void Set_Modified(bool bOn=true)
Definition dataobject.h:227
CSG_Distance_Weighting & Get_Weighting(void)
Definition grid.h:1144
bool is_Sector(void) const
Definition grid.h:1149
double Get_Radius(bool bOuter=true) const
Definition grid.h:1157
double Get_Distance(int Index) const
Definition grid.h:1166
double Get_Radius_Outer(void) const
Definition grid.h:1159
bool Set_Circle(class CSG_Parameters &Parameters)
bool Set_Annulus(class CSG_Parameters &Parameters)
int Get_Count(void) const
Definition grid.h:1163
int Get_X(int Index, int Offset=0) const
Definition grid.h:1164
double Get_Weight(int Index) const
Definition grid.h:1167
double Get_Direction(void) const
Definition grid.h:1160
double Get_Tolerance(void) const
Definition grid.h:1161
static bool Add_Parameters(class CSG_Parameters &Parameters, const CSG_String &Parent="", int Style=SG_GRIDCELLADDR_PARM_DEFAULT)
bool Set_Parameters(class CSG_Parameters &Parameters, int Type=0)
static bool Enable_Parameters(class CSG_Parameters &Parameters)
bool is_Square(void) const
Definition grid.h:1146
double Get_Radius_Inner(void) const
Definition grid.h:1158
bool is_Circle(void) const
Definition grid.h:1147
bool Set_Sector(class CSG_Parameters &Parameters)
bool is_Annulus(void) const
Definition grid.h:1148
bool Get_Values(int Index, int &x, int &y, double &Distance, double &Weight, bool bOffset=false) const
Definition grid.h:1168
int Get_Y(int Index, int Offset=0) const
Definition grid.h:1165
bool Set_Square(class CSG_Parameters &Parameters)
CSG_String m_Name
Definition grid.h:473
CSG_Grid_System m_System
Definition grid.h:475
bool m_bSwapBytes
Definition grid.h:465
TSG_Data_Type m_Type
Definition grid.h:471
bool Save(const CSG_String &File, bool bBinary=true)
Definition grid_io.cpp:1236
CSG_Projection m_Projection
Definition grid.h:477
double m_zScale
Definition grid.h:469
CSG_String m_Unit
Definition grid.h:473
CSG_String m_Data_File
Definition grid.h:473
bool Save_AUX_XML(const CSG_String &File)
Definition grid_io.cpp:1296
CSG_String m_Description
Definition grid.h:473
bool Create(const CSG_Grid_File_Info &Info)
Definition grid_io.cpp:1031
double m_zOffset
Definition grid.h:469
double m_NoData[2]
Definition grid.h:469
CSG_Grid_Stack(void)
Definition grid.h:1071
const TSG_Point_Int & operator[](size_t i) const
Definition grid.h:1074
virtual bool Push(int x, int y)
Definition grid.h:1077
virtual bool Pop(int &x, int &y)
Definition grid.h:1093
bool is_InGrid(int x, int y, int Rand) const
Definition grid.h:375
int Get_yFromSave(int Direction, int y) const
Definition grid.h:372
double Get_XMin(bool bCells=false) const
Definition grid.h:264
bool Destroy(void)
bool Get_RowColFromIndex(int &x, int &y, sLong i) const
Definition grid.h:393
bool Get_World_to_Grid(int &xGrid, int &yGrid, TSG_Point ptWorld) const
Definition grid.h:326
double Get_YMin(bool bCells=false) const
Definition grid.h:268
TSG_Point Get_Grid_to_World(int xGrid, int yGrid) const
Definition grid.h:306
int Get_xWorld_to_Grid(double xWorld) const
Definition grid.h:318
double Get_XRange(bool bCells=false) const
Definition grid.h:266
bool Get_Neighbor_Pos(int Direction, int x, int y, int &xPos, int &yPos) const
Definition grid.h:333
double Get_Cellsize(void) const
Definition grid.h:255
const SG_Char * Get_Name(bool bShort=true)
double Fit_xto_Grid_System(double x) const
Aligns the world coordinate x to the rows of the grid system and returns it.
Definition grid.h:287
int Get_yWorld_to_Grid(double yWorld) const
Definition grid.h:319
double Get_Length(int Direction) const
Definition grid.h:377
double Get_YRange(bool bCells=false) const
Definition grid.h:270
double Get_YMax(bool bCells=false) const
Definition grid.h:269
bool Get_World_to_Grid(int &xGrid, int &yGrid, double xWorld, double yWorld) const
Definition grid.h:321
int Get_NX(void) const
Definition grid.h:258
bool Assign(const CSG_Grid_System &System)
const SG_Char * asString(void)
double Fit_yto_Grid_System(double y) const
Aligns the world coordinate y to the columns of the grid system and returns it.
Definition grid.h:290
double Get_Cellarea(void) const
Definition grid.h:256
TSG_Point Fit_to_Grid_System(TSG_Point ptWorld) const
Aligns the world coordinate ptWorld to the rows and columns of the grid system and returns it.
Definition grid.h:293
static int Get_yTo(int Direction, int y=0)
Definition grid.h:352
static int Get_yFrom(int Direction, int y=0)
Definition grid.h:367
int Get_xToSave(int Direction, int x) const
Definition grid.h:369
static int Get_xTo(int Direction, int x=0)
Definition grid.h:338
sLong Get_NCells(void) const
Definition grid.h:260
const CSG_Rect & Get_Extent(bool bCells=false) const
Definition grid.h:262
double Get_XMax(bool bCells=false) const
Definition grid.h:265
sLong Get_IndexFromRowCol(int x, int y) const
Definition grid.h:383
static int Get_xFrom(int Direction, int x=0)
Definition grid.h:366
bool is_InGrid(int x, int y) const
Definition grid.h:374
static double Get_UnitLength(int Direction)
Definition grid.h:378
int Get_NY(void) const
Definition grid.h:259
bool Create(const CSG_Grid_System &System, int Precision=-1)
double Get_yGrid_to_World(int yGrid) const
Definition grid.h:304
bool is_Valid(void) const
int Get_xFromSave(int Direction, int x) const
Definition grid.h:371
double Get_xGrid_to_World(int xGrid) const
Definition grid.h:303
int Get_yToSave(int Direction, int y) const
Definition grid.h:370
int Get_NY(void) const
Definition grid.h:564
virtual int asInt(sLong i, bool bScaled=true) const
Definition grid.h:786
double Get_YMin(bool bCells=false) const
Definition grid.h:576
bool is_Cached(void) const
Definition grid.h:633
int Get_nValueBytes(void) const
Definition grid.h:549
double Get_XRange(bool bCells=false) const
Definition grid.h:574
bool Get_Sorted(sLong Position, int &x, int &y, bool bDown=true, bool bCheckNoData=true)
Definition grid.h:710
virtual bool Destroy(void)
Definition grid.cpp:379
double Get_YMax(bool bCells=false) const
Definition grid.h:577
virtual TSG_Data_Object_Type Get_ObjectType(void) const
Definition grid.h:542
bool Set_Index(bool bOn=true)
Definition grid.h:678
virtual int asInt(int x, int y, bool bScaled=true) const
Definition grid.h:785
double Get_Memory_Size_MB(void) const
Definition grid.h:630
double Get_XMin(bool bCells=false) const
Definition grid.h:572
double Get_YRange(bool bCells=false) const
Definition grid.h:578
virtual void Set_NoData(int x, int y)
Definition grid.h:730
virtual char asChar(int x, int y, bool bScaled=true) const
Definition grid.h:781
double Get_Cellsize(void) const
Definition grid.h:567
virtual bool is_NoData(sLong i) const
Definition grid.h:728
const CSG_Rect & Get_Extent(bool bCells=false) const
Definition grid.h:570
bool is_InGrid_byPos(const TSG_Point &p, bool bCheckNoData=true) const
Definition grid.h:623
virtual short asShort(int x, int y, bool bScaled=true) const
Definition grid.h:783
virtual void Mul_Value(int x, int y, double Value)
Definition grid.h:839
virtual bool is_NoData(int x, int y) const
Definition grid.h:727
virtual void Set_NoData(sLong i)
Definition grid.h:731
double Get_XMax(bool bCells=false) const
Definition grid.h:573
virtual void Set_Modified(bool bModified=true)
Definition grid.h:664
sLong Get_Sorted(sLong Position, bool bDown=true, bool bCheckNoData=true)
Definition grid.h:690
virtual float asFloat(sLong i, bool bScaled=true) const
Definition grid.h:790
virtual void Set_Value(int x, int y, double Value, bool bScaled=true)
Definition grid.h:848
virtual short asShort(sLong i, bool bScaled=true) const
Definition grid.h:784
CSG_Grid(void)
Definition grid.cpp:136
int Get_nLineBytes(void) const
Definition grid.h:550
const CSG_String & Get_Unit(void) const
Definition grid.h:553
virtual double asDouble(sLong i, bool bScaled=true) const
Definition grid.h:793
virtual double asDouble(int x, int y, bool bScaled=true) const
Definition grid.h:798
bool is_InGrid_byPos(double x, double y, bool bCheckNoData=true) const
Definition grid.h:622
virtual void Add_Value(int x, int y, double Value)
Definition grid.h:836
virtual BYTE asByte(int x, int y, bool bScaled=true) const
Definition grid.h:779
sLong Get_Memory_Size(void) const
Definition grid.h:629
virtual sLong asLong(sLong i, bool bScaled=true) const
Definition grid.h:788
virtual sLong asLong(int x, int y, bool bScaled=true) const
Definition grid.h:787
virtual bool Save(const wchar_t *File, int Format=0)
Definition grid.h:536
virtual BYTE asByte(sLong i, bool bScaled=true) const
Definition grid.h:780
virtual bool Save(const char *File, int Format=0)
Definition grid.h:535
virtual float asFloat(int x, int y, bool bScaled=true) const
Definition grid.h:789
sLong Get_NCells(void) const
Definition grid.h:565
virtual void Add_Value(sLong i, double Value)
Definition grid.h:837
bool Create(const CSG_Grid &Grid)
Definition grid.cpp:235
const CSG_Grid_System & Get_System(void) const
Definition grid.h:559
virtual const CSG_Rect & Get_Extent(void)
Definition grid.h:561
bool Get_Sorted(sLong Position, sLong &i, bool bDown=true, bool bCheckNoData=true)
Definition grid.h:705
int Get_NX(void) const
Definition grid.h:563
double Get_Cellarea(void) const
Definition grid.h:568
bool is_InGrid(int x, int y, bool bCheckNoData=true) const
Definition grid.h:621
bool is_Scaled(void) const
Definition grid.h:587
virtual void Set_Value(sLong i, double Value, bool bScaled=true)
Definition grid.h:843
virtual char asChar(sLong i, bool bScaled=true) const
Definition grid.h:782
virtual void Mul_Value(sLong i, double Value)
Definition grid.h:840
TSG_Data_Type Get_Type(void) const
Definition grid.h:547
void * Get_Record(size_t i) const
Definition api_core.h:955
void * Get_Record_Pop(void)
Definition api_core.h:965
void * Get_Record_Push(void)
Definition api_core.h:960
CSG_Stack(size_t RecordSize)
Definition api_core.h:935
double asDouble(int Field) const
int asInt(int Field) const
TSG_Data_Object_Type
Definition dataobject.h:117
@ SG_DATAOBJECT_TYPE_Grid
Definition dataobject.h:118
struct SSG_Point TSG_Point
struct SSG_Point_Int TSG_Point_Int
TSG_Intersection
Definition geo_tools.h:101
struct SSG_Rect TSG_Rect
SAGA_API_DLL_EXPORT void SG_Grid_Cache_Set_Mode(int Mode)
SAGA_API_DLL_EXPORT TSG_Grid_File_Format SG_Grid_Get_File_Format_Default(void)
Definition grid_io.cpp:123
SAGA_API_DLL_EXPORT void SG_Grid_Cache_Set_Threshold_MB(double nMegabytes)
SAGA_API_DLL_EXPORT double SG_Grid_Cache_Get_Threshold_MB(void)
SAGA_API_DLL_EXPORT bool SG_Grid_Set_File_Format_Default(int Format)
Definition grid_io.cpp:106
SAGA_API_DLL_EXPORT sLong SG_Grid_Cache_Get_Threshold(void)
SAGA_API_DLL_EXPORT int SG_Grid_Cache_Get_Mode(void)
SAGA_API_DLL_EXPORT void SG_Grid_Cache_Set_Threshold(int nBytes)
TSG_Grid_File_Key
Definition grid.h:101
@ GRID_FILE_KEY_DATAFORMAT
Definition grid.h:107
@ GRID_FILE_KEY_Count
Definition grid.h:118
@ GRID_FILE_KEY_CELLCOUNT_Y
Definition grid.h:112
@ GRID_FILE_KEY_DESCRIPTION
Definition grid.h:103
@ GRID_FILE_KEY_POSITION_YMIN
Definition grid.h:110
@ GRID_FILE_KEY_DATAFILE_OFFSET
Definition grid.h:106
@ GRID_FILE_KEY_NODATA_VALUE
Definition grid.h:116
@ GRID_FILE_KEY_UNITNAME
Definition grid.h:104
@ GRID_FILE_KEY_BYTEORDER_BIG
Definition grid.h:108
@ GRID_FILE_KEY_CELLSIZE
Definition grid.h:113
@ GRID_FILE_KEY_Z_FACTOR
Definition grid.h:114
@ GRID_FILE_KEY_Z_OFFSET
Definition grid.h:115
@ GRID_FILE_KEY_POSITION_XMIN
Definition grid.h:109
@ GRID_FILE_KEY_DATAFILE_NAME
Definition grid.h:105
@ GRID_FILE_KEY_CELLCOUNT_X
Definition grid.h:111
@ GRID_FILE_KEY_TOPTOBOTTOM
Definition grid.h:117
@ GRID_FILE_KEY_NAME
Definition grid.h:102
SAGA_API_DLL_EXPORT CSG_String SG_Grid_Get_File_Extension_Default(void)
Definition grid_io.cpp:129
TSG_Grid_File_Format
Definition grid.h:89
@ GRID_FILE_FORMAT_ASCII
Definition grid.h:93
@ GRID_FILE_FORMAT_Compressed
Definition grid.h:94
@ GRID_FILE_FORMAT_Binary_old
Definition grid.h:91
@ GRID_FILE_FORMAT_GeoTIFF
Definition grid.h:95
@ GRID_FILE_FORMAT_Binary
Definition grid.h:92
@ GRID_FILE_FORMAT_Undefined
Definition grid.h:90
SAGA_API_DLL_EXPORT CSG_Grid * SG_Create_Grid(void)
Definition grid.cpp:72
TSG_Grid_Operation
Definition grid.h:194
@ GRID_OPERATION_Multiplication
Definition grid.h:197
@ GRID_OPERATION_Division
Definition grid.h:198
@ GRID_OPERATION_Addition
Definition grid.h:195
@ GRID_OPERATION_Subtraction
Definition grid.h:196
const SG_Char gSG_Grid_File_Key_Names[GRID_FILE_KEY_Count][32]
Definition grid.h:123
SAGA_API_DLL_EXPORT void SG_Grid_Cache_Set_Directory(const SG_Char *Directory)
CSG_Grid_Resampling
Definition grid.h:156
#define SG_GRIDCELLADDR_PARM_DEFAULT
Definition grid.h:1125
SAGA_API_DLL_EXPORT const SG_Char * SG_Grid_Cache_Get_Directory(void)
CSG_Vector operator*(double Scalar, const CSG_Vector &Vector)
#define SG_ROUND_TO_INT(x)
Definition mat_tools.h:155
#define SG_ROUND_TO_CHAR(x)
Definition mat_tools.h:151
#define SG_ROUND_TO_ULONG(x)
Definition mat_tools.h:157
#define SG_ROUND_TO_BYTE(x)
Definition mat_tools.h:150
#define SG_ROUND_TO_SLONG(x)
Definition mat_tools.h:158
#define SG_ROUND_TO_WORD(x)
Definition mat_tools.h:152
#define N_MEGABYTE_BYTES
Definition mat_tools.h:115
#define SG_ROUND_TO_SHORT(x)
Definition mat_tools.h:153
#define SG_ROUND_TO_DWORD(x)
Definition mat_tools.h:154
double x
Definition geo_tools.h:129
double y
Definition geo_tools.h:129