1 /******************************************************************************
2  *
3  * Project:  Interlis 1 Translator
4  * Purpose:  Implements OGRILI1Layer class.
5  * Author:   Pirmin Kalberer, Sourcepole AG
6  *
7  ******************************************************************************
8  * Copyright (c) 2004, Pirmin Kalberer, Sourcepole AG
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 "cpl_conv.h"
30 #include "ogr_ili1.h"
31 #include "ogrsf_frmts.h"
32 
33 CPL_CVSID("$Id: ogrili1driver.cpp 1761acd90777d5bcc49eddbc13c193098f0ed40b 2020-10-01 12:12:00 +0200 Even Rouault $")
34 
35 /************************************************************************/
36 /*                                Open()                                */
37 /************************************************************************/
38 
OGRILI1DriverOpen(GDALOpenInfo * poOpenInfo)39 static GDALDataset *OGRILI1DriverOpen( GDALOpenInfo* poOpenInfo )
40 
41 {
42     if( poOpenInfo->eAccess == GA_Update ||
43         (!poOpenInfo->bStatOK && strchr(poOpenInfo->pszFilename, ',') == nullptr) )
44         return nullptr;
45 
46     if( poOpenInfo->pabyHeader != nullptr )
47     {
48         if( strstr((const char*)poOpenInfo->pabyHeader,"SCNT") == nullptr )
49         {
50             return nullptr;
51         }
52     }
53     else if( poOpenInfo->bIsDirectory )
54         return nullptr;
55 
56     OGRILI1DataSource *poDS = new OGRILI1DataSource();
57 
58     if( !poDS->Open( poOpenInfo->pszFilename, poOpenInfo->papszOpenOptions,
59                      TRUE )
60         || poDS->GetLayerCount() == 0 )
61     {
62         delete poDS;
63         return nullptr;
64     }
65 
66     return poDS;
67 }
68 
69 /************************************************************************/
70 /*                               Create()                               */
71 /************************************************************************/
72 
OGRILI1DriverCreate(const char * pszName,int,int,int,GDALDataType,char ** papszOptions)73 static GDALDataset *OGRILI1DriverCreate( const char * pszName,
74                                          int /* nBands */,
75                                          int /* nXSize */,
76                                          int /* nYSize */,
77                                          GDALDataType /* eDT */,
78                                          char **papszOptions )
79 {
80     OGRILI1DataSource *poDS = new OGRILI1DataSource();
81 
82     if( !poDS->Create( pszName, papszOptions ) )
83     {
84         delete poDS;
85         return nullptr;
86     }
87 
88     return poDS;
89 }
90 
91 /************************************************************************/
92 /*                           RegisterOGRILI1()                           */
93 /************************************************************************/
94 
RegisterOGRILI1()95 void RegisterOGRILI1() {
96     if( GDALGetDriverByName( "Interlis 1" ) != nullptr )
97         return;
98 
99     GDALDriver *poDriver = new GDALDriver();
100 
101     poDriver->SetDescription( "Interlis 1" );
102     poDriver->SetMetadataItem( GDAL_DCAP_VECTOR, "YES" );
103     poDriver->SetMetadataItem( GDAL_DMD_LONGNAME, "Interlis 1" );
104     poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC, "drivers/vector/ili.html" );
105     poDriver->SetMetadataItem( GDAL_DMD_EXTENSIONS, "itf ili" );
106     poDriver->SetMetadataItem( GDAL_DMD_OPENOPTIONLIST,
107 "<OpenOptionList>"
108 "  <Option name='MODEL' type='string' description='Filename of the model in IlisMeta format (.imd)'/>"
109 "</OpenOptionList>" );
110     poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" );
111 
112     poDriver->pfnOpen = OGRILI1DriverOpen;
113     poDriver->pfnCreate = OGRILI1DriverCreate;
114 
115     GetGDALDriverManager()->RegisterDriver( poDriver );
116 }
117