SAGA API v9.10
Loading...
Searching...
No Matches
shapes_ogis.cpp
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// shapes_ogis.cpp //
15// //
16// Copyright (C) 2010 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#include "shapes.h"
52
53
55// //
56// //
57// //
59
60//---------------------------------------------------------
62{
63 switch( Type )
64 {
65 case SG_OGIS_TYPE_Point : return( "Point" );
66 case SG_OGIS_TYPE_LineString : return( "LineString" );
67 case SG_OGIS_TYPE_Polygon : return( "Polygon" );
68 case SG_OGIS_TYPE_MultiPoint : return( "MultiPoint" );
69 case SG_OGIS_TYPE_MultiLineString : return( "MultiLineString" );
70 case SG_OGIS_TYPE_MultiPolygon : return( "MultiPolygon" );
71 case SG_OGIS_TYPE_GeometryCollection : return( "GeometryCollection" );
72 case SG_OGIS_TYPE_PolyhedralSurface : return( "PolyhedralSurface" );
73 case SG_OGIS_TYPE_TIN : return( "TIN" );
74 case SG_OGIS_TYPE_Triangle : return( "Triangle" );
75
76 case SG_OGIS_TYPE_PointZ : return( "PointZ" );
77 case SG_OGIS_TYPE_LineStringZ : return( "LineStringZ" );
78 case SG_OGIS_TYPE_PolygonZ : return( "PolygonZ" );
79 case SG_OGIS_TYPE_MultiPointZ : return( "MultiPointZ" );
80 case SG_OGIS_TYPE_MultiLineStringZ : return( "MultiLineStringZ" );
81 case SG_OGIS_TYPE_MultiPolygonZ : return( "MultiPolygonZ" );
82 case SG_OGIS_TYPE_GeometryCollectionZ : return( "GeometryCollectionZ" );
83 case SG_OGIS_TYPE_PolyhedralSurfaceZ : return( "PolyhedralSurfaceZ" );
84 case SG_OGIS_TYPE_TINZ : return( "TINZ" );
85 case SG_OGIS_TYPE_TriangleZ : return( "TriangleZ" );
86
87 case SG_OGIS_TYPE_PointM : return( "PointM" );
88 case SG_OGIS_TYPE_LineStringM : return( "LineStringM" );
89 case SG_OGIS_TYPE_PolygonM : return( "PolygonM" );
90 case SG_OGIS_TYPE_MultiPointM : return( "MultiPointM" );
91 case SG_OGIS_TYPE_MultiLineStringM : return( "MultiLineStringM" );
92 case SG_OGIS_TYPE_MultiPolygonM : return( "MultiPolygonM" );
93 case SG_OGIS_TYPE_GeometryCollectionM : return( "GeometryCollectionM" );
94 case SG_OGIS_TYPE_PolyhedralSurfaceM : return( "PolyhedralSurfaceM" );
95 case SG_OGIS_TYPE_TINM : return( "TINM" );
96 case SG_OGIS_TYPE_TriangleM : return( "TriangleM" );
97
98 case SG_OGIS_TYPE_PointZM : return( "PointZM" );
99 case SG_OGIS_TYPE_LineStringZM : return( "LineStringZM" );
100 case SG_OGIS_TYPE_PolygonZM : return( "PolygonZM" );
101 case SG_OGIS_TYPE_MultiPointZM : return( "MultiPointZM" );
102 case SG_OGIS_TYPE_MultiLineStringZM : return( "MultiLineStringZM" );
103 case SG_OGIS_TYPE_MultiPolygonZM : return( "MultiPolygonZM" );
104 case SG_OGIS_TYPE_GeometryCollectionZM : return( "GeometryCollectionZM" );
105 case SG_OGIS_TYPE_PolyhedralSurfaceZM : return( "PolyhedralSurfaceZM" );
106 case SG_OGIS_TYPE_TINZM : return( "TINZM" );
107 case SG_OGIS_TYPE_TriangleZM : return( "TriangleZM" );
108 }
109
110 return( "" );
111}
112
113//---------------------------------------------------------
115{
116 #define TYPE_AS_WKB(t) if( !Type.CmpNoCase(Type_asWKText(t)) ) return( t );
117
128
139
150
161
162 return( SG_OGIS_TYPE_Undefined );
163}
164
165
167// //
168// //
169// //
171
172//---------------------------------------------------------
173inline bool CSG_Shapes_OGIS_Converter::_WKT_Read_Point(const CSG_String &Text, CSG_Shape *pShape, int iPart)
174{
175 double x, y, z, m;
176
177 switch( pShape->Get_Vertex_Type() )
178 {
180 if( SG_SSCANF(Text.c_str(), SG_T("%lf %lf"), &x, &y) == 2 )
181 {
182 pShape->Add_Point(x, y, iPart);
183
184 return( true );
185 }
186 break;
187
189 if( SG_SSCANF(Text.c_str(), SG_T("%lf %lf %lf"), &x, &y, &z) == 3 )
190 {
191 pShape->Add_Point(x, y, iPart);
192 pShape->Set_Z (z, pShape->Get_Point_Count(iPart) - 1, iPart);
193
194 return( true );
195 }
196 break;
197
199 if( SG_SSCANF(Text.c_str(), SG_T("%lf %lf %lf %lf"), &x, &y, &z, &m) == 4 )
200 {
201 pShape->Add_Point(x, y, iPart);
202 pShape->Set_Z (z, pShape->Get_Point_Count(iPart) - 1, iPart);
203 pShape->Set_M (m, pShape->Get_Point_Count(iPart) - 1, iPart);
204
205 return( true );
206 }
207 break;
208 }
209
210 return( false );
211}
212
213//---------------------------------------------------------
214bool CSG_Shapes_OGIS_Converter::_WKT_Read_Points(const CSG_String &Text, CSG_Shape *pShape)
215{
216 CSG_String s(Text.AfterFirst('(').BeforeFirst(')')); int iPart = pShape->Get_Part_Count();
217
218 while( s.Length() > 0 )
219 {
220 if( !_WKT_Read_Point(s, pShape, iPart) )
221 {
222 return( false );
223 }
224
225 s = s.AfterFirst(',');
226 }
227
228 return( pShape->Get_Point_Count(iPart) > 0 );
229}
230
231//---------------------------------------------------------
232bool CSG_Shapes_OGIS_Converter::_WKT_Read_Parts(const CSG_String &Text, CSG_Shape *pShape)
233{
234 CSG_String s(Text.AfterFirst('(').BeforeLast(')'));
235
236 while( s.Length() > 0 )
237 {
238 _WKT_Read_Points(s, pShape);
239
240 s = s.AfterFirst(',');
241 }
242
243 return( pShape->Get_Part_Count() > 0 );
244}
245
246//---------------------------------------------------------
247bool CSG_Shapes_OGIS_Converter::_WKT_Read_Polygon(const CSG_String &Text, CSG_Shape *pShape)
248{
249 CSG_String Part;
250
251 for(int i=0, Level=-2; i<(int)Text.Length(); i++)
252 {
253 if( Text[i] == '(' )
254 {
255 Level++;
256 }
257 else if( Text[i] == ')' )
258 {
259 if( Level == 0 )
260 {
261 Part += Text[i];
262 _WKT_Read_Parts(Part, pShape);
263 Part.Clear();
264 }
265
266 Level--;
267 }
268
269 if( Level >= 0 )
270 {
271 Part += Text[i];
272 }
273 }
274
275 return( pShape->Get_Part_Count() > 0 );
276}
277
278//---------------------------------------------------------
280{
281 pShape->Del_Parts();
282
283 CSG_String Type(Text.BeforeFirst('(')); Type.Trim_Both();
284
285 if( pShape->Get_Type() == to_ShapeType(Type) )
286 {
287 switch( Type_asWKBinary(Type) )
288 {
289 case SG_OGIS_TYPE_Point :
292 case SG_OGIS_TYPE_PointZM : return( _WKT_Read_Point(Text.AfterFirst('(').BeforeFirst(')'), pShape, 0) );
293
297 case SG_OGIS_TYPE_MultiPointZM : return( _WKT_Read_Points (Text, pShape) );
298
302 case SG_OGIS_TYPE_LineStringZM : return( _WKT_Read_Points (Text, pShape) );
303
308 return( _WKT_Read_Parts (Text, pShape) );
309
313 case SG_OGIS_TYPE_PolygonZM : return( _WKT_Read_Parts (Text, pShape) );
314
318 case SG_OGIS_TYPE_MultiPolygonZM : return( _WKT_Read_Polygon(Text, pShape) );
319 }
320 }
321
322 return( false );
323}
324
325
327// //
329
330//---------------------------------------------------------
331inline bool CSG_Shapes_OGIS_Converter::_WKT_Write_Point(CSG_String &Text, CSG_Shape *pShape, int iPoint, int iPart)
332{
333 TSG_Point Point = pShape->Get_Point(iPoint, iPart);
334
335 switch( ((CSG_Shapes *)pShape->Get_Table())->Get_Vertex_Type() )
336 {
338 Text += CSG_String::Format("%f %f" , Point.x, Point.y);
339 break;
340
342 Text += CSG_String::Format("%f %f %f" , Point.x, Point.y, pShape->Get_Z(iPoint, iPart));
343 break;
344
346 Text += CSG_String::Format("%f %f %f %f", Point.x, Point.y, pShape->Get_Z(iPoint, iPart), pShape->Get_M(iPoint, iPart));
347 break;
348 }
349
350 return( false );
351}
352
353//---------------------------------------------------------
354inline bool CSG_Shapes_OGIS_Converter::_WKT_Write_Points(CSG_String &Text, CSG_Shape *pShape, int iPart)
355{
356 Text += "(";
357
358 for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
359 {
360 if( iPoint > 0 )
361 {
362 Text += ", ";
363 }
364
365 _WKT_Write_Point(Text, pShape, iPoint, iPart);
366 }
367
368 if( pShape->Get_Type() == SHAPE_TYPE_Polygon && CSG_Point(pShape->Get_Point(0, iPart)) != pShape->Get_Point(pShape->Get_Point_Count(iPart) -1, iPart) )
369 {
370 Text += ", ";
371
372 _WKT_Write_Point(Text, pShape, 0, iPart);
373 }
374
375 Text += ")";
376
377 return( true );
378}
379
380//---------------------------------------------------------
381inline bool CSG_Shapes_OGIS_Converter::_WKT_Write_Parts(CSG_String &Text, CSG_Shape *pShape)
382{
383 Text += "(";
384
385 for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
386 {
387 if( iPart > 0 )
388 {
389 Text += ", ";
390 }
391
392 _WKT_Write_Points(Text, pShape, iPart);
393 }
394
395 Text += ")";
396
397 return( true );
398}
399
400//---------------------------------------------------------
401inline bool CSG_Shapes_OGIS_Converter::_WKT_Write_Polygon(CSG_String &Text, CSG_Shape *pShape)
402{
403 Text += "(";
404
405 for(int iPart=0, nIslands=0; iPart<pShape->Get_Part_Count(); iPart++)
406 {
407 if( ((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) == false )
408 {
409 if( nIslands++ > 0 )
410 {
411 Text += ", ";
412 }
413
414 Text += "(";
415
416 _WKT_Write_Points(Text, pShape, iPart);
417
418 for(int jPart=0; jPart<pShape->Get_Part_Count(); jPart++)
419 {
420 if( ((CSG_Shape_Polygon *)pShape)->is_Lake(jPart) && ((CSG_Shape_Polygon *)pShape)->Contains(pShape->Get_Point(0, jPart), iPart) )
421 {
422 Text += ", ";
423
424 _WKT_Write_Points(Text, pShape, jPart);
425 }
426 }
427
428 Text += ")";
429 }
430 }
431
432 Text += ")";
433
434 return( true );
435}
436
437//---------------------------------------------------------
439{
440 switch( pShape->Get_Type() )
441 {
442 case SHAPE_TYPE_Point : _WKT_Write_Points (Text = from_ShapeType(pShape->Get_Type(), pShape->Get_Vertex_Type()), pShape, 0); break;
443 case SHAPE_TYPE_Points : _WKT_Write_Parts (Text = from_ShapeType(pShape->Get_Type(), pShape->Get_Vertex_Type()), pShape ); break;
444 case SHAPE_TYPE_Line : _WKT_Write_Parts (Text = from_ShapeType(pShape->Get_Type(), pShape->Get_Vertex_Type()), pShape ); break;
445 case SHAPE_TYPE_Polygon: _WKT_Write_Polygon(Text = from_ShapeType(pShape->Get_Type(), pShape->Get_Vertex_Type()), pShape ); break;
446
447 default:
448 return( false );
449 }
450
451 return( true );
452}
453
454
456// //
458
459//---------------------------------------------------------
460inline bool CSG_Shapes_OGIS_Converter::_WKB_Read_Point(CSG_Bytes &Bytes, bool bSwapBytes, TSG_Vertex_Type Vertex, CSG_Shape *pShape, int iPart)
461{
462 if( !Bytes.is_EOF() )
463 {
464 double x = Bytes.Read_Double(bSwapBytes);
465 double y = Bytes.Read_Double(bSwapBytes);
466
467 pShape->Add_Point(x, y, iPart);
468
469 switch( Vertex )
470 {
471 default:
472 break;
473
475 pShape->Set_Z(Bytes.Read_Double(bSwapBytes), pShape->Get_Point_Count(iPart) - 1, iPart);
476 break;
477
479 pShape->Set_Z(Bytes.Read_Double(bSwapBytes), pShape->Get_Point_Count(iPart) - 1, iPart);
480 pShape->Set_M(Bytes.Read_Double(bSwapBytes), pShape->Get_Point_Count(iPart) - 1, iPart);
481 break;
482 }
483
484 return( true );
485 }
486
487 return( false );
488}
489
490//---------------------------------------------------------
491bool CSG_Shapes_OGIS_Converter::_WKB_Read_Points(CSG_Bytes &Bytes, bool bSwapBytes, TSG_Vertex_Type Vertex, CSG_Shape *pShape)
492{
493 DWORD nPoints = Bytes.Read_DWord(bSwapBytes), iPart = pShape->Get_Part_Count();
494
495 for(DWORD iPoint=0; iPoint<nPoints; iPoint++)
496 {
497 if( !_WKB_Read_Point(Bytes, bSwapBytes, Vertex, pShape, iPart) )
498 {
499 return( false );
500 }
501 }
502
503 return( pShape->Get_Point_Count(iPart) > 0 );
504}
505
506//---------------------------------------------------------
507bool CSG_Shapes_OGIS_Converter::_WKB_Read_Polygon(CSG_Bytes &Bytes, bool bSwapBytes, TSG_Vertex_Type Vertex, CSG_Shape *pShape)
508{
509 int nParts = (int)Bytes.Read_DWord(bSwapBytes);
510
511 for(int iPart=0; iPart<nParts; iPart++)
512 {
513 if( !_WKB_Read_Points(Bytes, bSwapBytes, Vertex, pShape) )
514 {
515 return( false );
516 }
517 }
518
519 return( pShape->Get_Part_Count() > 0 );
520}
521
522//---------------------------------------------------------
523bool CSG_Shapes_OGIS_Converter::_WKB_Read_MultiPoint(CSG_Bytes &Bytes, bool bSwapBytes, TSG_Vertex_Type Vertex, CSG_Shape *pShape)
524{
525 DWORD nPoints = Bytes.Read_DWord(bSwapBytes), iPart = pShape->Get_Part_Count();
526
527 for(DWORD iPoint=0; iPoint<nPoints; iPoint++)
528 {
529 bSwapBytes = Bytes.Read_Byte() != SG_OGIS_BYTEORDER_NDR;
530
531 TSG_Shape_Type Geometry; TSG_Vertex_Type _Vertex; to_ShapeType(Bytes.Read_DWord(bSwapBytes), Geometry, _Vertex);
532
533 if( Geometry != SHAPE_TYPE_Point || Vertex != _Vertex || !_WKB_Read_Point(Bytes, bSwapBytes, Vertex, pShape, iPart) )
534 {
535 return( false );
536 }
537 }
538
539 return( pShape->Get_Point_Count(iPart) > 0 );
540}
541
542//---------------------------------------------------------
543bool CSG_Shapes_OGIS_Converter::_WKB_Read_MultiLine(CSG_Bytes &Bytes, bool bSwapBytes, TSG_Vertex_Type Vertex, CSG_Shape *pShape)
544{
545 DWORD nLines = Bytes.Read_DWord(bSwapBytes);
546
547 for(DWORD iLine=0; iLine<nLines; iLine++)
548 {
549 bSwapBytes = Bytes.Read_Byte() != SG_OGIS_BYTEORDER_NDR;
550
551 TSG_Shape_Type Geometry; TSG_Vertex_Type _Vertex; to_ShapeType(Bytes.Read_DWord(bSwapBytes), Geometry, _Vertex);
552
553 if( Geometry != SHAPE_TYPE_Line || Vertex != _Vertex || !_WKB_Read_Points(Bytes, bSwapBytes, Vertex, pShape) )
554 {
555 return( false );
556 }
557 }
558
559 return( pShape->Get_Part_Count() > 0 );
560}
561
562//---------------------------------------------------------
563bool CSG_Shapes_OGIS_Converter::_WKB_Read_MultiPolygon(CSG_Bytes &Bytes, bool bSwapBytes, TSG_Vertex_Type Vertex, CSG_Shape *pShape)
564{
565 DWORD nPolygons = Bytes.Read_DWord(bSwapBytes);
566
567 for(DWORD iPolygon=0; iPolygon<nPolygons; iPolygon++)
568 {
569 bSwapBytes = Bytes.Read_Byte() != SG_OGIS_BYTEORDER_NDR;
570
571 TSG_Shape_Type Geometry; TSG_Vertex_Type _Vertex; to_ShapeType(Bytes.Read_DWord(bSwapBytes), Geometry, _Vertex);
572
573 if( Geometry != SHAPE_TYPE_Polygon || Vertex != _Vertex || !_WKB_Read_Polygon(Bytes, bSwapBytes, Vertex, pShape) )
574 {
575 return( false );
576 }
577 }
578
579 return( pShape->Get_Part_Count() > 0 );
580}
581
582//---------------------------------------------------------
584{
585 pShape->Del_Parts();
586
587 if( Bytes.Get_Count() >= 4 )
588 {
589 Bytes.Rewind();
590
591 bool bSwapBytes = Bytes.Read_Byte() != SG_OGIS_BYTEORDER_NDR;
592
593 DWORD Type = Bytes.Read_DWord();
594
595 if( pShape->Get_Type() == to_ShapeType(Type) )
596 {
597 switch( Type )
598 {
599 case SG_OGIS_TYPE_Point : return( _WKB_Read_Point (Bytes, bSwapBytes, SG_VERTEX_TYPE_XY , pShape, 0) );
600 case SG_OGIS_TYPE_PointZ : return( _WKB_Read_Point (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape, 0) );
601 case SG_OGIS_TYPE_PointM : return( _WKB_Read_Point (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape, 0) );
602 case SG_OGIS_TYPE_PointZM : return( _WKB_Read_Point (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZM, pShape, 0) );
603
604 case SG_OGIS_TYPE_MultiPoint : return( _WKB_Read_MultiPoint (Bytes, bSwapBytes, SG_VERTEX_TYPE_XY , pShape ) );
605 case SG_OGIS_TYPE_MultiPointZ : return( _WKB_Read_MultiPoint (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape ) );
606 case SG_OGIS_TYPE_MultiPointM : return( _WKB_Read_MultiPoint (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape ) );
607 case SG_OGIS_TYPE_MultiPointZM : return( _WKB_Read_MultiPoint (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZM, pShape ) );
608
609 case SG_OGIS_TYPE_LineString : return( _WKB_Read_Points (Bytes, bSwapBytes, SG_VERTEX_TYPE_XY , pShape ) );
610 case SG_OGIS_TYPE_LineStringZ : return( _WKB_Read_Points (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape ) );
611 case SG_OGIS_TYPE_LineStringM : return( _WKB_Read_Points (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape ) );
612 case SG_OGIS_TYPE_LineStringZM : return( _WKB_Read_Points (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZM, pShape ) );
613
614 case SG_OGIS_TYPE_MultiLineString : return( _WKB_Read_MultiLine (Bytes, bSwapBytes, SG_VERTEX_TYPE_XY , pShape ) );
615 case SG_OGIS_TYPE_MultiLineStringZ : return( _WKB_Read_MultiLine (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape ) );
616 case SG_OGIS_TYPE_MultiLineStringM : return( _WKB_Read_MultiLine (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape ) );
617 case SG_OGIS_TYPE_MultiLineStringZM: return( _WKB_Read_MultiLine (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZM, pShape ) );
618
619 case SG_OGIS_TYPE_Polygon : return( _WKB_Read_Polygon (Bytes, bSwapBytes, SG_VERTEX_TYPE_XY , pShape ) );
620 case SG_OGIS_TYPE_PolygonZ : return( _WKB_Read_Polygon (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape ) );
621 case SG_OGIS_TYPE_PolygonM : return( _WKB_Read_Polygon (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape ) );
622 case SG_OGIS_TYPE_PolygonZM : return( _WKB_Read_Polygon (Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZM, pShape ) );
623
624 case SG_OGIS_TYPE_MultiPolygon : return( _WKB_Read_MultiPolygon(Bytes, bSwapBytes, SG_VERTEX_TYPE_XY , pShape ) );
625 case SG_OGIS_TYPE_MultiPolygonZ : return( _WKB_Read_MultiPolygon(Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape ) );
626 case SG_OGIS_TYPE_MultiPolygonM : return( _WKB_Read_MultiPolygon(Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZ , pShape ) );
627 case SG_OGIS_TYPE_MultiPolygonZM : return( _WKB_Read_MultiPolygon(Bytes, bSwapBytes, SG_VERTEX_TYPE_XYZM, pShape ) );
628 }
629 }
630 }
631
632 return( false );
633}
634
635
637// //
639
640//---------------------------------------------------------
641inline bool CSG_Shapes_OGIS_Converter::_WKB_Write_Point(CSG_Bytes &Bytes, CSG_Shape *pShape, int iPoint, int iPart)
642{
643 TSG_Point Point = pShape->Get_Point(iPoint, iPart);
644
645 Bytes += Point.x;
646 Bytes += Point.y;
647
648 switch( pShape->Get_Vertex_Type() )
649 {
651 break;
652
654 Bytes += pShape->Get_Z(iPoint, iPart);
655 break;
656
658 Bytes += pShape->Get_Z(iPoint, iPart);
659 Bytes += pShape->Get_M(iPoint, iPart);
660 break;
661 }
662
663 return( true );
664}
665
666//---------------------------------------------------------
667bool CSG_Shapes_OGIS_Converter::_WKB_Write_Points(CSG_Bytes &Bytes, CSG_Shape *pShape, int iPart)
668{
669 bool bFirstTwice = pShape->Get_Type() == SHAPE_TYPE_Polygon && CSG_Point(pShape->Get_Point(0, iPart)) != pShape->Get_Point(0, iPart, false);
670
671 Bytes += (DWORD)(pShape->Get_Point_Count(iPart) + (bFirstTwice ? 1 : 0));
672
673 for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
674 {
675 _WKB_Write_Point(Bytes, pShape, iPoint, iPart);
676 }
677
678 if( bFirstTwice )
679 {
680 _WKB_Write_Point(Bytes, pShape, 0, iPart);
681 }
682
683 return( true );
684}
685
686//---------------------------------------------------------
687bool CSG_Shapes_OGIS_Converter::_WKB_Write_MultiPoint(CSG_Bytes &Bytes, CSG_Shape *pShape)
688{
689 Bytes += (DWORD)pShape->Get_Point_Count(); // total number of points
690
691 for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
692 {
693 for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
694 {
695 Bytes += (BYTE)SG_OGIS_BYTEORDER_NDR;
696
697 switch( pShape->Get_Vertex_Type() )
698 {
699 case SG_VERTEX_TYPE_XY : Bytes += (DWORD)SG_OGIS_TYPE_Point ; break;
700 case SG_VERTEX_TYPE_XYZ : Bytes += (DWORD)SG_OGIS_TYPE_PointZ ; break;
701 case SG_VERTEX_TYPE_XYZM: Bytes += (DWORD)SG_OGIS_TYPE_PointZM; break;
702 }
703
704 if( !_WKB_Write_Point(Bytes, pShape, iPoint, iPart) )
705 {
706 return( false );
707 }
708 }
709 }
710
711 return( true );
712}
713
714//---------------------------------------------------------
715bool CSG_Shapes_OGIS_Converter::_WKB_Write_MultiLine(CSG_Bytes &Bytes, CSG_Shape *pShape)
716{
717 Bytes += (DWORD)pShape->Get_Part_Count();
718
719 for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
720 {
721 Bytes += (BYTE)SG_OGIS_BYTEORDER_NDR;
722
723 switch( pShape->Get_Vertex_Type() )
724 {
725 case SG_VERTEX_TYPE_XY : Bytes += (DWORD)SG_OGIS_TYPE_LineString ; break;
726 case SG_VERTEX_TYPE_XYZ : Bytes += (DWORD)SG_OGIS_TYPE_LineStringZ ; break;
727 case SG_VERTEX_TYPE_XYZM: Bytes += (DWORD)SG_OGIS_TYPE_LineStringZM; break;
728 }
729
730 if( !_WKB_Write_Points(Bytes, pShape, iPart) )
731 {
732 return( false );
733 }
734 }
735
736 return( true );
737}
738
739//---------------------------------------------------------
740bool CSG_Shapes_OGIS_Converter::_WKB_Write_MultiPolygon(CSG_Bytes &Bytes, CSG_Shape *pShape)
741{
742 int nPolygons = 0; CSG_Array_Int nRings(pShape->Get_Part_Count()), iPolygon(pShape->Get_Part_Count());
743
744 for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
745 {
746 nRings[iPart] = 0;
747
748 if( ((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) == false )
749 {
750 nPolygons ++;
751 nRings [iPart] ++;
752 iPolygon[iPart] = iPart;
753
754 for(int jPart=0; jPart<pShape->Get_Part_Count(); jPart++)
755 {
756 if( ((CSG_Shape_Polygon *)pShape)->is_Lake(jPart) && ((CSG_Shape_Polygon *)pShape)->Contains(pShape->Get_Point(0, jPart), iPart) )
757 {
758 nRings [iPart] ++;
759 iPolygon[jPart] = iPart;
760 }
761 }
762 }
763 }
764
765 Bytes += (DWORD)nPolygons;
766
767 for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
768 {
769 if( nRings[iPart] > 0 )
770 {
771 Bytes += (BYTE)SG_OGIS_BYTEORDER_NDR;
772
773 switch( pShape->Get_Vertex_Type() )
774 {
775 case SG_VERTEX_TYPE_XY : Bytes += (DWORD)SG_OGIS_TYPE_Polygon ; break;
776 case SG_VERTEX_TYPE_XYZ : Bytes += (DWORD)SG_OGIS_TYPE_PolygonZ ; break;
777 case SG_VERTEX_TYPE_XYZM: Bytes += (DWORD)SG_OGIS_TYPE_PolygonZM; break;
778 }
779
780 Bytes += (DWORD)nRings[iPart];
781
782 for(int jPart=0; jPart<pShape->Get_Part_Count(); jPart++)
783 {
784 if( iPolygon[jPart] == iPart )
785 {
786 if( !_WKB_Write_Points(Bytes, pShape, jPart) )
787 {
788 return( false );
789 }
790 }
791 }
792 }
793 }
794
795 return( nPolygons > 0 );
796}
797
798//---------------------------------------------------------
800{
801 DWORD Type;
802
803 if( from_ShapeType(Type, pShape->Get_Type(), pShape->Get_Vertex_Type()) )
804 {
805 Bytes.Destroy();
806
807 Bytes += (BYTE)SG_OGIS_BYTEORDER_NDR;
808 Bytes += Type;
809
810 switch( pShape->Get_Type() )
811 {
812 case SHAPE_TYPE_Point : return( _WKB_Write_Point (Bytes, pShape, 0, 0) );
813 case SHAPE_TYPE_Points : return( _WKB_Write_MultiPoint (Bytes, pShape ) );
814 case SHAPE_TYPE_Line : return( _WKB_Write_MultiLine (Bytes, pShape ) );
815 case SHAPE_TYPE_Polygon: return( _WKB_Write_MultiPolygon(Bytes, pShape ) );
816 default: break;
817 }
818 }
819
820 return( false );
821}
822
823
825// //
826// //
827// //
829
830//---------------------------------------------------------
832{
833 switch( Vertex )
834 {
836 switch( Shape )
837 {
838 case SHAPE_TYPE_Point : Type = Type_asWKText(SG_OGIS_TYPE_Point ); return( true );
839 case SHAPE_TYPE_Points : Type = Type_asWKText(SG_OGIS_TYPE_MultiPoint ); return( true );
840 case SHAPE_TYPE_Line : Type = Type_asWKText(SG_OGIS_TYPE_MultiLineString ); return( true );
841 case SHAPE_TYPE_Polygon: Type = Type_asWKText(SG_OGIS_TYPE_MultiPolygon ); return( true );
842 default: break;
843 }
844 break;
845
847 switch( Shape )
848 {
849 case SHAPE_TYPE_Point : Type = Type_asWKText(SG_OGIS_TYPE_PointZ ); return( true );
850 case SHAPE_TYPE_Points : Type = Type_asWKText(SG_OGIS_TYPE_MultiPointZ ); return( true );
851 case SHAPE_TYPE_Line : Type = Type_asWKText(SG_OGIS_TYPE_MultiLineStringZ ); return( true );
852 case SHAPE_TYPE_Polygon: Type = Type_asWKText(SG_OGIS_TYPE_MultiPolygonZ ); return( true );
853 default: break;
854 }
855 break;
856
858 switch( Shape )
859 {
860 case SHAPE_TYPE_Point : Type = Type_asWKText(SG_OGIS_TYPE_PointZM ); return( true );
861 case SHAPE_TYPE_Points : Type = Type_asWKText(SG_OGIS_TYPE_MultiPointZM ); return( true );
862 case SHAPE_TYPE_Line : Type = Type_asWKText(SG_OGIS_TYPE_MultiLineStringZM); return( true );
863 case SHAPE_TYPE_Polygon: Type = Type_asWKText(SG_OGIS_TYPE_MultiPolygonZM ); return( true );
864 default: break;
865 }
866 break;
867 }
868
869 return( false );
870}
871
872//---------------------------------------------------------
874{
875 switch( Vertex )
876 {
878 switch( Shape )
879 {
880 case SHAPE_TYPE_Point : Type = SG_OGIS_TYPE_Point ; return( true );
881 case SHAPE_TYPE_Points : Type = SG_OGIS_TYPE_MultiPoint ; return( true );
882 case SHAPE_TYPE_Line : Type = SG_OGIS_TYPE_MultiLineString; return( true );
883 case SHAPE_TYPE_Polygon: Type = SG_OGIS_TYPE_MultiPolygon ; return( true );
884 default: break;
885 }
886 break;
887
889 switch( Shape )
890 {
891 case SHAPE_TYPE_Point : Type = SG_OGIS_TYPE_PointZ ; return( true );
892 case SHAPE_TYPE_Points : Type = SG_OGIS_TYPE_MultiPointZ ; return( true );
893 case SHAPE_TYPE_Line : Type = SG_OGIS_TYPE_MultiLineStringZ; return( true );
894 case SHAPE_TYPE_Polygon: Type = SG_OGIS_TYPE_MultiPolygonZ ; return( true );
895 default: break;
896 }
897 break;
898
900 switch( Shape )
901 {
902 case SHAPE_TYPE_Point : Type = SG_OGIS_TYPE_PointZM ; return( true );
903 case SHAPE_TYPE_Points : Type = SG_OGIS_TYPE_MultiPointZM ; return( true );
904 case SHAPE_TYPE_Line : Type = SG_OGIS_TYPE_MultiLineStringZM; return( true );
905 case SHAPE_TYPE_Polygon: Type = SG_OGIS_TYPE_MultiPolygonZM ; return( true );
906 default: break;
907 }
908 break;
909 }
910
911 return( false );
912}
913
914//---------------------------------------------------------
916{
917 CSG_String Type;
918
919 from_ShapeType(Type, Shape, Vertex);
920
921 return( Type );
922}
923
924//---------------------------------------------------------
926{
927 switch( Type_asWKBinary(Type) )
928 {
929 case SG_OGIS_TYPE_Point : Shape = SHAPE_TYPE_Point ; Vertex = SG_VERTEX_TYPE_XY ; return( true );
930 case SG_OGIS_TYPE_MultiPoint : Shape = SHAPE_TYPE_Points ; Vertex = SG_VERTEX_TYPE_XY ; return( true );
931 case SG_OGIS_TYPE_LineString : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XY ; return( true );
932 case SG_OGIS_TYPE_MultiLineString : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XY ; return( true );
933 case SG_OGIS_TYPE_Polygon : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XY ; return( true );
934 case SG_OGIS_TYPE_MultiPolygon : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XY ; return( true );
935
936 case SG_OGIS_TYPE_PointZ : Shape = SHAPE_TYPE_Point ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
937 case SG_OGIS_TYPE_MultiPointZ : Shape = SHAPE_TYPE_Points ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
938 case SG_OGIS_TYPE_LineStringZ : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
939 case SG_OGIS_TYPE_MultiLineStringZ : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
940 case SG_OGIS_TYPE_PolygonZ : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
941 case SG_OGIS_TYPE_MultiPolygonZ : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
942
943 case SG_OGIS_TYPE_PointM : Shape = SHAPE_TYPE_Point ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
944 case SG_OGIS_TYPE_MultiPointM : Shape = SHAPE_TYPE_Points ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
945 case SG_OGIS_TYPE_LineStringM : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
946 case SG_OGIS_TYPE_MultiLineStringM : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
947 case SG_OGIS_TYPE_PolygonM : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
948 case SG_OGIS_TYPE_MultiPolygonM : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
949
950 case SG_OGIS_TYPE_PointZM : Shape = SHAPE_TYPE_Point ; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
951 case SG_OGIS_TYPE_MultiPointZM : Shape = SHAPE_TYPE_Points ; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
952 case SG_OGIS_TYPE_LineStringZM : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
953 case SG_OGIS_TYPE_MultiLineStringZM : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
954 case SG_OGIS_TYPE_PolygonZM : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
955 case SG_OGIS_TYPE_MultiPolygonZM : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
956 }
957
958 Shape = SHAPE_TYPE_Undefined; Vertex = SG_VERTEX_TYPE_XY;
959
960 return( false );
961}
962
963//---------------------------------------------------------
965{
966 switch( Type )
967 {
968 case SG_OGIS_TYPE_Point : Shape = SHAPE_TYPE_Point ; Vertex = SG_VERTEX_TYPE_XY ; return( true );
969 case SG_OGIS_TYPE_MultiPoint : Shape = SHAPE_TYPE_Points ; Vertex = SG_VERTEX_TYPE_XY ; return( true );
970 case SG_OGIS_TYPE_LineString : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XY ; return( true );
971 case SG_OGIS_TYPE_MultiLineString : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XY ; return( true );
972 case SG_OGIS_TYPE_Polygon : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XY ; return( true );
973 case SG_OGIS_TYPE_MultiPolygon : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XY ; return( true );
974
975 case SG_OGIS_TYPE_PointZ : Shape = SHAPE_TYPE_Point ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
976 case SG_OGIS_TYPE_MultiPointZ : Shape = SHAPE_TYPE_Points ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
977 case SG_OGIS_TYPE_LineStringZ : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
978 case SG_OGIS_TYPE_MultiLineStringZ : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
979 case SG_OGIS_TYPE_PolygonZ : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
980 case SG_OGIS_TYPE_MultiPolygonZ : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
981
982 case SG_OGIS_TYPE_PointM : Shape = SHAPE_TYPE_Point ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
983 case SG_OGIS_TYPE_MultiPointM : Shape = SHAPE_TYPE_Points ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
984 case SG_OGIS_TYPE_LineStringM : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
985 case SG_OGIS_TYPE_MultiLineStringM : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
986 case SG_OGIS_TYPE_PolygonM : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
987 case SG_OGIS_TYPE_MultiPolygonM : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZ ; return( true );
988
989 case SG_OGIS_TYPE_PointZM : Shape = SHAPE_TYPE_Point ; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
990 case SG_OGIS_TYPE_MultiPointZM : Shape = SHAPE_TYPE_Points ; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
991 case SG_OGIS_TYPE_LineStringZM : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
992 case SG_OGIS_TYPE_MultiLineStringZM : Shape = SHAPE_TYPE_Line ; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
993 case SG_OGIS_TYPE_PolygonZM : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
994 case SG_OGIS_TYPE_MultiPolygonZM : Shape = SHAPE_TYPE_Polygon; Vertex = SG_VERTEX_TYPE_XYZM; return( true );
995 }
996
997 Shape = SHAPE_TYPE_Undefined; Vertex = SG_VERTEX_TYPE_XY;
998
999 return( false );
1000}
1001
1002//---------------------------------------------------------
1004{
1005 TSG_Shape_Type Geometry; TSG_Vertex_Type Vertex; to_ShapeType(Type, Geometry, Vertex);
1006
1007 return( Geometry );
1008}
1009
1010//---------------------------------------------------------
1012{
1013 TSG_Shape_Type Geometry; TSG_Vertex_Type Vertex; to_ShapeType(Type, Geometry, Vertex);
1014
1015 return( Geometry );
1016}
1017
1018//---------------------------------------------------------
1020{
1021 TSG_Shape_Type Geometry; TSG_Vertex_Type Vertex; to_ShapeType(Type, Geometry, Vertex);
1022
1023 return( Vertex );
1024}
1025
1026//---------------------------------------------------------
1028{
1029 TSG_Shape_Type Geometry; TSG_Vertex_Type Vertex; to_ShapeType(Type, Geometry, Vertex);
1030
1031 return( Vertex );
1032}
1033
1034
1036// //
1037// //
1038// //
1040
1041//---------------------------------------------------------
1042// Basic Type definitions
1043// byte : 1 byte
1044// uint16 : 16 bit unsigned integer (2 bytes)
1045// uint32 : 32 bit unsigned integer (4 bytes)
1046// float64 : double precision floating point number (8 bytes)
1047//
1048// +------------------------------------------------------------+
1049// | RASTER |
1050// +---------------+-------------+------------------------------+
1051// | - name - | - type - | - meaning - |
1052// +---------------+-------------+------------------------------+
1053// | endianness | byte | 1:ndr/little endian |
1054// | | | 0:xdr/big endian |
1055// +---------------+-------------+------------------------------+
1056// | version | uint16 | format version (0 for this |
1057// | | | structure) |
1058// +---------------+-------------+------------------------------+
1059// | nBands | uint16 | Number of bands |
1060// +---------------+-------------+------------------------------+
1061// | scaleX | float64 | pixel width |
1062// | | | in geographical units |
1063// +---------------+-------------+------------------------------+
1064// | scaleY | float64 | pixel height |
1065// | | | in geographical units |
1066// +---------------+-------------+------------------------------+
1067// | ipX | float64 | X ordinate of upper-left |
1068// | | | pixel's upper-left corner |
1069// | | | in geographical units |
1070// +---------------+-------------+------------------------------+
1071// | ipY | float64 | Y ordinate of upper-left |
1072// | | | pixel's upper-left corner |
1073// | | | in geographical units |
1074// +---------------+-------------+------------------------------+
1075// | skewX | float64 | rotation about Y-axis |
1076// +---------------+-------------+------------------------------+
1077// | skewY | float64 | rotation about X-axis |
1078// +---------------+-------------+------------------------------+
1079// | srid | int32 | Spatial reference id |
1080// +---------------+-------------+------------------------------+
1081// | width | uint16 | number of pixel columns |
1082// +---------------+-------------+------------------------------+
1083// | height | uint16 | number of pixel rows |
1084// +---------------+-------------+------------------------------+
1085// | bands[nBands] | RASTERBAND | Bands data |
1086// +---------------+-------------+------------------------------+
1087
1089// //
1091
1092//---------------------------------------------------------
1093#include "grid.h"
1094
1095
1097// //
1099
1100//---------------------------------------------------------
1102{
1103 Bytes.Rewind();
1104
1105 //-----------------------------------------------------
1106 // Raster System
1107
1108 bool bSwap = Bytes.Read_Byte () == 0; // endianness: 1=ndr/little endian, 0=xdr/big endian
1109 short version = Bytes.Read_Short (bSwap); // version
1110 short nBands = Bytes.Read_Short (bSwap); // number of bands
1111 double dx = Bytes.Read_Double(bSwap); // scaleX
1112 double dy = Bytes.Read_Double(bSwap); // scaleY
1113 double xMin = Bytes.Read_Double(bSwap); // ipX
1114 double yMax = Bytes.Read_Double(bSwap); // ipY
1115 double skewX = Bytes.Read_Double(bSwap); // skewX
1116 double skewY = Bytes.Read_Double(bSwap); // skewY
1117 int SRID = Bytes.Read_Int (bSwap); // srid
1118 short NX = Bytes.Read_Short (bSwap); // width
1119 short NY = Bytes.Read_Short (bSwap); // height
1120
1121 //-----------------------------------------------------
1122 // Band
1123
1124 TSG_Data_Type Type; BYTE Flags = Bytes.Read_Byte();
1125
1126 switch( Flags & 0x0F )
1127 {
1128 case 0: Type = SG_DATATYPE_Bit ; break; // 0: 1-bit boolean
1129 case 1: Type = SG_DATATYPE_Char ; break; // 1: 2-bit unsigned integer
1130 case 2: Type = SG_DATATYPE_Char ; break; // 2: 4-bit unsigned integer
1131 case 3: Type = SG_DATATYPE_Char ; break; // 3: 8-bit signed integer
1132 case 4: Type = SG_DATATYPE_Byte ; break; // 4: 8-bit unsigned integer
1133 case 5: Type = SG_DATATYPE_Short ; break; // 5: 16-bit signed integer
1134 case 6: Type = SG_DATATYPE_Word ; break; // 6: 16-bit unsigned integer
1135 case 7: Type = SG_DATATYPE_Int ; break; // 7: 32-bit signed integer
1136 case 8: Type = SG_DATATYPE_DWord ; break; // 8: 32-bit unsigned integer
1137 case 10: Type = SG_DATATYPE_Float ; break; // 10: 32-bit float
1138 case 11: Type = SG_DATATYPE_Double ; break; // 11: 64-bit float
1139 default: Type = SG_DATATYPE_Undefined; break;
1140 }
1141
1142// Flags |= 0x80; // isOffline: no, never here!
1143 Flags |= 0x40; // hasNodataValue
1144// Flags |= 0x20; // isNoDataValue: no, never here!
1145// Flags |= 0x10; // reserved (unused)
1146
1147 if( !pGrid->Create(Type, NX, NY, dx, xMin + 0.5 * dx, yMax - (NY - 0.5) * dx) )
1148 {
1149 return( false );
1150 }
1151
1152 pGrid->Get_Projection().Create(SRID);
1153
1154 double noData;
1155
1156 switch( pGrid->Get_Type() )
1157 {
1158 case SG_DATATYPE_Bit : noData = Bytes.Read_Byte ( ); break; // 0: 1-bit boolean
1159 case SG_DATATYPE_Char : noData = Bytes.Read_Char ( ); break; // 3: 8-bit signed integer
1160 case SG_DATATYPE_Byte : noData = Bytes.Read_Byte ( ); break; // 4: 8-bit unsigned integer
1161 case SG_DATATYPE_Short : noData = Bytes.Read_Short (bSwap); break; // 5: 16-bit signed integer
1162 case SG_DATATYPE_Word : noData = Bytes.Read_Word (bSwap); break; // 6: 16-bit unsigned integer
1163 case SG_DATATYPE_Int : noData = Bytes.Read_Int (bSwap); break; // 7: 32-bit signed integer
1164 case SG_DATATYPE_DWord : noData = Bytes.Read_DWord (bSwap); break; // 8: 32-bit unsigned integer
1165 case SG_DATATYPE_Float : noData = Bytes.Read_Float (bSwap); break; // 9: 32-bit float
1166 case SG_DATATYPE_Double: noData = Bytes.Read_Double(bSwap); break; // 10: 64-bit float
1167 default : noData = -99999. ; break;
1168 }
1169
1170 pGrid->Set_NoData_Value(noData);
1171
1172 for(int y=0; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++)
1173 {
1174 for(int x=0; x<pGrid->Get_NX(); x++)
1175 {
1176 switch( pGrid->Get_Type() )
1177 {
1178 case SG_DATATYPE_Bit : pGrid->Set_Value(x, y, Bytes.Read_Byte ( )); break; // 0: 1-bit boolean
1179 case SG_DATATYPE_Char : pGrid->Set_Value(x, y, Bytes.Read_Char ( )); break; // 3: 8-bit signed integer
1180 case SG_DATATYPE_Byte : pGrid->Set_Value(x, y, Bytes.Read_Byte ( )); break; // 4: 8-bit unsigned integer
1181 case SG_DATATYPE_Short : pGrid->Set_Value(x, y, Bytes.Read_Short (bSwap)); break; // 5: 16-bit signed integer
1182 case SG_DATATYPE_Word : pGrid->Set_Value(x, y, Bytes.Read_Word (bSwap)); break; // 6: 16-bit unsigned integer
1183 case SG_DATATYPE_Int : pGrid->Set_Value(x, y, Bytes.Read_Int (bSwap)); break; // 7: 32-bit signed integer
1184 case SG_DATATYPE_DWord : pGrid->Set_Value(x, y, Bytes.Read_DWord (bSwap)); break; // 8: 32-bit unsigned integer
1185 case SG_DATATYPE_Float : pGrid->Set_Value(x, y, Bytes.Read_Float (bSwap)); break; // 9: 32-bit float
1186 case SG_DATATYPE_Double: pGrid->Set_Value(x, y, Bytes.Read_Double(bSwap)); break; // 10: 64-bit float
1187 default : break;
1188 }
1189 }
1190 }
1191
1192 return( true );
1193}
1194
1195//---------------------------------------------------------
1196bool CSG_Grid_OGIS_Converter::to_WKBinary(CSG_Bytes &Bytes, class CSG_Grid *pGrid, int SRID)
1197{
1198 Bytes.Clear();
1199
1200 //-----------------------------------------------------
1201 // Raster System
1202
1203 if( pGrid->Get_Projection().Get_EPSG() > 0 )
1204 {
1205 SRID = pGrid->Get_Projection().Get_EPSG();
1206 }
1207
1208 Bytes += (BYTE )1 ; // endianness
1209 Bytes += (short )0 ; // version
1210 Bytes += (short )1 ; // number of bands
1211 Bytes += (double)pGrid->Get_Cellsize(); // scaleX
1212 Bytes += (double)pGrid->Get_Cellsize(); // scaleY
1213 Bytes += (double)pGrid->Get_XMin(true); // ipX
1214 Bytes += (double)pGrid->Get_YMax(true); // ipY
1215 Bytes += (double)0. ; // skewX
1216 Bytes += (double)0. ; // skewY
1217 Bytes += (int )SRID ; // srid
1218 Bytes += (short )pGrid->Get_NX() ; // width
1219 Bytes += (short )pGrid->Get_NY() ; // height
1220
1221 //-----------------------------------------------------
1222 // Band
1223
1224 BYTE Flags;
1225
1226 switch( pGrid->Get_Type() )
1227 {
1228 case SG_DATATYPE_Bit : Flags = 0; break; // 0: 1-bit boolean
1229// case SG_DATATYPE_ : Flags = 1; break; // 1: 2-bit unsigned integer
1230// case SG_DATATYPE_ : Flags = 2; break; // 2: 4-bit unsigned integer
1231 case SG_DATATYPE_Char : Flags = 3; break; // 3: 8-bit signed integer
1232 case SG_DATATYPE_Byte : Flags = 4; break; // 4: 8-bit unsigned integer
1233 case SG_DATATYPE_Short : Flags = 5; break; // 5: 16-bit signed integer
1234 case SG_DATATYPE_Word : Flags = 6; break; // 6: 16-bit unsigned integer
1235 case SG_DATATYPE_Int : Flags = 7; break; // 7: 32-bit signed integer
1236 case SG_DATATYPE_DWord : Flags = 8; break; // 8: 32-bit unsigned integer
1237 default : Flags = 10; break; // 10: 32-bit float
1238 case SG_DATATYPE_Double: Flags = 11; break; // 11: 64-bit float
1239 }
1240
1241// Flags |= 0x80; // isOffline: no, never here!
1242 Flags |= 0x40; // hasNodataValue
1243// Flags |= 0x20; // isNoDataValue: no, never here!
1244// Flags |= 0x10; // reserved (unused)
1245
1246 Bytes += Flags;
1247
1248 switch( pGrid->Get_Type() )
1249 {
1250 case SG_DATATYPE_Bit : Bytes += (BYTE )0 ; break; // 0: 1-bit boolean
1251 case SG_DATATYPE_Char : Bytes += (char )pGrid->Get_NoData_Value(); break; // 3: 8-bit signed integer
1252 case SG_DATATYPE_Byte : Bytes += (BYTE )pGrid->Get_NoData_Value(); break; // 4: 8-bit unsigned integer
1253 case SG_DATATYPE_Short : Bytes += (short )pGrid->Get_NoData_Value(); break; // 5: 16-bit signed integer
1254 case SG_DATATYPE_Word : Bytes += (WORD )pGrid->Get_NoData_Value(); break; // 6: 16-bit unsigned integer
1255 case SG_DATATYPE_Int : Bytes += (int )pGrid->Get_NoData_Value(); break; // 7: 32-bit signed integer
1256 case SG_DATATYPE_DWord : Bytes += (DWORD )pGrid->Get_NoData_Value(); break; // 8: 32-bit unsigned integer
1257 default : Bytes += (float )pGrid->Get_NoData_Value(); break; // 9: 32-bit float
1258 case SG_DATATYPE_Double: Bytes += (double)pGrid->Get_NoData_Value(); break; // 10: 64-bit float
1259 }
1260
1261 for(int y=0; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++)
1262 {
1263 for(int x=0; x<pGrid->Get_NX(); x++)
1264 {
1265 double Value = pGrid->is_NoData(x, y) ? pGrid->Get_NoData_Value() : pGrid->asDouble(x, y);
1266
1267 switch( pGrid->Get_Type() )
1268 {
1269 case SG_DATATYPE_Bit : Bytes += (BYTE )Value; break; // 0: 1-bit boolean
1270 case SG_DATATYPE_Char : Bytes += (char )Value; break; // 3: 8-bit signed integer
1271 case SG_DATATYPE_Byte : Bytes += (BYTE )Value; break; // 4: 8-bit unsigned integer
1272 case SG_DATATYPE_Short : Bytes += (short )Value; break; // 5: 16-bit signed integer
1273 case SG_DATATYPE_Word : Bytes += (WORD )Value; break; // 6: 16-bit unsigned integer
1274 case SG_DATATYPE_Int : Bytes += (int )Value; break; // 7: 32-bit signed integer
1275 case SG_DATATYPE_DWord : Bytes += (DWORD )Value; break; // 8: 32-bit unsigned integer
1276 default : Bytes += (float )Value; break; // 9: 32-bit float
1277 case SG_DATATYPE_Double: Bytes += (double)Value; break; // 10: 64-bit float
1278 }
1279 }
1280 }
1281
1282 return( true );
1283}
1284
1285
1287// //
1288// //
1289// //
1291
1292//---------------------------------------------------------
bool SG_UI_Process_Set_Progress(int Position, int Range)
#define SG_T(s)
Definition api_core.h:537
TSG_Data_Type
Definition api_core.h:997
@ 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_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_SSCANF
Definition api_core.h:540
BYTE Read_Byte(void)
Definition api_core.h:876
bool Destroy(void)
int Get_Count(void) const
Definition api_core.h:833
DWORD Read_DWord(bool bSwapBytes=false)
Definition api_core.h:881
char Read_Char(void)
Definition api_core.h:877
double Read_Double(bool bSwapBytes=false)
Definition api_core.h:883
WORD Read_Word(bool bSwapBytes=false)
Definition api_core.h:879
int Read_Int(bool bSwapBytes=false)
Definition api_core.h:880
bool is_EOF(void)
Definition api_core.h:831
short Read_Short(bool bSwapBytes=false)
Definition api_core.h:878
float Read_Float(bool bSwapBytes=false)
Definition api_core.h:882
bool Clear(void)
void Rewind(void)
Definition api_core.h:830
double Get_NoData_Value(bool bUpper=false) const
Definition dataobject.h:253
virtual bool Set_NoData_Value(double Value)
CSG_Projection & Get_Projection(void)
static bool to_WKBinary(CSG_Bytes &Bytes, class CSG_Grid *pGrid, int SRID=-1)
static bool from_WKBinary(CSG_Bytes &Bytes, class CSG_Grid *pGrid)
int Get_NY(void) const
Definition grid.h:564
double Get_YMax(bool bCells=false) const
Definition grid.h:577
double Get_XMin(bool bCells=false) const
Definition grid.h:572
double Get_Cellsize(void) const
Definition grid.h:567
virtual bool is_NoData(int x, int y) const
Definition grid.h:727
virtual double asDouble(sLong i, bool bScaled=true) const
Definition grid.h:793
bool Create(const CSG_Grid &Grid)
Definition grid.cpp:235
int Get_NX(void) const
Definition grid.h:563
virtual void Set_Value(sLong i, double Value, bool bScaled=true)
Definition grid.h:843
TSG_Data_Type Get_Type(void) const
Definition grid.h:547
int Get_EPSG(void) const
Definition geo_tools.h:899
bool Create(const CSG_Projection &Projection)
virtual TSG_Point Get_Point(int iPoint=0) const
virtual int Get_Part_Count(void) const
Definition shapes.h:495
virtual int Get_Point_Count(void) const =0
virtual void Set_M(double m, int iPoint=0, int iPart=0)
Definition shapes.h:207
TSG_Shape_Type Get_Type(void) const
Definition shape.cpp:88
virtual int Add_Point(double x, double y, int iPart=0)=0
virtual int Get_Part_Count(void) const =0
virtual TSG_Point Get_Point(int iPoint=0) const =0
virtual int Del_Parts(void)
Definition shapes.h:168
virtual double Get_Z(int iPoint=0, int iPart=0, bool bAscending=true) const
Definition shapes.h:192
TSG_Vertex_Type Get_Vertex_Type(void) const
Definition shape.cpp:94
virtual double Get_M(int iPoint=0, int iPart=0, bool bAscending=true) const
Definition shapes.h:208
virtual void Set_Z(double z, int iPoint=0, int iPart=0)
Definition shapes.h:191
static bool from_WKText(const CSG_String &Text, CSG_Shape *pShape)
static TSG_Vertex_Type to_VertexType(const CSG_String &Type)
static bool from_ShapeType(CSG_String &Type, TSG_Shape_Type Shape, TSG_Vertex_Type Vertex=SG_VERTEX_TYPE_XY)
static CSG_String Type_asWKText(DWORD Type)
static bool from_WKBinary(CSG_Bytes &Bytes, CSG_Shape *pShape)
static bool to_WKBinary(CSG_Shape *pShape, CSG_Bytes &Bytes)
static bool to_ShapeType(const CSG_String &Type, TSG_Shape_Type &Shape, TSG_Vertex_Type &Vertex)
static bool to_WKText(CSG_Shape *pShape, CSG_String &Text)
static DWORD Type_asWKBinary(const CSG_String &Type)
size_t Length(void) const
CSG_String AfterFirst(char Character) const
void Clear(void)
CSG_String BeforeFirst(char Character) const
CSG_String BeforeLast(char Character) const
static CSG_String Format(const char *Format,...)
const SG_Char * c_str(void) const
int Trim_Both(void)
class CSG_Table * Get_Table(void)
Definition table.h:135
struct SSG_Point TSG_Point
@ SG_OGIS_BYTEORDER_NDR
Definition shapes.h:1483
TSG_Vertex_Type
Definition shapes.h:91
@ SG_VERTEX_TYPE_XYZM
Definition shapes.h:94
@ SG_VERTEX_TYPE_XY
Definition shapes.h:92
@ SG_VERTEX_TYPE_XYZ
Definition shapes.h:93
TSG_Shape_Type
Definition shapes.h:100
@ SHAPE_TYPE_Polygon
Definition shapes.h:105
@ SHAPE_TYPE_Line
Definition shapes.h:104
@ SHAPE_TYPE_Points
Definition shapes.h:103
@ SHAPE_TYPE_Point
Definition shapes.h:102
@ SHAPE_TYPE_Undefined
Definition shapes.h:101
@ SG_OGIS_TYPE_PolyhedralSurfaceZ
Definition shapes.h:1509
@ SG_OGIS_TYPE_MultiPolygon
Definition shapes.h:1496
@ SG_OGIS_TYPE_TriangleM
Definition shapes.h:1522
@ SG_OGIS_TYPE_GeometryCollectionM
Definition shapes.h:1519
@ SG_OGIS_TYPE_PolygonZM
Definition shapes.h:1526
@ SG_OGIS_TYPE_MultiPolygonZM
Definition shapes.h:1529
@ SG_OGIS_TYPE_MultiPoint
Definition shapes.h:1494
@ SG_OGIS_TYPE_MultiPolygonZ
Definition shapes.h:1507
@ SG_OGIS_TYPE_GeometryCollectionZM
Definition shapes.h:1530
@ SG_OGIS_TYPE_LineStringZ
Definition shapes.h:1503
@ SG_OGIS_TYPE_GeometryCollectionZ
Definition shapes.h:1508
@ SG_OGIS_TYPE_MultiLineStringM
Definition shapes.h:1517
@ SG_OGIS_TYPE_TriangleZM
Definition shapes.h:1533
@ SG_OGIS_TYPE_TINZ
Definition shapes.h:1510
@ SG_OGIS_TYPE_PolyhedralSurfaceM
Definition shapes.h:1520
@ SG_OGIS_TYPE_TIN
Definition shapes.h:1499
@ SG_OGIS_TYPE_TINZM
Definition shapes.h:1532
@ SG_OGIS_TYPE_Undefined
Definition shapes.h:1489
@ SG_OGIS_TYPE_PolyhedralSurface
Definition shapes.h:1498
@ SG_OGIS_TYPE_TINM
Definition shapes.h:1521
@ SG_OGIS_TYPE_Polygon
Definition shapes.h:1493
@ SG_OGIS_TYPE_Point
Definition shapes.h:1491
@ SG_OGIS_TYPE_LineString
Definition shapes.h:1492
@ SG_OGIS_TYPE_PolyhedralSurfaceZM
Definition shapes.h:1531
@ SG_OGIS_TYPE_LineStringZM
Definition shapes.h:1525
@ SG_OGIS_TYPE_PolygonM
Definition shapes.h:1515
@ SG_OGIS_TYPE_MultiLineStringZ
Definition shapes.h:1506
@ SG_OGIS_TYPE_MultiPointM
Definition shapes.h:1516
@ SG_OGIS_TYPE_PointZM
Definition shapes.h:1524
@ SG_OGIS_TYPE_Triangle
Definition shapes.h:1500
@ SG_OGIS_TYPE_MultiPointZM
Definition shapes.h:1527
@ SG_OGIS_TYPE_MultiLineStringZM
Definition shapes.h:1528
@ SG_OGIS_TYPE_MultiPolygonM
Definition shapes.h:1518
@ SG_OGIS_TYPE_MultiPointZ
Definition shapes.h:1505
@ SG_OGIS_TYPE_MultiLineString
Definition shapes.h:1495
@ SG_OGIS_TYPE_LineStringM
Definition shapes.h:1514
@ SG_OGIS_TYPE_PolygonZ
Definition shapes.h:1504
@ SG_OGIS_TYPE_PointM
Definition shapes.h:1513
@ SG_OGIS_TYPE_TriangleZ
Definition shapes.h:1511
@ SG_OGIS_TYPE_PointZ
Definition shapes.h:1502
@ SG_OGIS_TYPE_GeometryCollection
Definition shapes.h:1497
#define TYPE_AS_WKB(t)
double x
Definition geo_tools.h:129
double y
Definition geo_tools.h:129