1 /******************************************************************************
2  * $Id: FGdbUtils.h 28573 2015-02-27 18:13:19Z rouault $
3  *
4  * Project:  OpenGIS Simple Features Reference Implementation
5  * Purpose:  Various FileGDB OGR Datasource utility functions
6  * Author:   Ragi Yaser Burhum, ragi@burhum.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2010, Ragi Yaser Burhum
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 
31 #ifndef _FGDB_UTILS_H_INCLUDED
32 #define _FGDB_UTILS_H_INCLUDED
33 
34 #include "ogr_fgdb.h"
35 #include <iostream>
36 #include <string>
37 #include "cpl_minixml.h"
38 
39 std::wstring StringToWString(const std::string& s);
40 std::string WStringToString(const std::wstring& s);
41 
42 //
43 // GDB API to OGR Geometry Mapping
44 //
45 
46 // Type mapping
47 bool GDBToOGRGeometry(std::string geoType, bool hasZ, OGRwkbGeometryType* pOut);
48 bool OGRGeometryToGDB(OGRwkbGeometryType ogrType, std::string *gdbType, bool *hasZ);
49 
50 
51 bool GDBToOGRSpatialReference(const std::string & wkt, OGRSpatialReference** ppSR);
52 
53 // Feature mapping
54 bool GDBGeometryToOGRGeometry(bool forceMulti, FileGDBAPI::ShapeBuffer* pGdbGeometry,
55                               OGRSpatialReference* pOGRSR, OGRGeometry** ppOutGeometry);
56 
57 //temporary version - until we can parse the full binary format
58 bool GhettoGDBGeometryToOGRGeometry(bool forceMulti, FileGDBAPI::ShapeBuffer* pGdbGeometry,
59                                     OGRSpatialReference* pOGRSR, OGRGeometry** ppOutGeometry);
60 //
61 // GDB API to OGR Field Mapping
62 //
63 bool GDBToOGRFieldType(std::string gdbType, OGRFieldType* ogrType, OGRFieldSubType* pSubType);
64 bool OGRToGDBFieldType(OGRFieldType ogrType, OGRFieldSubType eSubType, std::string* gdbType);
65 
66 //
67 // GDB Field Width defaults
68 //
69 bool GDBFieldTypeToWidthPrecision(std::string &gdbType, int *width, int *precision);
70 
71 //
72 // GDBAPI error to OGR
73 //
74 bool GDBErr(long hr, std::string desc, CPLErr errType = CE_Failure, const char* pszAddMsg = "");
75 bool GDBDebug(long hr, std::string desc);
76 
77 //
78 // Utility for adding attributes to CPL nodes
79 //
80 void FGDB_CPLAddXMLAttribute(CPLXMLNode* node, const char* attrname, const char* attrvalue);
81 
82 //
83 // Utility for escaping reserved words and cleaning field names
84 //
85 std::string FGDBLaunderName(const std::string name);
86 std::string FGDBEscapeUnsupportedPrefixes(const std::string className);
87 std::string FGDBEscapeReservedKeywords(const std::string name);
88 
89 #endif
90