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

📄 ogrdodsgrid.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** * $Id: ogrdodsgrid.cpp,v 1.6 2005/02/22 12:57:39 fwarmerdam Exp $ * * Project:  OGR/DODS Interface * Purpose:  Implements OGRDODSGridLayer class, which implements the *           "Grid/Array" access strategy. * Author:   Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2004, 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: ogrdodsgrid.cpp,v $ * Revision 1.6  2005/02/22 12:57:39  fwarmerdam * use OGRLayer base spatial filter support * * Revision 1.5  2005/02/02 20:54:26  fwarmerdam * track m_nFeaturesRead * * Revision 1.4  2004/03/23 18:08:17  warmerda * Fixed row/column major orientedness of data for multi-dimensional arrays. * * Revision 1.3  2004/02/19 13:57:21  warmerda * complete support for extra_containers * * Revision 1.2  2004/02/17 18:47:05  warmerda * added geometry support * * Revision 1.1  2004/02/17 16:22:19  warmerda * New * */#include "cpl_conv.h"#include "ogr_dods.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrdodsgrid.cpp,v 1.6 2005/02/22 12:57:39 fwarmerdam Exp $");/************************************************************************//*                          OGRDODSGridLayer()                          *//************************************************************************/OGRDODSGridLayer::OGRDODSGridLayer( OGRDODSDataSource *poDSIn,                                             const char *pszTargetIn,                                            AttrTable *poOGRLayerInfoIn )        : OGRDODSLayer( poDSIn, pszTargetIn, poOGRLayerInfoIn ){    pRawData = NULL;/* -------------------------------------------------------------------- *//*      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.                                      *//* -------------------------------------------------------------------- */    BaseType *poTargVar = poDS->oDDS.var( pszTargetIn );    if( poTargVar->type() == dods_grid_c )    {        poTargetGrid = dynamic_cast<Grid *>( poTargVar );        poTargetArray = dynamic_cast<Array *>(poTargetGrid->array_var());    }    else if( poTargVar->type() == dods_array_c )    {        poTargetGrid = NULL;        poTargetArray = dynamic_cast<Array *>( poTargVar );    }    else    {        CPLAssert( FALSE );        return;    }/* -------------------------------------------------------------------- *//*      Count arrays in use.                                            *//* -------------------------------------------------------------------- */    AttrTable *poExtraContainers = NULL;    nArrayRefCount = 1; // primary target.    if( poOGRLayerInfo != NULL )        poExtraContainers = poOGRLayerInfo->find_container("extra_containers");    if( poExtraContainers != NULL )    {        AttrTable::Attr_iter dv_i;        for( dv_i = poExtraContainers->attr_begin();              dv_i != poExtraContainers->attr_end(); dv_i++ )        {            nArrayRefCount++;        }    }/* -------------------------------------------------------------------- *//*      Collect extra_containers.                                       *//* -------------------------------------------------------------------- */    paoArrayRefs = new OGRDODSArrayRef[nArrayRefCount];    paoArrayRefs[0].pszName = CPLStrdup( pszTargetIn );    paoArrayRefs[0].poArray = poTargetArray;    nArrayRefCount = 1;    if( poExtraContainers != NULL )    {        AttrTable::Attr_iter dv_i;        for( dv_i = poExtraContainers->attr_begin();              dv_i != poExtraContainers->attr_end(); dv_i++ )        {            const char *pszTargetName=poExtraContainers->get_attr(dv_i).c_str();            BaseType *poExtraTarget = poDS->oDDS.var( pszTargetName );            if( poExtraTarget == NULL )            {                CPLError( CE_Warning, CPLE_AppDefined,                           "Unable to find extra_container '%s', skipping.",                           pszTargetName );                continue;            }            if( poExtraTarget->type() == dods_array_c )                paoArrayRefs[nArrayRefCount].poArray =                     dynamic_cast<Array *>( poExtraTarget );            else if( poExtraTarget->type() == dods_grid_c )            {                Grid *poGrid = dynamic_cast<Grid *>( poExtraTarget );                paoArrayRefs[nArrayRefCount].poArray =                     dynamic_cast<Array *>( poGrid->array_var() );            }            else            {                CPLError( CE_Warning, CPLE_AppDefined,                           "Target container '%s' is not grid or array, skipping.",                           pszTargetName );                continue;            }            paoArrayRefs[nArrayRefCount++].pszName = CPLStrdup(pszTargetName);        }    }/* -------------------------------------------------------------------- *//*      Collect dimension information.                                  *//* -------------------------------------------------------------------- */    int iDim;    Array::Dim_iter iterDim;    nDimCount = poTargetArray->dimensions();    paoDimensions = new OGRDODSDim[nDimCount];    nMaxRawIndex = 1;    for( iterDim = poTargetArray->dim_begin(), iDim = 0;         iterDim != poTargetArray->dim_end();          iterDim++, iDim++ )    {        paoDimensions[iDim].pszDimName =             CPLStrdup(poTargetArray->dimension_name(iterDim).c_str());        paoDimensions[iDim].nDimStart =             poTargetArray->dimension_start(iterDim);        paoDimensions[iDim].nDimEnd =             poTargetArray->dimension_stop(iterDim);        paoDimensions[iDim].nDimStride =             poTargetArray->dimension_stride(iterDim);        paoDimensions[iDim].poMap = NULL;        paoDimensions[iDim].nDimEntries =             (paoDimensions[iDim].nDimEnd + 1 - paoDimensions[iDim].nDimStart             + paoDimensions[iDim].nDimStride - 1)             / paoDimensions[iDim].nDimStride;        nMaxRawIndex *= paoDimensions[iDim].nDimEntries;    }/* -------------------------------------------------------------------- *//*      If we are working with a grid, collect the maps.                *//* -------------------------------------------------------------------- */    if( poTargetGrid != NULL )    {        int iMap;        Grid::Map_iter iterMap;        for( iterMap = poTargetGrid->map_begin(), iMap = 0;             iterMap != poTargetGrid->map_end();              iterMap++, iMap++ )        {            paoDimensions[iMap].poMap = dynamic_cast<Array *>(*iterMap);        }        CPLAssert( iMap == nDimCount );    }/* -------------------------------------------------------------------- *//*      Setup field definitions.  The first nDimCount will be the       *//*      dimension attributes, and after that comes the actual target    *//*      array.                                                          *//* -------------------------------------------------------------------- */    for( iDim = 0; iDim < nDimCount; iDim++ )    {        OGRFieldDefn oField( paoDimensions[iDim].pszDimName, OFTInteger );        if( EQUAL(oField.GetNameRef(), poTargetArray->name().c_str()) )            oField.SetName(CPLSPrintf("%s_i",paoDimensions[iDim].pszDimName));        if( paoDimensions[iDim].poMap != NULL )        {            switch( paoDimensions[iDim].poMap->var()->type() )            {              case dods_byte_c:              case dods_int16_c:              case dods_uint16_c:              case dods_int32_c:              case dods_uint32_c:                oField.SetType( OFTInteger );                break;              case dods_float32_c:              case dods_float64_c:                oField.SetType( OFTReal );                break;              case dods_str_c:              case dods_url_c:                oField.SetType( OFTString );                break;              default:                // Ignore                break;            }        }        poFeatureDefn->AddFieldDefn( &oField );    }/* -------------------------------------------------------------------- *//*      Setup the array attributes themselves.                          *//* -------------------------------------------------------------------- */    int iArray;    for( iArray=0; iArray < nArrayRefCount; iArray++ )    {        OGRDODSArrayRef *poRef = paoArrayRefs + iArray;        OGRFieldDefn oArrayField( poRef->poArray->name().c_str(), OFTInteger );                switch( poRef->poArray->var()->type() )        {          case dods_byte_c:          case dods_int16_c:          case dods_uint16_c:          case dods_int32_c:          case dods_uint32_c:            oArrayField.SetType( OFTInteger );            break;          case dods_float32_c:          case dods_float64_c:            oArrayField.SetType( OFTReal );            break;          case dods_str_c:          case dods_url_c:            oArrayField.SetType( OFTString );            break;          default:            // Ignore            break;        }        poFeatureDefn->AddFieldDefn( &oArrayField );        poRef->iFieldIndex = poFeatureDefn->GetFieldCount() - 1;    }/* -------------------------------------------------------------------- *//*      X/Y/Z fields.                                                   *//* -------------------------------------------------------------------- */    if( poOGRLayerInfo != NULL )    {

⌨️ 快捷键说明

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