SDTS_AL
sdts_al.h
1 /******************************************************************************
2  * $Id: sdts_al.h 2ace03ec48c36dae8ba74089d85617c095643428 2018-11-02 18:02:33 +0100 Even Rouault $
3  *
4  * Project: SDTS Translator
5  * Purpose: Include file for entire SDTS Abstraction Layer functions.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 1999, Frank Warmerdam
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #ifndef SDTS_AL_H_INCLUDED
31 #define SDTS_AL_H_INCLUDED
32 
33 #include "cpl_conv.h"
34 #include "iso8211.h"
35 
36 class SDTS_IREF;
37 class SDTSModId;
38 class SDTSTransfer;
39 
40 #define SDTS_SIZEOF_SADR 8
41 
42 char **SDTSScanModuleReferences( DDFModule *, const char * );
43 
44 /************************************************************************/
45 /* SDTS_IREF */
46 /************************************************************************/
47 
53 class SDTS_IREF
54 {
55  int nDefaultSADRFormat;
56 
57  public:
58  SDTS_IREF();
59  ~SDTS_IREF();
60 
61  int Read( const char *pszFilename );
62 
63  char *pszXAxisName; /* XLBL */
64  char *pszYAxisName; /* YLBL */
65 
66  double dfXScale; /* SFAX */
67  double dfYScale; /* SFAY */
68 
69  double dfXOffset; /* XORG */
70  double dfYOffset; /* YORG */
71 
72  double dfXRes; /* XHRS */
73  double dfYRes; /* YHRS */
74 
75  char *pszCoordinateFormat; /* HFMT */
76 
77  int GetSADRCount( DDFField * ) const;
78  int GetSADR( DDFField *, int, double *, double *, double * );
79 };
80 
81 /************************************************************************/
82 /* SDTS_XREF */
83 /************************************************************************/
84 
90 class SDTS_XREF
91 {
92  public:
93  SDTS_XREF();
94  ~SDTS_XREF();
95 
96  int Read( const char *pszFilename );
97 
101 
104  char *pszDatum;
105 
107  int nZone;
108 };
109 
110 /************************************************************************/
111 /* SDTS_CATD */
112 /************************************************************************/
113 class SDTS_CATDEntry;
114 
119 typedef enum {
120  SLTUnknown,
121  SLTPoint,
122  SLTLine,
123  SLTAttr,
124  SLTPoly,
125  SLTRaster
126 } SDTSLayerType;
127 
133 {
134  char *pszPrefixPath;
135 
136  int nEntries;
137  SDTS_CATDEntry **papoEntries;
138 
139  public:
140  SDTS_CATD();
141  ~SDTS_CATD();
142 
143  int Read( const char * pszFilename );
144 
145  const char *GetModuleFilePath( const char * pszModule ) const;
146 
147  int GetEntryCount() const { return nEntries; }
148  const char * GetEntryModule(int) const;
149  const char * GetEntryTypeDesc(int) const;
150  const char * GetEntryFilePath(int) const;
151  SDTSLayerType GetEntryType(int) const;
152  void SetEntryTypeUnknown(int);
153 };
154 
155 /************************************************************************/
156 /* SDTSModId */
157 /************************************************************************/
158 
164 {
165  public:
166  SDTSModId() { szModule[0] = '\0';
167  nRecord = -1;
168  szOBRP[0] = '\0';
169  szName[0] = '\0'; }
170 
171  int Set( DDFField * );
172 
173  const char *GetName();
174 
176  char szModule[8];
177 
180  int nRecord;
181 
184  char szOBRP[8];
185 
187  char szName[20];
188 };
189 
190 /************************************************************************/
191 /* SDTSFeature */
192 /************************************************************************/
193 
199 {
200 public:
201 
202  SDTSFeature();
203  virtual ~SDTSFeature();
204 
207 
210 
214 
215  void ApplyATID( DDFField * );
216 
218  virtual void Dump( FILE * ) = 0;
219 };
220 
221 /************************************************************************/
222 /* SDTSIndexedReader */
223 /************************************************************************/
224 
231 {
232  int nIndexSize;
233  SDTSFeature **papoFeatures;
234 
235  int iCurrentFeature;
236 
237 protected:
238  DDFModule oDDFModule;
239 
240 public:
242  virtual ~SDTSIndexedReader();
243 
244  virtual SDTSFeature *GetNextRawFeature() = 0;
245 
247 
248  virtual void Rewind();
249 
250  void FillIndex();
251  void ClearIndex();
252  int IsIndexed() const;
253 
255  char ** ScanModuleReferences( const char * = "ATID" );
256 
257  DDFModule *GetModule() { return &oDDFModule; }
258 };
259 
260 /************************************************************************/
261 /* SDTSRawLine */
262 /************************************************************************/
263 
266 class SDTSRawLine : public SDTSFeature
267 {
268  public:
269  SDTSRawLine();
270  virtual ~SDTSRawLine();
271 
272  int Read( SDTS_IREF *, DDFRecord * );
273 
276 
278  double *padfX;
280  double *padfY;
282  double *padfZ;
283 
287 
291 
294  SDTSModId oStartNode; /* SNID */
295 
298  SDTSModId oEndNode; /* ENID */
299 
300  void Dump( FILE * ) override;
301 };
302 
303 /************************************************************************/
304 /* SDTSLineReader */
305 /* */
306 /* Class for reading any of the files lines. */
307 /************************************************************************/
308 
318 {
319  SDTS_IREF *poIREF;
320 
321  public:
322  explicit SDTSLineReader( SDTS_IREF * );
323  ~SDTSLineReader();
324 
325  int Open( const char * );
326  SDTSRawLine *GetNextLine();
327  void Close();
328 
329  SDTSFeature *GetNextRawFeature() override { return GetNextLine(); }
330 
331  void AttachToPolygons( SDTSTransfer *, int iPolyLayer );
332 };
333 
334 /************************************************************************/
335 /* SDTSAttrRecord */
336 /************************************************************************/
337 
348 {
349  public:
350  SDTSAttrRecord();
351  virtual ~SDTSAttrRecord();
352 
355 
360 
361  virtual void Dump( FILE * ) override;
362 };
363 
364 /************************************************************************/
365 /* SDTSAttrReader */
366 /************************************************************************/
367 
374 {
375  int bIsSecondary;
376 
377  public:
378  SDTSAttrReader();
379  virtual ~SDTSAttrReader();
380 
381  int Open( const char * );
382  DDFField *GetNextRecord( SDTSModId * = nullptr,
383  DDFRecord ** = nullptr,
384  int bDuplicate = FALSE );
385  SDTSAttrRecord *GetNextAttrRecord();
386  void Close();
387 
392  int IsSecondary() const { return bIsSecondary; }
393 
394  SDTSFeature *GetNextRawFeature() override { return GetNextAttrRecord(); }
395 };
396 
397 /************************************************************************/
398 /* SDTSRawPoint */
399 /************************************************************************/
400 
404 class SDTSRawPoint : public SDTSFeature
405 {
406  public:
407  SDTSRawPoint();
408  virtual ~SDTSRawPoint();
409 
410  int Read( SDTS_IREF *, DDFRecord * );
411 
413  double dfX;
415  double dfY;
417  double dfZ;
418 
420  SDTSModId oAreaId; /* ARID */
421 
422  virtual void Dump( FILE * ) override;
423 };
424 
425 /************************************************************************/
426 /* SDTSPointReader */
427 /************************************************************************/
428 
435 {
436  SDTS_IREF *poIREF;
437 
438  public:
439  explicit SDTSPointReader( SDTS_IREF * );
440  virtual ~SDTSPointReader();
441 
442  int Open( const char * );
443  SDTSRawPoint *GetNextPoint();
444  void Close();
445 
446  SDTSFeature *GetNextRawFeature() override { return GetNextPoint(); }
447 };
448 
449 /************************************************************************/
450 /* SDTSRawPolygon */
451 /************************************************************************/
452 
471 {
472  void AddEdgeToRing( int, double *, double *, double *, int, int );
473 
474  public:
475  SDTSRawPolygon();
476  virtual ~SDTSRawPolygon();
477 
478  int Read( DDFRecord * );
479 
480  int nEdges;
481  SDTSRawLine **papoEdges;
482 
483  void AddEdge( SDTSRawLine * );
484 
487  int AssembleRings();
488 
490  int nRings;
496 
499  double *padfX;
502  double *padfY;
505  double *padfZ;
506 
507  virtual void Dump( FILE * ) override;
508 };
509 
510 /************************************************************************/
511 /* SDTSPolygonReader */
512 /************************************************************************/
513 
517 {
518  int bRingsAssembled;
519 
520  public:
522  virtual ~SDTSPolygonReader();
523 
524  int Open( const char * );
525  SDTSRawPolygon *GetNextPolygon();
526  void Close();
527 
528  SDTSFeature *GetNextRawFeature() override { return GetNextPolygon(); }
529 
530  void AssembleRings( SDTSTransfer *, int iPolyLayer );
531 };
532 
533 /************************************************************************/
534 /* SDTSRasterReader */
535 /************************************************************************/
536 
546 {
547  DDFModule oDDFModule;
548 
549  char szModule[20];
550 
551  int nXSize;
552  int nYSize;
553  int nXBlockSize;
554  int nYBlockSize;
555 
556  int nXStart; /* SOCI */
557  int nYStart; /* SORI */
558 
559  double adfTransform[6];
560 
561  public:
562  char szINTR[4]; /* CE is center, TL is top left */
563  char szFMT[32];
564  char szUNITS[64];
565  char szLabel[64];
566 
568  ~SDTSRasterReader();
569 
570  int Open( SDTS_CATD * poCATD, SDTS_IREF *,
571  const char * pszModule );
572  void Close();
573 
574  int GetRasterType(); /* 1 = int16, see GDAL types */
575 #define SDTS_RT_INT16 1
576 #define SDTS_RT_FLOAT32 6
577 
578  int GetTransform( double * );
579 
580  int GetMinMax( double * pdfMin, double * pdfMax,
581  double dfNoData );
582 
588  int GetXSize() const { return nXSize; }
594  int GetYSize() const { return nYSize; }
595 
597  int GetBlockXSize() const { return nXBlockSize; }
599  int GetBlockYSize() const { return nYBlockSize; }
600 
601  int GetBlock( int nXOffset, int nYOffset, void * pData );
602 };
603 
604 /************************************************************************/
605 /* SDTSTransfer */
606 /************************************************************************/
607 
617 {
618  public:
619  SDTSTransfer();
620  ~SDTSTransfer();
621 
622  int Open( const char * );
623  void Close();
624 
625  int FindLayer( const char * );
626  int GetLayerCount() const { return nLayers; }
627  SDTSLayerType GetLayerType( int ) const;
628  int GetLayerCATDEntry( int ) const;
629 
630  SDTSLineReader *GetLayerLineReader( int );
631  SDTSPointReader *GetLayerPointReader( int );
632  SDTSPolygonReader *GetLayerPolygonReader( int );
633  SDTSAttrReader *GetLayerAttrReader( int );
635  DDFModule *GetLayerModuleReader( int );
636 
638 
644  SDTS_CATD *GetCATD() { return &oCATD ; }
645 
646  SDTS_IREF *GetIREF() { return &oIREF; }
647 
653  SDTS_XREF *GetXREF() { return &oXREF; }
654 
655  SDTSFeature *GetIndexedFeatureRef( SDTSModId *,
656  SDTSLayerType *peType = nullptr);
657 
658  DDFField *GetAttr( SDTSModId * );
659 
660  int GetBounds( double *pdfMinX, double *pdfMinY,
661  double *pdfMaxX, double *pdfMaxY );
662 
663  private:
664 
665  SDTS_CATD oCATD;
666  SDTS_IREF oIREF;
667  SDTS_XREF oXREF;
668 
669  int nLayers;
670  int *panLayerCATDEntry;
671  SDTSIndexedReader **papoLayerReader;
672 };
673 
674 #endif /* ifndef SDTS_AL_H_INCLUDED */
SDTSTransfer::GetBounds
int GetBounds(double *pdfMinX, double *pdfMinY, double *pdfMaxX, double *pdfMaxY)
Definition: sdtstransfer.cpp:570
SDTSAttrRecord::poWholeRecord
DDFRecord * poWholeRecord
Definition: sdts_al.h:354
SDTSRasterReader::GetTransform
int GetTransform(double *)
Definition: sdtsrasterreader.cpp:515
SDTSRawLine::Dump
void Dump(FILE *) override
Definition: sdtslinereader.cpp:140
SDTSRasterReader
Definition: sdts_al.h:546
SDTSPointReader
Definition: sdts_al.h:435
SDTSRasterReader::GetRasterType
int GetRasterType()
Definition: sdtsrasterreader.cpp:534
SDTSIndexedReader::GetIndexedFeatureRef
SDTSFeature * GetIndexedFeatureRef(int)
Definition: sdtsindexedreader.cpp:155
SDTSRasterReader::GetYSize
int GetYSize() const
Definition: sdts_al.h:594
SDTSIndexedReader
Definition: sdts_al.h:231
DDFModule
Definition: iso8211.h:80
SDTSTransfer::GetAttr
DDFField * GetAttr(SDTSModId *)
Definition: sdtstransfer.cpp:537
SDTSRawPolygon::AssembleRings
int AssembleRings()
Definition: sdtspolygonreader.cpp:226
SDTSFeature::oModId
SDTSModId oModId
Definition: sdts_al.h:206
SDTSModId
Definition: sdts_al.h:164
SDTSRawPoint
Definition: sdts_al.h:405
SDTS_IREF
Definition: sdts_al.h:54
SDTSIndexedReader::IsIndexed
int IsIndexed() const
Definition: sdtsindexedreader.cpp:68
SDTSRasterReader::GetMinMax
int GetMinMax(double *pdfMin, double *pdfMax, double dfNoData)
Definition: sdtsrasterreader.cpp:560
SDTSPolygonReader::AssembleRings
void AssembleRings(SDTSTransfer *, int iPolyLayer)
Definition: sdtspolygonreader.cpp:594
SDTSRawLine::oLeftPoly
SDTSModId oLeftPoly
Definition: sdts_al.h:286
SDTSRawPolygon::panRingStart
int * panRingStart
Definition: sdts_al.h:495
SDTSAttrReader
Definition: sdts_al.h:374
SDTSAttrReader::IsSecondary
int IsSecondary() const
Definition: sdts_al.h:392
SDTSRawPolygon::padfY
double * padfY
Definition: sdts_al.h:502
SDTSRawPolygon::nVertices
int nVertices
Definition: sdts_al.h:492
SDTSRawLine::nVertices
int nVertices
Definition: sdts_al.h:275
SDTS_CATDEntry
Definition: sdtscatd.cpp:46
SDTSIndexedReader::ScanModuleReferences
char ** ScanModuleReferences(const char *="ATID")
Definition: sdtsindexedreader.cpp:244
SDTS_CATD
Definition: sdts_al.h:133
SDTSRawPolygon::nRings
int nRings
Definition: sdts_al.h:490
SDTSIndexedReader::GetNextFeature
SDTSFeature * GetNextFeature()
Definition: sdtsindexedreader.cpp:119
SDTSTransfer::GetCATD
SDTS_CATD * GetCATD()
Definition: sdts_al.h:644
SDTSRawLine
Definition: sdts_al.h:267
SDTSRawLine::padfY
double * padfY
Definition: sdts_al.h:280
SDTS_XREF
Definition: sdts_al.h:91
SDTSIndexedReader::ClearIndex
void ClearIndex()
Definition: sdtsindexedreader.cpp:85
SDTSRawLine::oRightPoly
SDTSModId oRightPoly
Definition: sdts_al.h:290
SDTSLineReader
Definition: sdts_al.h:318
SDTSRawPoint::dfZ
double dfZ
Definition: sdts_al.h:417
SDTSRawLine::oEndNode
SDTSModId oEndNode
Definition: sdts_al.h:298
SDTSRawPoint::dfX
double dfX
Definition: sdts_al.h:413
SDTSModId::szOBRP
char szOBRP[8]
Definition: sdts_al.h:184
SDTSModId::nRecord
int nRecord
Definition: sdts_al.h:180
cpl_conv.h
SDTSAttrRecord::poATTR
DDFField * poATTR
Definition: sdts_al.h:359
SDTSTransfer::GetLayerRasterReader
SDTSRasterReader * GetLayerRasterReader(int)
Definition: sdtstransfer.cpp:349
SDTS_XREF::nZone
int nZone
Definition: sdts_al.h:107
SDTSIndexedReader::Rewind
virtual void Rewind()
Definition: sdtsindexedreader.cpp:260
DDFField
Definition: iso8211.h:512
SDTSFeature::paoATID
SDTSModId * paoATID
Definition: sdts_al.h:213
SDTSAttrRecord
Definition: sdts_al.h:348
SDTS_CATD::GetEntryFilePath
const char * GetEntryFilePath(int) const
Definition: sdtscatd.cpp:332
SDTSTransfer::Open
int Open(const char *)
Definition: sdtstransfer.cpp:68
SDTSRasterReader::GetBlock
int GetBlock(int nXOffset, int nYOffset, void *pData)
Definition: sdtsrasterreader.cpp:371
SDTSRawLine::padfZ
double * padfZ
Definition: sdts_al.h:282
SDTS_CATD::GetEntryType
SDTSLayerType GetEntryType(int) const
Definition: sdtscatd.cpp:276
SDTSRasterReader::GetBlockYSize
int GetBlockYSize() const
Definition: sdts_al.h:599
SDTS_XREF::pszSystemName
char * pszSystemName
Definition: sdts_al.h:100
SDTSTransfer::GetLayerType
SDTSLayerType GetLayerType(int) const
Definition: sdtstransfer.cpp:189
SDTS_XREF::pszDatum
char * pszDatum
Definition: sdts_al.h:104
SDTSRawLine::oStartNode
SDTSModId oStartNode
Definition: sdts_al.h:294
SDTSAttrRecord::Dump
virtual void Dump(FILE *) override
Definition: sdtsattrreader.cpp:63
SDTSIndexedReader::FillIndex
void FillIndex()
Definition: sdtsindexedreader.cpp:178
SDTSRawPolygon::padfZ
double * padfZ
Definition: sdts_al.h:505
SDTS_CATD::GetEntryTypeDesc
const char * GetEntryTypeDesc(int) const
Definition: sdtscatd.cpp:242
SDTSTransfer::GetLayerCATDEntry
int GetLayerCATDEntry(int) const
Definition: sdtstransfer.cpp:213
SDTSRasterReader::GetBlockXSize
int GetBlockXSize() const
Definition: sdts_al.h:597
SDTSTransfer
Definition: sdts_al.h:617
SDTSRawLine::padfX
double * padfX
Definition: sdts_al.h:278
SDTSRasterReader::GetXSize
int GetXSize() const
Definition: sdts_al.h:588
SDTSRawPoint::dfY
double dfY
Definition: sdts_al.h:415
SDTSPolygonReader
Definition: sdts_al.h:517
SDTSRawPolygon
Definition: sdts_al.h:471
SDTSModId::szName
char szName[20]
Definition: sdts_al.h:187
SDTSFeature::Dump
virtual void Dump(FILE *)=0
SDTSRawPoint::oAreaId
SDTSModId oAreaId
Definition: sdts_al.h:420
DDFRecord
Definition: iso8211.h:394
SDTSModId::szModule
char szModule[8]
Definition: sdts_al.h:176
SDTSRawPolygon::Dump
virtual void Dump(FILE *) override
Definition: sdtspolygonreader.cpp:476
SDTSLineReader::AttachToPolygons
void AttachToPolygons(SDTSTransfer *, int iPolyLayer)
Definition: sdtslinereader.cpp:274
SDTSRawPoint::Dump
virtual void Dump(FILE *) override
Definition: sdtspointreader.cpp:109
SDTSTransfer::GetLayerIndexedReader
SDTSIndexedReader * GetLayerIndexedReader(int)
Definition: sdtstransfer.cpp:428
SDTSRawPolygon::padfX
double * padfX
Definition: sdts_al.h:499
SDTSFeature::nAttributes
int nAttributes
Definition: sdts_al.h:209
SDTSTransfer::FindLayer
int FindLayer(const char *)
Definition: sdtstransfer.cpp:472
SDTSFeature
Definition: sdts_al.h:199
SDTSTransfer::GetXREF
SDTS_XREF * GetXREF()
Definition: sdts_al.h:653