Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: OpenGIS Simple Features Reference Implementation
4 : * Purpose: Implements Open FileGDB OGR driver.
5 : * Author: Even Rouault, <even dot rouault at spatialys.com>
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2021, Even Rouault <even dot rouault at spatialys.com>
9 : *
10 : * Permission is hereby granted, free of charge, to any person obtaining a
11 : * copy of this software and associated documentation files (the "Software"),
12 : * to deal in the Software without restriction, including without limitation
13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 : * and/or sell copies of the Software, and to permit persons to whom the
15 : * Software is furnished to do so, subject to the following conditions:
16 : *
17 : * The above copyright notice and this permission notice shall be included
18 : * in all copies or substantial portions of the Software.
19 : *
20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 : * DEALINGS IN THE SOFTWARE.
27 : ****************************************************************************/
28 :
29 : #ifndef FILEGDB_GDBTOOGRFIELDTYPE_H
30 : #define FILEGDB_GDBTOOGRFIELDTYPE_H
31 :
32 : #include <string>
33 : #include "ogr_api.h"
34 :
35 : /*************************************************************************/
36 : /* GDBToOGRFieldType() */
37 : /*************************************************************************/
38 :
39 : // We could make this function far more robust by doing automatic coercion of
40 : // types, and/or skipping fields we do not know. But, for our purposes. this
41 : // works fine.
42 4144 : static bool GDBToOGRFieldType(const std::string &gdbType, OGRFieldType *pOut,
43 : OGRFieldSubType *pSubType)
44 : {
45 : /*
46 : ESRI types
47 : esriFieldTypeSmallInteger = 0,
48 : esriFieldTypeInteger = 1,
49 : esriFieldTypeSingle = 2,
50 : esriFieldTypeDouble = 3,
51 : esriFieldTypeString = 4,
52 : esriFieldTypeDate = 5,
53 : esriFieldTypeOID = 6,
54 : esriFieldTypeGeometry = 7,
55 : esriFieldTypeBlob = 8,
56 : esriFieldTypeRaster = 9,
57 : esriFieldTypeGUID = 10,
58 : esriFieldTypeGlobalID = 11,
59 : esriFieldTypeXML = 12
60 : */
61 :
62 : // OGR Types
63 :
64 : // Desc Name GDB->OGR Mapped By
65 : // Us?
66 : /** Simple 32bit integer */ // OFTInteger = 0, YES
67 : /** List of 32bit integers */ // OFTIntegerList = 1, NO
68 : /** Double Precision floating point */ // OFTReal = 2, YES
69 : /** List of doubles */ // OFTRealList = 3, NO
70 : /** String of ASCII chars */ // OFTString = 4, YES
71 : /** Array of strings */ // OFTStringList = 5, NO
72 : /** deprecated */ // OFTWideString = 6, NO
73 : /** deprecated */ // OFTWideStringList = 7, NO
74 : /** Raw Binary data */ // OFTBinary = 8, YES
75 : /** Date */ // OFTDate = 9, NO
76 : /** Time */ // OFTTime = 10, NO
77 : /** Date and Time */ // OFTDateTime = 11 YES
78 :
79 4144 : *pSubType = OFSTNone;
80 4144 : if (gdbType == "esriFieldTypeSmallInteger")
81 : {
82 527 : *pSubType = OFSTInt16;
83 527 : *pOut = OFTInteger;
84 527 : return true;
85 : }
86 3617 : else if (gdbType == "esriFieldTypeInteger")
87 : {
88 432 : *pOut = OFTInteger;
89 432 : return true;
90 : }
91 3185 : else if (gdbType == "esriFieldTypeSingle")
92 : {
93 478 : *pSubType = OFSTFloat32;
94 478 : *pOut = OFTReal;
95 478 : return true;
96 : }
97 2707 : else if (gdbType == "esriFieldTypeDouble")
98 : {
99 261 : *pOut = OFTReal;
100 261 : return true;
101 : }
102 4599 : else if (gdbType == "esriFieldTypeGUID" ||
103 4299 : gdbType == "esriFieldTypeGlobalID" ||
104 6745 : gdbType == "esriFieldTypeXML" || gdbType == "esriFieldTypeString")
105 : {
106 1865 : *pOut = OFTString;
107 1865 : return true;
108 : }
109 581 : else if (gdbType == "esriFieldTypeDate")
110 : {
111 202 : *pOut = OFTDateTime;
112 202 : return true;
113 : }
114 379 : else if (gdbType == "esriFieldTypeBlob")
115 : {
116 379 : *pOut = OFTBinary;
117 379 : return true;
118 : }
119 : else
120 : {
121 : /* Intentionally fail at these
122 : esriFieldTypeOID
123 : esriFieldTypeGeometry
124 : esriFieldTypeRaster
125 : */
126 0 : CPLError(CE_Warning, CPLE_AppDefined, "%s",
127 0 : ("Cannot map field " + gdbType).c_str());
128 :
129 0 : return false;
130 : }
131 : }
132 :
133 : #endif // FILEGDB_GDBTOOGRFIELDTYPE_H
|