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 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef FILEGDB_GDBTOOGRFIELDTYPE_H 14 : #define FILEGDB_GDBTOOGRFIELDTYPE_H 15 : 16 : #include <string> 17 : #include "ogr_api.h" 18 : 19 : /*************************************************************************/ 20 : /* GDBToOGRFieldType() */ 21 : /*************************************************************************/ 22 : 23 : // We could make this function far more robust by doing automatic coercion of 24 : // types, and/or skipping fields we do not know. But, for our purposes. this 25 : // works fine. 26 4151 : static bool GDBToOGRFieldType(const std::string &gdbType, OGRFieldType *pOut, 27 : OGRFieldSubType *pSubType) 28 : { 29 : /* 30 : ESRI types 31 : esriFieldTypeSmallInteger = 0, 32 : esriFieldTypeInteger = 1, 33 : esriFieldTypeSingle = 2, 34 : esriFieldTypeDouble = 3, 35 : esriFieldTypeString = 4, 36 : esriFieldTypeDate = 5, 37 : esriFieldTypeOID = 6, 38 : esriFieldTypeGeometry = 7, 39 : esriFieldTypeBlob = 8, 40 : esriFieldTypeRaster = 9, 41 : esriFieldTypeGUID = 10, 42 : esriFieldTypeGlobalID = 11, 43 : esriFieldTypeXML = 12 44 : */ 45 : 46 : // OGR Types 47 : 48 : // Desc Name GDB->OGR Mapped By 49 : // Us? 50 : /** Simple 32bit integer */ // OFTInteger = 0, YES 51 : /** List of 32bit integers */ // OFTIntegerList = 1, NO 52 : /** Double Precision floating point */ // OFTReal = 2, YES 53 : /** List of doubles */ // OFTRealList = 3, NO 54 : /** String of ASCII chars */ // OFTString = 4, YES 55 : /** Array of strings */ // OFTStringList = 5, NO 56 : /** deprecated */ // OFTWideString = 6, NO 57 : /** deprecated */ // OFTWideStringList = 7, NO 58 : /** Raw Binary data */ // OFTBinary = 8, YES 59 : /** Date */ // OFTDate = 9, NO 60 : /** Time */ // OFTTime = 10, NO 61 : /** Date and Time */ // OFTDateTime = 11 YES 62 : 63 4151 : *pSubType = OFSTNone; 64 4151 : if (gdbType == "esriFieldTypeSmallInteger") 65 : { 66 533 : *pSubType = OFSTInt16; 67 533 : *pOut = OFTInteger; 68 533 : return true; 69 : } 70 3618 : else if (gdbType == "esriFieldTypeInteger") 71 : { 72 433 : *pOut = OFTInteger; 73 433 : return true; 74 : } 75 3185 : else if (gdbType == "esriFieldTypeSingle") 76 : { 77 478 : *pSubType = OFSTFloat32; 78 478 : *pOut = OFTReal; 79 478 : return true; 80 : } 81 2707 : else if (gdbType == "esriFieldTypeDouble") 82 : { 83 261 : *pOut = OFTReal; 84 261 : return true; 85 : } 86 4599 : else if (gdbType == "esriFieldTypeGUID" || 87 4299 : gdbType == "esriFieldTypeGlobalID" || 88 6745 : gdbType == "esriFieldTypeXML" || gdbType == "esriFieldTypeString") 89 : { 90 1865 : *pOut = OFTString; 91 1865 : return true; 92 : } 93 581 : else if (gdbType == "esriFieldTypeDate") 94 : { 95 202 : *pOut = OFTDateTime; 96 202 : return true; 97 : } 98 379 : else if (gdbType == "esriFieldTypeBlob") 99 : { 100 379 : *pOut = OFTBinary; 101 379 : return true; 102 : } 103 : else 104 : { 105 : /* Intentionally fail at these 106 : esriFieldTypeOID 107 : esriFieldTypeGeometry 108 : esriFieldTypeRaster 109 : */ 110 0 : CPLError(CE_Warning, CPLE_AppDefined, "%s", 111 0 : ("Cannot map field " + gdbType).c_str()); 112 : 113 0 : return false; 114 : } 115 : } 116 : 117 : #endif // FILEGDB_GDBTOOGRFIELDTYPE_H