1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
/**********************************************************************
* $Id: mitab_ogr_driver.cpp,v 1.11 2005-05-21 03:15:18 fwarmerdam Exp $
*
* Name: mitab_ogr_driver.cpp
* Project: MapInfo Mid/Mif, Tab ogr support
* Language: C++
* Purpose: Implementation of the MIDDATAFile class used to handle
* reading/writing of the MID/MIF files
* Author: Stephane Villeneuve, stephane.v@videotron.ca
*
**********************************************************************
* Copyright (c) 1999, 2000, Stephane Villeneuve
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**********************************************************************
*
* $Log: mitab_ogr_driver.cpp,v $
* Revision 1.11 2005-05-21 03:15:18 fwarmerdam
* Removed unused stat buffer.
*
* Revision 1.10 2004/02/27 21:06:03 fwarmerdam
* Better support for "single file" creation ... don't allow other layers to
* be created. But *do* single file to satisfy the first layer creation request
* made. Also, allow creating a datasource "on" an existing directory.
*
* Revision 1.9 2003/03/20 15:57:46 warmerda
* Added delete datasource support
*
* Revision 1.8 2001/01/22 16:03:58 warmerda
* expanded tabs
*
* Revision 1.7 2000/01/26 18:17:00 warmerda
* reimplement OGR driver
*
* Revision 1.6 2000/01/15 22:30:44 daniel
* Switch to MIT/X-Consortium OpenSource license
*
* Revision 1.5 1999/12/15 17:05:24 warmerda
* Only create OGRTABDataSource if SmartOpen() result is non-NULL.
*
* Revision 1.4 1999/12/15 16:28:17 warmerda
* fixed a few type problems
*
* Revision 1.3 1999/12/14 02:22:29 daniel
* Merged TAB+MIF DataSource/Driver into ane using IMapInfoFile class
*
* Revision 1.2 1999/11/12 02:44:36 stephane
* added comment, change Register name.
*
* Revision 1.1 1999/11/08 21:05:51 svillene
* first revision
*
* Revision 1.1 1999/11/08 04:16:07 stephane
* First Revision
*
**********************************************************************/
#include "mitab_ogr_driver.h"
/************************************************************************/
/* ~OGRTABDriver() */
/************************************************************************/
OGRTABDriver::~OGRTABDriver()
{
}
/************************************************************************/
/* OGRTABDriver::GetName() */
/************************************************************************/
const char *OGRTABDriver::GetName()
{
return "MapInfo File";
}
/************************************************************************/
/* OGRTABDriver::Open() */
/************************************************************************/
OGRDataSource *OGRTABDriver::Open( const char * pszFilename,
int bUpdate )
{
OGRTABDataSource *poDS;
if( bUpdate )
{
return NULL;
}
poDS = new OGRTABDataSource();
if( poDS->Open( pszFilename, TRUE ) )
return poDS;
else
{
delete poDS;
return NULL;
}
}
/************************************************************************/
/* CreateDataSource() */
/************************************************************************/
OGRDataSource *OGRTABDriver::CreateDataSource( const char * pszName,
char ** papszOptions )
{
OGRTABDataSource *poDS;
/* -------------------------------------------------------------------- */
/* Try to create the data source. */
/* -------------------------------------------------------------------- */
poDS = new OGRTABDataSource();
if( !poDS->Create( pszName, papszOptions ) )
{
delete poDS;
return NULL;
}
else
return poDS;
}
/************************************************************************/
/* TestCapability() */
/************************************************************************/
int OGRTABDriver::TestCapability( const char * pszCap )
{
if( EQUAL(pszCap,ODrCCreateDataSource) )
return TRUE;
else if( EQUAL(pszCap,ODrCDeleteDataSource) )
return TRUE;
else
return FALSE;
}
/************************************************************************/
/* DeleteDataSource() */
/************************************************************************/
OGRErr OGRTABDriver::DeleteDataSource( const char *pszDataSource )
{
int iExt;
VSIStatBuf sStatBuf;
static const char *apszExtensions[] =
{ "mif", "mid", "tab", "map", "ind", "dat", "id", NULL };
if( VSIStat( pszDataSource, &sStatBuf ) != 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"%s does not appear to be a file or directory.",
pszDataSource );
return OGRERR_FAILURE;
}
if( VSI_ISREG(sStatBuf.st_mode)
&& (EQUAL(CPLGetExtension(pszDataSource),"mif")
|| EQUAL(CPLGetExtension(pszDataSource),"mid")
|| EQUAL(CPLGetExtension(pszDataSource),"tab")) )
{
for( iExt=0; apszExtensions[iExt] != NULL; iExt++ )
{
const char *pszFile = CPLResetExtension(pszDataSource,
apszExtensions[iExt] );
if( VSIStat( pszFile, &sStatBuf ) == 0 )
VSIUnlink( pszFile );
}
}
else if( VSI_ISDIR(sStatBuf.st_mode) )
{
char **papszDirEntries = CPLReadDir( pszDataSource );
int iFile;
for( iFile = 0;
papszDirEntries != NULL && papszDirEntries[iFile] != NULL;
iFile++ )
{
if( CSLFindString( (char **) apszExtensions,
CPLGetExtension(papszDirEntries[iFile])) != -1)
{
VSIUnlink( CPLFormFilename( pszDataSource,
papszDirEntries[iFile],
NULL ) );
}
}
CSLDestroy( papszDirEntries );
VSIRmdir( pszDataSource );
}
return OGRERR_NONE;
}
/************************************************************************/
/* RegisterOGRTAB() */
/************************************************************************/
extern "C"
{
void RegisterOGRTAB()
{
OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRTABDriver );
}
}
|