⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrtigerdatasource.cpp

📁 支持各种栅格图像和矢量图像读取的库
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** * $Id: ogrtigerdatasource.cpp 10646 2007-01-18 02:38:10Z warmerdam $ * * Project:  TIGER/Line Translator * Purpose:  Implements OGRTigerDataSource class * Author:   Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 1999, Frank Warmerdam <warmerdam@pobox.com> * * 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. ****************************************************************************/#include "ogr_tiger.h"#include "cpl_conv.h"#include "cpl_string.h"#include <ctype.h>CPL_CVSID("$Id: ogrtigerdatasource.cpp 10646 2007-01-18 02:38:10Z warmerdam $");/************************************************************************//*                        TigerClassifyVersion()                        *//************************************************************************/TigerVersion TigerClassifyVersion( int nVersionCode ){    TigerVersion        nVersion;    int                 nYear, nMonth;/*** TIGER Versions**** 0000           TIGER/Line Precensus Files, 1990 ** 0002           TIGER/Line Initial Voting District Codes Files, 1990 ** 0003           TIGER/Line Files, 1990 ** 0005           TIGER/Line Files, 1992 ** 0021           TIGER/Line Files, 1994 ** 0024           TIGER/Line Files, 1995 ** 9706 to 9810   TIGER/Line Files, 1997 ** 9812 to 9904   TIGER/Line Files, 1998 ** 0006 to 0008   TIGER/Line Files, 1999 ** 0010 to 0011   TIGER/Line Files, Redistricting Census 2000** 0103 to 0108   TIGER/Line Files, Census 2000**** 0203 to 0205   TIGER/Line Files, UA 2000** ????    ????**** 0206 to 0299   TIGER/Line Files, 2002** 0300 to 0399   TIGER/Line Files, 2003** 0400+          TIGER/Line Files, 2004 - one sample is 0405** ????*/    nVersion = TIGER_Unknown;    if( nVersionCode == 0 )        nVersion = TIGER_1990_Precensus;    else if( nVersionCode == 2 )        nVersion = TIGER_1990;    else if( nVersionCode == 3 )        nVersion = TIGER_1992;    else if( nVersionCode == 5 )        nVersion = TIGER_1994;    else if( nVersionCode == 21 )        nVersion = TIGER_1994;    else if( nVersionCode == 24 )        nVersion = TIGER_1995;    else if( nVersionCode == 9999 )  /* special hack, fme bug 7625 */        nVersion = TIGER_UA2000;    nYear = nVersionCode % 100;    nMonth = nVersionCode / 100;    nVersionCode = nYear * 100 + nMonth;    if( nVersion != TIGER_Unknown )        /* do nothing */;    else if( nVersionCode >= 9706 && nVersionCode <= 9810 )        nVersion = TIGER_1997;    else if( nVersionCode >= 9812 && nVersionCode <= 9904 )        nVersion = TIGER_1998;    else if( nVersionCode >=    6 /*0006*/ && nVersionCode <=    8 /*0008*/ )        nVersion = TIGER_1999;    else if( nVersionCode >=   10 /*0010*/ && nVersionCode <=   11 /*0011*/ )        nVersion = TIGER_2000_Redistricting;    else if( nVersionCode >=  103 /*0103*/ && nVersionCode <= 108 /*0108*/ )        nVersion = TIGER_2000_Census;    else if( nVersionCode >=  203 /*0302*/ && nVersionCode <= 205 /*0502*/ )        nVersion = TIGER_UA2000;    else if( nVersionCode >=  210 /*1002*/ && nVersionCode <= 306 /*0603*/)        nVersion = TIGER_2002;    else if( nVersionCode >=  312 /*1203*/ && nVersionCode <= 403 /*0304*/)        nVersion = TIGER_2003;    else if( nVersionCode >=  404 )        nVersion = TIGER_2004;    return nVersion;}/************************************************************************//*                         TigerVersionString()                         *//************************************************************************/char * TigerVersionString( TigerVersion nVersion ){  if (nVersion == TIGER_1990_Precensus) { return "TIGER_1990_Precensus"; }  if (nVersion == TIGER_1990) { return "TIGER_1990"; }  if (nVersion == TIGER_1992) { return "TIGER_1992"; }  if (nVersion == TIGER_1994) { return "TIGER_1994"; }  if (nVersion == TIGER_1995) { return "TIGER_1995"; }  if (nVersion == TIGER_1997) { return "TIGER_1997"; }  if (nVersion == TIGER_1998) { return "TIGER_1998"; }  if (nVersion == TIGER_1999) { return "TIGER_1999"; }  if (nVersion == TIGER_2000_Redistricting) { return "TIGER_2000_Redistricting"; }  if (nVersion == TIGER_UA2000) { return "TIGER_UA2000"; }  if (nVersion == TIGER_2002) { return "TIGER_2002"; }  if (nVersion == TIGER_2003) { return "TIGER_2003"; }  if (nVersion == TIGER_2004) { return "TIGER_2004"; }  if (nVersion == TIGER_Unknown) { return "TIGER_Unknown"; }  return "???";}/************************************************************************//*                         TigerCheckVersion()                          *//*                                                                      *//*      Some tiger products seem to be generated with version info      *//*      that doesn't match the tiger specs.  We can sometimes           *//*      recognise the wrongness by checking the record length of        *//*      some well known changing files and adjusting the version        *//*      based on this.                                                  *//************************************************************************/TigerVersion OGRTigerDataSource::TigerCheckVersion( TigerVersion nOldVersion,                                                     const char *pszFilename ){    if( nOldVersion != TIGER_2002 )        return nOldVersion;    char *pszRTCFilename = BuildFilename( pszFilename, "C" );    FILE *fp = VSIFOpen( pszRTCFilename, "rb" );    CPLFree( pszRTCFilename );    if( fp == NULL )        return nOldVersion;        char        szHeader[115];    if( VSIFRead( szHeader, sizeof(szHeader)-1, 1, fp ) < 1 )    {        VSIFClose( fp );        return nOldVersion;    }    VSIFClose( fp );    /* -------------------------------------------------------------------- *//*      Is the record length 112?  If so, it is an older version        *//*      than 2002.                                                      *//* -------------------------------------------------------------------- */    if( szHeader[112] == 10 || szHeader[112] == 13 )    {        CPLDebug( "TIGER", "Forcing version back to UA2000 since RTC records are short." );        return TIGER_UA2000;    }    else        return nOldVersion;}/************************************************************************//*                         OGRTigerDataSource()                         *//************************************************************************/OGRTigerDataSource::OGRTigerDataSource(){    bWriteMode = FALSE;    nLayers = 0;    papoLayers = NULL;    nModules = 0;    papszModules = NULL;    pszName = NULL;    pszPath = NULL;    papszOptions = NULL;    poSpatialRef = new OGRSpatialReference( "GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS 1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]]" );}/************************************************************************//*                        ~OGRTigerDataSource()                         *//************************************************************************/OGRTigerDataSource::~OGRTigerDataSource(){    int         i;    for( i = 0; i < nLayers; i++ )        delete papoLayers[i];        CPLFree( papoLayers );    CPLFree( pszName );    CPLFree( pszPath );    CSLDestroy( papszOptions );    CSLDestroy( papszModules );    delete poSpatialRef;}/************************************************************************//*                              AddLayer()                              *//************************************************************************/void OGRTigerDataSource::AddLayer( OGRTigerLayer * poNewLayer ){    papoLayers = (OGRTigerLayer **)        CPLRealloc( papoLayers, sizeof(void*) * ++nLayers );        papoLayers[nLayers-1] = poNewLayer;}/************************************************************************//*                              GetLayer()                              *//************************************************************************/OGRLayer *OGRTigerDataSource::GetLayer( int iLayer ){    if( iLayer < 0 || iLayer >= nLayers )        return NULL;    else        return papoLayers[iLayer];}/************************************************************************//*                              GetLayer()                              *//************************************************************************/OGRLayer *OGRTigerDataSource::GetLayer( const char *pszLayerName ){    for( int iLayer = 0; iLayer < nLayers; iLayer++ )    {        if( EQUAL(papoLayers[iLayer]->GetLayerDefn()->GetName(),pszLayerName) )            return papoLayers[iLayer];    }    return NULL;}/************************************************************************//*                           GetLayerCount()                            *//************************************************************************/int OGRTigerDataSource::GetLayerCount(){    return nLayers;}/************************************************************************//*                                Open()                                *//************************************************************************/int OGRTigerDataSource::Open( const char * pszFilename, int bTestOpen,                              char ** papszLimitedFileList ){    VSIStatBuf      stat;    char            **papszFileList = NULL;    int             i;    pszName = CPLStrdup( pszFilename );/* -------------------------------------------------------------------- *//*      Is the given path a directory or a regular file?                *//* -------------------------------------------------------------------- */    if( CPLStat( pszFilename, &stat ) != 0         || (!VSI_ISDIR(stat.st_mode) && !VSI_ISREG(stat.st_mode)) )    {        if( !bTestOpen )            CPLError( CE_Failure, CPLE_AppDefined,                   "%s is neither a file or directory, Tiger access failed.\n",                      pszFilename );        return FALSE;    }    /* -------------------------------------------------------------------- *//*      Build a list of filenames we figure are Tiger files.            *//* -------------------------------------------------------------------- */    if( VSI_ISREG(stat.st_mode) )    {        char       szModule[128];        pszPath = CPLStrdup( CPLGetPath(pszFilename) );        strncpy( szModule, CPLGetFilename(pszFilename), sizeof(szModule)-1 );        szModule[strlen(szModule)-1] = '\0';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -