Line data Source code
1 : /****************************************************************************** 2 : * Project: OGR 3 : * Purpose: OGRGMLASDriver implementation 4 : * Author: Even Rouault, <even dot rouault at spatialys dot com> 5 : * 6 : * Initial development funded by the European Earth observation programme 7 : * Copernicus 8 : * 9 : ****************************************************************************** 10 : * Copyright (c) 2016, Even Rouault, <even dot rouault at spatialys dot com> 11 : * 12 : * SPDX-License-Identifier: MIT 13 : ****************************************************************************/ 14 : 15 : #include "ogrsf_frmts.h" 16 : 17 : #include "ogrgmlasdrivercore.h" 18 : #include "ogr_gmlas_consts.h" 19 : 20 : /************************************************************************/ 21 : /* OGRGMLASDriverIdentify() */ 22 : /************************************************************************/ 23 : 24 45079 : int OGRGMLASDriverIdentify(GDALOpenInfo *poOpenInfo) 25 : 26 : { 27 45079 : if (STARTS_WITH_CI(poOpenInfo->pszFilename, "GMLAS:")) 28 354 : return true; 29 : 30 44725 : if (poOpenInfo->IsSingleAllowedDriver("GMLAS")) 31 : { 32 2 : const char *pszPtr = 33 : reinterpret_cast<const char *>(poOpenInfo->pabyHeader); 34 : 35 : // Skip UTF-8 BOM 36 2 : if (poOpenInfo->nHeaderBytes > 3 && 37 2 : memcmp(poOpenInfo->pabyHeader, "\xEF\xBB\xBF", 3) == 0) 38 : { 39 0 : pszPtr += 3; 40 : } 41 : 42 : // Skip spaces 43 2 : while (*pszPtr && std::isspace(static_cast<unsigned char>(*pszPtr))) 44 0 : ++pszPtr; 45 : 46 : // Here, we expect the opening chevrons of GML tree root element */ 47 2 : return pszPtr[0] == '<'; 48 : } 49 : 50 44723 : return false; 51 : } 52 : 53 : /************************************************************************/ 54 : /* OGRGMLASDriverSetCommonMetadata() */ 55 : /************************************************************************/ 56 : 57 1293 : void OGRGMLASDriverSetCommonMetadata(GDALDriver *poDriver) 58 : { 59 1293 : poDriver->SetDescription(DRIVER_NAME); 60 1293 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 61 1293 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, 62 : "Geography Markup Language (GML) " 63 1293 : "driven by application schemas"); 64 1293 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "gml xml"); 65 1293 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/gmlas.html"); 66 : 67 1293 : poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, szGMLAS_PREFIX); 68 1293 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); 69 : 70 1293 : poDriver->SetMetadataItem( 71 : GDAL_DMD_OPENOPTIONLIST, 72 : "<OpenOptionList>" 73 : " <Option name='XSD' type='string' description='Space separated list " 74 : "of " 75 : "filenames of XML schemas that apply to the data file'/>" 76 : " <Option name='CONFIG_FILE' type='string' " 77 : "description='Filename of the configuration file'/>" 78 : " <Option name='EXPOSE_METADATA_LAYERS' type='boolean' " 79 : "description='Whether metadata layers should be reported by default.' " 80 : "default='NO'/>" 81 : " <Option name='SCHEMA_FULL_CHECKING' type='boolean' description=" 82 : "'Whether the full schema constraint checking should be enabled.' " 83 : "default='YES'/>" 84 : " <Option name='HANDLE_MULTIPLE_IMPORTS' type='boolean' " 85 : "description='Whether " 86 : "multiple imports of the same namespace can be done.' default='NO'/>" 87 : " <Option name='VALIDATE' type='boolean' description='Whether " 88 : "validation " 89 : "against the schema should be done' default='NO'/>" 90 : " <Option name='FAIL_IF_VALIDATION_ERROR' type='boolean' " 91 : "description='Whether a validation error should cause dataset opening " 92 : "to fail' " 93 : "default='NO'/>" 94 : " <Option name='REFRESH_CACHE' type='boolean' " 95 : "description='Whether remote schemas and resolved xlink resources " 96 : "should " 97 : "be downloaded from the server' " 98 : "default='NO'/>" 99 : " <Option name='SWAP_COORDINATES' type='string-select' " 100 : "description='Whether the order of geometry coordinates should be " 101 : "inverted.' " 102 : "default='AUTO'>" 103 : " <Value>AUTO</Value>" 104 : " <Value>YES</Value>" 105 : " <Value>NO</Value>" 106 : " </Option>" 107 : " <Option name='REMOVE_UNUSED_LAYERS' type='boolean' " 108 : "description='Whether unused layers should be removed' " 109 : "default='NO'/>" 110 : " <Option name='REMOVE_UNUSED_FIELDS' type='boolean' " 111 : "description='Whether unused fields should be removed' " 112 : "default='NO'/>" 113 1293 : "</OpenOptionList>"); 114 : 115 1293 : poDriver->SetMetadataItem( 116 : GDAL_DMD_CREATIONOPTIONLIST, 117 2586 : (CPLString("<CreationOptionList>") + " <Option name='" + 118 2586 : szINPUT_XSD_OPTION + 119 : "' type='string' description='" 120 : "Space separated list of filenames of XML schemas that apply to the " 121 : "data file'/>" 122 2586 : " <Option name='" + 123 2586 : szCONFIG_FILE_OPTION + 124 : "' type='string' " 125 : "description='Filename of the configuration file'/>" 126 2586 : " <Option name='" + 127 2586 : szLAYERS_OPTION + 128 : "' type='string' " 129 : "description='Comma separated list of layer names to export'/>" 130 2586 : " <Option name='" + 131 2586 : szSRSNAME_FORMAT_OPTION + 132 : "' type='string-select' " 133 : "description='Format of srsName' " 134 2586 : "default='" + 135 2586 : szSRSNAME_DEFAULT + 136 : "'>" 137 2586 : " <Value>" + 138 2586 : szSHORT + 139 : "</Value>" 140 2586 : " <Value>" + 141 2586 : szOGC_URN + 142 : "</Value>" 143 2586 : " <Value>" + 144 2586 : szOGC_URL + 145 : "</Value>" 146 : " </Option>" 147 2586 : " <Option name='" + 148 2586 : szINDENT_SIZE_OPTION + 149 : "' type='int' min='0' max='8' " 150 : "description='Number of spaces for each indentation level' " 151 : "default='2'/>" 152 2586 : " <Option name='" + 153 2586 : szCOMMENT_OPTION + 154 : "' type='string' description='" 155 : "Comment to add at top of generated XML file'/>" 156 2586 : " <Option name='" + 157 2586 : szLINEFORMAT_OPTION + 158 : "' type='string-select' " 159 : "description='end-of-line sequence' " 160 : #ifdef _WIN32 161 : "default='" + 162 : szCRLF + 163 : "'>" 164 : #else 165 2586 : "default='" + 166 2586 : szLF + 167 : "'>" 168 : #endif 169 2586 : " <Value>" + 170 2586 : szCRLF + 171 : "</Value>" 172 2586 : " <Value>" + 173 2586 : szLF + 174 : "</Value>" 175 : " </Option>" 176 2586 : " <Option name='" + 177 2586 : szWRAPPING_OPTION + 178 : "' type='string-select' " 179 : "description='How to wrap features' " 180 2586 : "default='" + 181 2586 : szWFS2_FEATURECOLLECTION + 182 : "'>" 183 2586 : " <Value>" + 184 2586 : szWFS2_FEATURECOLLECTION + 185 : "</Value>" 186 2586 : " <Value>" + 187 2586 : szGMLAS_FEATURECOLLECTION + 188 : "</Value>" 189 : " </Option>" 190 2586 : " <Option name='" + 191 2586 : szTIMESTAMP_OPTION + 192 : "' type='string' " 193 : "description='User-specified XML " 194 : "dateTime value for timestamp to use in wfs:FeatureCollection " 195 : "attribute." 196 2586 : "Only valid for " + 197 2586 : szWRAPPING_OPTION + "=" + szWFS2_FEATURECOLLECTION + 198 : "'/>" 199 2586 : " <Option name='" + 200 2586 : szWFS20_SCHEMALOCATION_OPTION + 201 : "' type='string' " 202 2586 : "description='Path or URL to wfs.xsd. Only valid for " + 203 2586 : szWRAPPING_OPTION + "=" + szWFS2_FEATURECOLLECTION + 204 : "'/>" 205 2586 : " <Option name='" + 206 2586 : szGENERATE_XSD_OPTION + 207 : "' type='boolean' " 208 2586 : "description='Whether to generate a .xsd file. Only valid for " + 209 2586 : szWRAPPING_OPTION + "=" + szGMLAS_FEATURECOLLECTION + 210 : "' " 211 : "default='YES'/>" 212 2586 : " <Option name='" + 213 2586 : szOUTPUT_XSD_FILENAME_OPTION + 214 : "' type='string' " 215 : "description='Wrapping .xsd filename. If not specified, same " 216 2586 : "basename as output file with .xsd extension. Only valid for " + 217 2586 : szWRAPPING_OPTION + "=" + szGMLAS_FEATURECOLLECTION + 218 : "'/>" 219 : "</CreationOptionList>") 220 1293 : .c_str()); 221 : 222 1293 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 223 1293 : poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES"); 224 : 225 1293 : poDriver->pfnIdentify = OGRGMLASDriverIdentify; 226 1293 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 227 1293 : poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES"); 228 1293 : } 229 : 230 : /************************************************************************/ 231 : /* DeclareDeferredOGRGMLASPlugin() */ 232 : /************************************************************************/ 233 : 234 : #ifdef PLUGIN_FILENAME 235 : void DeclareDeferredOGRGMLASPlugin() 236 : { 237 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 238 : { 239 : return; 240 : } 241 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 242 : #ifdef PLUGIN_INSTALLATION_MESSAGE 243 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 244 : PLUGIN_INSTALLATION_MESSAGE); 245 : #endif 246 : OGRGMLASDriverSetCommonMetadata(poDriver); 247 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 248 : } 249 : #endif