GDAL
ogr_p.h
1 /******************************************************************************
2  * $Id$
3  *
4  * Project: OpenGIS Simple Features Reference Implementation
5  * Purpose: Some private helper functions and stuff for OGR implementation.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 1999, Frank Warmerdam
10  * Copyright (c) 2008-2014, Even Rouault <even dot rouault at spatialys.com>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #ifndef OGR_P_H_INCLUDED
32 #define OGR_P_H_INCLUDED
33 
34 /* -------------------------------------------------------------------- */
35 /* Include the common portability library ... lets us do lots */
36 /* of stuff easily. */
37 /* -------------------------------------------------------------------- */
38 
39 #include "cpl_string.h"
40 #include "cpl_conv.h"
41 #include "cpl_minixml.h"
42 
43 #include "ogr_core.h"
44 
45 class OGRGeometry;
46 class OGRFieldDefn;
47 
48 /* A default name for the default geometry column, instead of '' */
49 #define OGR_GEOMETRY_DEFAULT_NON_EMPTY_NAME "_ogr_geometry_"
50 
51 #ifdef CPL_MSB
52 #define OGR_SWAP(x) (x == wkbNDR)
53 #else
54 #define OGR_SWAP(x) (x == wkbXDR)
55 #endif
56 
57 /* PostGIS 1.X has non standard codes for the following geometry types */
58 #define POSTGIS15_CURVEPOLYGON 13 /* instead of 10 */
59 #define POSTGIS15_MULTICURVE 14 /* instead of 11 */
60 #define POSTGIS15_MULTISURFACE 15 /* instead of 12 */
61 
62 /* Has been deprecated. Can only be used in very specific circumstances */
63 #ifdef GDAL_COMPILATION
64 #define wkb25DBitInternalUse 0x80000000
65 #endif
66 
67 /* -------------------------------------------------------------------- */
68 /* helper function for parsing well known text format vector objects.*/
69 /* -------------------------------------------------------------------- */
70 
71 #ifdef OGR_GEOMETRY_H_INCLUDED
72 #define OGR_WKT_TOKEN_MAX 64
73 
74 const char CPL_DLL *OGRWktReadToken(const char *pszInput, char *pszToken);
75 
76 const char CPL_DLL *OGRWktReadPoints(const char *pszInput,
77  OGRRawPoint **ppaoPoints, double **ppadfZ,
78  int *pnMaxPoints, int *pnReadPoints);
79 
80 const char CPL_DLL *
81 OGRWktReadPointsM(const char *pszInput, OGRRawPoint **ppaoPoints,
82  double **ppadfZ, double **ppadfM,
83  int *flags, /* geometry flags, are we expecting Z, M, or both;
84  may change due to input */
85  int *pnMaxPoints, int *pnReadPoints);
86 
87 void CPL_DLL OGRMakeWktCoordinate(char *, double, double, double, int);
88 std::string CPL_DLL OGRMakeWktCoordinate(double, double, double, int,
89  OGRWktOptions opts);
90 void CPL_DLL OGRMakeWktCoordinateM(char *, double, double, double, double,
92 std::string CPL_DLL OGRMakeWktCoordinateM(double, double, double, double,
94  OGRWktOptions opts);
95 
96 #endif
97 
98 void CPL_DLL OGRFormatDouble(char *pszBuffer, int nBufferLen, double dfVal,
99  char chDecimalSep, int nPrecision = 15,
100  char chConversionSpecifier = 'f');
101 
102 #ifdef OGR_GEOMETRY_H_INCLUDED
103 std::string CPL_DLL OGRFormatDouble(double val, const OGRWktOptions &opts);
104 #endif
105 
106 int OGRFormatFloat(char *pszBuffer, int nBufferLen, float fVal, int nPrecision,
107  char chConversionSpecifier);
108 
109 /* -------------------------------------------------------------------- */
110 /* Date-time parsing and processing functions */
111 /* -------------------------------------------------------------------- */
112 
113 /* Internal use by OGR drivers only, CPL_DLL is just there in case */
114 /* they are compiled as plugins */
115 
116 int CPL_DLL OGRTimezoneToTZFlag(const char *pszTZ,
117  bool bEmitErrorIfUnhandledFormat);
118 std::string CPL_DLL OGRTZFlagToTimezone(int nTZFlag,
119  const char *pszUTCRepresentation);
120 
121 int CPL_DLL OGRGetDayOfWeek(int day, int month, int year);
122 int CPL_DLL OGRParseXMLDateTime(const char *pszXMLDateTime, OGRField *psField);
123 int CPL_DLL OGRParseRFC822DateTime(const char *pszRFC822DateTime,
124  OGRField *psField);
125 char CPL_DLL *OGRGetRFC822DateTime(const OGRField *psField);
126 char CPL_DLL *OGRGetXMLDateTime(const OGRField *psField);
127 char CPL_DLL *OGRGetXMLDateTime(const OGRField *psField,
128  bool bAlwaysMillisecond);
129 // 30 = strlen("YYYY-MM-DDThh:mm:ss.sss+hh:mm") + 1
130 #define OGR_SIZEOF_ISO8601_DATETIME_BUFFER 30
131 int CPL_DLL
132 OGRGetISO8601DateTime(const OGRField *psField, bool bAlwaysMillisecond,
133  char szBuffer[OGR_SIZEOF_ISO8601_DATETIME_BUFFER]);
134 
136 enum class OGRISO8601Precision
137 {
139  AUTO,
141  MILLISECOND,
143  SECOND,
145  MINUTE
146 };
147 
150 {
152  OGRISO8601Precision ePrecision;
153 };
154 
155 int CPL_DLL
156 OGRGetISO8601DateTime(const OGRField *psField, const OGRISO8601Format &sFormat,
157  char szBuffer[OGR_SIZEOF_ISO8601_DATETIME_BUFFER]);
158 char CPL_DLL *OGRGetXML_UTF8_EscapedString(const char *pszString);
159 bool CPL_DLL OGRParseDateTimeYYYYMMDDTHHMMZ(const char *pszInput, size_t nLen,
160  OGRField *psField);
161 bool CPL_DLL OGRParseDateTimeYYYYMMDDTHHMMSSZ(const char *pszInput, size_t nLen,
162  OGRField *psField);
163 bool CPL_DLL OGRParseDateTimeYYYYMMDDTHHMMSSsssZ(const char *pszInput,
164  size_t nLen,
165  OGRField *psField);
166 
167 int OGRCompareDate(const OGRField *psFirstTuple,
168  const OGRField *psSecondTuple); /* used by ogr_gensql.cpp and
169  ogrfeaturequery.cpp */
170 
171 /* General utility option processing. */
172 int CPL_DLL OGRGeneralCmdLineProcessor(int nArgc, char ***ppapszArgv,
173  int nOptions);
174 
175 /************************************************************************/
176 /* Support for special attributes (feature query and selection) */
177 /************************************************************************/
178 #define SPF_FID 0
179 #define SPF_OGR_GEOMETRY 1
180 #define SPF_OGR_STYLE 2
181 #define SPF_OGR_GEOM_WKT 3
182 #define SPF_OGR_GEOM_AREA 4
183 #define SPECIAL_FIELD_COUNT 5
184 
185 extern const char *const SpecialFieldNames[SPECIAL_FIELD_COUNT];
186 
187 #ifdef SWQ_H_INCLUDED_
188 extern const swq_field_type SpecialFieldTypes[SPECIAL_FIELD_COUNT];
189 #endif
190 
191 /************************************************************************/
192 /* Some SRS related stuff, search in SRS data files. */
193 /************************************************************************/
194 
195 OGRErr CPL_DLL OSRGetEllipsoidInfo(int, char **, double *, double *);
196 
197 /* Fast atof function */
198 double OGRFastAtof(const char *pszStr);
199 
200 OGRErr CPL_DLL OGRCheckPermutation(const int *panPermutation, int nSize);
201 
202 /* GML related */
203 
204 OGRGeometry *GML2OGRGeometry_XMLNode(const CPLXMLNode *psNode,
205  int nPseudoBoolGetSecondaryGeometryOption,
206  int nRecLevel = 0, int nSRSDimension = 0,
207  bool bIgnoreGSG = false,
208  bool bOrientation = true,
209  bool bFaceHoleNegative = false);
210 
211 /************************************************************************/
212 /* PostGIS EWKB encoding */
213 /************************************************************************/
214 
215 OGRGeometry CPL_DLL *OGRGeometryFromEWKB(GByte *pabyWKB, int nLength,
216  int *pnSRID, int bIsPostGIS1_EWKB);
217 OGRGeometry CPL_DLL *OGRGeometryFromHexEWKB(const char *pszBytea, int *pnSRID,
218  int bIsPostGIS1_EWKB);
219 char CPL_DLL *OGRGeometryToHexEWKB(OGRGeometry *poGeometry, int nSRSId,
220  int nPostGISMajor, int nPostGISMinor);
221 
222 /************************************************************************/
223 /* WKB Type Handling encoding */
224 /************************************************************************/
225 
226 OGRErr CPL_DLL OGRReadWKBGeometryType(const unsigned char *pabyData,
227  OGRwkbVariant wkbVariant,
228  OGRwkbGeometryType *eGeometryType);
229 
230 /************************************************************************/
231 /* WKT Type Handling encoding */
232 /************************************************************************/
233 
234 OGRErr CPL_DLL OGRReadWKTGeometryType(const char *pszWKT,
235  OGRwkbGeometryType *peGeometryType);
236 
237 /************************************************************************/
238 /* Other */
239 /************************************************************************/
240 
241 void CPL_DLL OGRUpdateFieldType(OGRFieldDefn *poFDefn, OGRFieldType eNewType,
242  OGRFieldSubType eNewSubType);
243 
244 #endif /* ndef OGR_P_H_INCLUDED */
GByte
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:196
cpl_minixml.h
OGRGeometry
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:334
OGRISO8601Format::ePrecision
OGRISO8601Precision ePrecision
Precision of formatting.
Definition: ogr_p.h:152
CPLXMLNode
Document node structure.
Definition: cpl_minixml.h:69
OGRBoolean
int OGRBoolean
Type for a OGR boolean.
Definition: ogr_core.h:395
OGRRawPoint
Simple container for a position.
Definition: ogr_geometry.h:104
OGRISO8601Format
Configuration of the ISO8601 formatting output.
Definition: ogr_p.h:149
OGRField
OGRFeature field attribute value union.
Definition: ogr_core.h:900
OGRFieldDefn
Definition of an attribute of an OGRFeatureDefn.
Definition: ogr_feature.h:103
cpl_conv.h
cpl_string.h
OGRErr
int OGRErr
Type for a OGR error.
Definition: ogr_core.h:378
OGRwkbGeometryType
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:406
OGRFieldSubType
OGRFieldSubType
List of field subtypes.
Definition: ogr_core.h:811
OGRFieldType
OGRFieldType
List of feature field types.
Definition: ogr_core.h:783
OGRWktOptions
Options for formatting WKT output.
Definition: ogr_geometry.h:69
ogr_core.h
OGRwkbVariant
OGRwkbVariant
Output variants of WKB we support.
Definition: ogr_core.h:540