1 /******************************************************************************
2 * $Id: ogrwalkdriver.cpp
3 *
4 * Project: OpenGIS Simple Features Reference Implementation
5 * Purpose: Implements OGRWalkDriver class.
6 * Author: Xian Chen, chenxian at walkinfo.com.cn
7 *
8 ******************************************************************************
9 * Copyright (c) 2013, ZJU Walkinfo Technology Corp., Ltd.
10 * Copyright (c) 2013, Even Rouault <even dot rouault at mines-paris dot org>
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 ****************************************************************************/
30
31 #include "ogrwalk.h"
32
33 /************************************************************************/
34 /* ~OGRWalkDriver() */
35 /************************************************************************/
36
~OGRWalkDriver()37 OGRWalkDriver::~OGRWalkDriver()
38
39 {
40 }
41
42 /************************************************************************/
43 /* GetName() */
44 /************************************************************************/
45
GetName()46 const char *OGRWalkDriver::GetName()
47
48 {
49 return "Walk";
50 }
51
52 /************************************************************************/
53 /* Open() */
54 /************************************************************************/
55
Open(const char * pszFilename,int bUpdate)56 OGRDataSource *OGRWalkDriver::Open( const char * pszFilename, int bUpdate )
57 {
58
59 if( EQUALN(pszFilename, "PGEO:", strlen("PGEO:")) )
60 return NULL;
61
62 if( EQUALN(pszFilename, "GEOMEDIA:", strlen("GEOMEDIA:")) )
63 return NULL;
64
65 if( !EQUALN(pszFilename,"WALK:", strlen("WALK:"))
66 && !EQUAL(CPLGetExtension(pszFilename), "MDB") )
67 return NULL;
68
69 #ifndef WIN32
70 // Try to register MDB Tools driver
71 //
72 // ODBCINST.INI NOTE:
73 // This operation requires write access to odbcinst.ini file
74 // located in directory pointed by ODBCINISYS variable.
75 // Usually, it points to /etc, so non-root users can overwrite this
76 // setting ODBCINISYS with location they have write access to, e.g.:
77 // $ export ODBCINISYS=$HOME/etc
78 // $ touch $ODBCINISYS/odbcinst.ini
79 //
80 // See: http://www.unixodbc.org/internals.html
81 //
82 if ( !InstallMdbDriver() )
83 {
84 CPLError( CE_Warning, CPLE_AppDefined,
85 "Unable to install MDB driver for ODBC, MDB access may not supported.\n" );
86 }
87 else
88 CPLDebug( "Walk", "MDB Tools driver installed successfully!");
89
90 #endif /* ndef WIN32 */
91
92 OGRWalkDataSource *poDS = new OGRWalkDataSource();
93
94 if( !poDS->Open( pszFilename, bUpdate ) )
95 {
96 delete poDS;
97 return NULL;
98 }
99 else
100 return poDS;
101 }
102
103 /************************************************************************/
104 /* CreateDataSource() */
105 /************************************************************************/
106
CreateDataSource(const char * pszName,CPL_UNUSED char ** papszOptions)107 OGRDataSource *OGRWalkDriver::CreateDataSource( const char * pszName,
108 CPL_UNUSED char **papszOptions )
109 {
110 //if( !EQUAL(CPLGetExtension(pszName), "MDB") )
111 // return NULL;
112
113 OGRWalkDataSource *poDS = new OGRWalkDataSource();
114
115 if( !poDS->Open( pszName, TRUE ) )
116 {
117 delete poDS;
118 CPLError( CE_Failure, CPLE_AppDefined,
119 "Walk driver doesn't currently support database creation.\n"
120 "Please create database with the `createdb' command." );
121 return NULL;
122 }
123 else
124 return poDS;
125 }
126
127 /************************************************************************/
128 /* TestCapability() */
129 /************************************************************************/
130
TestCapability(CPL_UNUSED const char * pszCap)131 int OGRWalkDriver::TestCapability( CPL_UNUSED const char * pszCap )
132 {
133 return FALSE;
134 }
135
136 /************************************************************************/
137 /* RegisterOGRWalk() */
138 /************************************************************************/
139
RegisterOGRWalk()140 void RegisterOGRWalk()
141
142 {
143 OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRWalkDriver );
144 }
145