| 1 |
/****************************************************************************** |
| 2 |
* |
| 3 |
* Project: OpenGIS Simple Features Reference Implementation |
| 4 |
* Purpose: OGR Driver for DGNv8 |
| 5 |
* Author: Even Rouault <even.rouault at spatialys.com> |
| 6 |
* |
| 7 |
****************************************************************************** |
| 8 |
* Copyright (c) 2017, Even Rouault <even.rouault at spatialys.com> |
| 9 |
* |
| 10 |
* SPDX-License-Identifier: MIT |
| 11 |
****************************************************************************/ |
| 12 |
|
| 13 |
#include "ogr_dgnv8.h" |
| 14 |
#include "cpl_conv.h" |
| 15 |
#include "ogrteigha.h" |
| 16 |
#include "ogrdgnv8drivercore.h" |
| 17 |
|
| 18 |
/************************************************************************/ |
| 19 |
/* OGRDGNV8DriverUnload() */ |
| 20 |
/************************************************************************/ |
| 21 |
|
| 22 |
static void OGRDGNV8DriverUnload(GDALDriver *) |
| 23 |
{ |
| 24 |
CPLDebug("DGNv8", "Driver cleanup"); |
| 25 |
OGRTEIGHADeinitialize(); |
| 26 |
} |
| 27 |
|
| 28 |
/************************************************************************/ |
| 29 |
/* Open() */ |
| 30 |
/************************************************************************/ |
| 31 |
|
| 32 |
static GDALDataset *OGRDGNV8DriverOpen(GDALOpenInfo *poOpenInfo) |
| 33 |
|
| 34 |
{ |
| 35 |
if (!OGRDGNV8DriverIdentify(poOpenInfo)) |
| 36 |
return nullptr; |
| 37 |
|
| 38 |
if (!OGRTEIGHAInitialize()) |
| 39 |
return nullptr; |
| 40 |
|
| 41 |
OGRDGNV8DataSource *poDS = new OGRDGNV8DataSource(OGRDGNV8GetServices()); |
| 42 |
if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->eAccess == GA_Update)) |
| 43 |
{ |
| 44 |
delete poDS; |
| 45 |
return nullptr; |
| 46 |
} |
| 47 |
|
| 48 |
return poDS; |
| 49 |
} |
| 50 |
|
| 51 |
/************************************************************************/ |
| 52 |
/* Create() */ |
| 53 |
/************************************************************************/ |
| 54 |
|
| 55 |
static GDALDataset *OGRDGNV8DriverCreate(const char *pszName, int /* nBands */, |
| 56 |
int /* nXSize */, int /* nYSize */, |
| 57 |
GDALDataType /* eDT */, |
| 58 |
CSLConstList papszOptions) |
| 59 |
{ |
| 60 |
if (!OGRTEIGHAInitialize()) |
| 61 |
return nullptr; |
| 62 |
|
| 63 |
OGRDGNV8DataSource *poDS = new OGRDGNV8DataSource(OGRDGNV8GetServices()); |
| 64 |
if (!poDS->PreCreate(pszName, papszOptions)) |
| 65 |
{ |
| 66 |
delete poDS; |
| 67 |
return nullptr; |
| 68 |
} |
| 69 |
|
| 70 |
return poDS; |
| 71 |
} |
| 72 |
|
| 73 |
/************************************************************************/ |
| 74 |
/* RegisterOGRDGNV8() */ |
| 75 |
/************************************************************************/ |
| 76 |
|
| 77 |
void RegisterOGRDGNV8() |
| 78 |
|
| 79 |
{ |
| 80 |
if (GDALGetDriverByName(DRIVER_NAME) != nullptr) |
| 81 |
return; |
| 82 |
|
| 83 |
GDALDriver *poDriver = new GDALDriver(); |
| 84 |
OGRDGNV8DriverSetCommonMetadata(poDriver); |
| 85 |
|
| 86 |
poDriver->pfnOpen = OGRDGNV8DriverOpen; |
| 87 |
poDriver->pfnCreate = OGRDGNV8DriverCreate; |
| 88 |
poDriver->pfnUnloadDriver = OGRDGNV8DriverUnload; |
| 89 |
|
| 90 |
GetGDALDriverManager()->RegisterDriver(poDriver); |
| 91 |
} |