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

📄 ogrdodssequencelayer.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{    switch( poBT->type() )    {      case dods_byte_c:      {          signed char byVal;          void *pValPtr = &byVal;                        poBT->buf2val( &pValPtr );          return (double) byVal;      }      break;      case dods_int16_c:      {          GInt16 nIntVal;          void *pValPtr = &nIntVal;                        poBT->buf2val( &pValPtr );          return (double) nIntVal;      }      break;      case dods_uint16_c:      {          GUInt16 nIntVal;          void *pValPtr = &nIntVal;                        poBT->buf2val( &pValPtr );          return (double) nIntVal;      }      break;      case dods_int32_c:      {          GInt32 nIntVal;          void *pValPtr = &nIntVal;                        poBT->buf2val( &pValPtr );          return (double) nIntVal;      }      break;      case dods_uint32_c:      {          GUInt32 nIntVal;          void *pValPtr = &nIntVal;                        poBT->buf2val( &pValPtr );          return (double) nIntVal;      }      break;      case dods_float32_c:        return dynamic_cast<Float32 *>(poBT)->value();      case dods_float64_c:        return dynamic_cast<Float64 *>(poBT)->value();      case dods_str_c:      case dods_url_c:      {          string *poStrVal = NULL;          double dfResult;          poBT->buf2val( (void **) &poStrVal );          dfResult = atof(poStrVal->c_str());          delete poStrVal;          return dfResult;      }      break;      default:        CPLAssert( FALSE );        break;    }    return 0.0;}/************************************************************************//*                       GetFieldValueAsDouble()                        *//************************************************************************/double OGRDODSSequenceLayer::GetFieldValueAsDouble( OGRDODSFieldDefn *poFDefn,                                                    int nFeatureId ){    BaseType *poBT;    poBT = GetFieldValue( poFDefn, nFeatureId, NULL );    if( poBT == NULL )        return 0.0;    return BaseTypeToDouble( poBT );}/************************************************************************//*                             GetFeature()                             *//************************************************************************/OGRFeature *OGRDODSSequenceLayer::GetFeature( long nFeatureId ){/* -------------------------------------------------------------------- *//*      Ensure we have the dataset.                                     *//* -------------------------------------------------------------------- */    if( !ProvideDataDDS() )        return NULL;    Sequence *seq = dynamic_cast<Sequence *>(poTargetVar);/* -------------------------------------------------------------------- *//*      Figure out what the super and subsequence number this           *//*      feature will be, and validate it.  If there is not super        *//*      sequence the feature id is the subsequence number.              *//* -------------------------------------------------------------------- */    int iSubSeq = -1;    if( nFeatureId < 0 || nFeatureId >= nRecordCount )        return NULL;    if( poSuperSeq == NULL )        iSubSeq = nFeatureId;    else    {        int nSeqOffset = 0, iSuperSeq;        // for now we just scan through till find find out what        // super sequence this in.  In the long term we need a better (cached)        // approach that doesn't involve this quadratic cost.        for( iSuperSeq = 0;              iSuperSeq < nSuperSeqCount;              iSuperSeq++ )        {            if( nSeqOffset + panSubSeqSize[iSuperSeq] > nFeatureId )            {                iSubSeq = nFeatureId - nSeqOffset;                break;            }            nSeqOffset += panSubSeqSize[iSuperSeq];        }        CPLAssert( iSubSeq != -1 );        // Make sure we have the right target var ... the one         // corresponding to our current super sequence.         if( iSuperSeq != iLastSuperSeq )        {            iLastSuperSeq = iSuperSeq;            poTargetVar = poSuperSeq->var_value( iSuperSeq, pszSubSeqPath );            seq = dynamic_cast<Sequence *>(poTargetVar);        }    }/* -------------------------------------------------------------------- *//*      Create the feature being read.                                  *//* -------------------------------------------------------------------- */    OGRFeature *poFeature;    poFeature = new OGRFeature( poFeatureDefn );    poFeature->SetFID( nFeatureId );    m_nFeaturesRead++;/* -------------------------------------------------------------------- *//*      Process all the regular data fields.                            *//* -------------------------------------------------------------------- */    int      iField;    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )    {        if( papoFields[iField]->pszPathToSequence )            continue;        BaseType *poFieldVar = GetFieldValue( papoFields[iField], iSubSeq,                                              NULL );        if( poFieldVar == NULL )            continue;        switch( poFieldVar->type() )        {          case dods_byte_c:          {              signed char byVal;              void *pValPtr = &byVal;                            poFieldVar->buf2val( &pValPtr );              poFeature->SetField( iField, byVal );          }          break;          case dods_int16_c:          {              GInt16 nIntVal;              void *pValPtr = &nIntVal;                            poFieldVar->buf2val( &pValPtr );              poFeature->SetField( iField, nIntVal );          }          break;          case dods_uint16_c:          {              GUInt16 nIntVal;              void *pValPtr = &nIntVal;                            poFieldVar->buf2val( &pValPtr );              poFeature->SetField( iField, nIntVal );          }          break;          case dods_int32_c:          {              GInt32 nIntVal;              void *pValPtr = &nIntVal;                            poFieldVar->buf2val( &pValPtr );              poFeature->SetField( iField, nIntVal );          }          break;          case dods_uint32_c:          {              GUInt32 nIntVal;              void *pValPtr = &nIntVal;                            poFieldVar->buf2val( &pValPtr );              poFeature->SetField( iField, (int) nIntVal );          }          break;          case dods_float32_c:            poFeature->SetField( iField,                                  dynamic_cast<Float32 *>(poFieldVar)->value());            break;          case dods_float64_c:            poFeature->SetField( iField,                                  dynamic_cast<Float64 *>(poFieldVar)->value());            break;          case dods_str_c:          case dods_url_c:          {              string *poStrVal = NULL;              poFieldVar->buf2val( (void **) &poStrVal );              poFeature->SetField( iField, poStrVal->c_str() );              delete poStrVal;          }          break;          default:            break;        }    }    /* -------------------------------------------------------------------- *//*      Handle data nested in sequences.                                *//* -------------------------------------------------------------------- */    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )    {        OGRDODSFieldDefn *poFD = papoFields[iField];        const char *pszPathFromSubSeq;        if( poFD->pszPathToSequence == NULL )            continue;        CPLAssert( strlen(poFD->pszPathToSequence)                    < strlen(poFD->pszFieldName)-1 );        if( strstr(poFD->pszFieldName,poFD->pszPathToSequence) != NULL )            pszPathFromSubSeq =                 strstr(poFD->pszFieldName,poFD->pszPathToSequence)                + strlen(poFD->pszPathToSequence) + 1;        else            continue;/* -------------------------------------------------------------------- *//*      Get the sequence out of which this variable will be collected.  *//* -------------------------------------------------------------------- */        BaseType *poFieldVar = seq->var_value( iSubSeq,                                                poFD->pszPathToSequence );        Sequence *poSubSeq;        int nSubSeqCount;        if( poFieldVar == NULL )            continue;        poSubSeq = dynamic_cast<Sequence *>( poFieldVar );        if( poSubSeq == NULL )            continue;        nSubSeqCount = poSubSeq->number_of_rows();            /* -------------------------------------------------------------------- *//*      Allocate array to put values into.                              *//* -------------------------------------------------------------------- */        OGRFieldDefn *poOFD = poFeature->GetFieldDefnRef( iField );        int *panIntList = NULL;        double *padfDblList = NULL;        char **papszStrList = NULL;        if( poOFD->GetType() == OFTIntegerList )        {            panIntList = (int *) CPLCalloc(sizeof(int),nSubSeqCount);        }        else if( poOFD->GetType() == OFTRealList )        {            padfDblList = (double *) CPLCalloc(sizeof(double),nSubSeqCount);        }        else if( poOFD->GetType() == OFTStringList )        {            papszStrList = (char **) CPLCalloc(sizeof(char*),nSubSeqCount+1);        }        else            continue;/* -------------------------------------------------------------------- *//*      Loop, fetching subsequence values.                              *//* -------------------------------------------------------------------- */        int iSubIndex;        for( iSubIndex = 0; iSubIndex < nSubSeqCount; iSubIndex++ )        {            poFieldVar = poSubSeq->var_value( iSubIndex, pszPathFromSubSeq );            if( poFieldVar == NULL )                continue;            switch( poFieldVar->type() )            {              case dods_byte_c:              {                  signed char byVal;                  void *pValPtr = &byVal;                                    poFieldVar->buf2val( &pValPtr );                  panIntList[iSubIndex] = byVal;              }              break;                            case dods_int16_c:              {                  GInt16 nIntVal;                  void *pValPtr = &nIntVal;                                    poFieldVar->buf2val( &pValPtr );                  panIntList[iSubIndex] = nIntVal;              }

⌨️ 快捷键说明

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