1 : /**********************************************************************
2 : * $Id: mitab.h,v 1.121 2010-10-08 18:38:13 aboudreault Exp $
3 : *
4 : * Name: mitab.h
5 : * Project: MapInfo TAB Read/Write library
6 : * Language: C++
7 : * Purpose: Header file containing public definitions for the library.
8 : * Author: Daniel Morissette, dmorissette@dmsolutions.ca
9 : *
10 : **********************************************************************
11 : * Copyright (c) 1999-2005, Daniel Morissette
12 : *
13 : * Permission is hereby granted, free of charge, to any person obtaining a
14 : * copy of this software and associated documentation files (the "Software"),
15 : * to deal in the Software without restriction, including without limitation
16 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 : * and/or sell copies of the Software, and to permit persons to whom the
18 : * Software is furnished to do so, subject to the following conditions:
19 : *
20 : * The above copyright notice and this permission notice shall be included
21 : * in all copies or substantial portions of the Software.
22 : *
23 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 : * DEALINGS IN THE SOFTWARE.
30 : **********************************************************************
31 : *
32 : * $Log: mitab.h,v $
33 : * Revision 1.121 2010-10-08 18:38:13 aboudreault
34 : * Added attribute index support for the sql queries in mapinfo tab format (GDAL bug #3687)
35 : *
36 : * Revision 1.120 2010-01-07 20:39:11 aboudreault
37 : * Added support to handle duplicate field names, Added validation to check if a field name start with a number (bug 2141)
38 : *
39 : * Revision 1.119 2009-07-28 21:35:29 aboudreault
40 : * Added functions to get the file version (bug 1961)
41 : *
42 : * Revision 1.118 2009-03-10 13:50:02 aboudreault
43 : * Fixed Overflow of FIDs in Seamless tables (bug 2015)
44 : *
45 : * Revision 1.117 2008-10-29 12:55:10 dmorissette
46 : * Update version to 2.0.0-dev (2008-10) for GDAL 1.6.0 release
47 : *
48 : * Revision 1.116 2008/08/22 16:14:19 fwarmerdam
49 : * export spatialref/coordsys transformers
50 : *
51 : * Revision 1.115 2008/07/21 14:09:41 aboudreault
52 : * Add font text styles support (bold, italic, etc.) (bug 1922)
53 : *
54 : * Revision 1.114 2008/07/17 14:09:30 aboudreault
55 : * Add text outline color support (halo background in MapInfo)
56 : *
57 : * Revision 1.113 2008/07/01 14:33:17 aboudreault
58 : * * Fixed deprecated warnings generated by mitab.h by moving SetFontName to
59 : * mitab_feature.cpp.
60 : *
61 : * Revision 1.112 2008/03/05 20:35:39 dmorissette
62 : * Replace MITAB 1.x SetFeature() with a CreateFeature() for V2.x (bug 1859)
63 : *
64 : * Revision 1.111 2008/02/29 21:27:41 dmorissette
65 : * Update to v1.7.0-beta1
66 : *
67 : * Revision 1.110 2008/02/20 21:35:30 dmorissette
68 : * Added support for V800 COLLECTION of large objects (bug 1496)
69 : *
70 : * Revision 1.109 2008/02/13 21:10:43 dmorissette
71 : * Fixed error in TAB_GEOM_GET_VERSION() macro logic
72 : *
73 : * Revision 1.108 2008/02/05 22:21:59 dmorissette
74 : * Added macro TAB_GEOM_GET_VERSION()
75 : *
76 : * Revision 1.107 2008/02/01 19:55:55 dmorissette
77 : * Set version to 1.7.0-dev
78 : *
79 : * Revision 1.106 2008/02/01 19:36:31 dmorissette
80 : * Initial support for V800 REGION and MULTIPLINE (bug 1496)
81 : *
82 : * Revision 1.105 2008/01/29 21:56:39 dmorissette
83 : * Update dataset version properly for Date/Time/DateTime field types (#1754)
84 : *
85 : * Revision 1.104 2007/12/11 04:26:29 dmorissette
86 : * Update for 1.6.4 release
87 : *
88 : * Revision 1.103 2007/10/12 15:47:48 dmorissette
89 : * Updated for 1.6.3 release
90 : *
91 : * Revision 1.102 2007/09/18 18:13:42 dmorissette
92 : * Updated for 1.6.3-beta2
93 : *
94 : * Revision 1.101 2007/09/14 20:03:08 dmorissette
95 : * Removed stray ReadGeometryFromMAPFile() declaration
96 : *
97 : * Revision 1.100 2007/09/14 19:42:39 dmorissette
98 : * Updated for 1.6.3-beta1
99 : *
100 : * Revision 1.99 2007/09/14 18:30:18 dmorissette
101 : * Fixed the splitting of object blocks with the optimized spatial
102 : * index mode that was producing files with misaligned bytes that
103 : * confused MapInfo (bug 1732)
104 : *
105 : * Revision 1.98 2007/09/12 20:22:31 dmorissette
106 : * Added TABFeature::CreateFromMapInfoType()
107 : *
108 : * ...
109 : *
110 : * Revision 1.1 1999/07/12 04:18:23 daniel
111 : * Initial checkin
112 : *
113 : **********************************************************************/
114 :
115 : #ifndef _MITAB_H_INCLUDED_
116 : #define _MITAB_H_INCLUDED_
117 :
118 : #include "mitab_priv.h"
119 : #include "ogr_feature.h"
120 : #include "ogr_featurestyle.h"
121 : #include "ogrsf_frmts.h"
122 :
123 : /*---------------------------------------------------------------------
124 : * Current version of the MITAB library... always useful!
125 : *--------------------------------------------------------------------*/
126 : #define MITAB_VERSION "2.0.0-dev (2008-10)"
127 : #define MITAB_VERSION_INT 2000000 /* version x.y.z -> xxxyyyzzz */
128 :
129 : #ifndef PI
130 : # define PI 3.14159265358979323846
131 : #endif
132 :
133 : #ifndef ROUND_INT
134 : # define ROUND_INT(dX) ((int)((dX) < 0.0 ? (dX)-0.5 : (dX)+0.5 ))
135 : #endif
136 :
137 :
138 : #define MITAB_AREA(x1, y1, x2, y2) ((double)((x2)-(x1))*(double)((y2)-(y1)))
139 :
140 : class TABFeature;
141 :
142 : /*---------------------------------------------------------------------
143 : * Codes for the GetFileClass() in the IMapInfoFile-derived classes
144 : *--------------------------------------------------------------------*/
145 : typedef enum
146 : {
147 : TABFC_IMapInfoFile = 0,
148 : TABFC_TABFile,
149 : TABFC_TABView,
150 : TABFC_TABSeamless,
151 : TABFC_MIFFile
152 : } TABFileClass;
153 :
154 :
155 : /*---------------------------------------------------------------------
156 : * class IMapInfoFile
157 : *
158 : * Virtual base class for the TABFile and MIFFile classes.
159 : *
160 : * This is the definition of the public interface methods that should
161 : * be available for any type of MapInfo dataset.
162 : *--------------------------------------------------------------------*/
163 :
164 : class IMapInfoFile : public OGRLayer
165 : {
166 : private:
167 :
168 : protected:
169 : int m_nCurFeatureId;
170 : TABFeature *m_poCurFeature;
171 : GBool m_bBoundsSet;
172 :
173 : char *m_pszCharset;
174 :
175 : public:
176 : IMapInfoFile() ;
177 : virtual ~IMapInfoFile();
178 :
179 0 : virtual TABFileClass GetFileClass() {return TABFC_IMapInfoFile;}
180 :
181 : virtual int Open(const char *pszFname, const char *pszAccess,
182 : GBool bTestOpenNoError = FALSE ) = 0;
183 : virtual int Close() = 0;
184 :
185 0 : virtual int SetQuickSpatialIndexMode(GBool bQuickSpatialIndexMode=TRUE) {return -1;}
186 :
187 : virtual const char *GetTableName() = 0;
188 :
189 : ///////////////
190 : // Static method to detect file type, create an object to read that
191 : // file and open it.
192 : static IMapInfoFile *SmartOpen(const char *pszFname,
193 : GBool bTestOpenNoError = FALSE);
194 :
195 : ///////////////
196 : // OGR methods for read support
197 : virtual void ResetReading() = 0;
198 : virtual int GetFeatureCount (int bForce) = 0;
199 : virtual OGRFeature *GetNextFeature();
200 : virtual OGRFeature *GetFeature(long nFeatureId);
201 : virtual OGRErr CreateFeature(OGRFeature *poFeature);
202 : virtual int TestCapability( const char * pszCap ) =0;
203 : virtual int GetExtent(OGREnvelope *psExtent, int bForce) =0;
204 :
205 : ///////////////
206 : // Read access specific stuff
207 : //
208 : virtual int GetNextFeatureId(int nPrevId) = 0;
209 : virtual TABFeature *GetFeatureRef(int nFeatureId) = 0;
210 : virtual OGRFeatureDefn *GetLayerDefn() = 0;
211 :
212 : virtual TABFieldType GetNativeFieldType(int nFieldId) = 0;
213 :
214 : virtual int GetBounds(double &dXMin, double &dYMin,
215 : double &dXMax, double &dYMax,
216 : GBool bForce = TRUE ) = 0;
217 :
218 : virtual OGRSpatialReference *GetSpatialRef() = 0;
219 :
220 : virtual int GetFeatureCountByType(int &numPoints, int &numLines,
221 : int &numRegions, int &numTexts,
222 : GBool bForce = TRUE ) = 0;
223 :
224 : virtual GBool IsFieldIndexed(int nFieldId) = 0;
225 : virtual GBool IsFieldUnique(int nFieldId) = 0;
226 :
227 : ///////////////
228 : // Write access specific stuff
229 : //
230 22 : GBool IsBoundsSet() {return m_bBoundsSet;}
231 : virtual int SetBounds(double dXMin, double dYMin,
232 : double dXMax, double dYMax) = 0;
233 : virtual int SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
234 : TABFieldType *paeMapInfoNativeFieldTypes = NULL)=0;
235 : virtual int AddFieldNative(const char *pszName, TABFieldType eMapInfoType,
236 : int nWidth=0, int nPrecision=0,
237 : GBool bIndexed=FALSE, GBool bUnique=FALSE,
238 : int bApproxOK = TRUE) = 0;
239 : virtual OGRErr CreateField( OGRFieldDefn *poField, int bApproxOK = TRUE );
240 :
241 : virtual int SetSpatialRef(OGRSpatialReference *poSpatialRef) = 0;
242 :
243 : virtual OGRErr CreateFeature(TABFeature *poFeature) = 0;
244 :
245 : virtual int SetFieldIndexed(int nFieldId) = 0;
246 :
247 : virtual int SetCharset(const char* charset);
248 :
249 : ///////////////
250 : // semi-private.
251 : virtual int GetProjInfo(TABProjInfo *poPI) = 0;
252 : virtual int SetProjInfo(TABProjInfo *poPI) = 0;
253 : virtual int SetMIFCoordSys(const char *pszMIFCoordSys) = 0;
254 :
255 : #ifdef DEBUG
256 : virtual void Dump(FILE *fpOut = NULL) = 0;
257 : #endif
258 : };
259 :
260 : /*---------------------------------------------------------------------
261 : * class TABFile
262 : *
263 : * The main class for TAB datasets. External programs should use this
264 : * class to open a TAB dataset and read/write features from/to it.
265 : *
266 : *--------------------------------------------------------------------*/
267 : class TABFile: public IMapInfoFile
268 : {
269 : private:
270 : char *m_pszFname;
271 : TABAccess m_eAccessMode;
272 : char **m_papszTABFile;
273 : int m_nVersion;
274 : int *m_panIndexNo;
275 : TABTableType m_eTableType; // NATIVE (.DAT) or DBF
276 :
277 : TABDATFile *m_poDATFile; // Attributes file
278 : TABMAPFile *m_poMAPFile; // Object Geometry file
279 : TABINDFile *m_poINDFile; // Attributes index file
280 :
281 : OGRFeatureDefn *m_poDefn;
282 : OGRSpatialReference *m_poSpatialRef;
283 : int bUseSpatialTraversal;
284 :
285 : int m_nLastFeatureId;
286 :
287 : long *m_panMatchingFIDs;
288 : int m_iMatchingFID;
289 :
290 : ///////////////
291 : // Private Read access specific stuff
292 : //
293 : int ParseTABFileFirstPass(GBool bTestOpenNoError);
294 : int ParseTABFileFields();
295 :
296 : ///////////////
297 : // Private Write access specific stuff
298 : //
299 : int WriteTABFile();
300 :
301 : public:
302 : TABFile();
303 : virtual ~TABFile();
304 :
305 0 : virtual TABFileClass GetFileClass() {return TABFC_TABFile;}
306 :
307 : virtual int Open(const char *pszFname, const char *pszAccess,
308 : GBool bTestOpenNoError = FALSE );
309 : virtual int Close();
310 :
311 : virtual int SetQuickSpatialIndexMode(GBool bQuickSpatialIndexMode=TRUE);
312 :
313 0 : virtual const char *GetTableName()
314 0 : {return m_poDefn?m_poDefn->GetName():"";};
315 :
316 : virtual void ResetReading();
317 : virtual int TestCapability( const char * pszCap );
318 : virtual int GetFeatureCount (int bForce);
319 : virtual int GetExtent(OGREnvelope *psExtent, int bForce);
320 :
321 : /* Implement OGRLayer's SetFeature() for random write, only with TABFile */
322 : virtual OGRErr SetFeature( OGRFeature * );
323 :
324 : ///////////////
325 : // Read access specific stuff
326 : //
327 :
328 : int GetNextFeatureId_Spatial( int nPrevId );
329 :
330 : virtual int GetNextFeatureId(int nPrevId);
331 : virtual TABFeature *GetFeatureRef(int nFeatureId);
332 : virtual OGRFeatureDefn *GetLayerDefn();
333 :
334 : virtual TABFieldType GetNativeFieldType(int nFieldId);
335 :
336 : virtual int GetBounds(double &dXMin, double &dYMin,
337 : double &dXMax, double &dYMax,
338 : GBool bForce = TRUE );
339 :
340 : virtual OGRSpatialReference *GetSpatialRef();
341 :
342 : virtual int GetFeatureCountByType(int &numPoints, int &numLines,
343 : int &numRegions, int &numTexts,
344 : GBool bForce = TRUE);
345 :
346 : virtual GBool IsFieldIndexed(int nFieldId);
347 0 : virtual GBool IsFieldUnique(int /*nFieldId*/) {return FALSE;};
348 :
349 0 : virtual int GetVersion() { return m_nVersion; };
350 :
351 : ///////////////
352 : // Write access specific stuff
353 : //
354 : virtual int SetBounds(double dXMin, double dYMin,
355 : double dXMax, double dYMax);
356 : virtual int SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
357 : TABFieldType *paeMapInfoNativeFieldTypes = NULL);
358 : virtual int AddFieldNative(const char *pszName, TABFieldType eMapInfoType,
359 : int nWidth=0, int nPrecision=0,
360 : GBool bIndexed=FALSE, GBool bUnique=FALSE,
361 : int bApproxOK = TRUE);
362 : virtual int SetSpatialRef(OGRSpatialReference *poSpatialRef);
363 :
364 : virtual OGRErr CreateFeature(TABFeature *poFeature);
365 :
366 : virtual int SetFieldIndexed(int nFieldId);
367 :
368 : ///////////////
369 : // semi-private.
370 0 : virtual int GetProjInfo(TABProjInfo *poPI)
371 0 : { return m_poMAPFile->GetHeaderBlock()->GetProjInfo( poPI ); }
372 : virtual int SetProjInfo(TABProjInfo *poPI);
373 : virtual int SetMIFCoordSys(const char *pszMIFCoordSys);
374 :
375 : int GetFieldIndexNumber(int nFieldId);
376 : TABINDFile *GetINDFileRef();
377 :
378 : TABMAPFile *GetMAPFileRef() { return m_poMAPFile; }
379 :
380 : int WriteFeature(TABFeature *poFeature, int nFeatureId /*=-1*/);
381 :
382 : #ifdef DEBUG
383 : virtual void Dump(FILE *fpOut = NULL);
384 : #endif
385 : };
386 :
387 :
388 : /*---------------------------------------------------------------------
389 : * class TABView
390 : *
391 : * TABView is used to handle special type of .TAB files that are
392 : * composed of a number of .TAB datasets linked through some indexed
393 : * fields.
394 : *
395 : * NOTE: The current implementation supports only TABViews composed
396 : * of 2 TABFiles linked through an indexed field of integer type.
397 : * It is unclear if any other type of views could exist anyways.
398 : *--------------------------------------------------------------------*/
399 : class TABView: public IMapInfoFile
400 : {
401 : private:
402 : char *m_pszFname;
403 : TABAccess m_eAccessMode;
404 : char **m_papszTABFile;
405 : char *m_pszVersion;
406 :
407 : char **m_papszTABFnames;
408 : TABFile **m_papoTABFiles;
409 : int m_numTABFiles;
410 : int m_nMainTableIndex; // The main table is the one that also
411 : // contains the geometries
412 : char **m_papszFieldNames;
413 : char **m_papszWhereClause;
414 :
415 : TABRelation *m_poRelation;
416 : GBool m_bRelFieldsCreated;
417 :
418 : ///////////////
419 : // Private Read access specific stuff
420 : //
421 : int ParseTABFile(const char *pszDatasetPath,
422 : GBool bTestOpenNoError = FALSE);
423 :
424 : int OpenForRead(const char *pszFname,
425 : GBool bTestOpenNoError = FALSE );
426 :
427 : ///////////////
428 : // Private Write access specific stuff
429 : //
430 : int OpenForWrite(const char *pszFname );
431 : int WriteTABFile();
432 :
433 :
434 : public:
435 : TABView();
436 : virtual ~TABView();
437 :
438 0 : virtual TABFileClass GetFileClass() {return TABFC_TABView;}
439 :
440 : virtual int Open(const char *pszFname, const char *pszAccess,
441 : GBool bTestOpenNoError = FALSE );
442 : virtual int Close();
443 :
444 : virtual int SetQuickSpatialIndexMode(GBool bQuickSpatialIndexMode=TRUE);
445 :
446 0 : virtual const char *GetTableName()
447 0 : {return m_poRelation?m_poRelation->GetFeatureDefn()->GetName():"";};
448 :
449 : virtual void ResetReading();
450 : virtual int TestCapability( const char * pszCap );
451 : virtual int GetFeatureCount (int bForce);
452 : virtual int GetExtent(OGREnvelope *psExtent, int bForce);
453 :
454 : ///////////////
455 : // Read access specific stuff
456 : //
457 :
458 : virtual int GetNextFeatureId(int nPrevId);
459 : virtual TABFeature *GetFeatureRef(int nFeatureId);
460 : virtual OGRFeatureDefn *GetLayerDefn();
461 :
462 : virtual TABFieldType GetNativeFieldType(int nFieldId);
463 :
464 : virtual int GetBounds(double &dXMin, double &dYMin,
465 : double &dXMax, double &dYMax,
466 : GBool bForce = TRUE );
467 :
468 : virtual OGRSpatialReference *GetSpatialRef();
469 :
470 : virtual int GetFeatureCountByType(int &numPoints, int &numLines,
471 : int &numRegions, int &numTexts,
472 : GBool bForce = TRUE);
473 :
474 : virtual GBool IsFieldIndexed(int nFieldId);
475 : virtual GBool IsFieldUnique(int nFieldId);
476 :
477 : ///////////////
478 : // Write access specific stuff
479 : //
480 : virtual int SetBounds(double dXMin, double dYMin,
481 : double dXMax, double dYMax);
482 : virtual int SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
483 : TABFieldType *paeMapInfoNativeFieldTypes=NULL);
484 : virtual int AddFieldNative(const char *pszName,
485 : TABFieldType eMapInfoType,
486 : int nWidth=0, int nPrecision=0,
487 : GBool bIndexed=FALSE, GBool bUnique=FALSE,
488 : int bApproxOK = TRUE);
489 : virtual int SetSpatialRef(OGRSpatialReference *poSpatialRef);
490 :
491 : virtual OGRErr CreateFeature(TABFeature *poFeature);
492 :
493 : virtual int SetFieldIndexed(int nFieldId);
494 :
495 : ///////////////
496 : // semi-private.
497 0 : virtual int GetProjInfo(TABProjInfo *poPI)
498 : { return m_nMainTableIndex!=-1?
499 0 : m_papoTABFiles[m_nMainTableIndex]->GetProjInfo(poPI):-1; }
500 0 : virtual int SetProjInfo(TABProjInfo *poPI)
501 : { return m_nMainTableIndex!=-1?
502 0 : m_papoTABFiles[m_nMainTableIndex]->SetProjInfo(poPI):-1; }
503 0 : virtual int SetMIFCoordSys(const char * /*pszMIFCoordSys*/) {return -1;};
504 :
505 : #ifdef DEBUG
506 : virtual void Dump(FILE *fpOut = NULL);
507 : #endif
508 : };
509 :
510 :
511 : /*---------------------------------------------------------------------
512 : * class TABSeamless
513 : *
514 : * TABSeamless is used to handle seamless .TAB files that are
515 : * composed of a main .TAB file in which each feature is the MBR of
516 : * a base table.
517 : *
518 : * TABSeamless are supported for read access only.
519 : *--------------------------------------------------------------------*/
520 : class TABSeamless: public IMapInfoFile
521 : {
522 : private:
523 : char *m_pszFname;
524 : char *m_pszPath;
525 : TABAccess m_eAccessMode;
526 : OGRFeatureDefn *m_poFeatureDefnRef;
527 :
528 : TABFile *m_poIndexTable;
529 : int m_nIndexTableFIDBits;
530 : int m_nIndexTableFIDMask;
531 : int m_nTableNameField;
532 : int m_nCurBaseTableId;
533 : TABFile *m_poCurBaseTable;
534 : GBool m_bEOF;
535 :
536 : ///////////////
537 : // Private Read access specific stuff
538 : //
539 : int OpenForRead(const char *pszFname,
540 : GBool bTestOpenNoError = FALSE );
541 : int OpenBaseTable(TABFeature *poIndexFeature,
542 : GBool bTestOpenNoError = FALSE);
543 : int OpenBaseTable(int nTableId, GBool bTestOpenNoError = FALSE);
544 : int OpenNextBaseTable(GBool bTestOpenNoError =FALSE);
545 : int EncodeFeatureId(int nTableId, int nBaseFeatureId);
546 : int ExtractBaseTableId(int nEncodedFeatureId);
547 : int ExtractBaseFeatureId(int nEncodedFeatureId);
548 :
549 : public:
550 : TABSeamless();
551 : virtual ~TABSeamless();
552 :
553 0 : virtual TABFileClass GetFileClass() {return TABFC_TABSeamless;}
554 :
555 : virtual int Open(const char *pszFname, const char *pszAccess,
556 : GBool bTestOpenNoError = FALSE );
557 : virtual int Close();
558 :
559 0 : virtual const char *GetTableName()
560 0 : {return m_poFeatureDefnRef?m_poFeatureDefnRef->GetName():"";};
561 :
562 : virtual void SetSpatialFilter( OGRGeometry * );
563 :
564 : virtual void ResetReading();
565 : virtual int TestCapability( const char * pszCap );
566 : virtual int GetFeatureCount (int bForce);
567 : virtual int GetExtent(OGREnvelope *psExtent, int bForce);
568 :
569 : ///////////////
570 : // Read access specific stuff
571 : //
572 :
573 : virtual int GetNextFeatureId(int nPrevId);
574 : virtual TABFeature *GetFeatureRef(int nFeatureId);
575 : virtual OGRFeatureDefn *GetLayerDefn();
576 :
577 : virtual TABFieldType GetNativeFieldType(int nFieldId);
578 :
579 : virtual int GetBounds(double &dXMin, double &dYMin,
580 : double &dXMax, double &dYMax,
581 : GBool bForce = TRUE );
582 :
583 : virtual OGRSpatialReference *GetSpatialRef();
584 :
585 : virtual int GetFeatureCountByType(int &numPoints, int &numLines,
586 : int &numRegions, int &numTexts,
587 : GBool bForce = TRUE);
588 :
589 : virtual GBool IsFieldIndexed(int nFieldId);
590 : virtual GBool IsFieldUnique(int nFieldId);
591 :
592 : ///////////////
593 : // Write access specific stuff
594 : //
595 0 : virtual int SetBounds(double dXMin, double dYMin,
596 0 : double dXMax, double dYMax) {return -1;}
597 0 : virtual int SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
598 : TABFieldType *paeMapInfoNativeFieldTypes=NULL)
599 0 : {return -1;}
600 0 : virtual int AddFieldNative(const char *pszName,
601 : TABFieldType eMapInfoType,
602 : int nWidth=0, int nPrecision=0,
603 : GBool bIndexed=FALSE,
604 : GBool bUnique=FALSE,
605 0 : int bApproxOK = TRUE) {return -1;}
606 :
607 0 : virtual int SetSpatialRef(OGRSpatialReference *poSpatialRef) {return -1;}
608 :
609 0 : virtual OGRErr CreateFeature(TABFeature *poFeature)
610 0 : {return OGRERR_UNSUPPORTED_OPERATION;}
611 :
612 0 : virtual int SetFieldIndexed(int nFieldId) {return -1;}
613 :
614 : ///////////////
615 : // semi-private.
616 0 : virtual int GetProjInfo(TABProjInfo *poPI)
617 0 : { return m_poIndexTable?m_poIndexTable->GetProjInfo(poPI):-1; }
618 0 : virtual int SetProjInfo(TABProjInfo *poPI) { return -1; }
619 0 : virtual int SetMIFCoordSys(const char * /*pszMIFCoordSys*/) {return -1;};
620 :
621 : #ifdef DEBUG
622 : virtual void Dump(FILE *fpOut = NULL);
623 : #endif
624 : };
625 :
626 :
627 : /*---------------------------------------------------------------------
628 : * class MIFFile
629 : *
630 : * The main class for (MID/MIF) datasets. External programs should use this
631 : * class to open a (MID/MIF) dataset and read/write features from/to it.
632 : *
633 : *--------------------------------------------------------------------*/
634 : class MIFFile: public IMapInfoFile
635 : {
636 : private:
637 : char *m_pszFname;
638 : TABAccess m_eAccessMode;
639 : int m_nVersion; /* Dataset version: 300, 450, 600, 900, etc. */
640 : char *m_pszDelimiter;
641 : char *m_pszUnique;
642 : char *m_pszIndex;
643 : char *m_pszCoordSys;
644 :
645 : TABFieldType *m_paeFieldType;
646 : GBool *m_pabFieldIndexed;
647 : GBool *m_pabFieldUnique;
648 :
649 : double m_dfXMultiplier;
650 : double m_dfYMultiplier;
651 : double m_dfXDisplacement;
652 : double m_dfYDisplacement;
653 :
654 : /* these are the projection bounds, possibly much broader than extents */
655 : double m_dXMin;
656 : double m_dYMin;
657 : double m_dXMax;
658 : double m_dYMax;
659 :
660 : /* extents, as cached by MIFFile::PreParseFile() */
661 : int m_bExtentsSet;
662 : OGREnvelope m_sExtents;
663 :
664 : int m_nPoints;
665 : int m_nLines;
666 : int m_nRegions;
667 : int m_nTexts;
668 :
669 : int m_nPreloadedId; // preloaded mif line is for this feature id
670 : MIDDATAFile *m_poMIDFile; // Mid file
671 : MIDDATAFile *m_poMIFFile; // Mif File
672 :
673 : OGRFeatureDefn *m_poDefn;
674 : OGRSpatialReference *m_poSpatialRef;
675 :
676 : int m_nFeatureCount;
677 : int m_nWriteFeatureId;
678 : int m_nAttribut;
679 :
680 : ///////////////
681 : // Private Read access specific stuff
682 : //
683 : int ReadFeatureDefn();
684 : int ParseMIFHeader();
685 : void PreParseFile();
686 : int AddFields(const char *pszLine);
687 : int GotoFeature(int nFeatureId);
688 : int NextFeature();
689 :
690 : ///////////////
691 : // Private Write access specific stuff
692 : //
693 : GBool m_bPreParsed;
694 : GBool m_bHeaderWrote;
695 :
696 : int WriteMIFHeader();
697 : void UpdateExtents(double dfX,double dfY);
698 :
699 : public:
700 : MIFFile();
701 : virtual ~MIFFile();
702 :
703 0 : virtual TABFileClass GetFileClass() {return TABFC_MIFFile;}
704 :
705 : virtual int Open(const char *pszFname, const char *pszAccess,
706 : GBool bTestOpenNoError = FALSE );
707 : virtual int Close();
708 :
709 0 : virtual const char *GetTableName()
710 0 : {return m_poDefn?m_poDefn->GetName():"";};
711 :
712 : virtual int TestCapability( const char * pszCap ) ;
713 : virtual int GetFeatureCount (int bForce);
714 : virtual void ResetReading();
715 : virtual int GetExtent(OGREnvelope *psExtent, int bForce);
716 :
717 : ///////////////
718 : // Read access specific stuff
719 : //
720 :
721 : virtual int GetNextFeatureId(int nPrevId);
722 : virtual TABFeature *GetFeatureRef(int nFeatureId);
723 : virtual OGRFeatureDefn *GetLayerDefn();
724 :
725 : virtual TABFieldType GetNativeFieldType(int nFieldId);
726 :
727 : virtual int GetBounds(double &dXMin, double &dYMin,
728 : double &dXMax, double &dYMax,
729 : GBool bForce = TRUE );
730 :
731 : virtual OGRSpatialReference *GetSpatialRef();
732 :
733 : virtual int GetFeatureCountByType(int &numPoints, int &numLines,
734 : int &numRegions, int &numTexts,
735 : GBool bForce = TRUE);
736 :
737 : virtual GBool IsFieldIndexed(int nFieldId);
738 : virtual GBool IsFieldUnique(int nFieldId);
739 :
740 0 : virtual int GetVersion() { return m_nVersion; };
741 :
742 : ///////////////
743 : // Write access specific stuff
744 : //
745 : virtual int SetBounds(double dXMin, double dYMin,
746 : double dXMax, double dYMax);
747 : virtual int SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
748 : TABFieldType *paeMapInfoNativeFieldTypes = NULL);
749 : virtual int AddFieldNative(const char *pszName, TABFieldType eMapInfoType,
750 : int nWidth=0, int nPrecision=0,
751 : GBool bIndexed=FALSE, GBool bUnique=FALSE,
752 : int bApproxOK = TRUE);
753 : /* TODO */
754 : virtual int SetSpatialRef(OGRSpatialReference *poSpatialRef);
755 :
756 : virtual OGRErr CreateFeature(TABFeature *poFeature);
757 :
758 : virtual int SetFieldIndexed(int nFieldId);
759 :
760 : ///////////////
761 : // semi-private.
762 0 : virtual int GetProjInfo(TABProjInfo * /*poPI*/){return -1;}
763 : /* { return m_poMAPFile->GetHeaderBlock()->GetProjInfo( poPI ); }*/
764 0 : virtual int SetProjInfo(TABProjInfo * /*poPI*/){return -1;}
765 : /* { return m_poMAPFile->GetHeaderBlock()->SetProjInfo( poPI ); }*/
766 : virtual int SetMIFCoordSys(const char * pszMIFCoordSys);
767 :
768 : #ifdef DEBUG
769 0 : virtual void Dump(FILE * /*fpOut*/ = NULL) {};
770 : #endif
771 : };
772 :
773 : /*---------------------------------------------------------------------
774 : * Define some error codes specific to this lib.
775 : *--------------------------------------------------------------------*/
776 : #define TAB_WarningFeatureTypeNotSupported 501
777 : #define TAB_WarningInvalidFieldName 502
778 : #define TAB_WarningBoundsOverflow 503
779 :
780 : /*---------------------------------------------------------------------
781 : * Codes for the known MapInfo Geometry types
782 : *--------------------------------------------------------------------*/
783 : #define TAB_GEOM_NONE 0
784 : #define TAB_GEOM_SYMBOL_C 0x01
785 : #define TAB_GEOM_SYMBOL 0x02
786 : #define TAB_GEOM_LINE_C 0x04
787 : #define TAB_GEOM_LINE 0x05
788 : #define TAB_GEOM_PLINE_C 0x07
789 : #define TAB_GEOM_PLINE 0x08
790 : #define TAB_GEOM_ARC_C 0x0a
791 : #define TAB_GEOM_ARC 0x0b
792 : #define TAB_GEOM_REGION_C 0x0d
793 : #define TAB_GEOM_REGION 0x0e
794 : #define TAB_GEOM_TEXT_C 0x10
795 : #define TAB_GEOM_TEXT 0x11
796 : #define TAB_GEOM_RECT_C 0x13
797 : #define TAB_GEOM_RECT 0x14
798 : #define TAB_GEOM_ROUNDRECT_C 0x16
799 : #define TAB_GEOM_ROUNDRECT 0x17
800 : #define TAB_GEOM_ELLIPSE_C 0x19
801 : #define TAB_GEOM_ELLIPSE 0x1a
802 : #define TAB_GEOM_MULTIPLINE_C 0x25
803 : #define TAB_GEOM_MULTIPLINE 0x26
804 : #define TAB_GEOM_FONTSYMBOL_C 0x28
805 : #define TAB_GEOM_FONTSYMBOL 0x29
806 : #define TAB_GEOM_CUSTOMSYMBOL_C 0x2b
807 : #define TAB_GEOM_CUSTOMSYMBOL 0x2c
808 : /* Version 450 object types: */
809 : #define TAB_GEOM_V450_REGION_C 0x2e
810 : #define TAB_GEOM_V450_REGION 0x2f
811 : #define TAB_GEOM_V450_MULTIPLINE_C 0x31
812 : #define TAB_GEOM_V450_MULTIPLINE 0x32
813 : /* Version 650 object types: */
814 : #define TAB_GEOM_MULTIPOINT_C 0x34
815 : #define TAB_GEOM_MULTIPOINT 0x35
816 : #define TAB_GEOM_COLLECTION_C 0x37
817 : #define TAB_GEOM_COLLECTION 0x38
818 : /* Version 800 object types: */
819 : #define TAB_GEOM_UNKNOWN1_C 0x3a // ???
820 : #define TAB_GEOM_UNKNOWN1 0x3b // ???
821 : #define TAB_GEOM_V800_REGION_C 0x3d
822 : #define TAB_GEOM_V800_REGION 0x3e
823 : #define TAB_GEOM_V800_MULTIPLINE_C 0x40
824 : #define TAB_GEOM_V800_MULTIPLINE 0x41
825 : #define TAB_GEOM_V800_MULTIPOINT_C 0x43
826 : #define TAB_GEOM_V800_MULTIPOINT 0x44
827 : #define TAB_GEOM_V800_COLLECTION_C 0x46
828 : #define TAB_GEOM_V800_COLLECTION 0x47
829 :
830 : #define TAB_GEOM_GET_VERSION(nGeomType) \
831 : (((nGeomType) < TAB_GEOM_V450_REGION_C) ? 300: \
832 : ((nGeomType) < TAB_GEOM_MULTIPOINT_C) ? 450: \
833 : ((nGeomType) < TAB_GEOM_UNKNOWN1_C) ? 650: 800 )
834 :
835 :
836 : /*---------------------------------------------------------------------
837 : * Codes for the feature classes
838 : *--------------------------------------------------------------------*/
839 : typedef enum
840 : {
841 : TABFCNoGeomFeature = 0,
842 : TABFCPoint = 1,
843 : TABFCFontPoint = 2,
844 : TABFCCustomPoint = 3,
845 : TABFCText = 4,
846 : TABFCPolyline = 5,
847 : TABFCArc = 6,
848 : TABFCRegion = 7,
849 : TABFCRectangle = 8,
850 : TABFCEllipse = 9,
851 : TABFCMultiPoint = 10,
852 : TABFCCollection = 11,
853 : TABFCDebugFeature
854 : } TABFeatureClass;
855 :
856 : /*---------------------------------------------------------------------
857 : * Definitions for text attributes
858 : *--------------------------------------------------------------------*/
859 : typedef enum TABTextJust_t
860 : {
861 : TABTJLeft = 0, // Default: Left Justification
862 : TABTJCenter,
863 : TABTJRight
864 : } TABTextJust;
865 :
866 : typedef enum TABTextSpacing_t
867 : {
868 : TABTSSingle = 0, // Default: Single spacing
869 : TABTS1_5, // 1.5
870 : TABTSDouble
871 : } TABTextSpacing;
872 :
873 : typedef enum TABTextLineType_t
874 : {
875 : TABTLNoLine = 0, // Default: No line
876 : TABTLSimple,
877 : TABTLArrow
878 : } TABTextLineType;
879 :
880 : typedef enum TABFontStyle_t // Can be OR'ed
881 : { // except box and halo are mutually exclusive
882 : TABFSNone = 0,
883 : TABFSBold = 0x0001,
884 : TABFSItalic = 0x0002,
885 : TABFSUnderline = 0x0004,
886 : TABFSStrikeout = 0x0008,
887 : TABFSOutline = 0x0010,
888 : TABFSShadow = 0x0020,
889 : TABFSInverse = 0x0040,
890 : TABFSBlink = 0x0080,
891 : TABFSBox = 0x0100, // See note about box vs halo below.
892 : TABFSHalo = 0x0200, // MIF uses 256, see MIF docs, App.A
893 : TABFSAllCaps = 0x0400, // MIF uses 512
894 : TABFSExpanded = 0x0800 // MIF uses 1024
895 : } TABFontStyle;
896 :
897 : /* TABFontStyle enum notes:
898 : *
899 : * The enumeration values above correspond to the values found in a .MAP
900 : * file. However, they differ a little from what is found in a MIF file:
901 : * Values 0x01 to 0x80 are the same in .MIF and .MAP files.
902 : * Values 0x200 to 0x800 in .MAP are 0x100 to 0x400 in .MIF
903 : *
904 : * What about TABFSBox (0x100) ?
905 : * TABFSBox is stored just like the other styles in .MAP files but it is not
906 : * explicitly stored in a MIF file.
907 : * If a .MIF FONT() clause contains the optional BG color, then this implies
908 : * that either Halo or Box was set. Thus if TABFSHalo (value 256 in MIF)
909 : * is not set in the style, then this implies that TABFSBox should be set.
910 : */
911 :
912 : typedef enum TABCustSymbStyle_t // Can be OR'ed
913 : {
914 : TABCSNone = 0, // Transparent BG, use default colors
915 : TABCSBGOpaque = 0x01, // White pixels are opaque
916 : TABCSApplyColor = 0x02 // non-white pixels drawn using symbol color
917 : } TABCustSymbStyle;
918 :
919 : /*=====================================================================
920 : Base classes to be used to add supported drawing tools to each feature type
921 : =====================================================================*/
922 :
923 : class ITABFeaturePen
924 : {
925 : protected:
926 : int m_nPenDefIndex;
927 : TABPenDef m_sPenDef;
928 : public:
929 : ITABFeaturePen();
930 204 : ~ITABFeaturePen() {};
931 : int GetPenDefIndex() {return m_nPenDefIndex;};
932 0 : TABPenDef *GetPenDefRef() {return &m_sPenDef;};
933 :
934 : GByte GetPenWidthPixel();
935 : double GetPenWidthPoint();
936 : int GetPenWidthMIF();
937 68 : GByte GetPenPattern() {return m_sPenDef.nLinePattern;};
938 20 : GInt32 GetPenColor() {return m_sPenDef.rgbColor;};
939 :
940 : void SetPenWidthPixel(GByte val);
941 : void SetPenWidthPoint(double val);
942 : void SetPenWidthMIF(int val);
943 :
944 56 : void SetPenPattern(GByte val) {m_sPenDef.nLinePattern=val;};
945 56 : void SetPenColor(GInt32 clr) {m_sPenDef.rgbColor = clr;};
946 :
947 : const char *GetPenStyleString();
948 : void SetPenFromStyleString(const char *pszStyleString);
949 :
950 : void DumpPenDef(FILE *fpOut = NULL);
951 : };
952 :
953 : class ITABFeatureBrush
954 : {
955 : protected:
956 : int m_nBrushDefIndex;
957 : TABBrushDef m_sBrushDef;
958 : public:
959 : ITABFeatureBrush();
960 200 : ~ITABFeatureBrush() {};
961 : int GetBrushDefIndex() {return m_nBrushDefIndex;};
962 0 : TABBrushDef *GetBrushDefRef() {return &m_sBrushDef;};
963 :
964 20 : GInt32 GetBrushFGColor() {return m_sBrushDef.rgbFGColor;};
965 20 : GInt32 GetBrushBGColor() {return m_sBrushDef.rgbBGColor;};
966 40 : GByte GetBrushPattern() {return m_sBrushDef.nFillPattern;};
967 34 : GByte GetBrushTransparent() {return m_sBrushDef.bTransparentFill;};
968 :
969 56 : void SetBrushFGColor(GInt32 clr) { m_sBrushDef.rgbFGColor = clr;};
970 56 : void SetBrushBGColor(GInt32 clr) { m_sBrushDef.rgbBGColor = clr;};
971 56 : void SetBrushPattern(GByte val) { m_sBrushDef.nFillPattern=val;};
972 0 : void SetBrushTransparent(GByte val)
973 0 : {m_sBrushDef.bTransparentFill=val;};
974 :
975 : const char *GetBrushStyleString();
976 : void SetBrushFromStyleString(const char *pszStyleString);
977 :
978 : void DumpBrushDef(FILE *fpOut = NULL);
979 : };
980 :
981 : class ITABFeatureFont
982 : {
983 : protected:
984 : int m_nFontDefIndex;
985 : TABFontDef m_sFontDef;
986 : public:
987 : ITABFeatureFont();
988 0 : ~ITABFeatureFont() {};
989 : int GetFontDefIndex() {return m_nFontDefIndex;};
990 0 : TABFontDef *GetFontDefRef() {return &m_sFontDef;};
991 :
992 0 : const char *GetFontNameRef() {return m_sFontDef.szFontName;};
993 :
994 : void SetFontName(const char *pszName);
995 :
996 : void DumpFontDef(FILE *fpOut = NULL);
997 : };
998 :
999 : class ITABFeatureSymbol
1000 : {
1001 : protected:
1002 : int m_nSymbolDefIndex;
1003 : TABSymbolDef m_sSymbolDef;
1004 : public:
1005 : ITABFeatureSymbol();
1006 16 : ~ITABFeatureSymbol() {};
1007 : int GetSymbolDefIndex() {return m_nSymbolDefIndex;};
1008 0 : TABSymbolDef *GetSymbolDefRef() {return &m_sSymbolDef;};
1009 :
1010 8 : GInt16 GetSymbolNo() {return m_sSymbolDef.nSymbolNo;};
1011 8 : GInt16 GetSymbolSize() {return m_sSymbolDef.nPointSize;};
1012 8 : GInt32 GetSymbolColor() {return m_sSymbolDef.rgbColor;};
1013 :
1014 8 : void SetSymbolNo(GInt16 val) { m_sSymbolDef.nSymbolNo = val;};
1015 8 : void SetSymbolSize(GInt16 val) { m_sSymbolDef.nPointSize = val;};
1016 8 : void SetSymbolColor(GInt32 clr) { m_sSymbolDef.rgbColor = clr;};
1017 :
1018 : const char *GetSymbolStyleString(double dfAngle = 0.0);
1019 : void SetSymbolFromStyleString(const char *pszStyleString);
1020 :
1021 : void DumpSymbolDef(FILE *fpOut = NULL);
1022 : };
1023 :
1024 :
1025 : /*=====================================================================
1026 : Feature Classes
1027 : =====================================================================*/
1028 :
1029 : /*---------------------------------------------------------------------
1030 : * class TABFeature
1031 : *
1032 : * Extend the OGRFeature to support MapInfo specific extensions related
1033 : * to geometry types, representation strings, etc.
1034 : *
1035 : * TABFeature will be used as a base class for all the feature classes.
1036 : *
1037 : * This class will also be used to instanciate objects with no Geometry
1038 : * (i.e. type TAB_GEOM_NONE) which is a valid case in MapInfo.
1039 : *
1040 : * The logic to read/write the object from/to the .DAT and .MAP files is also
1041 : * implemented as part of this class and derived classes.
1042 : *--------------------------------------------------------------------*/
1043 : class TABFeature: public OGRFeature
1044 : {
1045 : protected:
1046 : int m_nMapInfoType;
1047 :
1048 : double m_dXMin;
1049 : double m_dYMin;
1050 : double m_dXMax;
1051 : double m_dYMax;
1052 :
1053 : GBool m_bDeletedFlag;
1054 :
1055 : void CopyTABFeatureBase(TABFeature *poDestFeature);
1056 :
1057 : // Compr. Origin is set for TAB files by ValidateCoordType()
1058 : GInt32 m_nXMin;
1059 : GInt32 m_nYMin;
1060 : GInt32 m_nXMax;
1061 : GInt32 m_nYMax;
1062 : GInt32 m_nComprOrgX;
1063 : GInt32 m_nComprOrgY;
1064 :
1065 : virtual int UpdateMBR(TABMAPFile *poMapFile = NULL);
1066 :
1067 : public:
1068 : TABFeature(OGRFeatureDefn *poDefnIn );
1069 : virtual ~TABFeature();
1070 :
1071 : static TABFeature *CreateFromMapInfoType(int nMapInfoType,
1072 : OGRFeatureDefn *poDefn);
1073 :
1074 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *pNewDefn = NULL);
1075 28 : virtual TABFeatureClass GetFeatureClass() { return TABFCNoGeomFeature; };
1076 0 : virtual int GetMapInfoType() { return m_nMapInfoType; };
1077 4 : virtual int ValidateMapInfoType(TABMAPFile *poMapFile = NULL)
1078 4 : {m_nMapInfoType=TAB_GEOM_NONE;
1079 4 : return m_nMapInfoType;};
1080 : GBool IsRecordDeleted() { return m_bDeletedFlag; };
1081 106 : void SetRecordDeleted(GBool bDeleted) { m_bDeletedFlag=bDeleted; };
1082 :
1083 : /*-----------------------------------------------------------------
1084 : * TAB Support
1085 : *----------------------------------------------------------------*/
1086 :
1087 : virtual int ReadRecordFromDATFile(TABDATFile *poDATFile);
1088 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1089 : GBool bCoordDataOnly=FALSE,
1090 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1091 :
1092 : virtual int WriteRecordToDATFile(TABDATFile *poDATFile,
1093 : TABINDFile *poINDFile, int *panIndexNo);
1094 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1095 : GBool bCoordDataOnly=FALSE,
1096 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1097 : GBool ValidateCoordType(TABMAPFile * poMapFile);
1098 : void ForceCoordTypeAndOrigin(int nMapInfoType, GBool bCompr,
1099 : GInt32 nComprOrgX, GInt32 nComprOrgY,
1100 : GInt32 nXMin, GInt32 nYMin,
1101 : GInt32 nXMax, GInt32 nYMax);
1102 :
1103 : /*-----------------------------------------------------------------
1104 : * Mid/Mif Support
1105 : *----------------------------------------------------------------*/
1106 :
1107 : virtual int ReadRecordFromMIDFile(MIDDATAFile *fp);
1108 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1109 :
1110 : virtual int WriteRecordToMIDFile(MIDDATAFile *fp);
1111 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1112 :
1113 : void ReadMIFParameters(MIDDATAFile *fp);
1114 : void WriteMIFParameters(MIDDATAFile *fp);
1115 :
1116 : /*-----------------------------------------------------------------
1117 : *----------------------------------------------------------------*/
1118 :
1119 : void SetMBR(double dXMin, double dYMin,
1120 : double dXMax, double dYMax);
1121 : void GetMBR(double &dXMin, double &dYMin,
1122 : double &dXMax, double &dYMax);
1123 : void SetIntMBR(GInt32 nXMin, GInt32 nYMin,
1124 : GInt32 nXMax, GInt32 nYMax);
1125 : void GetIntMBR(GInt32 &nXMin, GInt32 &nYMin,
1126 : GInt32 &nXMax, GInt32 &nYMax);
1127 :
1128 : virtual void DumpMID(FILE *fpOut = NULL);
1129 : virtual void DumpMIF(FILE *fpOut = NULL);
1130 :
1131 : };
1132 :
1133 :
1134 : /*---------------------------------------------------------------------
1135 : * class TABPoint
1136 : *
1137 : * Feature class to handle old style MapInfo point symbols:
1138 : *
1139 : * TAB_GEOM_SYMBOL_C 0x01
1140 : * TAB_GEOM_SYMBOL 0x02
1141 : *
1142 : * Feature geometry will be a OGRPoint
1143 : *
1144 : * The symbol number is in the range [31..67], with 31=None and corresponds
1145 : * to one of the 35 predefined "Old MapInfo Symbols"
1146 : *
1147 : * NOTE: This class is also used as a base class for the other point
1148 : * symbol types TABFontPoint and TABCustomPoint.
1149 : *--------------------------------------------------------------------*/
1150 : class TABPoint: public TABFeature,
1151 : public ITABFeatureSymbol
1152 : {
1153 : public:
1154 : TABPoint(OGRFeatureDefn *poDefnIn);
1155 : virtual ~TABPoint();
1156 :
1157 8 : virtual TABFeatureClass GetFeatureClass() { return TABFCPoint; };
1158 : virtual int ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1159 :
1160 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1161 :
1162 : double GetX();
1163 : double GetY();
1164 :
1165 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1166 : GBool bCoordDataOnly=FALSE,
1167 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1168 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1169 : GBool bCoordDataOnly=FALSE,
1170 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1171 :
1172 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1173 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1174 :
1175 : virtual const char *GetStyleString();
1176 :
1177 : virtual void DumpMIF(FILE *fpOut = NULL);
1178 : };
1179 :
1180 :
1181 : /*---------------------------------------------------------------------
1182 : * class TABFontPoint
1183 : *
1184 : * Feature class to handle MapInfo Font Point Symbol types:
1185 : *
1186 : * TAB_GEOM_FONTSYMBOL_C 0x28
1187 : * TAB_GEOM_FONTSYMBOL 0x29
1188 : *
1189 : * Feature geometry will be a OGRPoint
1190 : *
1191 : * The symbol number refers to a character code in the specified Windows
1192 : * Font (e.g. "Windings").
1193 : *--------------------------------------------------------------------*/
1194 : class TABFontPoint: public TABPoint,
1195 : public ITABFeatureFont
1196 : {
1197 : protected:
1198 : double m_dAngle;
1199 : GInt16 m_nFontStyle; // Bold/shadow/halo/etc.
1200 :
1201 : public:
1202 : TABFontPoint(OGRFeatureDefn *poDefnIn);
1203 : virtual ~TABFontPoint();
1204 :
1205 0 : virtual TABFeatureClass GetFeatureClass() { return TABFCFontPoint; };
1206 :
1207 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1208 :
1209 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1210 : GBool bCoordDataOnly=FALSE,
1211 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1212 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1213 : GBool bCoordDataOnly=FALSE,
1214 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1215 :
1216 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1217 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1218 :
1219 : virtual const char *GetStyleString();
1220 :
1221 : GBool QueryFontStyle(TABFontStyle eStyleToQuery);
1222 : void ToggleFontStyle(TABFontStyle eStyleToToggle, GBool bStatus);
1223 :
1224 : int GetFontStyleMIFValue();
1225 : void SetFontStyleMIFValue(int nStyle);
1226 0 : int GetFontStyleTABValue() {return m_nFontStyle;};
1227 0 : void SetFontStyleTABValue(int nStyle){m_nFontStyle=(GInt16)nStyle;};
1228 :
1229 : // GetSymbolAngle(): Return angle in degrees counterclockwise
1230 0 : double GetSymbolAngle() {return m_dAngle;};
1231 : void SetSymbolAngle(double dAngle);
1232 : };
1233 :
1234 :
1235 : /*---------------------------------------------------------------------
1236 : * class TABCustomPoint
1237 : *
1238 : * Feature class to handle MapInfo Custom Point Symbol (Bitmap) types:
1239 : *
1240 : * TAB_GEOM_CUSTOMSYMBOL_C 0x2b
1241 : * TAB_GEOM_CUSTOMSYMBOL 0x2c
1242 : *
1243 : * Feature geometry will be a OGRPoint
1244 : *
1245 : * The symbol name is the name of a BMP file stored in the "CustSymb"
1246 : * directory (e.g. "arrow.BMP"). The symbol number has no meaning for
1247 : * this symbol type.
1248 : *--------------------------------------------------------------------*/
1249 : class TABCustomPoint: public TABPoint,
1250 : public ITABFeatureFont
1251 : {
1252 : protected:
1253 : GByte m_nCustomStyle; // Show BG/Apply Color
1254 :
1255 : public:
1256 : GByte m_nUnknown_;
1257 :
1258 : public:
1259 : TABCustomPoint(OGRFeatureDefn *poDefnIn);
1260 : virtual ~TABCustomPoint();
1261 :
1262 0 : virtual TABFeatureClass GetFeatureClass() { return TABFCCustomPoint; };
1263 :
1264 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1265 :
1266 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1267 : GBool bCoordDataOnly=FALSE,
1268 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1269 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1270 : GBool bCoordDataOnly=FALSE,
1271 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1272 :
1273 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1274 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1275 :
1276 : virtual const char *GetStyleString();
1277 :
1278 : const char *GetSymbolNameRef() { return GetFontNameRef(); };
1279 : void SetSymbolName(const char *pszName) {SetFontName(pszName);};
1280 :
1281 0 : GByte GetCustomSymbolStyle() {return m_nCustomStyle;}
1282 0 : void SetCustomSymbolStyle(GByte nStyle) {m_nCustomStyle = nStyle;}
1283 : };
1284 :
1285 :
1286 : /*---------------------------------------------------------------------
1287 : * class TABPolyline
1288 : *
1289 : * Feature class to handle the various MapInfo line types:
1290 : *
1291 : * TAB_GEOM_LINE_C 0x04
1292 : * TAB_GEOM_LINE 0x05
1293 : * TAB_GEOM_PLINE_C 0x07
1294 : * TAB_GEOM_PLINE 0x08
1295 : * TAB_GEOM_MULTIPLINE_C 0x25
1296 : * TAB_GEOM_MULTIPLINE 0x26
1297 : * TAB_GEOM_V450_MULTIPLINE_C 0x31
1298 : * TAB_GEOM_V450_MULTIPLINE 0x32
1299 : *
1300 : * Feature geometry can be either a OGRLineString or a OGRMultiLineString
1301 : *--------------------------------------------------------------------*/
1302 : class TABPolyline: public TABFeature,
1303 : public ITABFeaturePen
1304 : {
1305 : private:
1306 : GBool m_bCenterIsSet;
1307 : double m_dCenterX, m_dCenterY;
1308 : GBool m_bWriteTwoPointLineAsPolyline;
1309 :
1310 : public:
1311 : TABPolyline(OGRFeatureDefn *poDefnIn);
1312 : virtual ~TABPolyline();
1313 :
1314 0 : virtual TABFeatureClass GetFeatureClass() { return TABFCPolyline; };
1315 : virtual int ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1316 :
1317 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1318 :
1319 : /* 2 methods to simplify access to rings in a multiple polyline
1320 : */
1321 : int GetNumParts();
1322 : OGRLineString *GetPartRef(int nPartIndex);
1323 :
1324 : GBool TwoPointLineAsPolyline();
1325 : void TwoPointLineAsPolyline(GBool bTwoPointLineAsPolyline);
1326 :
1327 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1328 : GBool bCoordDataOnly=FALSE,
1329 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1330 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1331 : GBool bCoordDataOnly=FALSE,
1332 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1333 :
1334 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1335 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1336 :
1337 : virtual const char *GetStyleString();
1338 :
1339 : virtual void DumpMIF(FILE *fpOut = NULL);
1340 :
1341 : int GetCenter(double &dX, double &dY);
1342 : void SetCenter(double dX, double dY);
1343 :
1344 : // MapInfo-specific attributes... made available through public vars
1345 : // for now.
1346 : GBool m_bSmooth;
1347 :
1348 : };
1349 :
1350 : /*---------------------------------------------------------------------
1351 : * class TABRegion
1352 : *
1353 : * Feature class to handle the MapInfo region types:
1354 : *
1355 : * TAB_GEOM_REGION_C 0x0d
1356 : * TAB_GEOM_REGION 0x0e
1357 : * TAB_GEOM_V450_REGION_C 0x2e
1358 : * TAB_GEOM_V450_REGION 0x2f
1359 : *
1360 : * Feature geometry will be returned as OGRPolygon (with a single ring)
1361 : * or OGRMultiPolygon (for multiple rings).
1362 : *
1363 : * REGIONs with multiple rings are returned as OGRMultiPolygon instead of
1364 : * as OGRPolygons since OGRPolygons require that the first ring be the
1365 : * outer ring, and the other all be inner rings, but this is not guaranteed
1366 : * inside MapInfo files. However, when writing features, OGRPolygons with
1367 : * multiple rings will be accepted without problem.
1368 : *--------------------------------------------------------------------*/
1369 : class TABRegion: public TABFeature,
1370 : public ITABFeaturePen,
1371 : public ITABFeatureBrush
1372 : {
1373 : GBool m_bSmooth;
1374 : private:
1375 : GBool m_bCenterIsSet;
1376 : double m_dCenterX, m_dCenterY;
1377 :
1378 : int ComputeNumRings(TABMAPCoordSecHdr **ppasSecHdrs,
1379 : TABMAPFile *poMAPFile);
1380 : int AppendSecHdrs(OGRPolygon *poPolygon,
1381 : TABMAPCoordSecHdr * &pasSecHdrs,
1382 : TABMAPFile *poMAPFile,
1383 : int &iLastRing);
1384 :
1385 : public:
1386 : TABRegion(OGRFeatureDefn *poDefnIn);
1387 : virtual ~TABRegion();
1388 :
1389 56 : virtual TABFeatureClass GetFeatureClass() { return TABFCRegion; };
1390 : virtual int ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1391 :
1392 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1393 :
1394 : /* 2 methods to make the REGION's geometry look like a single collection
1395 : * of OGRLinearRings
1396 : */
1397 : int GetNumRings();
1398 : OGRLinearRing *GetRingRef(int nRequestedRingIndex);
1399 : GBool IsInteriorRing(int nRequestedRingIndex);
1400 :
1401 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1402 : GBool bCoordDataOnly=FALSE,
1403 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1404 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1405 : GBool bCoordDataOnly=FALSE,
1406 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1407 :
1408 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1409 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1410 :
1411 : virtual const char *GetStyleString();
1412 :
1413 : virtual void DumpMIF(FILE *fpOut = NULL);
1414 :
1415 : int GetCenter(double &dX, double &dY);
1416 : void SetCenter(double dX, double dY);
1417 : };
1418 :
1419 :
1420 : /*---------------------------------------------------------------------
1421 : * class TABRectangle
1422 : *
1423 : * Feature class to handle the MapInfo rectangle types:
1424 : *
1425 : * TAB_GEOM_RECT_C 0x13
1426 : * TAB_GEOM_RECT 0x14
1427 : * TAB_GEOM_ROUNDRECT_C 0x16
1428 : * TAB_GEOM_ROUNDRECT 0x17
1429 : *
1430 : * A rectangle is defined by the coords of its 2 opposite corners (the MBR)
1431 : * Its corners can optionaly be rounded, in which case a X and Y rounding
1432 : * radius will be defined.
1433 : *
1434 : * Feature geometry will be OGRPolygon
1435 : *--------------------------------------------------------------------*/
1436 : class TABRectangle: public TABFeature,
1437 : public ITABFeaturePen,
1438 : public ITABFeatureBrush
1439 : {
1440 : private:
1441 : virtual int UpdateMBR(TABMAPFile *poMapFile = NULL);
1442 :
1443 : public:
1444 : TABRectangle(OGRFeatureDefn *poDefnIn);
1445 : virtual ~TABRectangle();
1446 :
1447 0 : virtual TABFeatureClass GetFeatureClass() { return TABFCRectangle; };
1448 : virtual int ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1449 :
1450 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1451 :
1452 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1453 : GBool bCoordDataOnly=FALSE,
1454 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1455 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1456 : GBool bCoordDataOnly=FALSE,
1457 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1458 :
1459 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1460 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1461 :
1462 : virtual const char *GetStyleString();
1463 :
1464 : virtual void DumpMIF(FILE *fpOut = NULL);
1465 :
1466 : // MapInfo-specific attributes... made available through public vars
1467 : // for now.
1468 : GBool m_bRoundCorners;
1469 : double m_dRoundXRadius;
1470 : double m_dRoundYRadius;
1471 :
1472 : };
1473 :
1474 :
1475 : /*---------------------------------------------------------------------
1476 : * class TABEllipse
1477 : *
1478 : * Feature class to handle the MapInfo ellipse types:
1479 : *
1480 : * TAB_GEOM_ELLIPSE_C 0x19
1481 : * TAB_GEOM_ELLIPSE 0x1a
1482 : *
1483 : * An ellipse is defined by the coords of its 2 opposite corners (the MBR)
1484 : *
1485 : * Feature geometry can be either an OGRPoint defining the center of the
1486 : * ellipse, or an OGRPolygon defining the ellipse itself.
1487 : *
1488 : * When an ellipse is read, the returned geometry is a OGRPolygon representing
1489 : * the ellipse with 2 degrees line segments.
1490 : *
1491 : * In the case of the OGRPoint, then the X/Y Radius MUST be set, but.
1492 : * However with an OGRPolygon, if the X/Y radius are not set (== 0) then
1493 : * the MBR of the polygon will be used to define the ellipse parameters
1494 : * and the center of the MBR is used as the center of the ellipse...
1495 : * (i.e. the polygon vertices themselves will be ignored).
1496 : *--------------------------------------------------------------------*/
1497 : class TABEllipse: public TABFeature,
1498 : public ITABFeaturePen,
1499 : public ITABFeatureBrush
1500 : {
1501 : private:
1502 : virtual int UpdateMBR(TABMAPFile *poMapFile = NULL);
1503 :
1504 : public:
1505 : TABEllipse(OGRFeatureDefn *poDefnIn);
1506 : virtual ~TABEllipse();
1507 :
1508 0 : virtual TABFeatureClass GetFeatureClass() { return TABFCEllipse; };
1509 : virtual int ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1510 :
1511 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1512 :
1513 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1514 : GBool bCoordDataOnly=FALSE,
1515 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1516 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1517 : GBool bCoordDataOnly=FALSE,
1518 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1519 :
1520 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1521 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1522 :
1523 : virtual const char *GetStyleString();
1524 :
1525 : virtual void DumpMIF(FILE *fpOut = NULL);
1526 :
1527 : // MapInfo-specific attributes... made available through public vars
1528 : // for now.
1529 : double m_dCenterX;
1530 : double m_dCenterY;
1531 : double m_dXRadius;
1532 : double m_dYRadius;
1533 :
1534 : };
1535 :
1536 :
1537 : /*---------------------------------------------------------------------
1538 : * class TABArc
1539 : *
1540 : * Feature class to handle the MapInfo arc types:
1541 : *
1542 : * TAB_GEOM_ARC_C 0x0a
1543 : * TAB_GEOM_ARC 0x0b
1544 : *
1545 : * In MapInfo, an arc is defined by the coords of the MBR corners of its
1546 : * defining ellipse, which in this case is different from the arc's MBR,
1547 : * and a start and end angle in degrees.
1548 : *
1549 : * Feature geometry can be either an OGRLineString or an OGRPoint.
1550 : *
1551 : * In any case, X/Y radius X/Y center, and start/end angle (in degrees
1552 : * counterclockwise) MUST be set.
1553 : *
1554 : * When an arc is read, the returned geometry is an OGRLineString
1555 : * representing the arc with 2 degrees line segments.
1556 : *--------------------------------------------------------------------*/
1557 : class TABArc: public TABFeature,
1558 : public ITABFeaturePen
1559 : {
1560 : private:
1561 : double m_dStartAngle; // In degrees, counterclockwise,
1562 : double m_dEndAngle; // starting at 3 o'clock
1563 :
1564 : virtual int UpdateMBR(TABMAPFile *poMapFile = NULL);
1565 :
1566 : public:
1567 : TABArc(OGRFeatureDefn *poDefnIn);
1568 : virtual ~TABArc();
1569 :
1570 0 : virtual TABFeatureClass GetFeatureClass() { return TABFCArc; };
1571 : virtual int ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1572 :
1573 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1574 :
1575 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1576 : GBool bCoordDataOnly=FALSE,
1577 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1578 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1579 : GBool bCoordDataOnly=FALSE,
1580 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1581 :
1582 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1583 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1584 :
1585 : virtual const char *GetStyleString();
1586 :
1587 : virtual void DumpMIF(FILE *fpOut = NULL);
1588 :
1589 0 : double GetStartAngle() { return m_dStartAngle; };
1590 0 : double GetEndAngle() { return m_dEndAngle; };
1591 : void SetStartAngle(double dAngle);
1592 : void SetEndAngle(double dAngle);
1593 :
1594 : // MapInfo-specific attributes... made available through public vars
1595 : // for now.
1596 : double m_dCenterX;
1597 : double m_dCenterY;
1598 : double m_dXRadius;
1599 : double m_dYRadius;
1600 : };
1601 :
1602 :
1603 : /*---------------------------------------------------------------------
1604 : * class TABText
1605 : *
1606 : * Feature class to handle the MapInfo text types:
1607 : *
1608 : * TAB_GEOM_TEXT_C 0x10
1609 : * TAB_GEOM_TEXT 0x11
1610 : *
1611 : * Feature geometry is an OGRPoint corresponding to the lower-left
1612 : * corner of the text MBR BEFORE ROTATION.
1613 : *
1614 : * Text string, and box height/width (box before rotation is applied)
1615 : * are required in a valid text feature and MUST be set.
1616 : * Text angle and other styles are optional.
1617 : *--------------------------------------------------------------------*/
1618 : class TABText: public TABFeature,
1619 : public ITABFeatureFont,
1620 : public ITABFeaturePen
1621 : {
1622 : protected:
1623 : char *m_pszString;
1624 :
1625 : double m_dAngle;
1626 : double m_dHeight;
1627 : double m_dWidth;
1628 : double m_dfLineEndX;
1629 : double m_dfLineEndY;
1630 : GBool m_bLineEndSet;
1631 : void UpdateTextMBR();
1632 :
1633 : GInt32 m_rgbForeground;
1634 : GInt32 m_rgbBackground;
1635 : GInt32 m_rgbOutline;
1636 : GInt32 m_rgbShadow;
1637 :
1638 : GInt16 m_nTextAlignment; // Justification/Vert.Spacing/arrow
1639 : GInt16 m_nFontStyle; // Bold/italic/underlined/shadow/...
1640 :
1641 : const char *GetLabelStyleString();
1642 :
1643 : virtual int UpdateMBR(TABMAPFile *poMapFile = NULL);
1644 :
1645 : public:
1646 : TABText(OGRFeatureDefn *poDefnIn);
1647 : virtual ~TABText();
1648 :
1649 0 : virtual TABFeatureClass GetFeatureClass() { return TABFCText; };
1650 : virtual int ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1651 :
1652 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1653 :
1654 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1655 : GBool bCoordDataOnly=FALSE,
1656 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1657 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1658 : GBool bCoordDataOnly=FALSE,
1659 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1660 :
1661 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1662 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1663 :
1664 : virtual const char *GetStyleString();
1665 :
1666 : virtual void DumpMIF(FILE *fpOut = NULL);
1667 :
1668 : const char *GetTextString();
1669 : double GetTextAngle();
1670 : double GetTextBoxHeight();
1671 : double GetTextBoxWidth();
1672 : GInt32 GetFontFGColor();
1673 : GInt32 GetFontBGColor();
1674 : GInt32 GetFontOColor();
1675 : GInt32 GetFontSColor();
1676 : void GetTextLineEndPoint(double &dX, double &dY);
1677 :
1678 : TABTextJust GetTextJustification();
1679 : TABTextSpacing GetTextSpacing();
1680 : TABTextLineType GetTextLineType();
1681 : GBool QueryFontStyle(TABFontStyle eStyleToQuery);
1682 :
1683 : void SetTextString(const char *pszStr);
1684 : void SetTextAngle(double dAngle);
1685 : void SetTextBoxHeight(double dHeight);
1686 : void SetTextBoxWidth(double dWidth);
1687 : void SetFontFGColor(GInt32 rgbColor);
1688 : void SetFontBGColor(GInt32 rgbColor);
1689 : void SetFontOColor(GInt32 rgbColor);
1690 : void SetFontSColor(GInt32 rgbColor);
1691 : void SetTextLineEndPoint(double dX, double dY);
1692 :
1693 : void SetTextJustification(TABTextJust eJust);
1694 : void SetTextSpacing(TABTextSpacing eSpacing);
1695 : void SetTextLineType(TABTextLineType eLineType);
1696 : void ToggleFontStyle(TABFontStyle eStyleToToggle, GBool bStatus);
1697 :
1698 : int GetFontStyleMIFValue();
1699 : void SetFontStyleMIFValue(int nStyle, GBool bBGColorSet=FALSE);
1700 : GBool IsFontBGColorUsed();
1701 : GBool IsFontOColorUsed();
1702 : GBool IsFontSColorUsed();
1703 : GBool IsFontBold();
1704 : GBool IsFontItalic();
1705 : GBool IsFontUnderline();
1706 0 : int GetFontStyleTABValue() {return m_nFontStyle;};
1707 0 : void SetFontStyleTABValue(int nStyle){m_nFontStyle=(GInt16)nStyle;};
1708 :
1709 : };
1710 :
1711 :
1712 : /*---------------------------------------------------------------------
1713 : * class TABMultiPoint
1714 : *
1715 : * Feature class to handle MapInfo Multipoint features:
1716 : *
1717 : * TAB_GEOM_MULTIPOINT_C 0x34
1718 : * TAB_GEOM_MULTIPOINT 0x35
1719 : *
1720 : * Feature geometry will be a OGRMultiPoint
1721 : *
1722 : * The symbol number is in the range [31..67], with 31=None and corresponds
1723 : * to one of the 35 predefined "Old MapInfo Symbols"
1724 : *--------------------------------------------------------------------*/
1725 : class TABMultiPoint: public TABFeature,
1726 : public ITABFeatureSymbol
1727 : {
1728 : private:
1729 : // We call it center, but it's more like a label point
1730 : // Its value default to be the location of the first point
1731 : GBool m_bCenterIsSet;
1732 : double m_dCenterX, m_dCenterY;
1733 :
1734 : public:
1735 : TABMultiPoint(OGRFeatureDefn *poDefnIn);
1736 : virtual ~TABMultiPoint();
1737 :
1738 0 : virtual TABFeatureClass GetFeatureClass() { return TABFCMultiPoint; };
1739 : virtual int ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1740 :
1741 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1742 :
1743 : int GetXY(int i, double &dX, double &dY);
1744 : int GetNumPoints();
1745 :
1746 : int GetCenter(double &dX, double &dY);
1747 : void SetCenter(double dX, double dY);
1748 :
1749 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1750 : GBool bCoordDataOnly=FALSE,
1751 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1752 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1753 : GBool bCoordDataOnly=FALSE,
1754 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1755 :
1756 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1757 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1758 :
1759 : virtual const char *GetStyleString();
1760 :
1761 : virtual void DumpMIF(FILE *fpOut = NULL);
1762 : };
1763 :
1764 : /*---------------------------------------------------------------------
1765 : *
1766 : * class TABCollection
1767 : *
1768 : * Feature class to handle MapInfo Collection features:
1769 : *
1770 : * TAB_GEOM_COLLECTION_C 0x37
1771 : * TAB_GEOM_COLLECTION 0x38
1772 : *
1773 : * Feature geometry will be a OGRCollection
1774 : *
1775 : * **** IMPORTANT NOTE: ****
1776 : *
1777 : * The current implementation does not allow setting the Geometry via
1778 : * OGRFeature::SetGeometry*(). The geometries must be set via the
1779 : * TABCollection::SetRegion/Pline/MpointDirectly() methods which will take
1780 : * care of keeping the OGRFeature's geometry in sync.
1781 : *
1782 : * If we ever want to support creating collections via the OGR interface then
1783 : * something should be added in TABCollection::WriteGeometryToMapFile(), or
1784 : * perhaps in ValidateMapInfoType(), or even better in a custom
1785 : * TABCollection::SetGeometry*()... but then this last option may not work
1786 : * unless OGRFeature::SetGeometry*() are made virtual in OGR.
1787 : *
1788 : *--------------------------------------------------------------------*/
1789 : class TABCollection: public TABFeature,
1790 : public ITABFeatureSymbol
1791 : {
1792 : private:
1793 : TABRegion *m_poRegion;
1794 : TABPolyline *m_poPline;
1795 : TABMultiPoint *m_poMpoint;
1796 :
1797 : void EmptyCollection();
1798 : int ReadLabelAndMBR(TABMAPCoordBlock *poCoordBlock,
1799 : GBool bComprCoord,
1800 : GInt32 nComprOrgX, GInt32 nComprOrgY,
1801 : GInt32 &pnMinX, GInt32 &pnMinY,
1802 : GInt32 &pnMaxX, GInt32 &pnMaxY,
1803 : GInt32 &pnLabelX, GInt32 &pnLabelY );
1804 : int WriteLabelAndMBR(TABMAPCoordBlock *poCoordBlock,
1805 : GBool bComprCoord,
1806 : GInt32 nMinX, GInt32 nMinY,
1807 : GInt32 nMaxX, GInt32 nMaxY,
1808 : GInt32 nLabelX, GInt32 nLabelY );
1809 : int SyncOGRGeometryCollection(GBool bSyncRegion,
1810 : GBool bSyncPline,
1811 : GBool bSyncMpoint);
1812 :
1813 : public:
1814 : TABCollection(OGRFeatureDefn *poDefnIn);
1815 : virtual ~TABCollection();
1816 :
1817 0 : virtual TABFeatureClass GetFeatureClass() { return TABFCCollection; };
1818 : virtual int ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1819 :
1820 : virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1821 :
1822 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1823 : GBool bCoordDataOnly=FALSE,
1824 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1825 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1826 : GBool bCoordDataOnly=FALSE,
1827 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1828 :
1829 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1830 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1831 :
1832 : virtual const char *GetStyleString();
1833 :
1834 : virtual void DumpMIF(FILE *fpOut = NULL);
1835 :
1836 : TABRegion *GetRegionRef() {return m_poRegion; };
1837 : TABPolyline *GetPolylineRef() {return m_poPline; };
1838 : TABMultiPoint *GetMultiPointRef() {return m_poMpoint; };
1839 :
1840 : int SetRegionDirectly(TABRegion *poRegion);
1841 : int SetPolylineDirectly(TABPolyline *poPline);
1842 : int SetMultiPointDirectly(TABMultiPoint *poMpoint);
1843 : };
1844 :
1845 :
1846 : /*---------------------------------------------------------------------
1847 : * class TABDebugFeature
1848 : *
1849 : * Feature class to use for testing purposes... this one does not
1850 : * correspond to any MapInfo type... it's just used to dump info about
1851 : * feature types that are not implemented yet.
1852 : *--------------------------------------------------------------------*/
1853 : class TABDebugFeature: public TABFeature
1854 : {
1855 : private:
1856 : GByte m_abyBuf[512];
1857 : int m_nSize;
1858 : int m_nCoordDataPtr; // -1 if none
1859 : int m_nCoordDataSize;
1860 :
1861 : public:
1862 : TABDebugFeature(OGRFeatureDefn *poDefnIn);
1863 : virtual ~TABDebugFeature();
1864 :
1865 0 : virtual TABFeatureClass GetFeatureClass() { return TABFCDebugFeature; };
1866 :
1867 : virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1868 : GBool bCoordDataOnly=FALSE,
1869 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1870 : virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1871 : GBool bCoordDataOnly=FALSE,
1872 : TABMAPCoordBlock **ppoCoordBlock=NULL);
1873 :
1874 : virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1875 : virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1876 :
1877 : virtual void DumpMIF(FILE *fpOut = NULL);
1878 : };
1879 :
1880 : /* -------------------------------------------------------------------- */
1881 : /* Some stuff related to spatial reference system handling. */
1882 : /* */
1883 : /* In GDAL we make use of the coordsys transformation from */
1884 : /* other places (sometimes even from plugins), so we */
1885 : /* deliberately export these two functions from the DLL. */
1886 : /* -------------------------------------------------------------------- */
1887 :
1888 : char CPL_DLL *MITABSpatialRef2CoordSys( OGRSpatialReference * );
1889 : OGRSpatialReference CPL_DLL * MITABCoordSys2SpatialRef( const char * );
1890 :
1891 : GBool MITABExtractCoordSysBounds( const char * pszCoordSys,
1892 : double &dXMin, double &dYMin,
1893 : double &dXMax, double &dYMax );
1894 : int MITABCoordSys2TABProjInfo(const char * pszCoordSys, TABProjInfo *psProj);
1895 :
1896 : typedef struct {
1897 : int nMapInfoDatumID;
1898 : const char *pszOGCDatumName;
1899 : int nEllipsoid;
1900 : double dfShiftX;
1901 : double dfShiftY;
1902 : double dfShiftZ;
1903 : double dfDatumParm0; /* RotX */
1904 : double dfDatumParm1; /* RotY */
1905 : double dfDatumParm2; /* RotZ */
1906 : double dfDatumParm3; /* Scale Factor */
1907 : double dfDatumParm4; /* Prime Meridian */
1908 : } MapInfoDatumInfo;
1909 :
1910 : typedef struct
1911 : {
1912 : int nMapInfoId;
1913 : const char *pszMapinfoName;
1914 : double dfA; /* semi major axis in meters */
1915 : double dfInvFlattening; /* Inverse flattening */
1916 : } MapInfoSpheroidInfo;
1917 :
1918 :
1919 : /*---------------------------------------------------------------------
1920 : * The following are used for coordsys bounds lookup
1921 : *--------------------------------------------------------------------*/
1922 : typedef struct
1923 : {
1924 : TABProjInfo sProj; /* Projection/datum definition */
1925 : double dXMin; /* Default bounds for that coordsys */
1926 : double dYMin;
1927 : double dXMax;
1928 : double dYMax;
1929 : } MapInfoBoundsInfo;
1930 :
1931 : GBool MITABLookupCoordSysBounds(TABProjInfo *psCS,
1932 : double &dXMin, double &dYMin,
1933 : double &dXMax, double &dYMax);
1934 : int MITABLoadCoordSysTable(const char *pszFname);
1935 : void MITABFreeCoordSysTable();
1936 : GBool MITABCoordSysTableLoaded();
1937 :
1938 : #endif /* _MITAB_H_INCLUDED_ */
1939 :
1940 :
|