?? ogrdodssequencelayer.cpp
字號:
/****************************************************************************** * $Id: ogrdodssequencelayer.cpp 10646 2007-01-18 02:38:10Z warmerdam $ * * Project: OGR/DODS Interface * Purpose: Implements OGRDODSSequenceLayer class, which implements the * "Simple Sequence" access strategy. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2003, 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 "cpl_conv.h"#include "ogr_dods.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrdodssequencelayer.cpp 10646 2007-01-18 02:38:10Z warmerdam $");/************************************************************************//* OGRDODSSequenceLayer() *//************************************************************************/OGRDODSSequenceLayer::OGRDODSSequenceLayer( OGRDODSDataSource *poDSIn, const char *pszTargetIn, AttrTable *poOGRLayerInfoIn ) : OGRDODSLayer( poDSIn, pszTargetIn, poOGRLayerInfoIn ){ pszSubSeqPath = "profile"; // hardcode for now. panSubSeqSize = NULL; iLastSuperSeq = -1;/* -------------------------------------------------------------------- *//* What is the layer name? *//* -------------------------------------------------------------------- */ string oLayerName; const char *pszLayerName = pszTargetIn; if( poOGRLayerInfo != NULL ) { oLayerName = poOGRLayerInfo->get_attr( "layer_name" ); if( strlen(oLayerName.c_str()) > 0 ) pszLayerName = oLayerName.c_str(); } poFeatureDefn = new OGRFeatureDefn( pszLayerName ); poFeatureDefn->Reference();/* -------------------------------------------------------------------- *//* Fetch the target variable. *//* -------------------------------------------------------------------- */ Sequence *seq = dynamic_cast<Sequence *>(poDS->poDDS->var( pszTargetIn )); poTargetVar = seq; poSuperSeq = FindSuperSequence( seq );/* -------------------------------------------------------------------- *//* X/Y/Z fields. *//* -------------------------------------------------------------------- */ if( poOGRLayerInfo != NULL ) { AttrTable *poField = poOGRLayerInfo->find_container("x_field"); if( poField != NULL ) oXField.Initialize( poField, poTargetVar, poSuperSeq ); poField = poOGRLayerInfo->find_container("y_field"); if( poField != NULL ) oYField.Initialize( poField, poTargetVar, poSuperSeq ); poField = poOGRLayerInfo->find_container("z_field"); if( poField != NULL ) oZField.Initialize( poField, poTargetVar, poSuperSeq ); }/* -------------------------------------------------------------------- *//* If we have no layerinfo, then check if there are obvious x/y *//* fields. *//* -------------------------------------------------------------------- */ else { string oTargName = pszTargetIn; string oSSTargName; string x, y; if( poSuperSeq != NULL ) oSSTargName = OGRDODSGetVarPath( poSuperSeq ); else oSSTargName = "impossiblexxx"; if( poDS->poDDS->var( oTargName + ".lon" ) != NULL && poDS->poDDS->var( oTargName + ".lat" ) != NULL ) { oXField.Initialize( (oTargName + ".lon").c_str(), "dds", poTargetVar, poSuperSeq ); oYField.Initialize( (oTargName + ".lat").c_str(), "dds", poTargetVar, poSuperSeq ); } else if( poDS->poDDS->var( oSSTargName + ".lon" ) != NULL && poDS->poDDS->var( oSSTargName + ".lat" ) != NULL ) { oXField.Initialize( (oSSTargName + ".lon").c_str(), "dds", poTargetVar, poSuperSeq ); oYField.Initialize( (oSSTargName + ".lat").c_str(), "dds", poTargetVar, poSuperSeq ); } }/* -------------------------------------------------------------------- *//* Add fields for the contents of the sequence. *//* -------------------------------------------------------------------- */ Sequence::Vars_iter v_i; for( v_i = seq->var_begin(); v_i != seq->var_end(); v_i++ ) BuildFields( *v_i, NULL, NULL );/* -------------------------------------------------------------------- *//* Add fields for the contents of the super-sequence if we have *//* one. *//* -------------------------------------------------------------------- */ if( poSuperSeq != NULL ) { for( v_i = poSuperSeq->var_begin(); v_i != poSuperSeq->var_end(); v_i++ ) BuildFields( *v_i, NULL, NULL ); }}/************************************************************************//* ~OGRDODSSequenceLayer() *//************************************************************************/OGRDODSSequenceLayer::~OGRDODSSequenceLayer(){}/************************************************************************//* FindSuperSequence() *//* *//* Are we a subsequence of a sequence? *//************************************************************************/Sequence *OGRDODSSequenceLayer::FindSuperSequence( BaseType *poChild ){ BaseType *poParent; for( poParent = poChild->get_parent(); poParent != NULL; poParent = poParent->get_parent() ) { if( poParent->type() == dods_sequence_c ) { return dynamic_cast<Sequence *>( poParent ); } } return NULL;}/************************************************************************//* BuildFields() *//* *//* Build the field definition or definitions corresponding to *//* the passed variable and it's children (if it has them). *//************************************************************************/int OGRDODSSequenceLayer::BuildFields( BaseType *poFieldVar, const char *pszPathToVar, const char *pszPathToSequence ) { OGRFieldDefn oField( "", OFTInteger );/* -------------------------------------------------------------------- *//* Setup field name, including path if non-local. *//* -------------------------------------------------------------------- */ if( pszPathToVar == NULL ) oField.SetName( poFieldVar->name().c_str() ); else oField.SetName( CPLSPrintf( "%s.%s", pszPathToVar, poFieldVar->name().c_str() ) ); /* -------------------------------------------------------------------- *//* Capture this field definition. *//* -------------------------------------------------------------------- */ switch( poFieldVar->type() ) { case dods_byte_c: case dods_int16_c: case dods_uint16_c: case dods_int32_c: case dods_uint32_c: if( pszPathToSequence ) oField.SetType( OFTIntegerList ); else oField.SetType( OFTInteger ); break; case dods_float32_c: case dods_float64_c: if( pszPathToSequence ) oField.SetType( OFTRealList ); else oField.SetType( OFTReal ); break; case dods_str_c: case dods_url_c: if( pszPathToSequence ) oField.SetType( OFTStringList ); else oField.SetType( OFTString ); break; case dods_sequence_c: { Sequence *seq = dynamic_cast<Sequence *>( poFieldVar ); Sequence::Vars_iter v_i; // We don't support a 3rd level of sequence nesting. if( pszPathToSequence != NULL ) return FALSE; // We don't explore down into the target sequence if we // are recursing from a supersequence. if( poFieldVar == this->poTargetVar ) return FALSE; for( v_i = seq->var_begin(); v_i != seq->var_end(); v_i++ ) { BuildFields( *v_i, oField.GetNameRef(), oField.GetNameRef() ); } } return FALSE; default: return FALSE; }/* -------------------------------------------------------------------- *//* Add field to feature defn, and capture mapping. *//* -------------------------------------------------------------------- */ poFeatureDefn->AddFieldDefn( &oField ); papoFields = (OGRDODSFieldDefn **) CPLRealloc( papoFields, sizeof(void*) * poFeatureDefn->GetFieldCount()); papoFields[poFeatureDefn->GetFieldCount()-1] = new OGRDODSFieldDefn(); papoFields[poFeatureDefn->GetFieldCount()-1]->Initialize( OGRDODSGetVarPath(poFieldVar).c_str(), "dds", poTargetVar, poSuperSeq ); if( pszPathToSequence ) papoFields[poFeatureDefn->GetFieldCount()-1]->pszPathToSequence = CPLStrdup( pszPathToSequence ); return TRUE;}/************************************************************************//* GetFieldValue() *//************************************************************************/BaseType *OGRDODSSequenceLayer::GetFieldValue( OGRDODSFieldDefn *poFDefn, int nFeatureId, Sequence *seq ){ if( seq == NULL ) seq = dynamic_cast<Sequence *>(poTargetVar); if( !poFDefn->bValid ) return NULL;/* ==================================================================== *//* Fetch the actual value. *//* ==================================================================== *//* -------------------------------------------------------------------- *//* Simple case of a direct field within the sequence object. *//* -------------------------------------------------------------------- */ if( poFDefn->iFieldIndex >= 0 && poFDefn->bRelativeToSequence ) { return seq->var_value( nFeatureId, poFDefn->iFieldIndex ); } else if( poFDefn->iFieldIndex >= 0 && poFDefn->bRelativeToSuperSequence ) { return poSuperSeq->var_value( iLastSuperSeq, poFDefn->iFieldIndex ); }/* -------------------------------------------------------------------- *//* More complex case where we need to drill down by name. *//* -------------------------------------------------------------------- */ if( poFDefn->bRelativeToSequence ) return seq->var_value( nFeatureId, poFDefn->pszFieldName ); else if( poSuperSeq != NULL && poFDefn->bRelativeToSuperSequence ) return poSuperSeq->var_value( iLastSuperSeq, poFDefn->pszFieldName ); else return poDataDDS->var( poFDefn->pszFieldName );}/************************************************************************//* BaseTypeToDouble() *//************************************************************************/double OGRDODSSequenceLayer::BaseTypeToDouble( BaseType *poBT ){ switch( poBT->type() ) { case dods_byte_c: { signed char byVal; void *pValPtr = &byVal; poBT->buf2val( &pValPtr ); return (double) byVal; } break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -