Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: AmigoCloud Translator
4 : * Purpose: Implements OGRAMIGOCLOUDDriver.
5 : * Author: Victor Chernetsky, <victor at amigocloud dot com>
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2015, Victor Chernetsky, <victor at amigocloud dot 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_amigocloud.h"
30 :
31 : extern "C" void RegisterOGRAmigoCloud();
32 :
33 : /************************************************************************/
34 : /* OGRAmigoCloudDriverIdentify() */
35 : /************************************************************************/
36 :
37 42043 : static int OGRAmigoCloudDriverIdentify(GDALOpenInfo *poOpenInfo)
38 : {
39 42043 : return EQUALN(poOpenInfo->pszFilename,
40 : "AMIGOCLOUD:", strlen("AMIGOCLOUD:"));
41 : }
42 :
43 : /************************************************************************/
44 : /* OGRAmigoCloudDriverOpen() */
45 : /************************************************************************/
46 :
47 0 : static GDALDataset *OGRAmigoCloudDriverOpen(GDALOpenInfo *poOpenInfo)
48 :
49 : {
50 0 : if (!OGRAmigoCloudDriverIdentify(poOpenInfo))
51 0 : return nullptr;
52 :
53 0 : OGRAmigoCloudDataSource *poDS = new OGRAmigoCloudDataSource();
54 :
55 0 : if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->papszOpenOptions,
56 0 : poOpenInfo->eAccess == GA_Update))
57 : {
58 0 : delete poDS;
59 0 : poDS = nullptr;
60 : }
61 :
62 0 : return poDS;
63 : }
64 :
65 : /************************************************************************/
66 : /* OGRAmigoCloudDriverCreate() */
67 : /************************************************************************/
68 :
69 0 : static GDALDataset *OGRAmigoCloudDriverCreate(const char *pszName,
70 : CPL_UNUSED int nBands,
71 : CPL_UNUSED int nXSize,
72 : CPL_UNUSED int nYSize,
73 : CPL_UNUSED GDALDataType eDT,
74 : CPL_UNUSED char **papszOptions)
75 :
76 : {
77 0 : OGRAmigoCloudDataSource *poDS = new OGRAmigoCloudDataSource();
78 :
79 0 : if (!poDS->Open(pszName, nullptr, TRUE))
80 : {
81 0 : delete poDS;
82 0 : return nullptr;
83 : }
84 :
85 0 : return poDS;
86 : }
87 :
88 : /************************************************************************/
89 : /* RegisterOGRAMIGOCLOUD() */
90 : /************************************************************************/
91 :
92 1520 : void RegisterOGRAmigoCloud()
93 : {
94 1520 : if (GDALGetDriverByName("AmigoCloud") != nullptr)
95 301 : return;
96 :
97 1219 : GDALDriver *poDriver = new GDALDriver();
98 :
99 1219 : poDriver->SetDescription("AmigoCloud");
100 1219 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "AmigoCloud");
101 1219 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
102 1219 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES");
103 1219 : poDriver->SetMetadataItem(GDAL_DCAP_DELETE_LAYER, "YES");
104 1219 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC,
105 1219 : "drivers/vector/amigocloud.html");
106 1219 : poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "AMIGOCLOUD:");
107 :
108 1219 : poDriver->SetMetadataItem(
109 : GDAL_DMD_OPENOPTIONLIST,
110 : "<OpenOptionList>"
111 : " <Option name='AMIGOCLOUD_API_KEY' type='string' "
112 : "description='AmigoCLoud API token'/>"
113 : " <Option name='OVERWRITE' type='boolean' description='Whether to "
114 : "overwrite an existing table without deleting it' default='NO'/>"
115 1219 : "</OpenOptionList>");
116 :
117 1219 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONOPTIONLIST,
118 1219 : "<CreationOptionList/>");
119 :
120 1219 : poDriver->SetMetadataItem(
121 : GDAL_DS_LAYER_CREATIONOPTIONLIST,
122 : "<LayerCreationOptionList>"
123 : " <Option name='GEOMETRY_NULLABLE' type='boolean' "
124 : "description='Whether the values of the geometry column can be NULL' "
125 : "default='YES'/>"
126 1219 : "</LayerCreationOptionList>");
127 :
128 1219 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATATYPES,
129 1219 : "String Integer Integer64 Real");
130 1219 : poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_FIELDS, "YES");
131 1219 : poDriver->SetMetadataItem(GDAL_DCAP_DEFAULT_FIELDS, "YES");
132 1219 : poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_GEOMFIELDS, "YES");
133 1219 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES");
134 1219 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS,
135 1219 : "NATIVE OGRSQL SQLITE");
136 :
137 1219 : poDriver->pfnOpen = OGRAmigoCloudDriverOpen;
138 1219 : poDriver->pfnIdentify = OGRAmigoCloudDriverIdentify;
139 1219 : poDriver->pfnCreate = OGRAmigoCloudDriverCreate;
140 :
141 1219 : GetGDALDriverManager()->RegisterDriver(poDriver);
142 : }
|