1 
2 ///////////////////////////////////////////////////////////
3 //                                                       //
4 //                         SAGA                          //
5 //                                                       //
6 //      System for Automated Geoscientific Analyses      //
7 //                                                       //
8 //           Application Programming Interface           //
9 //                                                       //
10 //                  Library: SAGA_API                    //
11 //                                                       //
12 //-------------------------------------------------------//
13 //                                                       //
14 //                       shapes.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 Goettingen               //
44 //                Goldschmidtstr. 5                      //
45 //                37077 Goettingen                       //
46 //                Germany                                //
47 //                                                       //
48 //    e-mail:     oconrad@saga-gis.org                   //
49 //                                                       //
50 ///////////////////////////////////////////////////////////
51 
52 //---------------------------------------------------------
53 #ifndef HEADER_INCLUDED__SAGA_API__shapes_H
54 #define HEADER_INCLUDED__SAGA_API__shapes_H
55 
56 
57 ///////////////////////////////////////////////////////////
58 //														 //
59 //														 //
60 //														 //
61 ///////////////////////////////////////////////////////////
62 
63 //---------------------------------------------------------
64 /** \file shapes.h
65 * The vector data container, a specialized CSG_Table class
66 * following a geometry object based approach.
67 * @see CSG_Shapes
68 * @see CSG_Table
69 * @see CSG_Data_Object
70 */
71 
72 
73 ///////////////////////////////////////////////////////////
74 //														 //
75 //														 //
76 //														 //
77 ///////////////////////////////////////////////////////////
78 
79 //---------------------------------------------------------
80 #include "table.h"
81 
82 
83 ///////////////////////////////////////////////////////////
84 //														 //
85 //														 //
86 //														 //
87 ///////////////////////////////////////////////////////////
88 
89 //---------------------------------------------------------
90 typedef enum ESG_Vertex_Type
91 {
92 	SG_VERTEX_TYPE_XY		= 0,
93 	SG_VERTEX_TYPE_XYZ,
94 	SG_VERTEX_TYPE_XYZM
95 }
96 TSG_Vertex_Type;
97 
98 //---------------------------------------------------------
99 typedef enum ESG_Shape_Type
100 {
101 	SHAPE_TYPE_Undefined	= 0,
102 	SHAPE_TYPE_Point,
103 	SHAPE_TYPE_Points,
104 	SHAPE_TYPE_Line,
105 	SHAPE_TYPE_Polygon
106 }
107 TSG_Shape_Type;
108 
109 //---------------------------------------------------------
110 SAGA_API_DLL_EXPORT CSG_String	SG_Get_ShapeType_Name	(TSG_Shape_Type Type);
111 
112 //---------------------------------------------------------
113 typedef enum ESG_Shape_File_Format
114 {
115 	SHAPE_FILE_FORMAT_Undefined	= 0,
116 	SHAPE_FILE_FORMAT_ESRI,
117 	SHAPE_FILE_FORMAT_GeoPackage,
118 	SHAPE_FILE_FORMAT_GeoJSON
119 }
120 TSG_Shape_File_Format;
121 
122 
123 ///////////////////////////////////////////////////////////
124 //														 //
125 //														 //
126 //														 //
127 ///////////////////////////////////////////////////////////
128 
129 //---------------------------------------------------------
130 class SAGA_API_DLL_EXPORT CSG_Shape : public CSG_Table_Record
131 {
132 	friend class CSG_Shapes;
133 
134 public:
135 
136 	//-----------------------------------------------------
137 	virtual void				Destroy				(void);
138 
139 	virtual bool				Assign				(CSG_Shape *pShape);
140 	virtual bool				Assign				(CSG_Shape *pShape, bool bAssign_Attributes);
141 
142 	TSG_Shape_Type				Get_Type			(void)	const;
143 	TSG_Vertex_Type				Get_Vertex_Type		(void)	const;
144 
asPoint(void)145 	class CSG_Shape_Point   *	asPoint				(void)	{	return( Get_Type() == SHAPE_TYPE_Point   ? (CSG_Shape_Point   *)this : NULL );	}
asPoints(void)146 	class CSG_Shape_Points  *	asPoints			(void)	{	return( Get_Type() == SHAPE_TYPE_Points  ? (CSG_Shape_Points  *)this : NULL );	}
asLine(void)147 	class CSG_Shape_Line    *	asLine				(void)	{	return( Get_Type() == SHAPE_TYPE_Line    ? (CSG_Shape_Line    *)this : NULL );	}
asPolygon(void)148 	class CSG_Shape_Polygon *	asPolygon			(void)	{	return( Get_Type() == SHAPE_TYPE_Polygon ? (CSG_Shape_Polygon *)this : NULL );	}
149 
150 	virtual bool				is_Valid			(void)											= 0;
151 
152 	//-----------------------------------------------------
153 	virtual int					Add_Point			(double x, double y,             int iPart = 0)	= 0;
154 	virtual int					Ins_Point			(double x, double y, int iPoint, int iPart = 0)	= 0;
155 	virtual int					Set_Point			(double x, double y, int iPoint, int iPart = 0)	= 0;
156 	virtual int					Del_Point			(                    int iPoint, int iPart = 0)	= 0;
157 
158 	virtual int					Add_Point			(TSG_Point Point,                int iPart = 0);
159 	virtual int					Ins_Point			(TSG_Point Point,    int iPoint, int iPart = 0);
160 	virtual int					Set_Point			(TSG_Point Point,    int iPoint, int iPart = 0);
161 
162 	virtual int					Add_Part			(class CSG_Shape_Part *pPart)					= 0;
163 	virtual int					Del_Part			(int iPart)										= 0;
164 	virtual int					Del_Parts			(void)											= 0;
165 
166 	virtual int					Get_Part_Count		(void)											= 0;
167 	virtual int					Get_Point_Count		(void)											= 0;
168 	virtual int					Get_Point_Count		(int iPart)										= 0;
169 	virtual TSG_Point			Get_Point			(int iPoint)									= 0;
170 	virtual TSG_Point			Get_Point			(int iPoint, int iPart, bool bAscending = true)	= 0;
171 
172 	virtual void				Set_Z				(double z, int iPoint, int iPart = 0)				{		}
173 	virtual double				Get_Z				(int iPoint, int iPart = 0, bool bAscending = true)	{	return( 0.0 );	}
Get_ZMin(void)174 	virtual double				Get_ZMin			(void)												{	return( 0.0 );	}
Get_ZMax(void)175 	virtual double				Get_ZMax			(void)												{	return( 0.0 );	}
176 
177 	virtual void				Set_M				(double m, int iPoint, int iPart = 0)				{		}
178 	virtual double				Get_M				(int iPoint, int iPart = 0, bool bAscending = true)	{	return( 0.0 );	}
Get_MMin(void)179 	virtual double				Get_MMin			(void)												{	return( 0.0 );	}
Get_MMax(void)180 	virtual double				Get_MMax			(void)												{	return( 0.0 );	}
181 
182 	//-----------------------------------------------------
183 	virtual const CSG_Rect &	Get_Extent			(void)											= 0;
Get_Extent(int iPart)184 	virtual const CSG_Rect &	Get_Extent			(int iPart)	{	return( Get_Extent() );		}
185 
186 	virtual TSG_Point			Get_Centroid		(void)											= 0;
187 
188 	TSG_Intersection			Intersects			(CSG_Shape *pShape);
189 	TSG_Intersection			Intersects			(TSG_Rect Extent);
190 
191 	virtual double				Get_Distance		(TSG_Point Point)								= 0;
192 	virtual double				Get_Distance		(TSG_Point Point, int iPart)					= 0;
193 	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next)				= 0;
194 	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next, int iPart)	= 0;
195 
Revert_Points(int iPart)196 	virtual bool				Revert_Points		(int iPart)	{	return( true );	}
197 
198 
199 protected:
200 
201 	CSG_Shape(class CSG_Shapes *pOwner, int Index);
202 	virtual ~CSG_Shape(void);
203 
204 	virtual bool				On_Assign			(CSG_Shape *pShape)								= 0;
205 	virtual TSG_Intersection	On_Intersects		(CSG_Shape *pShape)								= 0;
206 	virtual TSG_Intersection	On_Intersects		(TSG_Rect Extent)								= 0;
207 
208 	virtual void				_Invalidate			(void);
209 
210 };
211 
212 
213 ///////////////////////////////////////////////////////////
214 //														 //
215 //						Point							 //
216 //														 //
217 ///////////////////////////////////////////////////////////
218 
219 //---------------------------------------------------------
220 class SAGA_API_DLL_EXPORT CSG_Shape_Point : public CSG_Shape
221 {
222 	friend class CSG_Shapes;
223 
224 public:
225 
is_Valid(void)226 	virtual bool				is_Valid			(void)												{	return( true );				}
227 
228 	virtual int					Add_Point			(double x, double y,             int iPart = 0);
229 	virtual int					Ins_Point			(double x, double y, int iPoint, int iPart = 0)		{	return( Add_Point(x, y) );	}
230 	virtual int					Set_Point			(double x, double y, int iPoint, int iPart = 0)		{	return( Add_Point(x, y) );	}
231 	virtual int					Del_Point			(                    int iPoint, int iPart = 0)		{	return( -1 );				}
232 
Add_Part(class CSG_Shape_Part * pPart)233 	virtual int					Add_Part			(class CSG_Shape_Part *pPart)						{	return( -1 );				}
Del_Part(int iPart)234 	virtual int					Del_Part			(int iPart)											{	return( -1 );				}
Del_Parts(void)235 	virtual int					Del_Parts			(void)												{	return( -1 );				}
236 
Get_Part_Count(void)237 	virtual int					Get_Part_Count		(void)												{	return( 1 );				}
Get_Point_Count(void)238 	virtual int					Get_Point_Count		(void)												{	return( 1 );				}
Get_Point_Count(int iPart)239 	virtual int					Get_Point_Count		(int iPart)											{	return( 1 );				}
Get_Point(void)240 	virtual TSG_Point			Get_Point			(void)												{	return( m_Point );			}
Get_Point(int iPoint)241 	virtual TSG_Point			Get_Point			(int iPoint)										{	return( m_Point );			}
242 	virtual TSG_Point			Get_Point			(int iPoint, int iPart, bool bAscending = true)		{	return( m_Point );			}
243 
244 	virtual const CSG_Rect &	Get_Extent			(void);
245 
Get_Centroid(void)246 	virtual TSG_Point			Get_Centroid		(void)												{	return( m_Point );			}
247 
Get_Distance(TSG_Point Point)248 	virtual double				Get_Distance		(TSG_Point Point)									{	return( SG_Get_Distance(Point, m_Point) );	}
Get_Distance(TSG_Point Point,int iPart)249 	virtual double				Get_Distance		(TSG_Point Point, int iPart)						{	return( SG_Get_Distance(Point, m_Point) );	}
Get_Distance(TSG_Point Point,TSG_Point & Next)250 	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next)					{	Next = m_Point; return( SG_Get_Distance(Point, m_Point) );	}
Get_Distance(TSG_Point Point,TSG_Point & Next,int iPart)251 	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next, int iPart)		{	Next = m_Point; return( SG_Get_Distance(Point, m_Point) );	}
252 
253 
254 protected:
255 
256 	CSG_Shape_Point(class CSG_Shapes *pOwner, int Index);
257 	virtual ~CSG_Shape_Point(void);
258 
259 
260 	TSG_Point					m_Point;
261 
262 
263 	virtual bool				On_Assign			(CSG_Shape *pShape);
264 	virtual TSG_Intersection	On_Intersects		(CSG_Shape *pShape);
265 	virtual TSG_Intersection	On_Intersects		(TSG_Rect Region);
266 
267 };
268 
269 //---------------------------------------------------------
270 class SAGA_API_DLL_EXPORT CSG_Shape_Point_Z : public CSG_Shape_Point
271 {
272 	friend class CSG_Shapes;
273 
274 public:
275 
CSG_Shape_Point_Z(class CSG_Shapes * pOwner,int Index)276 	CSG_Shape_Point_Z(class CSG_Shapes *pOwner, int Index) : CSG_Shape_Point(pOwner, Index)				{	m_Z	= 0.0;	}
277 
278 	virtual void				Set_Z				(double z, int iPoint, int iPart = 0)				{	m_Z	= z;	_Invalidate();	}
279 	virtual double				Get_Z				(int iPoint, int iPart = 0, bool bAscending = true)	{	return( m_Z );	}
Get_ZMin(void)280 	virtual double				Get_ZMin			(void)												{	return( m_Z );	}
Get_ZMax(void)281 	virtual double				Get_ZMax			(void)												{	return( m_Z );	}
282 
283 
284 private:
285 
286 	double						m_Z;
287 
288 };
289 
290 //---------------------------------------------------------
291 class SAGA_API_DLL_EXPORT CSG_Shape_Point_ZM : public CSG_Shape_Point_Z
292 {
293 	friend class CSG_Shapes;
294 
295 public:
296 
CSG_Shape_Point_ZM(class CSG_Shapes * pOwner,int Index)297 	CSG_Shape_Point_ZM(class CSG_Shapes *pOwner, int Index) : CSG_Shape_Point_Z(pOwner, Index)			{	m_M	= 0.0;	}
298 
299 	virtual void				Set_M				(double m, int iPoint, int iPart = 0)				{	m_M	= m;	_Invalidate();	}
300 	virtual double				Get_M				(int iPoint, int iPart = 0, bool bAscending = true)	{	return( m_M );	}
Get_MMin(void)301 	virtual double				Get_MMin			(void)												{	return( m_M );	}
Get_MMax(void)302 	virtual double				Get_MMax			(void)												{	return( m_M );	}
303 
304 
305 private:
306 
307 	double						m_M;
308 
309 };
310 
311 
312 ///////////////////////////////////////////////////////////
313 //														 //
314 //						Points							 //
315 //														 //
316 ///////////////////////////////////////////////////////////
317 
318 //---------------------------------------------------------
319 class SAGA_API_DLL_EXPORT CSG_Shape_Part
320 {
321 	friend class CSG_Shape_Points;
322 	friend class CSG_Shape_Line;
323 	friend class CSG_Shape_Polygon;
324 
325 public:
326 
Get_Owner(void)327 	class CSG_Shape_Points *	Get_Owner			(void)	{	return( m_pOwner );	}
328 
329 	virtual bool				Destroy				(void);
330 	virtual bool				Assign				(CSG_Shape_Part *pPart);
331 
Get_Extent(void)332 	const CSG_Rect &			Get_Extent			(void)	{	_Update_Extent();	return( m_Extent );	}
333 
Get_Count(void)334 	int							Get_Count			(void)	{	return( m_nPoints );	}
335 
336 	TSG_Point					Get_Point			(int iPoint, bool bAscending = true)
337 	{
338 		if( iPoint >= 0 && iPoint < m_nPoints )
339 		{
340 			return( m_Points[bAscending ? iPoint : m_nPoints - 1 - iPoint] );
341 		}
342 
343 		return( CSG_Point(0.0, 0.0) );
344 	}
345 
Add_Point(TSG_Point Point)346 	int							Add_Point			(TSG_Point Point               )		{	return( Add_Point(Point.x, Point.y)         );	}
Ins_Point(TSG_Point Point,int iPoint)347 	int							Ins_Point			(TSG_Point Point,    int iPoint)		{	return( Ins_Point(Point.x, Point.y, iPoint) );	}
Set_Point(TSG_Point Point,int iPoint)348 	int							Set_Point			(TSG_Point Point,    int iPoint)		{	return( Set_Point(Point.x, Point.y, iPoint) );	}
349 
350 	int							Add_Point			(double x, double y            );
351 	int							Ins_Point			(double x, double y, int iPoint);
352 	int							Set_Point			(double x, double y, int iPoint);
353 	int							Del_Point			(                    int iPoint);
354 
Set_Z(double z,int iPoint)355 	void						Set_Z				(double z, int iPoint)					{	if    ( m_Z && iPoint >= 0 && iPoint < m_nPoints ) { m_Z[iPoint] = z; _Invalidate(); }	}
356 	double						Get_Z				(int iPoint, bool bAscending = true)	{	return( m_Z && iPoint >= 0 && iPoint < m_nPoints ?   m_Z[bAscending ? iPoint : m_nPoints - 1 - iPoint] : 0.0 );	}
Get_ZMin(void)357 	double						Get_ZMin			(void)									{	_Update_Extent(); return( m_ZMin );	}
Get_ZMax(void)358 	double						Get_ZMax			(void)									{	_Update_Extent(); return( m_ZMax );	}
359 
Set_M(double m,int iPoint)360 	void						Set_M				(double m, int iPoint)					{	if    ( m_M && iPoint >= 0 && iPoint < m_nPoints ) { m_M[iPoint] = m; _Invalidate(); }	}
361 	double						Get_M				(int iPoint, bool bAscending = true)	{	return( m_M && iPoint >= 0 && iPoint < m_nPoints ?	 m_M[bAscending ? iPoint : m_nPoints - 1 - iPoint] : 0.0 );	}
Get_MMin(void)362 	double						Get_MMin			(void)									{	_Update_Extent(); return( m_MMin );	}
Get_MMax(void)363 	double						Get_MMax			(void)									{	_Update_Extent(); return( m_MMax );	}
364 
365 	bool						Revert_Points		(void);
366 
367 
368 protected:
369 
370 	CSG_Shape_Part(class CSG_Shape_Points *pOwner);
371 	virtual ~CSG_Shape_Part(void);
372 
373 
374 	bool						m_bUpdate;
375 
376 	int							m_nPoints, m_nBuffer;
377 
378 	double						*m_Z, m_ZMin, m_ZMax, *m_M, m_MMin, m_MMax;
379 
380 	TSG_Point					*m_Points;
381 
382 	CSG_Rect					m_Extent;
383 
384 	class CSG_Shape_Points		*m_pOwner;
385 
386 
387 	virtual bool				_Alloc_Memory		(int nPoints);
388 	virtual void				_Invalidate			(void);
389 	virtual void				_Update_Extent		(void);
390 
391 };
392 
393 
394 ///////////////////////////////////////////////////////////
395 //														 //
396 //						Points							 //
397 //														 //
398 ///////////////////////////////////////////////////////////
399 
400 //---------------------------------------------------------
401 class SAGA_API_DLL_EXPORT CSG_Shape_Points : public CSG_Shape
402 {
403 	friend class CSG_Shapes;
404 	friend class CSG_Shape_Part;
405 
406 public:
407 
408 	virtual void				Destroy				(void);
409 
is_Valid(void)410 	virtual bool				is_Valid			(void)		{	return( m_nParts > 0 && m_pParts[0]->Get_Count() > 0 );	}
411 
412 	virtual int					Add_Point			(double x, double y,             int iPart = 0);
413 	virtual int					Ins_Point			(double x, double y, int iPoint, int iPart = 0);
414 	virtual int					Set_Point			(double x, double y, int iPoint, int iPart = 0);
415 	virtual int					Del_Point			(                    int iPoint, int iPart = 0);
416 
417 	int							Add_Point			(const TSG_Point &p,             int iPart = 0)	{	return( Add_Point(p.x, p.y        , iPart) );	}
418 	int							Ins_Point			(const TSG_Point &p, int iPoint, int iPart = 0)	{	return( Ins_Point(p.x, p.y, iPoint, iPart) );	}
419 	int							Set_Point			(const TSG_Point &p, int iPoint, int iPart = 0)	{	return( Set_Point(p.x, p.y, iPoint, iPart) );	}
420 
421 	virtual int					Add_Part			(class CSG_Shape_Part *pPart);
422 	virtual int					Del_Part			(int iPart);
423 	virtual int					Del_Parts			(void);
424 
Get_Part_Count(void)425 	virtual int					Get_Part_Count		(void)		{	return( m_nParts );		}
Get_Part(int iPart)426 	virtual CSG_Shape_Part *	Get_Part			(int iPart)	{	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart] : NULL );	}
427 
Get_Point_Count(void)428 	virtual int					Get_Point_Count		(void)		{	_Update_Extent();	return( m_nPoints );	}
Get_Point_Count(int iPart)429 	virtual int					Get_Point_Count		(int iPart)	{	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart]->Get_Count() : 0 );	}
430 
431 	virtual TSG_Point			Get_Point			(int iPoint);
432 	virtual TSG_Point			Get_Point			(int iPoint, int iPart, bool bAscending = true)
433 	{
434 		if( iPart >= 0 && iPart < m_nParts )
435 		{
436 			return( m_pParts[iPart]->Get_Point(iPoint, bAscending) );
437 		}
438 
439 		return( CSG_Point(0.0, 0.0) );
440 	}
441 
442 	virtual void				Set_Z				(double z, int iPoint, int iPart = 0)							{	if    ( iPart >= 0 && iPart < m_nParts ) m_pParts[iPart]->Set_Z(z, iPoint);	}
443 	virtual double				Get_Z				(          int iPoint, int iPart = 0, bool bAscending = true)	{	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart]->Get_Z(   iPoint, bAscending) : 0.0 );	}
Get_ZMin(void)444 	virtual double				Get_ZMin			(void)		{	_Update_Extent();	return( m_ZMin );	}
Get_ZMax(void)445 	virtual double				Get_ZMax			(void)		{	_Update_Extent();	return( m_ZMax );	}
446 
447 	virtual void				Set_M				(double m, int iPoint, int iPart = 0)							{	if    ( iPart >= 0 && iPart < m_nParts ) m_pParts[iPart]->Set_M(m, iPoint);	}
448 	virtual double				Get_M				(          int iPoint, int iPart = 0, bool bAscending = true)	{	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart]->Get_M(   iPoint, bAscending) : 0.0 );	}
Get_MMin(void)449 	virtual double				Get_MMin			(void)		{	_Update_Extent();	return( m_MMin );	}
Get_MMax(void)450 	virtual double				Get_MMax			(void)		{	_Update_Extent();	return( m_MMax );	}
451 
Get_Extent(void)452 	virtual const CSG_Rect &	Get_Extent			(void)		{	_Update_Extent();	return( m_Extent );	}
453 
454 	virtual TSG_Point			Get_Centroid		(void);
455 
456 	virtual double				Get_Distance		(TSG_Point Point);
457 	virtual double				Get_Distance		(TSG_Point Point, int iPart);
458 	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next);
459 	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next, int iPart);
460 
Revert_Points(int iPart)461 	virtual bool				Revert_Points		(int iPart)	{	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart]->Revert_Points() : false );	}
462 
463 
464 protected:
465 
466 	CSG_Shape_Points(class CSG_Shapes *pOwner, int Index);
467 	virtual ~CSG_Shape_Points(void);
468 
469 
470 	bool						m_bUpdate;
471 
472 	int							m_nParts, m_nPoints;
473 
474 	double						m_ZMin, m_ZMax, m_MMin, m_MMax;
475 
476 	CSG_Rect					m_Extent;
477 
478 	CSG_Shape_Part				**m_pParts;
479 
480 
481 	int							_Add_Part			(void);
482 
_Get_Part(void)483 	virtual CSG_Shape_Part *	_Get_Part			(void)	{	return( new CSG_Shape_Part(this) );	}
484 
_Invalidate(void)485 	virtual void				_Invalidate			(void)
486 	{
487 		if( !m_bUpdate )
488 		{
489 			m_bUpdate	= true;
490 
491 			CSG_Shape::_Invalidate();
492 		}
493 	}
494 
495 	void						_Update_Extent		(void);
496 
497 	virtual bool				On_Assign			(CSG_Shape *pShape);
498 	virtual TSG_Intersection	On_Intersects		(CSG_Shape *pShape);
499 	virtual TSG_Intersection	On_Intersects		(TSG_Rect Region);
500 
501 };
502 
503 
504 ///////////////////////////////////////////////////////////
505 //														 //
506 //						Line							 //
507 //														 //
508 ///////////////////////////////////////////////////////////
509 
510 //---------------------------------------------------------
511 class SAGA_API_DLL_EXPORT CSG_Shape_Line : public CSG_Shape_Points
512 {
513 	friend class CSG_Shapes;
514 
515 public:
516 
is_Valid(void)517 	virtual bool				is_Valid			(void)	{	return( m_nParts > 0 && m_pParts[0]->Get_Count() > 1 );	}
518 
519 	virtual TSG_Point			Get_Centroid		(void);
520 
521 	double						Get_Length			(void);
522 	double						Get_Length			(int iPart);
523 
524 	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next, int iPart);
525 
526 
527 protected:
528 
529 	CSG_Shape_Line(class CSG_Shapes *pOwner, int Index);
530 	virtual ~CSG_Shape_Line(void);
531 
532 	virtual TSG_Intersection	On_Intersects		(CSG_Shape *pShape);
533 	virtual TSG_Intersection	On_Intersects		(TSG_Rect Region);
534 
535 };
536 
537 
538 ///////////////////////////////////////////////////////////
539 //														 //
540 //						Polygon							 //
541 //														 //
542 ///////////////////////////////////////////////////////////
543 
544 //---------------------------------------------------------
545 typedef enum ESG_Polygon_Point_Relation
546 {
547 	SG_POLYGON_POINT_Outside,
548 	SG_POLYGON_POINT_Vertex,
549 	SG_POLYGON_POINT_Edge,
550 	SG_POLYGON_POINT_Interior
551 }
552 TSG_Polygon_Point_Relation;
553 
554 //---------------------------------------------------------
555 class SAGA_API_DLL_EXPORT CSG_Shape_Polygon_Part : public CSG_Shape_Part
556 {
557 	friend class CSG_Shape_Polygon;
558 
559 public:
560 
is_Clockwise(void)561 	bool						is_Clockwise		(void)	{	_Update_Area();	return( m_bClockwise == 1 );	}
562 
Get_Perimeter(void)563 	double						Get_Perimeter		(void)	{	_Update_Area();	return( m_Perimeter );	}
564 
Get_Area(void)565 	double						Get_Area			(void)	{	_Update_Area();	return( m_Area );	}
566 
Get_Centroid(void)567 	const TSG_Point &			Get_Centroid		(void)	{	_Update_Area();	return( m_Centroid );	}
568 
569 	TSG_Polygon_Point_Relation	Get_Point_Relation	(const TSG_Point &p);
570 	TSG_Polygon_Point_Relation	Get_Point_Relation	(double x, double y);
571 
572 	bool						is_OnEdge			(const TSG_Point &p);
573 	bool						is_OnEdge			(double x, double y);
574 
575 	bool						Contains			(const TSG_Point &p);
576 	bool						Contains			(double x, double y);
577 
578 	bool						is_Neighbour		(CSG_Shape_Polygon_Part *pPart, bool bSimpleCheck = true);
579 
580 	double						Get_Distance		(TSG_Point Point, TSG_Point &Next);
581 
582 
583 protected:
584 
585 	CSG_Shape_Polygon_Part(class CSG_Shape_Points *pOwner);
586 	virtual ~CSG_Shape_Polygon_Part(void);
587 
588 
589 	int							m_bClockwise, m_bLake;
590 
591 	double						m_Area, m_Perimeter;
592 
593 	TSG_Point					m_Centroid;
594 
595 
596 	virtual void				_Invalidate			(void);
597 
598 	void						_Update_Area		(void);
599 
600 };
601 
602 //---------------------------------------------------------
603 class SAGA_API_DLL_EXPORT CSG_Shape_Polygon : public CSG_Shape_Points
604 {
605 	friend class CSG_Shapes;
606 
607 public:
608 
is_Valid(void)609 	virtual bool				is_Valid			(void)		{	return( m_nParts > 0 && m_pParts[0]->Get_Count() > 2 );	}
610 
611 
Get_Polygon_Part(int iPart)612 	CSG_Shape_Polygon_Part *	Get_Polygon_Part	(int iPart)	{	return( (CSG_Shape_Polygon_Part *)Get_Part(iPart) );	}
613 
614 	bool						is_Lake				(int iPart);
615 
616 	bool						is_Clockwise		(int iPart);
617 
618 	double						Get_Perimeter		(int iPart);
619 	double						Get_Perimeter		(void);
620 
621 	double						Get_Area			(int iPart);
622 	double						Get_Area			(void);
623 
624 	TSG_Point					Get_Centroid		(int iPart);
625 	TSG_Point					Get_Centroid		(void);
626 
627 	TSG_Polygon_Point_Relation	Get_Point_Relation	(const TSG_Point &p, int iPart);
628 	TSG_Polygon_Point_Relation	Get_Point_Relation	(double x, double y, int iPart);
629 	TSG_Polygon_Point_Relation	Get_Point_Relation	(const TSG_Point &p);
630 	TSG_Polygon_Point_Relation	Get_Point_Relation	(double x, double y);
631 
632 
633 	bool						is_OnEdge			(const TSG_Point &p, int iPart);
634 	bool						is_OnEdge			(double x, double y, int iPart);
635 	bool						is_OnEdge			(const TSG_Point &p);
636 	bool						is_OnEdge			(double x, double y);
637 
638 	bool						Contains			(const TSG_Point &p, int iPart);
639 	bool						Contains			(double x, double y, int iPart);
640 	bool						Contains			(const TSG_Point &p);
641 	bool						Contains			(double x, double y);
642 
643 	bool						is_Neighbour		(CSG_Shape_Polygon *pPolygon, bool bSimpleCheck = true);
644 
645 	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next, int iPart);
646 
647 
648 protected:
649 
650 	CSG_Shape_Polygon(class CSG_Shapes *pOwner, int Index);
651 	virtual ~CSG_Shape_Polygon(void);
652 
653 
654 	int							m_bUpdate_Lakes;
655 
656 
_Get_Part(void)657 	virtual CSG_Shape_Part *	_Get_Part			(void)	{	return( new CSG_Shape_Polygon_Part(this) );	}
658 
659 	virtual void				_Invalidate			(void);
660 
661 	virtual TSG_Intersection	On_Intersects		(CSG_Shape *pShape);
662 	virtual TSG_Intersection	On_Intersects		(TSG_Rect Region);
663 
664 };
665 
666 
667 ///////////////////////////////////////////////////////////
668 //														 //
669 //						Shapes							 //
670 //														 //
671 ///////////////////////////////////////////////////////////
672 
673 //---------------------------------------------------------
674 typedef enum ESG_Shape_Copy_Mode
675 {
676 	SHAPE_NO_COPY	= 0,
677 	SHAPE_COPY_GEOM,
678 	SHAPE_COPY_ATTR,
679 	SHAPE_COPY
680 }
681 TSG_ADD_Shape_Copy_Mode;
682 
683 //---------------------------------------------------------
684 class SAGA_API_DLL_EXPORT CSG_Shapes : public CSG_Table
685 {
686 	friend class CSG_Shape;
687 
688 public:
689 
690 	CSG_Shapes(void);
691 
692 									CSG_Shapes	(const CSG_Shapes &Shapes);
693 	bool							Create		(const CSG_Shapes &Shapes);
694 
695 									CSG_Shapes	(const CSG_String &File_Name);
696 	bool							Create		(const CSG_String &File_Name);
697 
698 									CSG_Shapes	(TSG_Shape_Type Type, const SG_Char *Name = NULL, CSG_Table *pStructure = NULL, TSG_Vertex_Type Vertex_Type = SG_VERTEX_TYPE_XY);
699 	bool							Create		(TSG_Shape_Type Type, const SG_Char *Name = NULL, CSG_Table *pStructure = NULL, TSG_Vertex_Type Vertex_Type = SG_VERTEX_TYPE_XY);
700 
701 	virtual ~CSG_Shapes(void);
702 
703 	virtual bool					Destroy					(void);
704 
Get_ObjectType(void)705 	virtual TSG_Data_Object_Type	Get_ObjectType			(void)	const			{	return( SG_DATAOBJECT_TYPE_Shapes );	}
706 
707 	virtual bool					Assign					(CSG_Data_Object *pObject);
708 
709 	virtual bool					Save					(const CSG_String &File, int Format = 0);
710 	virtual bool					Save					(const char       *File, int Format = 0)	{	return( Save(CSG_String(File), Format) );	}
711 	virtual bool					Save					(const wchar_t    *File, int Format = 0)	{	return( Save(CSG_String(File), Format) );	}
712 
is_Valid(void)713 	virtual bool					is_Valid				(void)	const			{	return( m_Type != SHAPE_TYPE_Undefined && Get_Count() >= 0 );		}
714 
Get_Type(void)715 	virtual TSG_Shape_Type			Get_Type				(void)	const			{	return( m_Type );		}
716 
Get_Vertex_Type(void)717 	TSG_Vertex_Type					Get_Vertex_Type			(void)	const			{	return( m_Vertex_Type );	}
718 
Get_Extent(void)719 	virtual const CSG_Rect &		Get_Extent				(void)					{	Update();	return( m_Extent );	}
720 
Get_ZMin(void)721 	double							Get_ZMin				(void)					{	Update();	return( m_ZMin );	}
Get_ZMax(void)722 	double							Get_ZMax				(void)					{	Update();	return( m_ZMax );	}
Get_MMin(void)723 	double							Get_MMin				(void)					{	Update();	return( m_MMin );	}
Get_MMax(void)724 	double							Get_MMax				(void)					{	Update();	return( m_MMax );	}
725 
726 	//-----------------------------------------------------
727 	virtual CSG_Shape *				Add_Shape				(CSG_Table_Record *pCopy = NULL, TSG_ADD_Shape_Copy_Mode mCopy = SHAPE_COPY);
728 	virtual bool					Del_Shape				(int iShape);
729 	virtual bool					Del_Shape				(CSG_Shape *pShape);
Del_Shapes(void)730 	virtual bool					Del_Shapes				(void)					{	return( Del_Records() );	}
731 
732 	virtual CSG_Shape *				Get_Shape				(const TSG_Point &Point, double Epsilon = 0.);
Get_Shape(int Index)733 	virtual CSG_Shape *				Get_Shape				(int    Index)	const	{	return( (CSG_Shape *)Get_Record        (Index) );	}
Get_Shape(size_t Index)734 	virtual CSG_Shape *				Get_Shape				(size_t Index)	const	{	return( (CSG_Shape *)Get_Record        (Index) );	}
Get_Shape(sLong Index)735 	virtual CSG_Shape *				Get_Shape				(sLong  Index)	const	{	return( (CSG_Shape *)Get_Record        (Index) );	}
Get_Shape_byIndex(int Index)736 	virtual CSG_Shape *				Get_Shape_byIndex		(int    Index)	const	{	return( (CSG_Shape *)Get_Record_byIndex(Index) );	}
Get_Shape_byIndex(size_t Index)737 	virtual CSG_Shape *				Get_Shape_byIndex		(size_t Index)	const	{	return( (CSG_Shape *)Get_Record_byIndex(Index) );	}
Get_Shape_byIndex(sLong Index)738 	virtual CSG_Shape *				Get_Shape_byIndex		(sLong  Index)	const	{	return( (CSG_Shape *)Get_Record_byIndex(Index) );	}
739 
740 	//-----------------------------------------------------
741 	bool							Make_Clean				(void);
742 
743 	//-----------------------------------------------------
744 	virtual CSG_Shape *				Get_Selection			(int Index = 0)			{	return( (CSG_Shape *)CSG_Table::Get_Selection(Index) );	};
745 	virtual const CSG_Rect &		Get_Selection_Extent	(void);
746 
747 	virtual bool					Select					(int Index					, bool bInvert = false);
748 	virtual bool					Select					(CSG_Shape *pShape = NULL	, bool bInvert = false);
749 	virtual bool					Select					(TSG_Rect Extent			, bool bInvert = false);
750 	virtual bool					Select					(TSG_Point Point			, bool bInvert = false);
751 
752 
753 protected:
754 
755 	double							m_ZMin, m_ZMax, m_MMin, m_MMax;
756 
757 	TSG_Shape_Type					m_Type;
758 
759 	TSG_Vertex_Type					m_Vertex_Type;
760 
761 	CSG_Rect						m_Extent_Selected;
762 
763 
764 	virtual bool					On_Update				(void);
765 	virtual bool					On_Reload				(void);
766 	virtual bool					On_Delete				(void);
767 
768 	virtual void					_On_Construction		(void);
769 
770 	virtual CSG_Table_Record *		_Get_New_Record			(int Index);
771 
772 
773 private:
774 
775 	bool							_Load_GDAL				(const CSG_String &File_Name);
776 	bool							_Save_GDAL				(const CSG_String &File_Name, const CSG_String &Driver);
777 
778 	bool							_Load_ESRI				(const CSG_String &File_Name);
779 	bool							_Save_ESRI				(const CSG_String &File_Name);
780 
781 };
782 
783 
784 ///////////////////////////////////////////////////////////
785 //														 //
786 //														 //
787 //														 //
788 ///////////////////////////////////////////////////////////
789 
790 //---------------------------------------------------------
791 /** Safe shapes construction */
792 SAGA_API_DLL_EXPORT CSG_Shapes *	SG_Create_Shapes	(void);
793 
794 /** Safe shapes construction */
795 SAGA_API_DLL_EXPORT CSG_Shapes *	SG_Create_Shapes	(const CSG_Shapes &Shapes);
796 
797 /** Safe shapes construction */
798 SAGA_API_DLL_EXPORT CSG_Shapes *	SG_Create_Shapes	(const CSG_String &File_Name);
799 
800 /** Safe shapes construction */
801 SAGA_API_DLL_EXPORT CSG_Shapes *	SG_Create_Shapes	(TSG_Shape_Type Type, const SG_Char *Name = NULL, CSG_Table *pStructure = NULL, TSG_Vertex_Type Vertex_Type = SG_VERTEX_TYPE_XY);
802 
803 /** Safe shapes construction */
804 SAGA_API_DLL_EXPORT CSG_Shapes *	SG_Create_Shapes	(CSG_Shapes *pTemplate);
805 
806 
807 //---------------------------------------------------------
808 SAGA_API_DLL_EXPORT bool					SG_Shapes_Set_File_Format_Default		(int Format);
809 SAGA_API_DLL_EXPORT TSG_Shape_File_Format	SG_Shapes_Get_File_Format_Default		(void);
810 SAGA_API_DLL_EXPORT CSG_String				SG_Shapes_Get_File_Extension_Default	(void);
811 
812 
813 ///////////////////////////////////////////////////////////
814 //														 //
815 //				Point Region QuadTree					 //
816 //														 //
817 ///////////////////////////////////////////////////////////
818 
819 //---------------------------------------------------------
820 class SAGA_API_DLL_EXPORT CSG_PRQuadTree_Item
821 {
822 public:
823 
is_Leaf(void)824 	virtual bool			is_Leaf			(void)	const	{	return( false );	}
is_Node(void)825 	virtual bool			is_Node			(void)	const	{	return( false );	}
has_Statistics(void)826 	virtual bool			has_Statistics	(void)	const	{	return( false );	}
827 
Get_Extent(void)828 	const CSG_Rect &		Get_Extent		(void)	const	{	return( m_Extent );	}
Get_xMin(void)829 	double					Get_xMin		(void)	const	{	return( m_Extent.m_rect.xMin   );	}
Get_xCenter(void)830 	double					Get_xCenter		(void)	const	{	return( m_Extent.Get_XCenter() );	}
Get_xMax(void)831 	double					Get_xMax		(void)	const	{	return( m_Extent.m_rect.xMax   );	}
Get_yMin(void)832 	double					Get_yMin		(void)	const	{	return( m_Extent.m_rect.yMin   );	}
Get_yCenter(void)833 	double					Get_yCenter		(void)	const	{	return( m_Extent.Get_YCenter() );	}
Get_yMax(void)834 	double					Get_yMax		(void)	const	{	return( m_Extent.m_rect.yMax   );	}
Get_Size(void)835 	double					Get_Size		(void)	const	{	return( m_Extent.Get_XRange()  );	}
836 
Contains(const TSG_Point & p)837 	bool					Contains		(const TSG_Point &p)	const	{	return(	m_Extent.Contains(p   ) );	}
Contains(double x,double y)838 	bool					Contains		(double x, double y)	const	{	return(	m_Extent.Contains(x, y) );	}
839 
asLeaf(void)840 	class CSG_PRQuadTree_Leaf *	asLeaf		(void)	const	{	return( (class CSG_PRQuadTree_Leaf *)this );	}
asNode(void)841 	class CSG_PRQuadTree_Node *	asNode		(void)	const	{	return( (class CSG_PRQuadTree_Node *)this );	}
842 
843 
844 protected:
845 
846 	CSG_PRQuadTree_Item(const CSG_Rect &Extent, int Quadrant = -1)	{	Set_Extent(Extent, Quadrant);	}
847 
~CSG_PRQuadTree_Item(void)848 	virtual ~CSG_PRQuadTree_Item(void)	{}
849 
850 	void					Set_Extent		(const CSG_Rect &Extent, int Quadrant = -1)
851 	{
852 		switch( Quadrant )
853 		{
854 		case  0: m_Extent.Assign(Extent.Get_XMin   (), Extent.Get_YMin   (), Extent.Get_XCenter(), Extent.Get_YCenter()); break; // bottom left
855 		case  1: m_Extent.Assign(Extent.Get_XMin   (), Extent.Get_YCenter(), Extent.Get_XCenter(), Extent.Get_YMax   ()); break; // top left
856 		case  2: m_Extent.Assign(Extent.Get_XCenter(), Extent.Get_YCenter(), Extent.Get_XMax   (), Extent.Get_YMax   ()); break; // top right
857 		case  3: m_Extent.Assign(Extent.Get_XCenter(), Extent.Get_YMin   (), Extent.Get_XMax   (), Extent.Get_YCenter()); break; // bottom right
858 		default: m_Extent.Assign(Extent); break;
859 		}
860 	}
861 
Get_Quadrant(const TSG_Point & p)862 	int						Get_Quadrant	(const TSG_Point &p)	const	{	return( Get_Quadrant(p.x, p.y) );	}
863 
Get_Quadrant(double x,double y)864 	int						Get_Quadrant	(double x, double y)	const
865 	{
866 		return( y < Get_yCenter() ? (x < Get_xCenter() ? 0 : 3) : (x < Get_xCenter() ? 1 : 2) );
867 	}
868 
869 
870 	CSG_Rect				m_Extent;
871 
872 };
873 
874 //---------------------------------------------------------
875 class SAGA_API_DLL_EXPORT CSG_PRQuadTree_Leaf : public CSG_PRQuadTree_Item
876 {
877 	friend class CSG_PRQuadTree_Node;
878 
879 public:
880 
is_Leaf(void)881 	virtual bool			is_Leaf			(void)	const	{	return( true );		}
882 
Get_Point(void)883 	const TSG_Point &		Get_Point		(void)	const	{	return( m_Point );		}
Get_X(void)884 	double					Get_X			(void)	const	{	return( m_Point.x );	}
Get_Y(void)885 	double					Get_Y			(void)	const	{	return( m_Point.y );	}
Get_Z(void)886 	double					Get_Z			(void)	const	{	return( m_z );			}
887 
888 
889 protected:
890 
CSG_PRQuadTree_Leaf(const CSG_Rect & Extent,int Quadrant,double x,double y,double z)891 	CSG_PRQuadTree_Leaf(const CSG_Rect &Extent, int Quadrant, double x, double y, double z)
892 		: CSG_PRQuadTree_Item(Extent, Quadrant)
893 	{
894 		m_Point.x	= x;
895 		m_Point.y	= y;
896 		m_z			= z;
897 	}
898 
~CSG_PRQuadTree_Leaf(void)899 	virtual ~CSG_PRQuadTree_Leaf(void)	{}
900 
901 
902 	double					m_z;
903 
904 	TSG_Point				m_Point;
905 
906 };
907 
908 //---------------------------------------------------------
909 class SAGA_API_DLL_EXPORT CSG_PRQuadTree_Leaf_List : public CSG_PRQuadTree_Leaf
910 {
911 	friend class CSG_PRQuadTree_Node;
912 
913 public:
914 
has_Statistics(void)915 	virtual bool			has_Statistics	(void)	const	{	return( true );	}
916 
Get_Count(void)917 	sLong					Get_Count		(void)	{	return( s_z.Get_Count   () );	}
Get_Value(int i)918 	double					Get_Value		(int i)	{	return( s_z.Get_Value  (i) );	}
Get_Minimum(void)919 	double					Get_Minimum		(void)	{	return( s_z.Get_Minimum () );	}
Get_Maximum(void)920 	double					Get_Maximum		(void)	{	return( s_z.Get_Maximum () );	}
Get_Range(void)921 	double					Get_Range		(void)	{	return( s_z.Get_Range   () );	}
Get_Sum(void)922 	double					Get_Sum			(void)	{	return( s_z.Get_Sum     () );	}
Get_Mean(void)923 	double					Get_Mean		(void)	{	return( s_z.Get_Mean    () );	}
Get_Variance(void)924 	double					Get_Variance	(void)	{	return( s_z.Get_Variance() );	}
Get_StdDev(void)925 	double					Get_StdDev		(void)	{	return( s_z.Get_StdDev  () );	}
926 
927 
928 protected:
929 
CSG_PRQuadTree_Leaf_List(const CSG_Rect & Extent,int Quadrant,double x,double y,double z)930 	CSG_PRQuadTree_Leaf_List(const CSG_Rect &Extent, int Quadrant, double x, double y, double z)
931 		: CSG_PRQuadTree_Leaf(Extent, Quadrant, x, y, z)
932 	{
933 		s_z.Create(true);
934 
935 		s_z.Add_Value(z);
936 	}
937 
~CSG_PRQuadTree_Leaf_List(void)938 	virtual ~CSG_PRQuadTree_Leaf_List(void)	{}
939 
Add_Value(double z)940 	void					Add_Value		(double z)
941 	{
942 		s_z.Add_Value(z);
943 
944 		m_z	= s_z.Get_Mean();
945 	}
946 
947 	CSG_Simple_Statistics	s_z;
948 
949 };
950 
951 //---------------------------------------------------------
952 class SAGA_API_DLL_EXPORT CSG_PRQuadTree_Node : public CSG_PRQuadTree_Item
953 {
954 	friend class CSG_PRQuadTree;
955 
956 public:
957 
is_Node(void)958 	virtual bool			is_Node			(void)	const	{	return( true );		}
959 
Get_Child(int i)960 	CSG_PRQuadTree_Item *	Get_Child		(int i)	const	{	return( i >= 0 && i < 4 ? m_pChildren[i] : NULL );	}
961 	CSG_PRQuadTree_Item *	Get_Child		(double x, double y);
962 
963 	bool					Add_Point		(double x, double y, double z);
964 
Get_X(void)965 	virtual CSG_Simple_Statistics *	Get_X	(void)			{	return( NULL );	}
Get_Y(void)966 	virtual CSG_Simple_Statistics *	Get_Y	(void)			{	return( NULL );	}
Get_Z(void)967 	virtual CSG_Simple_Statistics *	Get_Z	(void)			{	return( NULL );	}
968 
969 
970 protected:
971 
972 	CSG_PRQuadTree_Node(const CSG_Rect &Extent, int Quadrant = -1);
973 	CSG_PRQuadTree_Node(CSG_PRQuadTree_Leaf *pLeaf);
974 	virtual ~CSG_PRQuadTree_Node(void);
975 
976 
977 	CSG_PRQuadTree_Item		*m_pChildren[4];
978 
979 };
980 
981 //---------------------------------------------------------
982 class SAGA_API_DLL_EXPORT CSG_PRQuadTree_Node_Statistics : public CSG_PRQuadTree_Node
983 {
984 	friend class CSG_PRQuadTree;
985 	friend class CSG_PRQuadTree_Node;
986 
987 public:
988 
has_Statistics(void)989 	virtual bool			has_Statistics	(void)	const	{	return( true );	}
990 
Get_X(void)991 	virtual CSG_Simple_Statistics *	Get_X	(void)			{	return( &m_x );	}
Get_Y(void)992 	virtual CSG_Simple_Statistics *	Get_Y	(void)			{	return( &m_y );	}
Get_Z(void)993 	virtual CSG_Simple_Statistics *	Get_Z	(void)			{	return( &m_z );	}
994 
995 
996 protected:
997 
998 	CSG_PRQuadTree_Node_Statistics(const CSG_Rect &Extent, int Quadrant = -1)
CSG_PRQuadTree_Node(Extent,Quadrant)999 		: CSG_PRQuadTree_Node(Extent, Quadrant)
1000 	{}
1001 
CSG_PRQuadTree_Node_Statistics(CSG_PRQuadTree_Leaf * pLeaf)1002 	CSG_PRQuadTree_Node_Statistics(CSG_PRQuadTree_Leaf *pLeaf)
1003 		: CSG_PRQuadTree_Node(pLeaf)
1004 	{}
1005 
~CSG_PRQuadTree_Node_Statistics(void)1006 	virtual ~CSG_PRQuadTree_Node_Statistics(void)	{}
1007 
1008 
1009 	CSG_Simple_Statistics	m_x, m_y, m_z;
1010 
1011 };
1012 
1013 //---------------------------------------------------------
1014 class SAGA_API_DLL_EXPORT CSG_PRQuadTree
1015 {
1016 public:
1017 	CSG_PRQuadTree(void);
1018 	virtual ~CSG_PRQuadTree(void);
1019 
1020 								CSG_PRQuadTree			(const TSG_Rect &Extent, bool bStatistics = false);
1021 	bool						Create					(const CSG_Rect &Extent, bool bStatistics = false);
1022 
1023 								CSG_PRQuadTree			(CSG_Shapes *pShapes, int Attribute, bool bStatistics = false);
1024 	bool						Create					(CSG_Shapes *pShapes, int Attribute, bool bStatistics = false);
1025 
1026 	void						Destroy					(void);
1027 
1028 	bool						Add_Point				(double x, double y, double z);
1029 	bool						Add_Point				(const TSG_Point &p, double z);
1030 
Get_Point_Count(void)1031 	int							Get_Point_Count			(void)	const	{	return( m_nPoints );		}
1032 
Get_Root(void)1033 	const CSG_PRQuadTree_Node &	Get_Root				(void)	const	{	return( *m_pRoot );			}
Get_Root_Pointer(void)1034 	CSG_PRQuadTree_Node *		Get_Root_Pointer		(void)	const	{	return(  m_pRoot );			}
1035 
is_Okay(void)1036 	bool						is_Okay					(void)	const	{	return( m_pRoot != NULL );	}
1037 
is_Polar(void)1038 	bool						is_Polar				(void)	const	{	return( m_bPolar );			}
Set_Polar_Search(bool bOn)1039 	void						Set_Polar_Search		(bool bOn)		{	m_bPolar	= bOn;			}
1040 
1041 	CSG_PRQuadTree_Leaf *		Get_Nearest_Leaf		(const TSG_Point &p, double &Distance)	const;
1042 	CSG_PRQuadTree_Leaf *		Get_Nearest_Leaf		(double x, double y, double &Distance)	const;
1043 	bool						Get_Nearest_Point		(const TSG_Point &p, TSG_Point &Point, double &Value, double &Distance)	const;
1044 	bool						Get_Nearest_Point		(double x, double y, TSG_Point &Point, double &Value, double &Distance)	const;
1045 
1046 	size_t						Get_Nearest_Points		(CSG_Points_Z &Points, const TSG_Point &p, size_t maxPoints, double Radius = 0.0, int iQuadrant = -1)	const;
1047 	size_t						Get_Nearest_Points		(CSG_Points_Z &Points, double x, double y, size_t maxPoints, double Radius = 0.0, int iQuadrant = -1)	const;
1048 
1049 	size_t						Select_Nearest_Points	(const TSG_Point &p, size_t maxPoints, double Radius = 0.0, int iQuadrant = -1);
1050 	size_t						Select_Nearest_Points	(double x, double y, size_t maxPoints, double Radius = 0.0, int iQuadrant = -1);
1051 
Get_Selected_Count(void)1052 	size_t						Get_Selected_Count		(void)     const	{	return( m_Selection.Get_Size() );	}
Get_Selected_Leaf(size_t i)1053 	CSG_PRQuadTree_Leaf *		Get_Selected_Leaf		(size_t i) const	{	return( i >= m_Selection.Get_Size() ? NULL : (((TLeaf *)m_Selection.Get_Array()) + i)->pLeaf          );	}
Get_Selected_Z(size_t i)1054 	double						Get_Selected_Z			(size_t i) const	{	return( i >= m_Selection.Get_Size() ?  0.0 : (((TLeaf *)m_Selection.Get_Array()) + i)->pLeaf->Get_Z() );	}
Get_Selected_Distance(size_t i)1055 	double						Get_Selected_Distance	(size_t i) const	{	return( i >= m_Selection.Get_Size() ? -1.0 : (((TLeaf *)m_Selection.Get_Array()) + i)->Distance       );	}
Get_Selected_Point(size_t i,double & x,double & y,double & z)1056 	bool						Get_Selected_Point		(size_t i, double &x, double &y, double &z) const
1057 	{
1058 		CSG_PRQuadTree_Leaf	*pLeaf	= Get_Selected_Leaf(i);
1059 
1060 		if( pLeaf )
1061 		{
1062 			x	= pLeaf->Get_X();
1063 			y	= pLeaf->Get_Y();
1064 			z	= pLeaf->Get_Z();
1065 
1066 			return( true );
1067 		}
1068 
1069 		return( false );
1070 	}
1071 
1072 
1073 private:
1074 
1075 	typedef struct SLeaf
1076 	{
1077 		CSG_PRQuadTree_Leaf		*pLeaf;
1078 
1079 		double					Distance;
1080 	}
1081 	TLeaf;
1082 
1083 
1084 private:
1085 
1086 	bool						m_bPolar;
1087 
1088 	int							m_nPoints;
1089 
1090 	CSG_Array					m_Selection;
1091 
1092 	CSG_PRQuadTree_Node			*m_pRoot;
1093 
1094 	bool						_Check_Root				(double x, double y);
1095 
1096 	bool						_Quadrant_Contains		(double x, double y, int iQuadrant, const TSG_Point &p)						const;
1097 	bool						_Radius_Contains		(double x, double y, double r, const TSG_Point &p)							const;
1098 	bool						_Radius_Contains		(double x, double y, double r, int iQuadrant, const TSG_Point &p)			const;
1099 	bool						_Quadrant_Intersects	(double x, double y, int iQuadrant, CSG_PRQuadTree_Item *pItem)				const;
1100 	bool						_Radius_Intersects		(double x, double y, double r, CSG_PRQuadTree_Item *pItem)					const;
1101 	bool						_Radius_Intersects		(double x, double y, double r, int iQuadrant, CSG_PRQuadTree_Item *pItem)	const;
1102 
1103 	CSG_PRQuadTree_Leaf	*		_Get_Nearest_Point		(CSG_PRQuadTree_Item *pItem, double x, double y, double &Distance)			const;
1104 
1105 	TLeaf *						_Get_Selected			(const CSG_Array &Selection, size_t i)										const;
1106 	bool						_Add_Selected			(      CSG_Array &Selection          , CSG_PRQuadTree_Leaf *pLeaf, double Distance)	const;
1107 	bool						_Set_Selected			(      CSG_Array &Selection, size_t i, CSG_PRQuadTree_Leaf *pLeaf, double Distance)	const;
1108 	void						_Select_Nearest_Points	(      CSG_Array &Selection, CSG_PRQuadTree_Item *pItem, double x, double y, double &Distance, double Radius, size_t maxPoints, int iQuadrant)	const;
1109 	size_t						_Select_Nearest_Points	(      CSG_Array &Selection, double x, double y, size_t maxPoints, double Radius, int iQuadrant)	const;
1110 
1111 };
1112 
1113 
1114 ///////////////////////////////////////////////////////////
1115 //														 //
1116 //														 //
1117 //														 //
1118 ///////////////////////////////////////////////////////////
1119 
1120 //---------------------------------------------------------
1121 class SAGA_API_DLL_EXPORT CSG_KDTree
1122 {
1123 public:
1124 	CSG_KDTree(void);
1125 	virtual ~CSG_KDTree(void);
1126 
1127 	virtual bool				Destroy				(void);
1128 
is_Okay(void)1129 	bool						is_Okay				(void)		const	{	return( m_pKDTree != NULL );	}
1130 
Get_Match_Count(void)1131 	size_t						Get_Match_Count		(void    )	const	{	return( m_Indices.Get_Size() );	}
Get_Match_Index(size_t i)1132 	size_t						Get_Match_Index		(size_t i)	const	{	return( m_Indices  [i]       );	}
Get_Match_Distance(size_t i)1133 	double						Get_Match_Distance	(size_t i)	const	{	return( m_Distances[i]       );	}
1134 	CSG_Shape *					Get_Match_Shape		(size_t i)	const;
1135 
Get_Point_Count(void)1136 	int							Get_Point_Count		(void)		const	{	return( m_Points.Get_NRows() );	}
Get_Point(int i)1137 	double *					Get_Point			(int    i)	const	{	return( m_Points[i]          );	}
Get_Point(size_t i)1138 	double *					Get_Point			(size_t i)	const	{	return( m_Points[i]          );	}
1139 	double *					operator []			(int    i)	const	{	return( m_Points[i]          );	}
1140 	double *					operator []			(size_t i)	const	{	return( m_Points[i]          );	}
1141 	virtual double				Get_Point_Value		(int    i)	const = 0;
Get_Point_Value(size_t i)1142 	virtual double				Get_Point_Value		(size_t i)	const	{	return( Get_Point_Value((int)i) );	}
1143 
1144 
1145 protected:
1146 
1147 	class CSG_KDTree_Adaptor	*m_pAdaptor;
1148 
1149 	void						*m_pKDTree;
1150 
1151 	CSG_Array_Int				m_Indices;
1152 
1153 	CSG_Vector					m_Distances;
1154 
1155 	CSG_Matrix					m_Points;
1156 
1157 
1158 	void						_On_Construction	(void);
1159 
1160 };
1161 
1162 
1163 ///////////////////////////////////////////////////////////
1164 //														 //
1165 ///////////////////////////////////////////////////////////
1166 
1167 //---------------------------------------------------------
1168 class SAGA_API_DLL_EXPORT CSG_KDTree_2D : public CSG_KDTree
1169 {
1170 public:
1171 	CSG_KDTree_2D(void);
1172 	virtual ~CSG_KDTree_2D(void);
1173 
1174 								CSG_KDTree_2D		(CSG_Shapes *pPoints, int Field = -1);
1175 	bool						Create				(CSG_Shapes *pPoints, int Field = -1);
1176 
1177 								CSG_KDTree_2D		(CSG_PointCloud *pPoints);
1178 	bool						Create				(CSG_PointCloud *pPoints);
1179 
1180 								CSG_KDTree_2D		(const CSG_Matrix &Points);
1181 	bool						Create				(const CSG_Matrix &Points);
1182 
1183 								CSG_KDTree_2D		(const double **Points, size_t nPoints);
1184 	bool						Create				(const double **Points, size_t nPoints);
1185 
1186 	virtual bool				Destroy				(void);
1187 
Get_Point_Value(int i)1188 	virtual double				Get_Point_Value		(int i)	const	{	return( m_Points[i][2] );	}
1189 
1190 	virtual size_t				Get_Nearest_Points	(double Coordinate[2], size_t Count, double Radius);
1191 	virtual size_t				Get_Nearest_Points	(double Coordinate[2], size_t Count, double Radius, CSG_Array_Int &Indices, CSG_Vector &Distances);
1192 	virtual size_t				Get_Nearest_Points	(double Coordinate[2], size_t Count, size_t *Indices, double *Distances);
1193 	virtual bool				Get_Nearest_Point	(double Coordinate[2], size_t &Index, double &Distance);
1194 	virtual bool				Get_Nearest_Point	(double Coordinate[2], size_t &Index);
1195 	virtual CSG_Shape *			Get_Nearest_Shape	(double Coordinate[2]);
1196 
1197 	virtual size_t				Get_Nearest_Points	(double x, double y, size_t Count, double Radius);
1198 	virtual size_t				Get_Nearest_Points	(double x, double y, size_t Count, double Radius, CSG_Array_Int &Indices, CSG_Vector &Distances);
1199 	virtual size_t				Get_Nearest_Points	(double x, double y, size_t Count, size_t *Indices, double *Distances);
1200 	virtual bool				Get_Nearest_Point	(double x, double y, size_t &Index, double &Distance);
1201 	virtual bool				Get_Nearest_Point	(double x, double y, size_t &Index);
1202 	virtual CSG_Shape *			Get_Nearest_Shape	(double x, double y);
1203 
1204 };
1205 
1206 
1207 ///////////////////////////////////////////////////////////
1208 //														 //
1209 ///////////////////////////////////////////////////////////
1210 
1211 //---------------------------------------------------------
1212 class SAGA_API_DLL_EXPORT CSG_KDTree_3D : public CSG_KDTree
1213 {
1214 public:
1215 	CSG_KDTree_3D(void);
1216 	virtual ~CSG_KDTree_3D(void);
1217 
1218 								CSG_KDTree_3D		(CSG_Shapes *pPoints, int Field = -1, int zField = -1, double zScale = 1.);
1219 	bool						Create				(CSG_Shapes *pPoints, int Field = -1, int zField = -1, double zScale = 1.);
1220 
1221 								CSG_KDTree_3D		(CSG_PointCloud *pPoints);
1222 	bool						Create				(CSG_PointCloud *pPoints);
1223 
1224 								CSG_KDTree_3D		(const CSG_Matrix &Points);
1225 	bool						Create				(const CSG_Matrix &Points);
1226 
1227 								CSG_KDTree_3D		(const double **Points, size_t nPoints);
1228 	bool						Create				(const double **Points, size_t nPoints);
1229 
1230 	virtual bool				Destroy				(void);
1231 
Get_Point_Value(int i)1232 	virtual double				Get_Point_Value		(int i)	const	{	return( m_Points[i][3] );	}
1233 
1234 	virtual size_t				Get_Nearest_Points	(double Coordinate[3], size_t Count, double Radius);
1235 
1236 	virtual size_t				Get_Nearest_Points	(double Coordinate[3], size_t Count, size_t *Indices, double *Distances);
1237 	virtual size_t				Get_Nearest_Points	(double Coordinate[3], size_t Count, double Radius, CSG_Array_Int &Indices, CSG_Vector &Distances);
1238 	virtual bool				Get_Nearest_Point	(double Coordinate[3], size_t &Index, double &Distance);
1239 	virtual bool				Get_Nearest_Point	(double Coordinate[3], size_t &Index);
1240 	virtual CSG_Shape *			Get_Nearest_Shape	(double Coordinate[3]);
1241 
1242 	virtual size_t				Get_Nearest_Points	(double x, double y, double z, size_t Count, double Radius);
1243 	virtual size_t				Get_Nearest_Points	(double x, double y, double z, size_t Count, double Radius, CSG_Array_Int &Indices, CSG_Vector &Distances);
1244 	virtual size_t				Get_Nearest_Points	(double x, double y, double z, size_t Count, size_t *Indices, double *Distances);
1245 	virtual bool				Get_Nearest_Point	(double x, double y, double z, size_t &Index, double &Distance);
1246 	virtual bool				Get_Nearest_Point	(double x, double y, double z, size_t &Index);
1247 	virtual CSG_Shape *			Get_Nearest_Shape	(double x, double y, double z);
1248 
1249 };
1250 
1251 
1252 ///////////////////////////////////////////////////////////
1253 //														 //
1254 //					Search Engine						 //
1255 //														 //
1256 ///////////////////////////////////////////////////////////
1257 
1258 //---------------------------------------------------------
1259 class SAGA_API_DLL_EXPORT CSG_Parameters_PointSearch
1260 {
1261 public:
1262 	CSG_Parameters_PointSearch(void);
~CSG_Parameters_PointSearch(void)1263 	virtual ~CSG_Parameters_PointSearch(void)	{}
1264 
1265 	virtual bool				Create					(class CSG_Parameters *pParameters, const CSG_String &Parent = "", size_t minPoints = 0);
1266 
1267 	virtual bool				On_Parameter_Changed	(class CSG_Parameters *pParameters, class CSG_Parameter *pParameter);
1268 	virtual bool				On_Parameters_Enable	(class CSG_Parameters *pParameters, class CSG_Parameter *pParameter);
1269 
1270 	virtual bool				Update					(void);
1271 
1272 	bool						Do_Use_All				(bool bUpdate = false);
1273 
Get_Min_Points(void)1274 	size_t						Get_Min_Points			(void)	const	{	return( m_minPoints );	}
Get_Max_Points(void)1275 	size_t						Get_Max_Points			(void)	const	{	return( m_maxPoints );	}
Get_Radius(void)1276 	double						Get_Radius				(void)	const	{	return( m_Radius    );	}
1277 
1278 
1279 protected:
1280 
1281 	size_t						m_minPoints, m_maxPoints;
1282 
1283 	double						m_Radius;
1284 
1285 	class CSG_Parameters		*m_pParameters;
1286 
1287 };
1288 
1289 //---------------------------------------------------------
1290 class SAGA_API_DLL_EXPORT CSG_Parameters_Search_Points : public CSG_Parameters_PointSearch
1291 {
1292 public:
1293 	CSG_Parameters_Search_Points(void);
~CSG_Parameters_Search_Points(void)1294 	virtual ~CSG_Parameters_Search_Points(void)	{}
1295 
1296 	virtual bool				Create					(class CSG_Parameters *pParameters, class CSG_Parameter *pParent       , int nPoints_Min = -1);
1297 	virtual bool				Create					(class CSG_Parameters *pParameters, const CSG_String     &Parent = ""  , int nPoints_Min = -1);
1298 
1299 	virtual bool				Update					(void);
1300 
1301 	bool						Initialize				(CSG_Shapes *pPoints, int zField);
1302 	bool						Finalize				(void);
1303 
1304 	int							Set_Location			(double x, double y);
1305 	int							Set_Location			(const TSG_Point &p);
1306 
Get_Count(void)1307 	int							Get_Count				(void)	const	{	return( m_nPoints );	}
1308 	bool						Get_Point				(int Index, double &x, double &y, double &z);
1309 
1310 	bool						Get_Points				(double x, double y, CSG_Points_Z &Points);
1311 	bool						Get_Points				(const TSG_Point &p, CSG_Points_Z &Points);
1312 
1313 
1314 private:
1315 
1316 	int							m_zField, m_nPoints, m_Quadrant;
1317 
1318 	CSG_Shapes					*m_pPoints;
1319 
1320 	CSG_PRQuadTree				m_Search;
1321 
1322 };
1323 
1324 
1325 ///////////////////////////////////////////////////////////
1326 //														 //
1327 //					Search Engine						 //
1328 //														 //
1329 ///////////////////////////////////////////////////////////
1330 
1331 //---------------------------------------------------------
1332 class SAGA_API_DLL_EXPORT CSG_Shapes_Search
1333 {
1334 public:
1335 	CSG_Shapes_Search(void);
1336 	CSG_Shapes_Search(CSG_Shapes *pPoints);
1337 
1338 	virtual ~CSG_Shapes_Search(void);
1339 
1340 	bool						Create				(CSG_Shapes *pPoints);
1341 	void						Destroy				(void);
1342 
is_Valid(void)1343 	bool						is_Valid			(void)	{	return( m_nPoints > 0 );	}
1344 
1345 	CSG_Shape *					Get_Point_Nearest	(double x, double y);
1346 	CSG_Shape *					Get_Point_Nearest	(double x, double y, int iQuadrant);
1347 
1348 	int							Select_Radius		(double x, double y, double Radius, bool bSort = false, int MaxPoints = -1, int iQuadrant = -1);
1349 	int							Select_Quadrants	(double x, double y, double Radius, int MaxPoints, int MinPoints = 0);
Get_Selected_Count(void)1350 	int							Get_Selected_Count	(void)	{	return( m_nSelected );		}
1351 
Get_Selected_Point(int iSelected)1352 	CSG_Shape *					Get_Selected_Point	(int iSelected)
1353 	{
1354 		if( iSelected >= 0 && iSelected < m_nSelected )
1355 		{
1356 			return( m_nSelected == m_Selected_Idx.Get_Count()
1357 				? m_Selected[m_Selected_Idx[iSelected]]
1358 				: m_Selected               [iSelected]
1359 			);
1360 		}
1361 
1362 		return( NULL );
1363 	}
1364 
1365 
1366 protected:
1367 
1368 	bool						m_bDestroy;
1369 
1370 	int							m_nPoints, m_nSelected, m_Selected_Buf;
1371 
1372 	double						*m_Selected_Dst;
1373 
1374 	TSG_Point					*m_Pos;
1375 
1376 	CSG_Index					m_Idx, m_Selected_Idx;
1377 
1378 	CSG_Shape					**m_Selected;
1379 
1380 	CSG_Shapes					*m_pPoints;
1381 
1382 
1383 	void						_On_Construction	(void);
1384 
1385 	int							_Get_Index_Next		(double Position);
1386 	int							_Get_Point_Nearest	(double x, double y, int iQuadrant);
1387 	void						_Select_Add			(CSG_Shape *pPoint, double Distance);
1388 
1389 };
1390 
1391 
1392 ///////////////////////////////////////////////////////////
1393 //														 //
1394 //					Polygon Tools						 //
1395 //														 //
1396 ///////////////////////////////////////////////////////////
1397 
1398 //---------------------------------------------------------
1399 SAGA_API_DLL_EXPORT bool		SG_Polygon_Intersection	(CSG_Shape *pPolygon, CSG_Shape *pClip, CSG_Shape *pResult = NULL);
1400 SAGA_API_DLL_EXPORT bool		SG_Polygon_Difference	(CSG_Shape *pPolygon, CSG_Shape *pClip, CSG_Shape *pResult = NULL);
1401 SAGA_API_DLL_EXPORT bool		SG_Polygon_ExclusiveOr	(CSG_Shape *pPolygon, CSG_Shape *pClip, CSG_Shape *pResult = NULL);
1402 SAGA_API_DLL_EXPORT bool		SG_Polygon_Union		(CSG_Shape *pPolygon, CSG_Shape *pClip, CSG_Shape *pResult = NULL);
1403 SAGA_API_DLL_EXPORT bool		SG_Polygon_Dissolve		(CSG_Shape *pPolygon, CSG_Shape *pResult = NULL);
1404 SAGA_API_DLL_EXPORT bool		SG_Polygon_Simplify		(CSG_Shape *pPolygon, CSG_Shape *pResult = NULL);
1405 SAGA_API_DLL_EXPORT bool		SG_Polygon_Offset		(CSG_Shape *pPolygon, double dSize, double dArc, CSG_Shape *pResult = NULL);
1406 
1407 
1408 ///////////////////////////////////////////////////////////
1409 //														 //
1410 //						OpenGIS							 //
1411 //														 //
1412 ///////////////////////////////////////////////////////////
1413 
1414 //---------------------------------------------------------
1415 enum ESG_OGIS_ByteOrder
1416 {
1417 	SG_OGIS_BYTEORDER_XDR				= 0,	// Big Endian
1418 	SG_OGIS_BYTEORDER_NDR				= 1		// Little Endian
1419 };
1420 
1421 //---------------------------------------------------------
1422 typedef enum ESG_OGIS_Type_Geometry
1423 {
1424 	SG_OGIS_TYPE_Undefined				=    0,
1425 
1426 	SG_OGIS_TYPE_Point					=    1,
1427 	SG_OGIS_TYPE_LineString				=    2,
1428 	SG_OGIS_TYPE_Polygon				=    3,
1429 	SG_OGIS_TYPE_MultiPoint				=    4,
1430 	SG_OGIS_TYPE_MultiLineString		=    5,
1431 	SG_OGIS_TYPE_MultiPolygon			=    6,
1432 	SG_OGIS_TYPE_GeometryCollection		=    7,
1433 	SG_OGIS_TYPE_PolyhedralSurface		=   15,
1434 	SG_OGIS_TYPE_TIN					=   16,
1435 	SG_OGIS_TYPE_Triangle				=   17,
1436 
1437 	SG_OGIS_TYPE_PointZ					= 1001,
1438 	SG_OGIS_TYPE_LineStringZ			= 1002,
1439 	SG_OGIS_TYPE_PolygonZ				= 1003,
1440 	SG_OGIS_TYPE_MultiPointZ			= 1004,
1441 	SG_OGIS_TYPE_MultiLineStringZ		= 1005,
1442 	SG_OGIS_TYPE_MultiPolygonZ			= 1006,
1443 	SG_OGIS_TYPE_GeometryCollectionZ	= 1007,
1444 	SG_OGIS_TYPE_PolyhedralSurfaceZ		= 1015,
1445 	SG_OGIS_TYPE_TINZ					= 1016,
1446 	SG_OGIS_TYPE_TriangleZ				= 1017,
1447 
1448 	SG_OGIS_TYPE_PointM					= 2001,
1449 	SG_OGIS_TYPE_LineStringM			= 2002,
1450 	SG_OGIS_TYPE_PolygonM				= 2003,
1451 	SG_OGIS_TYPE_MultiPointM			= 2004,
1452 	SG_OGIS_TYPE_MultiLineStringM		= 2005,
1453 	SG_OGIS_TYPE_MultiPolygonM			= 2006,
1454 	SG_OGIS_TYPE_GeometryCollectionM	= 2007,
1455 	SG_OGIS_TYPE_PolyhedralSurfaceM		= 2015,
1456 	SG_OGIS_TYPE_TINM					= 2016,
1457 	SG_OGIS_TYPE_TriangleM				= 2017,
1458 
1459 	SG_OGIS_TYPE_PointZM				= 3001,
1460 	SG_OGIS_TYPE_LineStringZM			= 3002,
1461 	SG_OGIS_TYPE_PolygonZM				= 3003,
1462 	SG_OGIS_TYPE_MultiPointZM			= 3004,
1463 	SG_OGIS_TYPE_MultiLineStringZM		= 3005,
1464 	SG_OGIS_TYPE_MultiPolygonZM			= 3006,
1465 	SG_OGIS_TYPE_GeometryCollectionZM	= 3007,
1466 	SG_OGIS_TYPE_PolyhedralSurfaceZM	= 3015,
1467 	SG_OGIS_TYPE_TINZM					= 3016,
1468 	SG_OGIS_TYPE_TriangleZM				= 3017
1469 }
1470 TSG_OGIS_Type_Geometry;
1471 
1472 
1473 ///////////////////////////////////////////////////////////
1474 //														 //
1475 ///////////////////////////////////////////////////////////
1476 
1477 //---------------------------------------------------------
1478 class SAGA_API_DLL_EXPORT CSG_Shapes_OGIS_Converter
1479 {
1480 public:
CSG_Shapes_OGIS_Converter(void)1481 	CSG_Shapes_OGIS_Converter(void)	{}
1482 
1483 	static bool				from_WKText				(const CSG_String &Text, CSG_Shape *pShape);
1484 	static bool				to_WKText				(CSG_Shape *pShape, CSG_String &Text);
1485 
1486 	static bool				from_WKBinary			(CSG_Bytes &Bytes, CSG_Shape *pShape);
1487 	static bool				to_WKBinary				(CSG_Shape *pShape, CSG_Bytes &Bytes);
1488 
1489 	static bool				from_ShapeType			(      CSG_String &Type, TSG_Shape_Type  Shape, TSG_Vertex_Type  Vertex = SG_VERTEX_TYPE_XY);
1490 	static CSG_String		from_ShapeType			(                        TSG_Shape_Type  Shape, TSG_Vertex_Type  Vertex = SG_VERTEX_TYPE_XY);
1491 	static bool				to_ShapeType			(const CSG_String &Type, TSG_Shape_Type &Shape, TSG_Vertex_Type &Vertex);
1492 	static TSG_Shape_Type	to_ShapeType			(const CSG_String &Type);
1493 
1494 	static bool				from_ShapeType			(DWORD            &Type, TSG_Shape_Type  Shape, TSG_Vertex_Type  Vertex = SG_VERTEX_TYPE_XY);
1495 	static bool				to_ShapeType			(DWORD             Type, TSG_Shape_Type &Shape, TSG_Vertex_Type &Vertex);
1496 	static TSG_Shape_Type	to_ShapeType			(DWORD             Type);
1497 
1498 	static CSG_String		Type_asWKText			(DWORD             Type);
1499 	static DWORD			Type_asWKBinary			(const CSG_String &Type);
1500 
1501 
1502 private:
1503 
1504 	static bool				_WKT_Read_Point			(const CSG_String &Text, CSG_Shape *pShape, int iPart);
1505 	static bool				_WKT_Read_Points		(const CSG_String &Text, CSG_Shape *pShape);
1506 	static bool				_WKT_Read_Parts			(const CSG_String &Text, CSG_Shape *pShape);
1507 	static bool				_WKT_Read_Polygon		(const CSG_String &Text, CSG_Shape *pShape);
1508 
1509 	static bool				_WKT_Write_Point		(CSG_String &Text, CSG_Shape *pShape, int iPoint, int iPart);
1510 	static bool				_WKT_Write_Points		(CSG_String &Text, CSG_Shape *pShape, int iPart);
1511 	static bool				_WKT_Write_Parts		(CSG_String &Text, CSG_Shape *pShape);
1512 	static bool				_WKT_Write_Polygon		(CSG_String &Text, CSG_Shape *pShape);
1513 
1514 	static bool				_WKB_Read_Point			(CSG_Bytes &Bytes, bool bSwapBytes, CSG_Shape *pShape, int iPart);
1515 	static bool				_WKB_Read_Points		(CSG_Bytes &Bytes, bool bSwapBytes, CSG_Shape *pShape);
1516 	static bool				_WKB_Read_Parts			(CSG_Bytes &Bytes, bool bSwapBytes, CSG_Shape *pShape);
1517 	static bool				_WKB_Read_MultiLine		(CSG_Bytes &Bytes, bool bSwapBytes, CSG_Shape *pShape);
1518 	static bool				_WKB_Read_MultiPolygon	(CSG_Bytes &Bytes, bool bSwapBytes, CSG_Shape *pShape);
1519 
1520 	static bool				_WKB_Write_Point		(CSG_Bytes &Bytes, CSG_Shape *pShape, int iPoint, int iPart);
1521 	static bool				_WKB_Write_Points		(CSG_Bytes &Bytes, CSG_Shape *pShape, int iPart);
1522 	static bool				_WKB_Write_Parts		(CSG_Bytes &Bytes, CSG_Shape *pShape);
1523 	static bool				_WKB_Write_MultiLine	(CSG_Bytes &Bytes, CSG_Shape *pShape);
1524 	static bool				_WKB_Write_MultiPolygon	(CSG_Bytes &Bytes, CSG_Shape *pShape);
1525 
1526 };
1527 
1528 
1529 ///////////////////////////////////////////////////////////
1530 //														 //
1531 ///////////////////////////////////////////////////////////
1532 
1533 //---------------------------------------------------------
1534 class SAGA_API_DLL_EXPORT CSG_Grid_OGIS_Converter
1535 {
1536 public:
CSG_Grid_OGIS_Converter(void)1537 	CSG_Grid_OGIS_Converter(void)	{}
1538 
1539 	static bool				from_WKBinary			(CSG_Bytes &Bytes, class CSG_Grid *pGrid);
1540 	static bool				to_WKBinary				(CSG_Bytes &Bytes, class CSG_Grid *pGrid, int SRID = -1);
1541 
1542 };
1543 
1544 
1545 ///////////////////////////////////////////////////////////
1546 //														 //
1547 //														 //
1548 //														 //
1549 ///////////////////////////////////////////////////////////
1550 
1551 //---------------------------------------------------------
1552 #endif // #ifndef HEADER_INCLUDED__SAGA_API__shapes_H
1553