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

📄 ntf_generic.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** * $Id: ntf_generic.cpp,v 1.19 2002/10/29 03:28:59 warmerda Exp $ * * Project:  NTF Translator * Purpose:  Handle NTF products that aren't recognised generically. * Author:   Frank Warmerdam, warmerda@home.com * ****************************************************************************** * Copyright (c) 1999, Frank Warmerdam * * 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: ntf_generic.cpp,v $ * Revision 1.19  2002/10/29 03:28:59  warmerda * fixed 2.5D flag * * Revision 1.18  2002/10/02 20:48:39  warmerda * Added support for GENERIC_CPOLY layer * * Revision 1.17  2002/08/26 20:15:56  warmerda * fixed _LIST if attributes split over multiple records for one feature * * Revision 1.16  2002/02/08 20:43:06  warmerda * improved error checking and propagation * * Revision 1.15  2001/12/11 20:37:49  warmerda * add option to avoid caching indexed records on multiple readers * * Revision 1.14  2001/08/28 20:50:03  warmerda * expand tabs * * Revision 1.13  2001/08/23 14:47:31  warmerda * Added support for adding an _LIST attribute to the OGRFeatures in * cases of GENERIC features for which an attribute appears more than * once per features.  This has occured with the SAMPE1250.NTF Irish * dataset which has multiple feature codes for some line features. * * Revision 1.12  2001/07/18 04:55:16  warmerda * added CPL_CSVID * * Revision 1.11  2001/05/01 15:09:33  warmerda * raised MAX_LINK from 200 to 5000, added error reporting * * Revision 1.10  2001/05/01 13:47:36  warmerda * keep track if generic geometry is 3D * * Revision 1.9  2001/04/30 15:10:43  warmerda * added support for 3D geometry * * Revision 1.8  2001/02/06 14:30:48  warmerda * don't crash if polygons missing point geometry * * Revision 1.7  2001/01/19 20:31:12  warmerda * expand tabs * * Revision 1.6  2001/01/17 19:08:37  warmerda * added CODELIST support * * Revision 1.5  1999/10/04 18:17:16  warmerda * Fixed redeclaration of for loop variables. * * Revision 1.4  1999/10/04 03:07:34  warmerda * added text_ht_ground and rename TX TEXT and FC FEAT_CODE * * Revision 1.3  1999/10/03 01:12:50  warmerda * ensure generic translators are attached to all files in a set * * Revision 1.2  1999/10/03 01:02:56  warmerda * added NAMEREC and COLLECT handling * * Revision 1.1  1999/10/01 14:45:42  warmerda * New * */#include <stdarg.h>#include "ntf.h"#include "cpl_string.h"CPL_CVSID("$Id: ntf_generic.cpp,v 1.19 2002/10/29 03:28:59 warmerda Exp $");#define MAX_LINK        5000/************************************************************************//* ==================================================================== *//*                          NTFGenericClass                             *//*                                                                      *//*      The NTFGenericClass class exists to hold aggregated             *//*      information for each type of record encountered in a set of     *//*      NTF files, primarily the list of attributes actually            *//*      encountered.                                                    *//* ==================================================================== *//************************************************************************//************************************************************************//*                           NTFGenericClass                            *//************************************************************************/NTFGenericClass::NTFGenericClass(){    nFeatureCount = 0;    b3D = FALSE;    nAttrCount = 0;    papszAttrNames = NULL;    papszAttrFormats = NULL;    panAttrMaxWidth = NULL;    pabAttrMultiple = NULL;}/************************************************************************//*                           ~NTFGenericClass                           *//************************************************************************/NTFGenericClass::~NTFGenericClass(){    CSLDestroy( papszAttrNames );    CSLDestroy( papszAttrFormats );    CPLFree( panAttrMaxWidth );    CPLFree( pabAttrMultiple );}/************************************************************************//*                            CheckAddAttr()                            *//*                                                                      *//*      Check if an attribute already exists.  If not add it with       *//*      it's format.  Note we don't check for format conflicts at       *//*      this time.                                                      *//************************************************************************/void NTFGenericClass::CheckAddAttr( const char * pszName,                                    const char * pszFormat,                                    int nWidth ){    int         iAttrOffset;    if( EQUAL(pszName,"TX") )        pszName = "TEXT";    if( EQUAL(pszName,"FC") )        pszName = "FEAT_CODE";    iAttrOffset = CSLFindString( papszAttrNames, pszName );        if( iAttrOffset == -1 )    {        nAttrCount++;        papszAttrNames = CSLAddString( papszAttrNames, pszName );        papszAttrFormats = CSLAddString( papszAttrFormats, pszFormat );        panAttrMaxWidth = (int *)            CPLRealloc( panAttrMaxWidth, sizeof(int) * nAttrCount );        panAttrMaxWidth[nAttrCount-1] = nWidth;        pabAttrMultiple = (int *)            CPLRealloc( pabAttrMultiple, sizeof(int) * nAttrCount );        pabAttrMultiple[nAttrCount-1] = FALSE;    }    else    {        if( panAttrMaxWidth[iAttrOffset] < nWidth )            panAttrMaxWidth[iAttrOffset] = nWidth;    }}/************************************************************************//*                            SetMultiple()                             *//*                                                                      *//*      Mark this attribute as appearing multiple times on some         *//*      features.                                                       *//************************************************************************/void NTFGenericClass::SetMultiple( const char *pszName ){    int         iAttrOffset;    if( EQUAL(pszName,"TX") )        pszName = "TEXT";    if( EQUAL(pszName,"FC") )        pszName = "FEAT_CODE";    iAttrOffset = CSLFindString( papszAttrNames, pszName );    if( iAttrOffset == -1 )        return;    pabAttrMultiple[iAttrOffset] = TRUE;}/************************************************************************//*                           WorkupGeneric()                            *//*                                                                      *//*      Scan a whole file, in order to build up a list of attributes    *//*      for the generic types.                                          *//************************************************************************/void OGRNTFDataSource::WorkupGeneric( NTFFileReader * poReader ){    NTFRecord   **papoGroup = NULL;    if( poReader->GetNTFLevel() > 2 )    {        poReader->IndexFile();        if( CPLGetLastErrorType() == CE_Failure )            return;    }    else        poReader->Reset();/* ==================================================================== *//*      Read all record groups in the file.                             *//* ==================================================================== */    while( TRUE )    {/* -------------------------------------------------------------------- *//*      Read a record group                                             *//* -------------------------------------------------------------------- */        if( poReader->GetNTFLevel() > 2 )            papoGroup = poReader->GetNextIndexedRecordGroup(papoGroup);        else            papoGroup = poReader->ReadRecordGroup();        if( papoGroup == NULL || papoGroup[0]->GetType() == 99 )            break;        /* -------------------------------------------------------------------- *//*      Get the class corresponding to the anchor record.               *//* -------------------------------------------------------------------- */        NTFGenericClass *poClass = GetGClass( papoGroup[0]->GetType() );        char           **papszFullAttList = NULL;        poClass->nFeatureCount++;        /* -------------------------------------------------------------------- *//*      Loop over constituent records collecting attributes.            *//* -------------------------------------------------------------------- */        for( int iRec = 0; papoGroup[iRec] != NULL; iRec++ )        {            NTFRecord   *poRecord = papoGroup[iRec];            switch( poRecord->GetType() )            {              case NRT_ATTREC:              {                  char  **papszTypes, **papszValues;                  poReader->ProcessAttRec( poRecord, NULL,                                           &papszTypes, &papszValues );                  for( int iAtt = 0; papszTypes[iAtt] != NULL; iAtt++ )                  {                      NTFAttDesc        *poAttDesc;                      poAttDesc = poReader->GetAttDesc( papszTypes[iAtt] );                      if( poAttDesc != NULL )                      {                          poClass->CheckAddAttr( poAttDesc->val_type,                                                 poAttDesc->finter,                                                 strlen(papszValues[iAtt]) );                      }                      if( CSLFindString( papszFullAttList,                                          papszTypes[iAtt] ) == -1 )                          papszFullAttList =                               CSLAddString( papszFullAttList,                                             papszTypes[iAtt] );                      else                          poClass->SetMultiple( poAttDesc->val_type );                  }                  CSLDestroy( papszTypes );                  CSLDestroy( papszValues );              }              break;              case NRT_TEXTREP:              case NRT_NAMEPOSTN:                poClass->CheckAddAttr( "FONT", "I4", 4 );                poClass->CheckAddAttr( "TEXT_HT", "R3,1", 3 );                poClass->CheckAddAttr( "TEXT_HT_GROUND", "R9,3", 9 );                poClass->CheckAddAttr( "TEXT_HT", "R3,1", 3 );                poClass->CheckAddAttr( "DIG_POSTN", "I1", 1 );                poClass->CheckAddAttr( "ORIENT", "R4,1", 4 );                break;              case NRT_NAMEREC:                poClass->CheckAddAttr( "TEXT", "A*",                                       atoi(poRecord->GetField(13,14)) );                break;              case NRT_GEOMETRY:              case NRT_GEOMETRY3D:                  if( atoi(poRecord->GetField(3,8)) != 0 )                      poClass->CheckAddAttr( "GEOM_ID", "I6", 6 );                  if( poRecord->GetType() == NRT_GEOMETRY3D )                      poClass->b3D = TRUE;                  break;              case NRT_POINTREC:              case NRT_LINEREC:                if( poReader->GetNTFLevel() < 3 )                {                    NTFAttDesc  *poAttDesc;                                          poAttDesc = poReader->GetAttDesc(poRecord->GetField(9,10));                    if( poAttDesc != NULL )                        poClass->CheckAddAttr( poAttDesc->val_type,                                               poAttDesc->finter, 6 );                    if( !EQUAL(poRecord->GetField(17,20),"    ") )                        poClass->CheckAddAttr( "FEAT_CODE", "A4", 4 );                }                break;                              default:                break;            }        }        CSLDestroy( papszFullAttList );    }    if( GetOption("CACHING") != NULL        && EQUAL(GetOption("CACHING"),"OFF") )        poReader->DestroyIndex();    poReader->Reset();}/************************************************************************/

⌨️ 快捷键说明

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