| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Project: OGR |
| 4 | * Purpose: OGRGMLDriver implementation |
| 5 | * Author: Frank Warmerdam, [email protected] |
| 6 | * |
| 7 | ****************************************************************************** |
| 8 | * Copyright (c) 2002, Frank Warmerdam <[email protected]> |
| 9 | * |
| 10 | * SPDX-License-Identifier: MIT |
| 11 | ****************************************************************************/ |
| 12 | |
| 13 | #include "ogr_gml.h"cxx . . $ `<file>/ogr/ogrsf_frmts/gml/ogr_gml.h`/ |
| 14 | #include "cpl_conv.h"cxx . . $ `<file>/port/cpl_conv.h`/ |
| 15 | #include "cpl_multiproc.h"cxx . . $ `<file>/port/cpl_multiproc.h`/ |
| 16 | #include "gmlreaderp.h"cxx . . $ `<file>/ogr/ogrsf_frmts/gml/gmlreaderp.h`/ |
| 17 | |
| 18 | /************************************************************************/ |
| 19 | /* OGRGMLDriverIdentify() */ |
| 20 | /************************************************************************/ |
| 21 | |
| 22 | static int OGRGMLDriverIdentifycxx . . $ OGRGMLDriverIdentify(48f695ac6b30cd84).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 23 | |
| 24 | { |
| 25 | if (poOpenInfo->fpLcxx . . $ GDALOpenInfo#fpL. == nullptr) |
| 26 | { |
| 27 | if (strstr(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., "xsd=") != nullptr) |
| 28 | return -1; /* must be later checked */ |
| 29 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 30 | } |
| 31 | /* Might be a OS-Mastermap gzipped GML, so let be nice and try to open */ |
| 32 | /* it transparently with /vsigzip/ */ |
| 33 | else if (poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.[0] == 0x1f && |
| 34 | poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.[1] == 0x8b && |
| 35 | poOpenInfo->IsExtensionEqualToCIcxx . . $ GDALOpenInfo#IsExtensionEqualToCI(7d4bdb1abc417636).("gz") && |
| 36 | !STARTS_WITHcxx . . $ `port/cpl_port.h:541:9`!(poOpenInfo->pszFilename, "/vsigzip/")) |
| 37 | { |
| 38 | return -1; /* must be later checked */ |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | const char *szPtr = |
| 43 | reinterpret_cast<const char *>(poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.); |
| 44 | |
| 45 | if ((static_cast<unsigned char>(szPtr[0]) == 0xEF) && |
| 46 | (static_cast<unsigned char>(szPtr[1]) == 0xBB) && |
| 47 | (static_cast<unsigned char>(szPtr[2]) == 0xBF)) |
| 48 | { |
| 49 | szPtr += 3; |
| 50 | } |
| 51 | /* -------------------------------------------------------------------- |
| 52 | */ |
| 53 | /* Here, we expect the opening chevrons of GML tree root element */ |
| 54 | /* -------------------------------------------------------------------- |
| 55 | */ |
| 56 | if (szPtr[0] != '<') |
| 57 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 58 | |
| 59 | if (!poOpenInfo->TryToIngestcxx . . $ GDALOpenInfo#TryToIngest(7864480464b09eea).(4096)) |
| 60 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 61 | |
| 62 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("GML")) |
| 63 | return TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 64 | |
| 65 | return OGRGMLDataSourcecxx . . $ OGRGMLDataSource#::CheckHeadercxx . . $ OGRGMLDataSource#CheckHeader(c5f7da30cbc0f4e9).( |
| 66 | reinterpret_cast<const char *>(poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.)); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /************************************************************************/ |
| 71 | /* Open() */ |
| 72 | /************************************************************************/ |
| 73 | |
| 74 | static GDALDatasetcxx . . $ GDALDataset# *OGRGMLDriverOpencxx . . $ OGRGMLDriverOpen(905b7966ba8c1649).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 75 | |
| 76 | { |
| 77 | if (poOpenInfo->eAccesscxx . . $ GDALOpenInfo#eAccess. == GA_Update) |
| 78 | return nullptr; |
| 79 | |
| 80 | if (OGRGMLDriverIdentifycxx . . $ OGRGMLDriverIdentify(48f695ac6b30cd84).(poOpenInfo) == FALSEcxx . . $ `port/cpl_port.h:1180:9`!) |
| 81 | return nullptr; |
| 82 | |
| 83 | OGRGMLDataSourcecxx . . $ OGRGMLDataSource# *poDS = new OGRGMLDataSourcecxx . . $ OGRGMLDataSource#OGRGMLDataSource(49f6e7a06ebc5aa8).(); |
| 84 | |
| 85 | if (!poDS->Opencxx . . $ OGRGMLDataSource#Open(8e59e7504f0850f4).(poOpenInfo)) |
| 86 | { |
| 87 | delete poDS; |
| 88 | return nullptr; |
| 89 | } |
| 90 | else |
| 91 | return poDS; |
| 92 | } |
| 93 | |
| 94 | /************************************************************************/ |
| 95 | /* Create() */ |
| 96 | /************************************************************************/ |
| 97 | |
| 98 | static GDALDatasetcxx . . $ GDALDataset# * |
| 99 | OGRGMLDriverCreatecxx . . $ OGRGMLDriverCreate(2a509bdc7a404bec).(const char *pszName, CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! int nBands, |
| 100 | CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! int nXSize, CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! int nYSize, |
| 101 | CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! GDALDataType eDT, CSLConstListcxx . . $ CSLConstList# papszOptions) |
| 102 | { |
| 103 | OGRGMLDataSourcecxx . . $ OGRGMLDataSource# *poDS = new OGRGMLDataSourcecxx . . $ OGRGMLDataSource#OGRGMLDataSource(49f6e7a06ebc5aa8).(); |
| 104 | |
| 105 | if (!poDS->Createcxx . . $ OGRGMLDataSource#Create(16997358fa22d8dc).(pszName, papszOptions)) |
| 106 | { |
| 107 | delete poDS; |
| 108 | return nullptr; |
| 109 | } |
| 110 | else |
| 111 | return poDS; |
| 112 | } |
| 113 | |
| 114 | /************************************************************************/ |
| 115 | /* RegisterOGRGML() */ |
| 116 | /************************************************************************/ |
| 117 | |
| 118 | void RegisterOGRGMLcxx . . $ RegisterOGRGML(49f6e7a06ebc5aa8).() |
| 119 | |
| 120 | { |
| 121 | if (GDALGetDriverByName("GML") != nullptr) |
| 122 | return; |
| 123 | |
| 124 | GDALDrivercxx . . $ GDALDriver# *poDriver = new GDALDrivercxx . . $ GDALDriver#GDALDriver(49f6e7a06ebc5aa8).(); |
| 125 | |
| 126 | poDriver->SetDescriptioncxx . . $ GDALMajorObject#SetDescription(85c52e162fed56f9).("GML"); |
| 127 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_VECTORcxx . . $ `gcore/gdal.h:682:9`!, "YES"); |
| 128 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_CREATE_LAYERcxx . . $ `gcore/gdal.h:691:9`!, "YES"); |
| 129 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_CREATE_FIELDcxx . . $ `gcore/gdal.h:701:9`!, "YES"); |
| 130 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_CURVE_GEOMETRIEScxx . . $ `gcore/gdal.h:768:9`!, "YES"); |
| 131 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_Z_GEOMETRIEScxx . . $ `gcore/gdal.h:780:9`!, "YES"); |
| 132 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_LONGNAMEcxx . . $ `gcore/gdal.h:443:9`!, |
| 133 | "Geography Markup Language (GML)"); |
| 134 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_EXTENSIONcxx . . $ `gcore/gdal.h:452:9`!, "gml"); |
| 135 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_EXTENSIONScxx . . $ `gcore/gdal.h:461:9`!, "gml xml"); |
| 136 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_HELPTOPICcxx . . $ `gcore/gdal.h:446:9`!, "drivers/vector/gml.html"); |
| 137 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_SUPPORTED_SQL_DIALECTScxx . . $ `gcore/gdal.h:991:9`!, "OGRSQL SQLITE"); |
| 138 | |
| 139 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).( |
| 140 | GDAL_DMD_OPENOPTIONLISTcxx . . $ `gcore/gdal.h:509:9`!, |
| 141 | "<OpenOptionList>" |
| 142 | " <Option name='XSD' type='string' description='Name of the related " |
| 143 | "application schema file (.xsd).'/>" |
| 144 | " <Option name='GFS_TEMPLATE' type='string' description='Filename of " |
| 145 | "a .gfs template file to apply.'/>" |
| 146 | " <Option name='WRITE_GFS' type='string-select' description='Whether " |
| 147 | "to write a .gfs file' default='AUTO'>" |
| 148 | " <Value>AUTO</Value>" |
| 149 | " <Value>YES</Value>" |
| 150 | " <Value>NO</Value>" |
| 151 | " </Option>" |
| 152 | " <Option name='FORCE_SRS_DETECTION' type='boolean' " |
| 153 | "description='Force a full scan to detect the SRS of layers.' " |
| 154 | "default='NO'/>" |
| 155 | " <Option name='EMPTY_AS_NULL' type='boolean' description='Force " |
| 156 | "empty fields to be reported as NULL. Set to NO so that not-nullable " |
| 157 | "fields can be exposed' default='YES'/>" |
| 158 | " <Option name='GML_ATTRIBUTES_TO_OGR_FIELDS' type='boolean' " |
| 159 | "description='Whether GML attributes should be reported as OGR fields' " |
| 160 | "default='NO'/>" |
| 161 | " <Option name='INVERT_AXIS_ORDER_IF_LAT_LONG' type='boolean' " |
| 162 | "description='Whether to present SRS and coordinate ordering in " |
| 163 | "traditional GIS order' default='YES'/>" |
| 164 | " <Option name='CONSIDER_EPSG_AS_URN' type='string-select' " |
| 165 | "description='Whether to consider srsName like EPSG:XXXX as respecting " |
| 166 | "EPSG axis order' default='AUTO'>" |
| 167 | " <Value>AUTO</Value>" |
| 168 | " <Value>YES</Value>" |
| 169 | " <Value>NO</Value>" |
| 170 | " </Option>" |
| 171 | " <Option name='SWAP_COORDINATES' type='string-select' " |
| 172 | "description='Whether the order of geometry coordinates should be " |
| 173 | "inverted.' " |
| 174 | "default='AUTO'>" |
| 175 | " <Value>AUTO</Value>" |
| 176 | " <Value>YES</Value>" |
| 177 | " <Value>NO</Value>" |
| 178 | " </Option>" |
| 179 | " <Option name='READ_MODE' type='string-select' description='Read " |
| 180 | "mode' default='AUTO'>" |
| 181 | " <Value>AUTO</Value>" |
| 182 | " <Value>STANDARD</Value>" |
| 183 | " <Value>SEQUENTIAL_LAYERS</Value>" |
| 184 | " <Value>INTERLEAVED_LAYERS</Value>" |
| 185 | " </Option>" |
| 186 | " <Option name='EXPOSE_GML_ID' type='string-select' " |
| 187 | "description='Whether to make feature gml:id as a gml_id attribute' " |
| 188 | "default='AUTO'>" |
| 189 | " <Value>AUTO</Value>" |
| 190 | " <Value>YES</Value>" |
| 191 | " <Value>NO</Value>" |
| 192 | " </Option>" |
| 193 | " <Option name='EXPOSE_FID' type='string-select' description='Whether " |
| 194 | "to make feature fid as a fid attribute' default='AUTO'>" |
| 195 | " <Value>AUTO</Value>" |
| 196 | " <Value>YES</Value>" |
| 197 | " <Value>NO</Value>" |
| 198 | " </Option>" |
| 199 | " <Option name='OGR_SCHEMA' type='string' description='" |
| 200 | "Partially or totally overrides the auto-detected schema to use for " |
| 201 | "creating the layer. " |
| 202 | "The overrides are defined as a JSON list of field definitions. " |
| 203 | "This can be a filename or a JSON string or a URL.'/>" |
| 204 | " <Option name='DOWNLOAD_SCHEMA' type='boolean' description='Whether " |
| 205 | "to download the remote application schema if needed (only for WFS " |
| 206 | "currently)' default='YES'/>" |
| 207 | " <Option name='REGISTRY' type='string' description='Filename of the " |
| 208 | "registry with application schemas.'/>" |
| 209 | " <Option name='USE_BBOX' type='boolean' description='Whether " |
| 210 | "to use gml:boundedBy at feature level as feature geometry, " |
| 211 | "if there are no other geometry' default='NO'/>" |
| 212 | " <Option name='USE_SCHEMA_IMPORT' type='boolean' " |
| 213 | "description='Whether " |
| 214 | "to read schema for imports along with includes or not' default='NO'/>" |
| 215 | " <Option name='SKIP_CORRUPTED_FEATURES' type='boolean' " |
| 216 | "description='Whether to skip features that cannot be parsed instead " |
| 217 | "of failing' default='NO'/>" |
| 218 | " <Option name='SKIP_RESOLVE_ELEMS' type='string' " |
| 219 | "description='Configure xlink element resolution. Set to NONE to " |
| 220 | "resolve all elements, set to ALL to skip all xlink elements, " |
| 221 | "set to HUGE to store linked elements in a temporary SQLite DB, " |
| 222 | "set to a comma separated list of names of specific elements to be " |
| 223 | "skipped.' " |
| 224 | "default='ALL'/>" |
| 225 | "</OpenOptionList>"); |
| 226 | |
| 227 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).( |
| 228 | GDAL_DMD_CREATIONOPTIONLISTcxx . . $ `gcore/gdal.h:464:9`!, |
| 229 | "<CreationOptionList>" |
| 230 | " <Option name='XSISCHEMAURI' type='string' description='URI to be " |
| 231 | "inserted as the schema location.'/>" |
| 232 | " <Option name='XSISCHEMA' type='string-select' description='where to " |
| 233 | "write a .xsd application schema. INTERNAL should not normally be " |
| 234 | "used' default='EXTERNAL'>" |
| 235 | " <Value>EXTERNAL</Value>" |
| 236 | " <Value>INTERNAL</Value>" |
| 237 | " <Value>OFF</Value>" |
| 238 | " </Option>" |
| 239 | " <Option name='PREFIX' type='string' description='Prefix for the " |
| 240 | "application target namespace.' default='ogr'/>" |
| 241 | " <Option name='STRIP_PREFIX' type='boolean' description='Whether to " |
| 242 | "avoid writing the prefix of the application target namespace in the " |
| 243 | "GML file.' default='NO'/>" |
| 244 | " <Option name='TARGET_NAMESPACE' type='string' " |
| 245 | "description='Application target namespace.' " |
| 246 | "default='http://ogr.maptools.org/'/>" |
| 247 | " <Option name='FORMAT' type='string-select' description='Version of " |
| 248 | "GML to use' default='GML3.2'>" |
| 249 | " <Value>GML2</Value>" |
| 250 | " <Value>GML3</Value>" |
| 251 | " <Value>GML3.2</Value>" |
| 252 | " <Value>GML3Deegree</Value>" |
| 253 | " </Option>" |
| 254 | " <Option name='GML_FEATURE_COLLECTION' type='boolean' " |
| 255 | "description='Whether to use the gml:FeatureCollection. Only valid for " |
| 256 | "FORMAT=GML3/GML3.2' default='NO'/>" |
| 257 | " <Option name='GML3_LONGSRS' type='boolean' description='Whether to " |
| 258 | "write SRS with \"urn:ogc:def:crs:EPSG::\" prefix with GML3* versions' " |
| 259 | "default='YES'/>" |
| 260 | " <Option name='SRSNAME_FORMAT' type='string-select' " |
| 261 | "description='Format of srsName (for GML3* versions)' " |
| 262 | "default='OGC_URL'>" |
| 263 | " <Value>SHORT</Value>" |
| 264 | " <Value>OGC_URN</Value>" |
| 265 | " <Value>OGC_URL</Value>" |
| 266 | " </Option>" |
| 267 | " <Option name='WRITE_FEATURE_BOUNDED_BY' type='boolean' " |
| 268 | "description='Whether to write <gml:boundedBy> element for each " |
| 269 | "feature with GML3* versions' default='YES'/>" |
| 270 | " <Option name='SPACE_INDENTATION' type='boolean' " |
| 271 | "description='Whether to indent the output for readability' " |
| 272 | "default='YES'/>" |
| 273 | " <Option name='SRSDIMENSION_LOC' type='string-select' " |
| 274 | "description='(only valid for FORMAT=GML3xx) Location where to put " |
| 275 | "srsDimension attribute' default='POSLIST'>" |
| 276 | " <Value>POSLIST</Value>" |
| 277 | " <Value>GEOMETRY</Value>" |
| 278 | " <Value>GEOMETRY,POSLIST</Value>" |
| 279 | " </Option>" |
| 280 | " <Option name='GML_ID' type='string' description='Value of feature " |
| 281 | "collection gml:id (GML 3.2 only)' default='aFeatureCollection'/>" |
| 282 | " <Option name='NAME' type='string' description='Content of GML name " |
| 283 | "element'/>" |
| 284 | " <Option name='DESCRIPTION' type='string' description='Content of " |
| 285 | "GML description element'/>" |
| 286 | "</CreationOptionList>"); |
| 287 | |
| 288 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DS_LAYER_CREATIONOPTIONLISTcxx . . $ `gcore/gdal.h:1330:9`!, |
| 289 | "<LayerCreationOptionList/>"); |
| 290 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_CREATIONFIELDDATATYPEScxx . . $ `gcore/gdal.h:518:9`!, |
| 291 | "Integer Integer64 Real String Date DateTime " |
| 292 | "IntegerList Integer64List RealList StringList"); |
| 293 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_CREATIONFIELDDATASUBTYPEScxx . . $ `gcore/gdal.h:523:9`!, |
| 294 | "Boolean Int16 Float32"); |
| 295 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_CREATION_FIELD_DEFN_FLAGScxx . . $ `gcore/gdal.h:555:9`!, |
| 296 | "WidthPrecision Nullable Unique Comment"); |
| 297 | |
| 298 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_NOTNULL_FIELDScxx . . $ `gcore/gdal.h:743:9`!, "YES"); |
| 299 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_UNIQUE_FIELDScxx . . $ `gcore/gdal.h:748:9`!, "YES"); |
| 300 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_NOTNULL_GEOMFIELDScxx . . $ `gcore/gdal.h:757:9`!, "YES"); |
| 301 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_VIRTUALIOcxx . . $ `gcore/gdal.h:674:9`!, "YES"); |
| 302 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_MULTIPLE_VECTOR_LAYERScxx . . $ `gcore/gdal.h:831:9`!, "YES"); |
| 303 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_HONOR_GEOM_COORDINATE_PRECISIONcxx . . $ `gcore/gdal.h:890:9`!, "YES"); |
| 304 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_REOPEN_AFTER_WRITE_REQUIREDcxx . . $ `gcore/gdal.h:1048:9`!, "YES"); |
| 305 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_CAN_READ_AFTER_DELETEcxx . . $ `gcore/gdal.h:1056:9`!, "YES"); |
| 306 | |
| 307 | poDriver->pfnOpencxx . . $ GDALDriver#pfnOpen. = OGRGMLDriverOpencxx . . $ OGRGMLDriverOpen(905b7966ba8c1649).; |
| 308 | poDriver->pfnIdentifycxx . . $ GDALDriver#pfnIdentify. = OGRGMLDriverIdentifycxx . . $ OGRGMLDriverIdentify(48f695ac6b30cd84).; |
| 309 | poDriver->pfnCreatecxx . . $ GDALDriver#pfnCreate. = OGRGMLDriverCreatecxx . . $ OGRGMLDriverCreate(2a509bdc7a404bec).; |
| 310 | |
| 311 | GetGDALDriverManager()->RegisterDrivercxx . . $ GDALDriverManager#RegisterDriver(ed1dabcc01594d64).(poDriver); |
| 312 | } |