1 /******************************************************************************
2 *
3 * Project: OpenGIS Simple Features Reference Implementation
4 * Purpose: Implements OGRDGNDriver class.
5 * Author: Frank Warmerdam, warmerdam@pobox.com
6 *
7 ******************************************************************************
8 * Copyright (c) 2000, Frank Warmerdam (warmerdam@pobox.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_dgn.h"
30 #include "cpl_conv.h"
31
32 CPL_CVSID("$Id: ogrdgndriver.cpp 1761acd90777d5bcc49eddbc13c193098f0ed40b 2020-10-01 12:12:00 +0200 Even Rouault $")
33
34 /************************************************************************/
35 /* Open() */
36 /************************************************************************/
37
OGRDGNDriverIdentify(GDALOpenInfo * poOpenInfo)38 static int OGRDGNDriverIdentify( GDALOpenInfo* poOpenInfo )
39
40 {
41 return poOpenInfo->fpL != nullptr &&
42 poOpenInfo->nHeaderBytes >= 512 &&
43 DGNTestOpen(poOpenInfo->pabyHeader, poOpenInfo->nHeaderBytes);
44 }
45
46 /************************************************************************/
47 /* Open() */
48 /************************************************************************/
49
OGRDGNDriverOpen(GDALOpenInfo * poOpenInfo)50 static GDALDataset *OGRDGNDriverOpen( GDALOpenInfo* poOpenInfo )
51
52 {
53 if( !OGRDGNDriverIdentify(poOpenInfo) )
54 return nullptr;
55
56 OGRDGNDataSource *poDS = new OGRDGNDataSource();
57
58 if( !poDS->Open( poOpenInfo->pszFilename, TRUE,
59 (poOpenInfo->eAccess == GA_Update) )
60 || poDS->GetLayerCount() == 0 )
61 {
62 delete poDS;
63 return nullptr;
64 }
65
66 return poDS;
67 }
68
69 /************************************************************************/
70 /* Create() */
71 /************************************************************************/
72
OGRDGNDriverCreate(const char * pszName,int,int,int,GDALDataType,char ** papszOptions)73 static GDALDataset *OGRDGNDriverCreate( const char * pszName,
74 int /* nBands */,
75 int /* nXSize */,
76 int /* nYSize */,
77 GDALDataType /* eDT */,
78 char **papszOptions )
79 {
80 /* -------------------------------------------------------------------- */
81 /* Return a new OGRDataSource() */
82 /* -------------------------------------------------------------------- */
83 OGRDGNDataSource* poDS = new OGRDGNDataSource();
84
85 if( !poDS->PreCreate( pszName, papszOptions ) )
86 {
87 delete poDS;
88 return nullptr;
89 }
90
91 return poDS;
92 }
93
94 /************************************************************************/
95 /* RegisterOGRDGN() */
96 /************************************************************************/
97
RegisterOGRDGN()98 void RegisterOGRDGN()
99
100 {
101 if( GDALGetDriverByName( "DGN" ) != nullptr )
102 return;
103
104 GDALDriver *poDriver = new GDALDriver();
105
106 poDriver->SetDescription( "DGN" );
107 poDriver->SetMetadataItem( GDAL_DCAP_VECTOR, "YES" );
108 poDriver->SetMetadataItem( GDAL_DMD_LONGNAME, "Microstation DGN" );
109 poDriver->SetMetadataItem( GDAL_DMD_EXTENSION, "dgn" );
110 poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC, "drivers/vector/dgn.html" );
111
112 poDriver->SetMetadataItem( GDAL_DMD_CREATIONOPTIONLIST,
113 "<CreationOptionList>"
114 " <Option name='3D' type='boolean' description='whether 2D (seed_2d.dgn) or 3D (seed_3d.dgn) seed file should be used. This option is ignored if the SEED option is provided'/>"
115 " <Option name='SEED' type='string' description='Filename of seed file to use'/>"
116 " <Option name='COPY_WHOLE_SEED_FILE' type='boolean' description='whether the whole seed file should be copied. If not, only the first three elements (and potentially the color table) will be copied.' default='NO'/>"
117 " <Option name='COPY_SEED_FILE_COLOR_TABLE' type='boolean' description='whether the color table should be copied from the seed file.' default='NO'/>"
118 " <Option name='MASTER_UNIT_NAME' type='string' description='Override the master unit name from the seed file with the provided one or two character unit name.'/>"
119 " <Option name='SUB_UNIT_NAME' type='string' description='Override the master unit name from the seed file with the provided one or two character unit name.'/>"
120 " <Option name='MASTER_UNIT_NAME' type='string' description='Override the master unit name from the seed file with the provided one or two character unit name.'/>"
121 " <Option name='SUB_UNIT_NAME' type='string' description='Override the sub unit name from the seed file with the provided one or two character unit name.'/>"
122 " <Option name='SUB_UNITS_PER_MASTER_UNIT' type='int' description='Override the number of subunits per master unit. By default the seed file value is used.'/>"
123 " <Option name='UOR_PER_SUB_UNIT' type='int' description='Override the number of UORs (Units of Resolution) per sub unit. By default the seed file value is used.'/>"
124 " <Option name='ORIGIN' type='string' description='Value as x,y,z. Override the origin of the design plane. By default the origin from the seed file is used.'/>"
125 "</CreationOptionList>");
126
127 poDriver->SetMetadataItem( GDAL_DS_LAYER_CREATIONOPTIONLIST,
128 "<LayerCreationOptionList/>" );
129 poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" );
130 poDriver->SetMetadataItem( GDAL_DCAP_FEATURE_STYLES, "YES" );
131
132 poDriver->pfnOpen = OGRDGNDriverOpen;
133 poDriver->pfnIdentify = OGRDGNDriverIdentify;
134 poDriver->pfnCreate = OGRDGNDriverCreate;
135
136 GetGDALDriverManager()->RegisterDriver( poDriver );
137 }
138