1 /******************************************************************************
2  *
3  * Project:  PDS Translator
4  * Purpose:  Implements OGRPDSDriver.
5  * Author:   Even Rouault, even dot rouault at spatialys.com
6  *
7  ******************************************************************************
8  * Copyright (c) 2010, Even Rouault <even dot rouault at spatialys.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 "cpl_conv.h"
30 #include "ogr_pds.h"
31 
32 CPL_CVSID("$Id: ogrpdsdriver.cpp 1761acd90777d5bcc49eddbc13c193098f0ed40b 2020-10-01 12:12:00 +0200 Even Rouault $")
33 
34 extern "C" void RegisterOGRPDS();
35 
36 using namespace OGRPDS;
37 
38 /************************************************************************/
39 /*                                Open()                                */
40 /************************************************************************/
41 
OGRPDSDriverOpen(GDALOpenInfo * poOpenInfo)42 static GDALDataset *OGRPDSDriverOpen( GDALOpenInfo* poOpenInfo )
43 
44 {
45     if( poOpenInfo->eAccess == GA_Update ||
46         poOpenInfo->fpL == nullptr )
47         return nullptr;
48 
49     if( strstr((const char*)poOpenInfo->pabyHeader, "PDS_VERSION_ID") == nullptr )
50         return nullptr;
51 
52     OGRPDSDataSource *poDS = new OGRPDSDataSource();
53 
54     if( !poDS->Open( poOpenInfo->pszFilename ) )
55     {
56         delete poDS;
57         poDS = nullptr;
58     }
59 
60     return poDS;
61 }
62 
63 /************************************************************************/
64 /*                           RegisterOGRPDS()                           */
65 /************************************************************************/
66 
RegisterOGRPDS()67 void RegisterOGRPDS()
68 
69 {
70     if( GDALGetDriverByName( "OGR_PDS" ) != nullptr )
71         return;
72 
73     GDALDriver *poDriver = new GDALDriver();
74 
75     poDriver->SetDescription( "OGR_PDS" );
76     poDriver->SetMetadataItem( GDAL_DCAP_VECTOR, "YES" );
77     poDriver->SetMetadataItem( GDAL_DMD_LONGNAME,
78                                "Planetary Data Systems TABLE" );
79     poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC, "drivers/vector/pds.html" );
80     poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" );
81 
82     poDriver->pfnOpen = OGRPDSDriverOpen;
83 
84     GetGDALDriverManager()->RegisterDriver( poDriver );
85 }
86