1 : /******************************************************************************
2 : * $Id: sdts_al.h 10645 2007-01-18 02:22:39Z warmerdam $
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 STDS_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 :
48 : /**
49 : Class holding SDTS IREF (internal reference) information, internal
50 : coordinate system format, scaling and resolution. This object isn't
51 : normally needed by applications.
52 : */
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 * );
78 : int GetSADR( DDFField *, int, double *, double *, double * );
79 : };
80 :
81 : /************************************************************************/
82 : /* SDTS_XREF */
83 : /************************************************************************/
84 :
85 : /**
86 : Class for reading the XREF (external reference) module containing the
87 : data projection definition.
88 : */
89 :
90 : class SDTS_XREF
91 : {
92 : public:
93 : SDTS_XREF();
94 : ~SDTS_XREF();
95 :
96 : int Read( const char *pszFilename );
97 :
98 : /** Projection system name, from the RSNM field. One of GEO, SPCS, UTM,
99 : UPS, OTHR, UNSP. */
100 : char *pszSystemName;
101 :
102 :
103 : /** Horizontal datum name, from the HDAT field. One of NAS, NAX, WGA,
104 : WGB, WGC, WGE. */
105 : char *pszDatum;
106 :
107 : /** Zone number for UTM and SPCS projections, from the ZONE field. */
108 : int nZone;
109 : };
110 :
111 : /************************************************************************/
112 : /* SDTS_CATD */
113 : /************************************************************************/
114 : class SDTS_CATDEntry;
115 :
116 : /**
117 : List of feature layer types. See SDTSTransfer::GetLayerType().
118 : */
119 :
120 : typedef enum {
121 : SLTUnknown,
122 : SLTPoint,
123 : SLTLine,
124 : SLTAttr,
125 : SLTPoly,
126 : SLTRaster
127 : } SDTSLayerType;
128 :
129 : /**
130 : Class for accessing the CATD (Catalog Directory) file containing a list of
131 : all other files (modules) in the transfer.
132 : */
133 : class SDTS_CATD
134 : {
135 : char *pszPrefixPath;
136 :
137 : int nEntries;
138 : SDTS_CATDEntry **papoEntries;
139 :
140 : public:
141 : SDTS_CATD();
142 : ~SDTS_CATD();
143 :
144 : int Read( const char * pszFilename );
145 :
146 : const char *GetModuleFilePath( const char * pszModule );
147 :
148 69 : int GetEntryCount() { return nEntries; }
149 : const char * GetEntryModule(int);
150 : const char * GetEntryTypeDesc(int);
151 : const char * GetEntryFilePath(int);
152 : SDTSLayerType GetEntryType(int);
153 : };
154 :
155 : /************************************************************************/
156 : /* SDTSModId */
157 : /************************************************************************/
158 :
159 : /**
160 : Object representing a unique module/record identifier within an SDTS
161 : transfer.
162 : */
163 : class SDTSModId
164 : {
165 : public:
166 1278 : SDTSModId() { szModule[0] = '\0';
167 1278 : nRecord = -1;
168 1278 : szOBRP[0] = '\0'; }
169 :
170 : int Set( DDFField * );
171 :
172 : const char *GetName();
173 :
174 : /** The module name, such as PC01, containing the indicated record. */
175 : char szModule[8];
176 :
177 : /** The record within the module referred to. This is -1 for unused
178 : SDTSModIds. */
179 : long nRecord;
180 :
181 : /** The "role" of this record within the module. This is normally empty
182 : for references, but set in the oModId member of a feature. */
183 : char szOBRP[8];
184 : };
185 :
186 : /************************************************************************/
187 : /* SDTSFeature */
188 : /************************************************************************/
189 :
190 : /**
191 : Base class for various SDTS features classes, providing a generic
192 : module identifier, and list of attribute references.
193 : */
194 : class SDTSFeature
195 : {
196 : public:
197 :
198 : SDTSFeature();
199 : virtual ~SDTSFeature();
200 :
201 : /** Unique identifier for this record/feature within transfer. */
202 : SDTSModId oModId;
203 :
204 : /** Number of attribute links (aoATID[]) on this feature. */
205 : int nAttributes;
206 :
207 : /** List of nAttributes attribute record identifiers related to this
208 : feature. */
209 : SDTSModId *paoATID;
210 :
211 : void ApplyATID( DDFField * );
212 :
213 :
214 : /** Dump reable description of feature to indicated stream. */
215 : virtual void Dump( FILE * ) = 0;
216 : };
217 :
218 : /************************************************************************/
219 : /* SDTSIndexedReader */
220 : /************************************************************************/
221 :
222 : /**
223 : Base class for all the SDTSFeature type readers. Provides feature
224 : caching semantics and fetching based on a record number.
225 : */
226 :
227 : class SDTSIndexedReader
228 : {
229 : int nIndexSize;
230 : SDTSFeature **papoFeatures;
231 :
232 : int iCurrentFeature;
233 :
234 : protected:
235 : DDFModule oDDFModule;
236 :
237 : public:
238 : SDTSIndexedReader();
239 : virtual ~SDTSIndexedReader();
240 :
241 : virtual SDTSFeature *GetNextRawFeature() = 0;
242 :
243 : SDTSFeature *GetNextFeature();
244 :
245 : virtual void Rewind();
246 :
247 : void FillIndex();
248 : void ClearIndex();
249 : int IsIndexed();
250 :
251 : SDTSFeature *GetIndexedFeatureRef( int );
252 : char ** ScanModuleReferences( const char * = "ATID" );
253 :
254 : DDFModule *GetModule() { return &oDDFModule; }
255 : };
256 :
257 :
258 : /************************************************************************/
259 : /* SDTSRawLine */
260 : /************************************************************************/
261 :
262 : /** SDTS line feature, as read from LE* modules by SDTSLineReader. */
263 :
264 : class SDTSRawLine : public SDTSFeature
265 : {
266 : public:
267 : SDTSRawLine();
268 : virtual ~SDTSRawLine();
269 :
270 : int Read( SDTS_IREF *, DDFRecord * );
271 :
272 : /** Number of vertices in the padfX, padfY and padfZ arrays. */
273 : int nVertices;
274 :
275 : /** List of nVertices X coordinates. */
276 : double *padfX;
277 : /** List of nVertices Y coordinates. */
278 : double *padfY;
279 : /** List of nVertices Z coordinates - currently always zero. */
280 : double *padfZ;
281 :
282 : /** Identifier of polygon to left of this line. This is the SDTS PIDL
283 : subfield. */
284 : SDTSModId oLeftPoly;
285 :
286 : /** Identifier of polygon to right of this line. This is the SDTS PIDR
287 : subfield. */
288 : SDTSModId oRightPoly;
289 :
290 : /** Identifier for the start node of this line. This is the SDTS SNID
291 : subfield. */
292 : SDTSModId oStartNode; /* SNID */
293 :
294 : /** Identifier for the end node of this line. This is the SDTS ENID
295 : subfield. */
296 : SDTSModId oEndNode; /* ENID */
297 :
298 : void Dump( FILE * );
299 : };
300 :
301 : /************************************************************************/
302 : /* SDTSLineReader */
303 : /* */
304 : /* Class for reading any of the files lines. */
305 : /************************************************************************/
306 :
307 : /**
308 : Reader for SDTS line modules.
309 :
310 : Returns SDTSRawLine features. Normally readers are instantiated with
311 : the SDTSTransfer::GetIndexedReader() method.
312 :
313 : */
314 :
315 : class SDTSLineReader : public SDTSIndexedReader
316 : {
317 : SDTS_IREF *poIREF;
318 :
319 : public:
320 : SDTSLineReader( SDTS_IREF * );
321 : ~SDTSLineReader();
322 :
323 : int Open( const char * );
324 : SDTSRawLine *GetNextLine( void );
325 : void Close();
326 :
327 57 : SDTSFeature *GetNextRawFeature( void ) { return GetNextLine(); }
328 :
329 : void AttachToPolygons( SDTSTransfer * );
330 : };
331 :
332 : /************************************************************************/
333 : /* SDTSAttrRecord */
334 : /************************************************************************/
335 :
336 : /**
337 : SDTS attribute record feature, as read from A* modules by
338 : SDTSAttrReader.
339 :
340 : Note that even though SDTSAttrRecord is derived from SDTSFeature, there
341 : are never any attribute records associated with attribute records using
342 : the aoATID[] mechanism. SDTSFeature::nAttributes will always be zero.
343 : */
344 :
345 : class SDTSAttrRecord : public SDTSFeature
346 : {
347 : public:
348 : SDTSAttrRecord();
349 : virtual ~SDTSAttrRecord();
350 :
351 : /** The entire DDFRecord read from the file. */
352 : DDFRecord *poWholeRecord;
353 :
354 : /** The ATTR DDFField with the user attribute. Each subfield is a
355 : attribute value. */
356 :
357 : DDFField *poATTR;
358 :
359 : virtual void Dump( FILE * );
360 : };
361 :
362 : /************************************************************************/
363 : /* SDTSAttrReader */
364 : /************************************************************************/
365 :
366 : /**
367 : Class for reading SDTSAttrRecord features from a primary or secondary
368 : attribute module.
369 : */
370 :
371 : class SDTSAttrReader : public SDTSIndexedReader
372 : {
373 : SDTS_IREF *poIREF;
374 :
375 : int bIsSecondary;
376 :
377 : public:
378 : SDTSAttrReader( SDTS_IREF * );
379 : virtual ~SDTSAttrReader();
380 :
381 : int Open( const char * );
382 : DDFField *GetNextRecord( SDTSModId * = NULL,
383 : DDFRecord ** = NULL,
384 : int bDuplicate = FALSE );
385 : SDTSAttrRecord *GetNextAttrRecord();
386 : void Close();
387 :
388 : /**
389 : Returns TRUE if this is a Attribute Secondary layer rather than
390 : an Attribute Primary layer.
391 : */
392 : int IsSecondary() { return bIsSecondary; }
393 :
394 357 : SDTSFeature *GetNextRawFeature( void ) { return GetNextAttrRecord(); }
395 : };
396 :
397 : /************************************************************************/
398 : /* SDTSRawPoint */
399 : /************************************************************************/
400 :
401 : /**
402 : Object containing a point feature (type NA, NO or NP).
403 : */
404 : class SDTSRawPoint : public SDTSFeature
405 : {
406 : public:
407 : SDTSRawPoint();
408 : virtual ~SDTSRawPoint();
409 :
410 : int Read( SDTS_IREF *, DDFRecord * );
411 :
412 : /** X coordinate of point. */
413 : double dfX;
414 : /** Y coordinate of point. */
415 : double dfY;
416 : /** Z coordinate of point. */
417 : double dfZ;
418 :
419 : /** Optional identifier of area marked by this point (ie. PC01:27). */
420 : SDTSModId oAreaId; /* ARID */
421 :
422 : virtual void Dump( FILE * );
423 : };
424 :
425 : /************************************************************************/
426 : /* SDTSPointReader */
427 : /************************************************************************/
428 :
429 : /**
430 : Class for reading SDTSRawPoint features from a point module (type NA, NO
431 : or NP).
432 : */
433 :
434 : class SDTSPointReader : public SDTSIndexedReader
435 : {
436 : SDTS_IREF *poIREF;
437 :
438 : public:
439 : SDTSPointReader( SDTS_IREF * );
440 : virtual ~SDTSPointReader();
441 :
442 : int Open( const char * );
443 : SDTSRawPoint *GetNextPoint( void );
444 : void Close();
445 :
446 132 : SDTSFeature *GetNextRawFeature( void ) { return GetNextPoint(); }
447 : };
448 :
449 : /************************************************************************/
450 : /* SDTSRawPolygon */
451 : /************************************************************************/
452 :
453 : /**
454 : Class for holding information about a polygon feature.
455 :
456 : When directly read from a polygon module, the polygon has no concept
457 : of it's geometry. Just it's ID, and references to attribute records.
458 : However, if the SDTSLineReader::AttachToPolygons() method is called on
459 : the module containing the lines forming the polygon boundaries, then the
460 : nEdges/papoEdges information on the SDTSRawPolygon will be filled in.
461 :
462 : Once this is complete the AssembleRings() method can be used to fill in the
463 : nRings/nVertices/panRingStart/padfX/padfY/padfZ information defining the
464 : ring geometry.
465 :
466 : Note that the rings may not appear in any particular order, nor with any
467 : meaningful direction (clockwise or counterclockwise).
468 : */
469 :
470 : class SDTSRawPolygon : public SDTSFeature
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 :
485 : /** This method will assemble the edges associated with a polygon into
486 : rings, returning FALSE if problems are encountered during assembly. */
487 : int AssembleRings();
488 :
489 : /** Number of rings in assembled polygon. */
490 : int nRings;
491 : /** Total number of vertices in all rings of assembled polygon. */
492 : int nVertices;
493 : /** Offsets into padfX/padfY/padfZ for the beginning of each ring in the
494 : polygon. This array is nRings long. */
495 : int *panRingStart;
496 :
497 : /** List of nVertices X coordinates for the polygon (split over multiple
498 : rings via panRingStart. */
499 : double *padfX;
500 : /** List of nVertices Y coordinates for the polygon (split over multiple
501 : rings via panRingStart. */
502 : double *padfY;
503 : /** List of nVertices Z coordinates for the polygon (split over multiple
504 : rings via panRingStart. The values are almost always zero. */
505 : double *padfZ;
506 :
507 : virtual void Dump( FILE * );
508 : };
509 :
510 : /************************************************************************/
511 : /* SDTSPolygonReader */
512 : /************************************************************************/
513 :
514 : /** Class for reading SDTSRawPolygon features from a polygon (PC*) module. */
515 :
516 : class SDTSPolygonReader : public SDTSIndexedReader
517 : {
518 : int bRingsAssembled;
519 :
520 : public:
521 : SDTSPolygonReader();
522 : virtual ~SDTSPolygonReader();
523 :
524 : int Open( const char * );
525 : SDTSRawPolygon *GetNextPolygon( void );
526 : void Close();
527 :
528 36 : SDTSFeature *GetNextRawFeature( void ) { return GetNextPolygon(); }
529 :
530 : void AssembleRings( SDTSTransfer * );
531 : };
532 :
533 : /************************************************************************/
534 : /* SDTSRasterReader */
535 : /************************************************************************/
536 :
537 : /**
538 : Class for reading raster data from a raster layer.
539 :
540 : This class is somewhat unique amoung the reader classes in that it isn't
541 : derived from SDTSIndexedFeature, and it doesn't return "features". Instead
542 : it is used to read raster blocks, in the natural block size of the dataset.
543 : */
544 :
545 : class SDTSRasterReader
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 :
567 : SDTSRasterReader();
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 :
583 : /**
584 : Fetch the raster width.
585 :
586 : @return the width in pixels.
587 : */
588 2 : int GetXSize() { return nXSize; }
589 : /**
590 : Fetch the raster height.
591 :
592 : @return the height in pixels.
593 : */
594 2 : int GetYSize() { return nYSize; }
595 :
596 : /** Fetch the width of a source block (usually same as raster width). */
597 2 : int GetBlockXSize() { return nXBlockSize; }
598 : /** Fetch the height of a source block (usually one). */
599 2 : int GetBlockYSize() { return nYBlockSize; }
600 :
601 : int GetBlock( int nXOffset, int nYOffset, void * pData );
602 : };
603 :
604 : /************************************************************************/
605 : /* SDTSTransfer */
606 : /************************************************************************/
607 :
608 : /**
609 : Master class representing an entire SDTS transfer.
610 :
611 : This class is used to open the transfer, to get a list of available
612 : feature layers, and to instantiate readers for those layers.
613 :
614 : */
615 :
616 : class SDTSTransfer
617 : {
618 : public:
619 : SDTSTransfer();
620 : ~SDTSTransfer();
621 :
622 : int Open( const char * );
623 : void Close();
624 :
625 : int FindLayer( const char * );
626 20 : int GetLayerCount() { return nLayers; }
627 : SDTSLayerType GetLayerType( int );
628 : int GetLayerCATDEntry( int );
629 :
630 : SDTSLineReader *GetLayerLineReader( int );
631 : SDTSPointReader *GetLayerPointReader( int );
632 : SDTSPolygonReader *GetLayerPolygonReader( int );
633 : SDTSAttrReader *GetLayerAttrReader( int );
634 : SDTSRasterReader *GetLayerRasterReader( int );
635 : DDFModule *GetLayerModuleReader( int );
636 :
637 : SDTSIndexedReader *GetLayerIndexedReader( int );
638 :
639 : /**
640 : Fetch the catalog object for this transfer.
641 :
642 : @return pointer to the internally managed SDTS_CATD for the transfer.
643 : */
644 13 : SDTS_CATD *GetCATD() { return &oCATD ; }
645 :
646 : SDTS_IREF *GetIREF() { return &oIREF; }
647 :
648 : /**
649 : Fetch the external reference object for this transfer.
650 :
651 : @return pointer to the internally managed SDTS_XREF for the transfer.
652 : */
653 3 : SDTS_XREF *GetXREF() { return &oXREF; }
654 :
655 : SDTSFeature *GetIndexedFeatureRef( SDTSModId *,
656 : SDTSLayerType *peType = NULL);
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 /* ndef SDTS_AL_H_INCLUDED */
|