1 /******************************************************************************
2 *
3 * Project: CouchDB Translator
4 * Purpose: Implements OGRCloudantDriver.
5 * Author: Even Rouault, even dot rouault at spatialys.com
6 *
7 ******************************************************************************
8 * Copyright (c) 2011, 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 #include "ogr_cloudant.h"
30
31 CPL_CVSID("$Id: ogrcloudantdriver.cpp 2dc350b1c738a002da1ec5c4cbe3e42fec4069dc 2021-03-04 16:15:13 +0100 Even Rouault $")
32
33 extern "C" void RegisterOGRCloudant();
34
35 /************************************************************************/
36 /* OGRCloudantDriverIdentify() */
37 /************************************************************************/
38
OGRCloudantDriverIdentify(GDALOpenInfo * poOpenInfo)39 static int OGRCloudantDriverIdentify( GDALOpenInfo* poOpenInfo )
40
41 {
42 if (STARTS_WITH_CI(poOpenInfo->pszFilename, "Cloudant:"))
43 return 1;
44 else
45 return 0;
46
47 }
48
49 /************************************************************************/
50 /* OGRCloudantDriverOpen() */
51 /************************************************************************/
52
OGRCloudantDriverOpen(GDALOpenInfo * poOpenInfo)53 static GDALDataset* OGRCloudantDriverOpen( GDALOpenInfo* poOpenInfo )
54
55 {
56 if( OGRCloudantDriverIdentify(poOpenInfo) == 0 )
57 return nullptr;
58
59 if( !GDALIsDriverDeprecatedForGDAL35StillEnabled("CLOUDANT") )
60 return nullptr;
61
62 OGRCloudantDataSource *poDS = new OGRCloudantDataSource();
63
64 if( !poDS->Open( poOpenInfo->pszFilename, poOpenInfo->eAccess == GA_Update ) )
65 {
66 delete poDS;
67 poDS = nullptr;
68 }
69
70 return poDS;
71 }
72
73 /************************************************************************/
74 /* CreateDataSource() */
75 /************************************************************************/
76
OGRCloudantDriverCreate(const char * pszName,int,int,int,GDALDataType,char **)77 static GDALDataset* OGRCloudantDriverCreate( const char * pszName,
78 int /* nXSize */,
79 int /* nYSize */,
80 int /* nBands */,
81 GDALDataType /* eDT */,
82 char ** /* papszOptions */ )
83 {
84 if( !GDALIsDriverDeprecatedForGDAL35StillEnabled("CLOUDANT") )
85 return nullptr;
86
87 OGRCloudantDataSource *poDS = new OGRCloudantDataSource();
88
89 if( !poDS->Open( pszName, TRUE ) )
90 {
91 delete poDS;
92 poDS = nullptr;
93 }
94
95 return poDS;
96 }
97
98 /************************************************************************/
99 /* RegisterOGRCloudant() */
100 /************************************************************************/
101
RegisterOGRCloudant()102 void RegisterOGRCloudant()
103
104 {
105 if( GDALGetDriverByName( "Cloudant" ) != nullptr )
106 return;
107
108 GDALDriver *poDriver = new GDALDriver();
109
110 poDriver->SetDescription( "Cloudant" );
111 poDriver->SetMetadataItem( GDAL_DCAP_VECTOR, "YES" );
112 poDriver->SetMetadataItem( GDAL_DMD_LONGNAME, "Cloudant / CouchDB" );
113 poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC, "drivers/vector/cloudant.html" );
114 poDriver->SetMetadataItem( GDAL_DMD_CONNECTION_PREFIX, "Cloudant:" );
115 poDriver->SetMetadataItem( GDAL_DMD_CREATIONOPTIONLIST,
116 "<CreationOptionList/>");
117
118 poDriver->SetMetadataItem( GDAL_DS_LAYER_CREATIONOPTIONLIST,
119 "<LayerCreationOptionList>"
120 " <Option name='UPDATE_PERMISSIONS' type='string' description='Update permissions for the new layer.'/>"
121 " <Option name='GEOJSON' type='boolean' description='Whether to write documents as GeoJSON documents.' default='YES'/>"
122 " <Option name='COORDINATE_PRECISION' type='int' description='Maximum number of figures after decimal separator to write in coordinates.' default='15'/>"
123 "</LayerCreationOptionList>");
124
125 poDriver->SetMetadataItem( GDAL_DMD_CREATIONFIELDDATATYPES,
126 "Integer Integer64 Real String Date DateTime "
127 "Time IntegerList Integer64List RealList "
128 "StringList Binary" );
129
130 poDriver->pfnIdentify = OGRCloudantDriverIdentify;
131 poDriver->pfnOpen = OGRCloudantDriverOpen;
132 poDriver->pfnCreate = OGRCloudantDriverCreate;
133
134 GetGDALDriverManager()->RegisterDriver( poDriver );
135 }
136