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

📄 s57reader.cpp

📁 支持各种栅格图像和矢量图像读取的库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************** * $Id: s57reader.cpp 10646 2007-01-18 02:38:10Z warmerdam $ * * Project:  S-57 Translator * Purpose:  Implements S57Reader class. * Author:   Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 1999, 2001, 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 "s57.h"#include "ogr_api.h"#include "cpl_conv.h"#include "cpl_string.h"#include <string>#include <fstream>CPL_CVSID("$Id: s57reader.cpp 10646 2007-01-18 02:38:10Z warmerdam $");#ifndef PI#define PI  3.14159265358979323846#endif/************************************************************************//*                             S57Reader()                              *//************************************************************************/S57Reader::S57Reader( const char * pszFilename ){    pszModuleName = CPLStrdup( pszFilename );    pszDSNM = NULL;    poModule = NULL;    nFDefnCount = 0;    papoFDefnList = NULL;    nCOMF = 1000000;    nSOMF = 10;    poRegistrar = NULL;    bFileIngested = FALSE;    nNextFEIndex = 0;    nNextVIIndex = 0;    nNextVCIndex = 0;    nNextVEIndex = 0;    nNextVFIndex = 0;    nNextDSIDIndex = 0;    poDSIDRecord = NULL;    poDSPMRecord = NULL;    szUPDNUpdate[0] = '\0';    iPointOffset = 0;    poMultiPoint = NULL;    papszOptions = NULL;    nOptionFlags = S57M_UPDATES;    bMissingWarningIssued = FALSE;    bAttrWarningIssued = FALSE;    memset( apoFDefnByOBJL, 0, sizeof(apoFDefnByOBJL) );}/************************************************************************//*                             ~S57Reader()                             *//************************************************************************/S57Reader::~S57Reader(){    Close();        CPLFree( pszModuleName );    CSLDestroy( papszOptions );    CPLFree( papoFDefnList );}/************************************************************************//*                                Open()                                *//************************************************************************/int S57Reader::Open( int bTestOpen ){    if( poModule != NULL )    {        Rewind();        return TRUE;    }    poModule = new DDFModule();    if( !poModule->Open( pszModuleName ) )    {        // notdef: test bTestOpen.        delete poModule;        poModule = NULL;        return FALSE;    }    // note that the following won't work for catalogs.    if( poModule->FindFieldDefn("DSID") == NULL )    {        if( !bTestOpen )        {            CPLError( CE_Failure, CPLE_AppDefined,                      "%s is an ISO8211 file, but not an S-57 data file.\n",                      pszModuleName );        }        delete poModule;        poModule = NULL;        return FALSE;    }    // Make sure the FSPT field is marked as repeating.    DDFFieldDefn *poFSPT = poModule->FindFieldDefn( "FSPT" );    if( poFSPT != NULL && !poFSPT->IsRepeating() )    {        CPLDebug( "S57", "Forcing FSPT field to be repeating." );        poFSPT->SetRepeatingFlag( TRUE );    }    nNextFEIndex = 0;    nNextVIIndex = 0;    nNextVCIndex = 0;    nNextVEIndex = 0;    nNextVFIndex = 0;    nNextDSIDIndex = 0;        return TRUE;}/************************************************************************//*                               Close()                                *//************************************************************************/void S57Reader::Close(){    if( poModule != NULL )    {        oVI_Index.Clear();        oVC_Index.Clear();        oVE_Index.Clear();        oVF_Index.Clear();        oFE_Index.Clear();        if( poDSIDRecord != NULL )        {            delete poDSIDRecord;            poDSIDRecord = NULL;        }        if( poDSPMRecord != NULL )        {            delete poDSPMRecord;            poDSPMRecord = NULL;        }        ClearPendingMultiPoint();        delete poModule;        poModule = NULL;        bFileIngested = FALSE;        CPLFree( pszDSNM );        pszDSNM = NULL;    }}/************************************************************************//*                       ClearPendingMultiPoint()                       *//************************************************************************/void S57Reader::ClearPendingMultiPoint(){    if( poMultiPoint != NULL )    {        delete poMultiPoint;        poMultiPoint = NULL;    }}/************************************************************************//*                       NextPendingMultiPoint()                        *//************************************************************************/OGRFeature *S57Reader::NextPendingMultiPoint(){    CPLAssert( poMultiPoint != NULL );    CPLAssert( wkbFlatten(poMultiPoint->GetGeometryRef()->getGeometryType())                                                        == wkbMultiPoint );    OGRFeatureDefn *poDefn = poMultiPoint->GetDefnRef();    OGRFeature  *poPoint = new OGRFeature( poDefn );    OGRMultiPoint *poMPGeom = (OGRMultiPoint *) poMultiPoint->GetGeometryRef();    OGRPoint    *poSrcPoint;    poPoint->SetFID( poMultiPoint->GetFID() );        for( int i = 0; i < poDefn->GetFieldCount(); i++ )    {        poPoint->SetField( i, poMultiPoint->GetRawFieldRef(i) );    }    poSrcPoint = (OGRPoint *) poMPGeom->getGeometryRef( iPointOffset++ );    poPoint->SetGeometry( poSrcPoint );    if( poPoint != NULL )        poPoint->SetField( "DEPTH", poSrcPoint->getZ() );    if( iPointOffset >= poMPGeom->getNumGeometries() )        ClearPendingMultiPoint();    return poPoint;}/************************************************************************//*                             SetOptions()                             *//************************************************************************/void S57Reader::SetOptions( char ** papszOptionsIn ){    const char * pszOptionValue;        CSLDestroy( papszOptions );    papszOptions = CSLDuplicate( papszOptionsIn );    pszOptionValue = CSLFetchNameValue( papszOptions, S57O_SPLIT_MULTIPOINT );    if( pszOptionValue != NULL && !EQUAL(pszOptionValue,"OFF") )        nOptionFlags |= S57M_SPLIT_MULTIPOINT;    else        nOptionFlags &= ~S57M_SPLIT_MULTIPOINT;    pszOptionValue = CSLFetchNameValue( papszOptions, S57O_ADD_SOUNDG_DEPTH );    if( pszOptionValue != NULL && !EQUAL(pszOptionValue,"OFF") )        nOptionFlags |= S57M_ADD_SOUNDG_DEPTH;    else        nOptionFlags &= ~S57M_ADD_SOUNDG_DEPTH;    CPLAssert( ! (nOptionFlags & S57M_ADD_SOUNDG_DEPTH)               || (nOptionFlags & S57M_SPLIT_MULTIPOINT) );    pszOptionValue = CSLFetchNameValue( papszOptions, S57O_LNAM_REFS );    if( pszOptionValue != NULL && !EQUAL(pszOptionValue,"OFF") )        nOptionFlags |= S57M_LNAM_REFS;    else        nOptionFlags &= ~S57M_LNAM_REFS;    pszOptionValue = CSLFetchNameValue( papszOptions, S57O_UPDATES );    if( pszOptionValue == NULL )        /* no change */;    else if( pszOptionValue != NULL && !EQUAL(pszOptionValue,"APPLY") )        nOptionFlags &= ~S57M_UPDATES;    else        nOptionFlags |= S57M_UPDATES;    pszOptionValue = CSLFetchNameValue(papszOptions,                                        S57O_PRESERVE_EMPTY_NUMBERS);    if( pszOptionValue != NULL && !EQUAL(pszOptionValue,"OFF") )        nOptionFlags |= S57M_PRESERVE_EMPTY_NUMBERS;    else        nOptionFlags &= ~S57M_PRESERVE_EMPTY_NUMBERS;    pszOptionValue = CSLFetchNameValue( papszOptions, S57O_RETURN_PRIMITIVES );    if( pszOptionValue != NULL && CSLTestBoolean(pszOptionValue) )        nOptionFlags |= S57M_RETURN_PRIMITIVES;    else        nOptionFlags &= ~S57M_RETURN_PRIMITIVES;    pszOptionValue = CSLFetchNameValue( papszOptions, S57O_RETURN_LINKAGES );    if( pszOptionValue != NULL && CSLTestBoolean(pszOptionValue) )        nOptionFlags |= S57M_RETURN_LINKAGES;    else        nOptionFlags &= ~S57M_RETURN_LINKAGES;    pszOptionValue = CSLFetchNameValue( papszOptions, S57O_RETURN_DSID );    if( pszOptionValue == NULL || CSLTestBoolean(pszOptionValue) )        nOptionFlags |= S57M_RETURN_DSID;    else        nOptionFlags &= ~S57M_RETURN_DSID;}/************************************************************************//*                           SetClassBased()                            *//************************************************************************/void S57Reader::SetClassBased( S57ClassRegistrar * poReg ){    poRegistrar = poReg;}/************************************************************************//*                               Rewind()                               *//************************************************************************/void S57Reader::Rewind(){    ClearPendingMultiPoint();    nNextFEIndex = 0;    nNextVIIndex = 0;    nNextVCIndex = 0;    nNextVEIndex = 0;    nNextVFIndex = 0;    nNextDSIDIndex = 0;}/************************************************************************//*                               Ingest()                               *//*                                                                      *//*      Read all the records into memory, adding to the appropriate     *//*      indexes.                                                        *//************************************************************************/void S57Reader::Ingest(){    DDFRecord   *poRecord;        if( poModule == NULL || bFileIngested )        return;/* -------------------------------------------------------------------- *//*      Read all the records in the module, and place them in           *//*      appropriate indexes.                                            *//* -------------------------------------------------------------------- */    while( (poRecord = poModule->ReadRecord()) != NULL )    {        DDFField        *poKeyField = poRecord->GetField(1);                if( EQUAL(poKeyField->GetFieldDefn()->GetName(),"VRID") )        {            int         nRCNM = poRecord->GetIntSubfield( "VRID",0, "RCNM",0);            int         nRCID = poRecord->GetIntSubfield( "VRID",0, "RCID",0);

⌨️ 快捷键说明

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