1 : /******************************************************************************
2 : * $Id: ogr_core.h 22448 2011-05-28 18:49:54Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Define some core portability services for cross-platform OGR code.
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 OGR_CORE_H_INCLUDED
31 : #define OGR_CORE_H_INCLUDED
32 :
33 : #include "cpl_port.h"
34 : #include "gdal_version.h"
35 :
36 : /**
37 : * \file
38 : *
39 : * Core portability services for cross-platform OGR code.
40 : */
41 :
42 : /**
43 : * Simple container for a bounding region.
44 : */
45 :
46 : #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
47 : class CPL_DLL OGREnvelope
48 : {
49 : public:
50 161546 : OGREnvelope() : MinX(0.0), MaxX(0.0), MinY(0.0), MaxY(0.0)
51 : {
52 161546 : }
53 : double MinX;
54 : double MaxX;
55 : double MinY;
56 : double MaxY;
57 :
58 : int IsInit() const { return MinX != 0 || MinY != 0 || MaxX != 0 || MaxY != 0; }
59 : void Merge( OGREnvelope const& sOther ) {
60 : if( IsInit() )
61 : {
62 : MinX = MIN(MinX,sOther.MinX);
63 : MaxX = MAX(MaxX,sOther.MaxX);
64 : MinY = MIN(MinY,sOther.MinY);
65 : MaxY = MAX(MaxY,sOther.MaxY);
66 : }
67 : else
68 : {
69 : MinX = sOther.MinX;
70 : MaxX = sOther.MaxX;
71 : MinY = sOther.MinY;
72 : MaxY = sOther.MaxY;
73 : }
74 : }
75 : void Merge( double dfX, double dfY ) {
76 : if( IsInit() )
77 : {
78 : MinX = MIN(MinX,dfX);
79 : MaxX = MAX(MaxX,dfX);
80 : MinY = MIN(MinY,dfY);
81 : MaxY = MAX(MaxY,dfY);
82 : }
83 : else
84 : {
85 : MinX = MaxX = dfX;
86 : MinY = MaxY = dfY;
87 : }
88 : }
89 :
90 : void Intersect( OGREnvelope const& sOther ) {
91 : if(Intersects(sOther))
92 : {
93 : if( IsInit() )
94 : {
95 : MinX = MAX(MinX,sOther.MinX);
96 : MaxX = MIN(MaxX,sOther.MaxX);
97 : MinY = MAX(MinY,sOther.MinY);
98 : MaxY = MIN(MaxY,sOther.MaxY);
99 : }
100 : else
101 : {
102 : MinX = sOther.MinX;
103 : MaxX = sOther.MaxX;
104 : MinY = sOther.MinY;
105 : MaxY = sOther.MaxY;
106 : }
107 : }
108 : else
109 : {
110 : MinX = 0;
111 : MaxX = 0;
112 : MinY = 0;
113 : MaxY = 0;
114 : }
115 : }
116 :
117 0 : int Intersects(OGREnvelope const& other) const
118 : {
119 : return MinX <= other.MaxX && MaxX >= other.MinX &&
120 0 : MinY <= other.MaxY && MaxY >= other.MinY;
121 : }
122 :
123 429 : int Contains(OGREnvelope const& other) const
124 : {
125 : return MinX <= other.MinX && MinY <= other.MinY &&
126 429 : MaxX >= other.MaxX && MaxY >= other.MaxY;
127 : }
128 : };
129 : #else
130 : typedef struct
131 : {
132 : double MinX;
133 : double MaxX;
134 : double MinY;
135 : double MaxY;
136 : } OGREnvelope;
137 : #endif
138 :
139 :
140 : /**
141 : * Simple container for a bounding region in 3D.
142 : */
143 :
144 : #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
145 : class CPL_DLL OGREnvelope3D : public OGREnvelope
146 : {
147 : public:
148 470 : OGREnvelope3D() : OGREnvelope(), MinZ(0.0), MaxZ(0.0)
149 : {
150 470 : }
151 :
152 : double MinZ;
153 : double MaxZ;
154 :
155 : int IsInit() const { return MinX != 0 || MinY != 0 || MaxX != 0 || MaxY != 0 || MinZ != 0 || MaxZ != 0; }
156 : void Merge( OGREnvelope3D const& sOther ) {
157 : if( IsInit() )
158 : {
159 : MinX = MIN(MinX,sOther.MinX);
160 : MaxX = MAX(MaxX,sOther.MaxX);
161 : MinY = MIN(MinY,sOther.MinY);
162 : MaxY = MAX(MaxY,sOther.MaxY);
163 : MinZ = MIN(MinZ,sOther.MinZ);
164 : MaxZ = MAX(MaxZ,sOther.MaxZ);
165 : }
166 : else
167 : {
168 : MinX = sOther.MinX;
169 : MaxX = sOther.MaxX;
170 : MinY = sOther.MinY;
171 : MaxY = sOther.MaxY;
172 : MinZ = sOther.MinZ;
173 : MaxZ = sOther.MaxZ;
174 : }
175 : }
176 : void Merge( double dfX, double dfY, double dfZ ) {
177 : if( IsInit() )
178 : {
179 : MinX = MIN(MinX,dfX);
180 : MaxX = MAX(MaxX,dfX);
181 : MinY = MIN(MinY,dfY);
182 : MaxY = MAX(MaxY,dfY);
183 : MinZ = MIN(MinZ,dfZ);
184 : MaxZ = MAX(MaxZ,dfZ);
185 : }
186 : else
187 : {
188 : MinX = MaxX = dfX;
189 : MinY = MaxY = dfY;
190 : MinZ = MaxZ = dfZ;
191 : }
192 : }
193 :
194 : void Intersect( OGREnvelope3D const& sOther ) {
195 : if(Intersects(sOther))
196 : {
197 : if( IsInit() )
198 : {
199 : MinX = MAX(MinX,sOther.MinX);
200 : MaxX = MIN(MaxX,sOther.MaxX);
201 : MinY = MAX(MinY,sOther.MinY);
202 : MaxY = MIN(MaxY,sOther.MaxY);
203 : MinZ = MAX(MinZ,sOther.MinZ);
204 : MaxZ = MIN(MaxZ,sOther.MaxZ);
205 : }
206 : else
207 : {
208 : MinX = sOther.MinX;
209 : MaxX = sOther.MaxX;
210 : MinY = sOther.MinY;
211 : MaxY = sOther.MaxY;
212 : MinZ = sOther.MinZ;
213 : MaxZ = sOther.MaxZ;
214 : }
215 : }
216 : else
217 : {
218 : MinX = 0;
219 : MaxX = 0;
220 : MinY = 0;
221 : MaxY = 0;
222 : MinZ = 0;
223 : MaxZ = 0;
224 : }
225 : }
226 :
227 : int Intersects(OGREnvelope3D const& other) const
228 : {
229 : return MinX <= other.MaxX && MaxX >= other.MinX &&
230 : MinY <= other.MaxY && MaxY >= other.MinY &&
231 : MinZ <= other.MaxZ && MaxZ >= other.MinZ;
232 : }
233 :
234 : int Contains(OGREnvelope3D const& other) const
235 : {
236 : return MinX <= other.MinX && MinY <= other.MinY &&
237 : MaxX >= other.MaxX && MaxY >= other.MaxY &&
238 : MaxZ >= other.MaxZ && MaxZ >= other.MaxZ;
239 : }
240 : };
241 : #else
242 : typedef struct
243 : {
244 : double MinX;
245 : double MaxX;
246 : double MinY;
247 : double MaxY;
248 : double MinZ;
249 : double MaxZ;
250 : } OGREnvelope3D;
251 : #endif
252 :
253 :
254 : CPL_C_START
255 :
256 : void CPL_DLL *OGRMalloc( size_t );
257 : void CPL_DLL *OGRCalloc( size_t, size_t );
258 : void CPL_DLL *OGRRealloc( void *, size_t );
259 : char CPL_DLL *OGRStrdup( const char * );
260 : void CPL_DLL OGRFree( void * );
261 :
262 : typedef int OGRErr;
263 :
264 : #define OGRERR_NONE 0
265 : #define OGRERR_NOT_ENOUGH_DATA 1 /* not enough data to deserialize */
266 : #define OGRERR_NOT_ENOUGH_MEMORY 2
267 : #define OGRERR_UNSUPPORTED_GEOMETRY_TYPE 3
268 : #define OGRERR_UNSUPPORTED_OPERATION 4
269 : #define OGRERR_CORRUPT_DATA 5
270 : #define OGRERR_FAILURE 6
271 : #define OGRERR_UNSUPPORTED_SRS 7
272 : #define OGRERR_INVALID_HANDLE 8
273 :
274 : typedef int OGRBoolean;
275 :
276 : /* -------------------------------------------------------------------- */
277 : /* ogr_geometry.h related definitions. */
278 : /* -------------------------------------------------------------------- */
279 : /**
280 : * List of well known binary geometry types. These are used within the BLOBs
281 : * but are also returned from OGRGeometry::getGeometryType() to identify the
282 : * type of a geometry object.
283 : */
284 :
285 : typedef enum
286 : {
287 : wkbUnknown = 0, /**< unknown type, non-standard */
288 : wkbPoint = 1, /**< 0-dimensional geometric object, standard WKB */
289 : wkbLineString = 2, /**< 1-dimensional geometric object with linear
290 : * interpolation between Points, standard WKB */
291 : wkbPolygon = 3, /**< planar 2-dimensional geometric object defined
292 : * by 1 exterior boundary and 0 or more interior
293 : * boundaries, standard WKB */
294 : wkbMultiPoint = 4, /**< GeometryCollection of Points, standard WKB */
295 : wkbMultiLineString = 5, /**< GeometryCollection of LineStrings, standard WKB */
296 : wkbMultiPolygon = 6, /**< GeometryCollection of Polygons, standard WKB */
297 : wkbGeometryCollection = 7, /**< geometric object that is a collection of 1
298 : or more geometric objects, standard WKB */
299 : wkbNone = 100, /**< non-standard, for pure attribute records */
300 : wkbLinearRing = 101, /**< non-standard, just for createGeometry() */
301 : wkbPoint25D = 0x80000001, /**< 2.5D extension as per 99-402 */
302 : wkbLineString25D = 0x80000002, /**< 2.5D extension as per 99-402 */
303 : wkbPolygon25D = 0x80000003, /**< 2.5D extension as per 99-402 */
304 : wkbMultiPoint25D = 0x80000004, /**< 2.5D extension as per 99-402 */
305 : wkbMultiLineString25D = 0x80000005, /**< 2.5D extension as per 99-402 */
306 : wkbMultiPolygon25D = 0x80000006, /**< 2.5D extension as per 99-402 */
307 : wkbGeometryCollection25D = 0x80000007 /**< 2.5D extension as per 99-402 */
308 : } OGRwkbGeometryType;
309 :
310 : #define wkb25DBit 0x80000000
311 : #define wkbFlatten(x) ((OGRwkbGeometryType) ((x) & (~wkb25DBit)))
312 :
313 : #define ogrZMarker 0x21125711
314 :
315 : const char CPL_DLL * OGRGeometryTypeToName( OGRwkbGeometryType eType );
316 : OGRwkbGeometryType CPL_DLL OGRMergeGeometryTypes( OGRwkbGeometryType eMain,
317 : OGRwkbGeometryType eExtra );
318 :
319 : typedef enum
320 : {
321 : wkbXDR = 0, /* MSB/Sun/Motoroloa: Most Significant Byte First */
322 : wkbNDR = 1 /* LSB/Intel/Vax: Least Significant Byte First */
323 : } OGRwkbByteOrder;
324 :
325 : #ifndef NO_HACK_FOR_IBM_DB2_V72
326 : # define HACK_FOR_IBM_DB2_V72
327 : #endif
328 :
329 : #ifdef HACK_FOR_IBM_DB2_V72
330 : # define DB2_V72_FIX_BYTE_ORDER(x) ((((x) & 0x31) == (x)) ? (OGRwkbByteOrder) ((x) & 0x1) : (x))
331 : # define DB2_V72_UNFIX_BYTE_ORDER(x) ((unsigned char) (OGRGeometry::bGenerate_DB2_V72_BYTE_ORDER ? ((x) | 0x30) : (x)))
332 : #else
333 : # define DB2_V72_FIX_BYTE_ORDER(x) (x)
334 : # define DB2_V72_UNFIX_BYTE_ORDER(x) (x)
335 : #endif
336 :
337 : #define ALTER_NAME_FLAG 0x1
338 : #define ALTER_TYPE_FLAG 0x2
339 : #define ALTER_WIDTH_PRECISION_FLAG 0x4
340 : #define ALTER_ALL_FLAG (ALTER_NAME_FLAG | ALTER_TYPE_FLAG | ALTER_WIDTH_PRECISION_FLAG)
341 :
342 : /************************************************************************/
343 : /* ogr_feature.h related definitions. */
344 : /************************************************************************/
345 :
346 : /**
347 : * List of feature field types. This list is likely to be extended in the
348 : * future ... avoid coding applications based on the assumption that all
349 : * field types can be known.
350 : */
351 :
352 : typedef enum
353 : {
354 : /** Simple 32bit integer */ OFTInteger = 0,
355 : /** List of 32bit integers */ OFTIntegerList = 1,
356 : /** Double Precision floating point */ OFTReal = 2,
357 : /** List of doubles */ OFTRealList = 3,
358 : /** String of ASCII chars */ OFTString = 4,
359 : /** Array of strings */ OFTStringList = 5,
360 : /** deprecated */ OFTWideString = 6,
361 : /** deprecated */ OFTWideStringList = 7,
362 : /** Raw Binary data */ OFTBinary = 8,
363 : /** Date */ OFTDate = 9,
364 : /** Time */ OFTTime = 10,
365 : /** Date and Time */ OFTDateTime = 11,
366 : OFTMaxType = 11
367 : } OGRFieldType;
368 :
369 : /**
370 : * Display justification for field values.
371 : */
372 :
373 : typedef enum
374 : {
375 : OJUndefined = 0,
376 : OJLeft = 1,
377 : OJRight = 2
378 : } OGRJustification;
379 :
380 : #define OGRNullFID -1
381 : #define OGRUnsetMarker -21121
382 :
383 : /************************************************************************/
384 : /* OGRField */
385 : /************************************************************************/
386 :
387 : /**
388 : * OGRFeature field attribute value union.
389 : */
390 :
391 : typedef union {
392 : int Integer;
393 : double Real;
394 : char *String;
395 :
396 : struct {
397 : int nCount;
398 : int *paList;
399 : } IntegerList;
400 :
401 : struct {
402 : int nCount;
403 : double *paList;
404 : } RealList;
405 :
406 : struct {
407 : int nCount;
408 : char **paList;
409 : } StringList;
410 :
411 : struct {
412 : int nCount;
413 : GByte *paData;
414 : } Binary;
415 :
416 : struct {
417 : int nMarker1;
418 : int nMarker2;
419 : } Set;
420 :
421 : struct {
422 : GInt16 Year;
423 : GByte Month;
424 : GByte Day;
425 : GByte Hour;
426 : GByte Minute;
427 : GByte Second;
428 : GByte TZFlag; /* 0=unknown, 1=localtime(ambiguous),
429 : 100=GMT, 104=GMT+1, 80=GMT-5, etc */
430 : } Date;
431 : } OGRField;
432 :
433 : int CPL_DLL OGRParseDate( const char *pszInput, OGRField *psOutput,
434 : int nOptions );
435 :
436 : /* -------------------------------------------------------------------- */
437 : /* Constants from ogrsf_frmts.h for capabilities. */
438 : /* -------------------------------------------------------------------- */
439 : #define OLCRandomRead "RandomRead"
440 : #define OLCSequentialWrite "SequentialWrite"
441 : #define OLCRandomWrite "RandomWrite"
442 : #define OLCFastSpatialFilter "FastSpatialFilter"
443 : #define OLCFastFeatureCount "FastFeatureCount"
444 : #define OLCFastGetExtent "FastGetExtent"
445 : #define OLCCreateField "CreateField"
446 : #define OLCDeleteField "DeleteField"
447 : #define OLCReorderFields "ReorderFields"
448 : #define OLCAlterFieldDefn "AlterFieldDefn"
449 : #define OLCTransactions "Transactions"
450 : #define OLCDeleteFeature "DeleteFeature"
451 : #define OLCFastSetNextByIndex "FastSetNextByIndex"
452 : #define OLCStringsAsUTF8 "StringsAsUTF8"
453 : #define OLCIgnoreFields "IgnoreFields"
454 :
455 : #define ODsCCreateLayer "CreateLayer"
456 : #define ODsCDeleteLayer "DeleteLayer"
457 :
458 : #define ODrCCreateDataSource "CreateDataSource"
459 : #define ODrCDeleteDataSource "DeleteDataSource"
460 :
461 :
462 : /************************************************************************/
463 : /* ogr_featurestyle.h related definitions. */
464 : /************************************************************************/
465 :
466 : /**
467 : * OGRStyleTool derived class types (returned by GetType()).
468 : */
469 :
470 : typedef enum ogr_style_tool_class_id
471 : {
472 : OGRSTCNone = 0,
473 : OGRSTCPen = 1,
474 : OGRSTCBrush = 2,
475 : OGRSTCSymbol = 3,
476 : OGRSTCLabel = 4,
477 : OGRSTCVector = 5
478 : } OGRSTClassId;
479 :
480 : /**
481 : * List of units supported by OGRStyleTools.
482 : */
483 : typedef enum ogr_style_tool_units_id
484 : {
485 : OGRSTUGround = 0,
486 : OGRSTUPixel = 1,
487 : OGRSTUPoints = 2,
488 : OGRSTUMM = 3,
489 : OGRSTUCM = 4,
490 : OGRSTUInches = 5
491 : } OGRSTUnitId;
492 :
493 : /**
494 : * List of parameters for use with OGRStylePen.
495 : */
496 : typedef enum ogr_style_tool_param_pen_id
497 : {
498 : OGRSTPenColor = 0,
499 : OGRSTPenWidth = 1,
500 : OGRSTPenPattern = 2,
501 : OGRSTPenId = 3,
502 : OGRSTPenPerOffset = 4,
503 : OGRSTPenCap = 5,
504 : OGRSTPenJoin = 6,
505 : OGRSTPenPriority = 7,
506 : OGRSTPenLast = 8
507 :
508 : } OGRSTPenParam;
509 :
510 : /**
511 : * List of parameters for use with OGRStyleBrush.
512 : */
513 : typedef enum ogr_style_tool_param_brush_id
514 : {
515 : OGRSTBrushFColor = 0,
516 : OGRSTBrushBColor = 1,
517 : OGRSTBrushId = 2,
518 : OGRSTBrushAngle = 3,
519 : OGRSTBrushSize = 4,
520 : OGRSTBrushDx = 5,
521 : OGRSTBrushDy = 6,
522 : OGRSTBrushPriority = 7,
523 : OGRSTBrushLast = 8
524 :
525 : } OGRSTBrushParam;
526 :
527 :
528 : /**
529 : * List of parameters for use with OGRStyleSymbol.
530 : */
531 : typedef enum ogr_style_tool_param_symbol_id
532 : {
533 : OGRSTSymbolId = 0,
534 : OGRSTSymbolAngle = 1,
535 : OGRSTSymbolColor = 2,
536 : OGRSTSymbolSize = 3,
537 : OGRSTSymbolDx = 4,
538 : OGRSTSymbolDy = 5,
539 : OGRSTSymbolStep = 6,
540 : OGRSTSymbolPerp = 7,
541 : OGRSTSymbolOffset = 8,
542 : OGRSTSymbolPriority = 9,
543 : OGRSTSymbolFontName = 10,
544 : OGRSTSymbolOColor = 11,
545 : OGRSTSymbolLast = 12
546 :
547 : } OGRSTSymbolParam;
548 :
549 : /**
550 : * List of parameters for use with OGRStyleLabel.
551 : */
552 : typedef enum ogr_style_tool_param_label_id
553 : {
554 : OGRSTLabelFontName = 0,
555 : OGRSTLabelSize = 1,
556 : OGRSTLabelTextString = 2,
557 : OGRSTLabelAngle = 3,
558 : OGRSTLabelFColor = 4,
559 : OGRSTLabelBColor = 5,
560 : OGRSTLabelPlacement = 6,
561 : OGRSTLabelAnchor = 7,
562 : OGRSTLabelDx = 8,
563 : OGRSTLabelDy = 9,
564 : OGRSTLabelPerp = 10,
565 : OGRSTLabelBold = 11,
566 : OGRSTLabelItalic = 12,
567 : OGRSTLabelUnderline = 13,
568 : OGRSTLabelPriority = 14,
569 : OGRSTLabelStrikeout = 15,
570 : OGRSTLabelStretch = 16,
571 : OGRSTLabelAdjHor = 17,
572 : OGRSTLabelAdjVert = 18,
573 : OGRSTLabelHColor = 19,
574 : OGRSTLabelOColor = 20,
575 : OGRSTLabelLast = 21
576 :
577 : } OGRSTLabelParam;
578 :
579 : /* ------------------------------------------------------------------- */
580 : /* Version checking */
581 : /* -------------------------------------------------------------------- */
582 :
583 : /* Note to developers : please keep this section in sync with gdal.h */
584 :
585 : #ifndef GDAL_VERSION_INFO_DEFINED
586 : #define GDAL_VERSION_INFO_DEFINED
587 : const char CPL_DLL * CPL_STDCALL GDALVersionInfo( const char * );
588 : #endif
589 :
590 : #ifndef GDAL_CHECK_VERSION
591 :
592 : /** Return TRUE if GDAL library version at runtime matches nVersionMajor.nVersionMinor.
593 :
594 : The purpose of this method is to ensure that calling code will run with the GDAL
595 : version it is compiled for. It is primarly intented for external plugins.
596 :
597 : @param nVersionMajor Major version to be tested against
598 : @param nVersionMinor Minor version to be tested against
599 : @param pszCallingComponentName If not NULL, in case of version mismatch, the method
600 : will issue a failure mentionning the name of
601 : the calling component.
602 : */
603 : int CPL_DLL CPL_STDCALL GDALCheckVersion( int nVersionMajor, int nVersionMinor,
604 : const char* pszCallingComponentName);
605 :
606 : /** Helper macro for GDALCheckVersion */
607 : #define GDAL_CHECK_VERSION(pszCallingComponentName) \
608 : GDALCheckVersion(GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR, pszCallingComponentName)
609 :
610 : #endif
611 :
612 : CPL_C_END
613 :
614 : #endif /* ndef OGR_CORE_H_INCLUDED */
|