?? ntf_generic.cpp
字號:
/****************************************************************************** * $Id: ntf_generic.cpp 10646 2007-01-18 02:38:10Z warmerdam $ * * Project: NTF Translator * Purpose: Handle NTF products that aren't recognised generically. * Author: Frank Warmerdam, warmerdam@pobox.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. ****************************************************************************/#include <stdarg.h>#include "ntf.h"#include "cpl_string.h"CPL_CVSID("$Id: ntf_generic.cpp 10646 2007-01-18 02:38:10Z warmerdam $");#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();}/************************************************************************//* AddGenericAttributes() *//************************************************************************/static void AddGenericAttributes( NTFFileReader * poReader, NTFRecord **papoGroup, OGRFeature * poFeature ){ char **papszTypes, **papszValues; if( !poReader->ProcessAttRecGroup( papoGroup, &papszTypes, &papszValues ) ) return; for( int iAtt = 0; papszTypes != NULL && papszTypes[iAtt] != NULL; iAtt++ ) { int iField; if( EQUAL(papszTypes[iAtt],"TX") ) iField = poFeature->GetFieldIndex("TEXT"); else if( EQUAL(papszTypes[iAtt],"FC") ) iField = poFeature->GetFieldIndex("FEAT_CODE"); else iField = poFeature->GetFieldIndex(papszTypes[iAtt]); if( iField == -1 ) continue; poReader->ApplyAttributeValue( poFeature, iField, papszTypes[iAtt], papszTypes, papszValues );/* -------------------------------------------------------------------- *//* Do we have a corresponding list field we should be *//* accumulating this into? *//* -------------------------------------------------------------------- */ char szListName[128]; int iListField; sprintf( szListName, "%s_LIST", poFeature->GetFieldDefnRef(iField)->GetNameRef() ); iListField = poFeature->GetFieldIndex( szListName );/* -------------------------------------------------------------------- */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -