?? ogrsdtslayer.cpp
字號:
/****************************************************************************** * $Id: ogrsdtslayer.cpp 10646 2007-01-18 02:38:10Z warmerdam $ * * Project: SDTSReader * Purpose: Implements OGRSDTSLayer class. * 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 "ogr_sdts.h"#include "cpl_conv.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrsdtslayer.cpp 10646 2007-01-18 02:38:10Z warmerdam $");/************************************************************************//* OGRSDTSLayer() *//* *//* Note that the OGRSDTSLayer assumes ownership of the passed *//* OGRFeatureDefn object. *//************************************************************************/OGRSDTSLayer::OGRSDTSLayer( SDTSTransfer * poTransferIn, int iLayerIn, OGRSDTSDataSource * poDSIn ){ poDS = poDSIn; poTransfer = poTransferIn; iLayer = iLayerIn; poReader = poTransfer->GetLayerIndexedReader( iLayer );/* -------------------------------------------------------------------- *//* Define the feature. *//* -------------------------------------------------------------------- */ int iCATDEntry = poTransfer->GetLayerCATDEntry( iLayer ); poFeatureDefn = new OGRFeatureDefn(poTransfer->GetCATD()->GetEntryModule(iCATDEntry)); poFeatureDefn->Reference(); OGRFieldDefn oRecId( "RCID", OFTInteger ); poFeatureDefn->AddFieldDefn( &oRecId ); if( poTransfer->GetLayerType(iLayer) == SLTPoint ) { poFeatureDefn->SetGeomType( wkbPoint ); } else if( poTransfer->GetLayerType(iLayer) == SLTLine ) { poFeatureDefn->SetGeomType( wkbLineString ); oRecId.SetName( "SNID" ); poFeatureDefn->AddFieldDefn( &oRecId ); oRecId.SetName( "ENID" ); poFeatureDefn->AddFieldDefn( &oRecId ); } else if( poTransfer->GetLayerType(iLayer) == SLTPoly ) { poFeatureDefn->SetGeomType( wkbPolygon ); } else if( poTransfer->GetLayerType(iLayer) == SLTAttr ) { poFeatureDefn->SetGeomType( wkbNone ); }/* -------------------------------------------------------------------- *//* Add schema from referenced attribute records. *//* -------------------------------------------------------------------- */ char **papszATIDRefs = NULL; if( poTransfer->GetLayerType(iLayer) != SLTAttr ) papszATIDRefs = poReader->ScanModuleReferences(); else papszATIDRefs = CSLAddString( papszATIDRefs, poTransfer->GetCATD()->GetEntryModule(iCATDEntry) ); for( int iTable = 0; papszATIDRefs != NULL && papszATIDRefs[iTable] != NULL; iTable++ ) { SDTSAttrReader *poAttrReader; DDFFieldDefn *poFDefn; /* -------------------------------------------------------------------- *//* Get the attribute table reader, and the associated user *//* attribute field. *//* -------------------------------------------------------------------- */ poAttrReader = (SDTSAttrReader *) poTransfer->GetLayerIndexedReader( poTransfer->FindLayer( papszATIDRefs[iTable] ) ); if( poAttrReader == NULL ) continue; poFDefn = poAttrReader->GetModule()->FindFieldDefn( "ATTP" ); if( poFDefn == NULL ) poFDefn = poAttrReader->GetModule()->FindFieldDefn( "ATTS" ); if( poFDefn == NULL ) continue; /* -------------------------------------------------------------------- *//* Process each user subfield on the attribute table into an *//* OGR field definition. *//* -------------------------------------------------------------------- */ for( int iSF=0; iSF < poFDefn->GetSubfieldCount(); iSF++ ) { DDFSubfieldDefn *poSFDefn = poFDefn->GetSubfield( iSF ); int nWidth = poSFDefn->GetWidth(); char *pszFieldName; if( poFeatureDefn->GetFieldIndex( poSFDefn->GetName() ) != -1 ) pszFieldName = CPLStrdup( CPLSPrintf( "%s_%s", papszATIDRefs[iTable], poSFDefn->GetName() ) ); else pszFieldName = CPLStrdup( poSFDefn->GetName() ); switch( poSFDefn->GetType() ) { case DDFString: { OGRFieldDefn oStrField( pszFieldName, OFTString ); if( nWidth != 0 ) oStrField.SetWidth( nWidth ); } break; case DDFInt: { OGRFieldDefn oIntField( pszFieldName, OFTInteger ); if( nWidth != 0 ) oIntField.SetWidth( nWidth ); poFeatureDefn->AddFieldDefn( &oIntField ); } break; case DDFFloat: { OGRFieldDefn oRealField( pszFieldName, OFTReal ); // We don't have a precision in DDF files, so we never even // use the width. Otherwise with a precision of zero the // result would look like an integer. poFeatureDefn->AddFieldDefn( &oRealField ); } break; default: break; } CPLFree( pszFieldName ); } /* next iSF (subfield) */ } /* next iTable */ CSLDestroy( papszATIDRefs );}/************************************************************************//* ~OGRSDTSLayer() *//************************************************************************/OGRSDTSLayer::~OGRSDTSLayer(){ if( m_nFeaturesRead > 0 && poFeatureDefn != NULL ) { CPLDebug( "SDTS", "%d features read on layer '%s'.", (int) m_nFeaturesRead, poFeatureDefn->GetName() ); } if( poFeatureDefn ) poFeatureDefn->Release();}/************************************************************************//* ResetReading() *//************************************************************************/void OGRSDTSLayer::ResetReading(){ poReader->Rewind();}/************************************************************************//* AssignAttrRecordToFeature() *//************************************************************************/static voidAssignAttrRecordToFeature( OGRFeature * poFeature, SDTSTransfer * poTransfer, DDFField * poSR ){/* -------------------------------------------------------------------- *//* Process each subfield in the record. *//* -------------------------------------------------------------------- */ DDFFieldDefn *poFDefn = poSR->GetFieldDefn(); for( int iSF=0; iSF < poFDefn->GetSubfieldCount(); iSF++ ) { DDFSubfieldDefn *poSFDefn = poFDefn->GetSubfield( iSF ); int iField; int nMaxBytes; const char * pachData = poSR->GetSubfieldData(poSFDefn, &nMaxBytes);/* -------------------------------------------------------------------- *//* Indentify this field on the feature. *//* -------------------------------------------------------------------- */ iField = poFeature->GetFieldIndex( poSFDefn->GetName() );/* -------------------------------------------------------------------- *//* Handle each of the types. *//* -------------------------------------------------------------------- */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -