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

📄 ogrdodssequencelayer.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** * $Id: ogrdodssequencelayer.cpp,v 1.6 2005/02/02 20:54:26 fwarmerdam Exp $ * * 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. ****************************************************************************** * * $Log: ogrdodssequencelayer.cpp,v $ * Revision 1.6  2005/02/02 20:54:26  fwarmerdam * track m_nFeaturesRead * * Revision 1.5  2004/03/17 18:16:30  warmerda * added support for linestring from nested seq, and floating point validity tests * * Revision 1.4  2004/03/12 22:13:07  warmerda * major upgrade with normalized sequen nested sequence support * * Revision 1.3  2004/01/29 21:01:03  warmerda * added sequences within sequences support * * Revision 1.2  2004/01/22 21:16:06  warmerda * fixed up auto-lat/lon support * * Revision 1.1  2004/01/21 20:08:29  warmerda * New * */#include "cpl_conv.h"#include "ogr_dods.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrdodssequencelayer.cpp,v 1.6 2005/02/02 20:54:26 fwarmerdam Exp $");/************************************************************************//*                        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 );/* -------------------------------------------------------------------- *//*      Fetch the target variable.                                      *//* -------------------------------------------------------------------- */    Sequence *seq = dynamic_cast<Sequence *>(poDS->oDDS.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->oDDS.var( oTargName + ".lon" ) != NULL             && poDS->oDDS.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->oDDS.var( oSSTargName + ".lon" ) != NULL                  && poDS->oDDS.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 oDataDDS.var( poFDefn->pszFieldName );}/************************************************************************//*                          BaseTypeToDouble()                          *//************************************************************************/double OGRDODSSequenceLayer::BaseTypeToDouble( BaseType *poBT )

⌨️ 快捷键说明

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