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

📄 ogrociloaderlayer.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** * $Id: ogrociloaderlayer.cpp,v 1.4 2005/02/10 15:46:02 fwarmerdam Exp $ * * Project:  Oracle Spatial Driver * Purpose:  Implementation of the OGROCILoaderLayer class.  This implements *           an output only OGRLayer for writing an SQL*Loader file. * 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: ogrociloaderlayer.cpp,v $ * Revision 1.4  2005/02/10 15:46:02  fwarmerdam * added GEOMETRY_NAME layer creation option * * Revision 1.3  2003/04/11 18:20:57  warmerda * added external dat file in VARIABLE mode * * Revision 1.2  2003/04/04 22:04:28  warmerda * added incomplete support for variable mode * * Revision 1.1  2003/04/04 06:17:47  warmerda * New * */#include "ogr_oci.h"#include "cpl_conv.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrociloaderlayer.cpp,v 1.4 2005/02/10 15:46:02 fwarmerdam Exp $");/************************************************************************//*                         OGROCILoaderLayer()                          *//************************************************************************/OGROCILoaderLayer::OGROCILoaderLayer( OGROCIDataSource *poDSIn,                                       const char * pszTableName,                                      const char * pszGeomColIn,                                      int nSRIDIn,                                       const char *pszLoaderFilenameIn ){    poDS = poDSIn;    iNextFIDToWrite = 1;    bTruncationReported = FALSE;    bHeaderWritten = FALSE;    nLDRMode = LDRM_UNKNOWN;    poFeatureDefn = new OGRFeatureDefn( pszTableName );    poFeatureDefn->Reference();        pszGeomName = CPLStrdup( pszGeomColIn );    pszFIDName = CPLStrdup( "OGR_FID" );    nSRID = nSRIDIn;    poSRS = poDSIn->FetchSRS( nSRID );    if( poSRS != NULL )        poSRS->Reference();/* -------------------------------------------------------------------- *//*      Open the loader file.                                           *//* -------------------------------------------------------------------- */    pszLoaderFilename = CPLStrdup( pszLoaderFilenameIn );    fpData = NULL;    fpLoader = VSIFOpen( pszLoaderFilename, "wt" );    if( fpLoader == NULL )    {        CPLError( CE_Failure, CPLE_OpenFailed,                   "Failed to open SQL*Loader control file:%s",                   pszLoaderFilename );        return;    }}/************************************************************************//*                         ~OGROCILoaderLayer()                         *//************************************************************************/OGROCILoaderLayer::~OGROCILoaderLayer(){    if( fpData != NULL )        VSIFClose( fpData );    if( fpLoader != NULL )    {        VSIFClose( fpLoader );        FinalizeNewLayer();    }    CPLFree( pszLoaderFilename );    if( poSRS != NULL && poSRS->Dereference() == 0 )        delete poSRS;}/************************************************************************//*                         WriteLoaderHeader()                          *//************************************************************************/void OGROCILoaderLayer::WriteLoaderHeader(){    if( bHeaderWritten )        return;/* -------------------------------------------------------------------- *//*      Determine name of geometry column to use.                       *//* -------------------------------------------------------------------- */    const char *pszGeometryName =         CSLFetchNameValue( papszOptions, "GEOMETRY_NAME" );    if( pszGeometryName == NULL )        pszGeometryName = "ORA_GEOMETRY";/* -------------------------------------------------------------------- *//*      Dermine our operation mode.                                     *//* -------------------------------------------------------------------- */    const char *pszLDRMode = CSLFetchNameValue( papszOptions, "LOADER_MODE" );        if( pszLDRMode != NULL && EQUAL(pszLDRMode,"VARIABLE") )        nLDRMode = LDRM_VARIABLE;    else if( pszLDRMode != NULL && EQUAL(pszLDRMode,"BINARY") )        nLDRMode = LDRM_BINARY;    else        nLDRMode = LDRM_STREAM;/* -------------------------------------------------------------------- *//*      Write loader header info.                                       *//* -------------------------------------------------------------------- */    VSIFPrintf( fpLoader, "LOAD DATA\n" );    if( nLDRMode == LDRM_STREAM )    {        VSIFPrintf( fpLoader, "INFILE *\n" );        VSIFPrintf( fpLoader, "CONTINUEIF NEXT(1:1) = '#'\n" );    }    else if( nLDRMode == LDRM_VARIABLE )    {        const char *pszDataFilename = CPLResetExtension( pszLoaderFilename,                                                          "dat" );        fpData = VSIFOpen( pszDataFilename, "wb" );        if( fpData == NULL )        {            CPLError( CE_Failure, CPLE_OpenFailed,                       "Unable to open data output file `%s'.",                       pszDataFilename );            return;        }                    VSIFPrintf( fpLoader, "INFILE %s \"var 8\"\n", pszDataFilename );    }    VSIFPrintf( fpLoader, "INTO TABLE \"%s\" REPLACE\n",                 poFeatureDefn->GetName() );    VSIFPrintf( fpLoader, "FIELDS TERMINATED BY '|'\n" );    VSIFPrintf( fpLoader, "TRAILING NULLCOLS (\n" );    VSIFPrintf( fpLoader, "    ogr_fid INTEGER EXTERNAL,\n" );    VSIFPrintf( fpLoader, "    %s COLUMN OBJECT (\n",                pszGeometryName );    VSIFPrintf( fpLoader, "      SDO_GTYPE INTEGER EXTERNAL,\n" );    VSIFPrintf( fpLoader, "      SDO_ELEM_INFO VARRAY TERMINATED BY '|/'\n" );    VSIFPrintf( fpLoader, "        (elements INTEGER EXTERNAL),\n" );    VSIFPrintf( fpLoader, "      SDO_ORDINATES VARRAY TERMINATED BY '|/'\n" );    VSIFPrintf( fpLoader, "        (ordinates FLOAT EXTERNAL)\n" );    VSIFPrintf( fpLoader, "    ),\n" );/* -------------------------------------------------------------------- *//*      Write user field schema.                                        *//* -------------------------------------------------------------------- */    int iField;    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )    {        OGRFieldDefn *poFldDefn = poFeatureDefn->GetFieldDefn(iField);        if( poFldDefn->GetType() == OFTInteger )        {            VSIFPrintf( fpLoader, "    \"%s\" INTEGER EXTERNAL",                         poFldDefn->GetNameRef() );        }        else if( poFldDefn->GetType() == OFTReal )        {            VSIFPrintf( fpLoader, "    \"%s\" FLOAT EXTERNAL",                         poFldDefn->GetNameRef() );        }        else if( poFldDefn->GetType() == OFTString )        {            VSIFPrintf( fpLoader, "    \"%s\" VARCHARC(4)",                         poFldDefn->GetNameRef() );        }        else        {            VSIFPrintf( fpLoader, "    \"%s\" VARCHARC(4)",                         poFldDefn->GetNameRef() );        }        if( iField < poFeatureDefn->GetFieldCount() - 1 )            VSIFPrintf( fpLoader, "," );        VSIFPrintf( fpLoader, "\n" );    }    VSIFPrintf( fpLoader, ")\n" );    if( nLDRMode == LDRM_STREAM )        VSIFPrintf( fpLoader, "begindata\n" );    bHeaderWritten = TRUE;}/************************************************************************//*                           GetNextFeature()                           *//*                                                                      *//*      We override the next feature method because we know that we     *//*      implement the attribute query within the statement and so we    *//*      don't have to test here.   Eventually the spatial query will    *//*      be fully tested within the statement as well.                   *//************************************************************************/OGRFeature *OGROCILoaderLayer::GetNextFeature(){    CPLError( CE_Failure, CPLE_NotSupported,               "GetNextFeature() not supported for an OGROCILoaderLayer." );    return NULL;}/************************************************************************//*                            ResetReading()                            *//************************************************************************/void OGROCILoaderLayer::ResetReading(){    OGROCILayer::ResetReading();}/************************************************************************//*                       WriteFeatureStreamMode()                       *//************************************************************************/OGRErr OGROCILoaderLayer::WriteFeatureStreamMode( OGRFeature *poFeature ){/* -------------------------------------------------------------------- *//*      Write the FID.                                                  *//* -------------------------------------------------------------------- */    VSIFPrintf( fpLoader, " %d|", poFeature->GetFID() );/* -------------------------------------------------------------------- *//*      Set the geometry                                                *//* -------------------------------------------------------------------- */    int  nLineLen = 0;    if( poFeature->GetGeometryRef() != NULL)    {        char szSRID[128];        int  nGType;        int  i;        if( nSRID == -1 )            strcpy( szSRID, "NULL" );        else            sprintf( szSRID, "%d", nSRID );        if( TranslateToSDOGeometry( poFeature->GetGeometryRef(), &nGType )            == OGRERR_NONE )        {            VSIFPrintf( fpLoader, "%d|", nGType );            for( i = 0; i < nElemInfoCount; i++ )            {                VSIFPrintf( fpLoader, "%d|", panElemInfo[i] );                if( ++nLineLen > 18 && i < nElemInfoCount-1 )                {                    VSIFPrintf( fpLoader, "\n#" );                    nLineLen = 0;                }            }            VSIFPrintf( fpLoader, "/" );            for( i = 0; i < nOrdinalCount; i++ )            {                VSIFPrintf( fpLoader, "%.16g|", padfOrdinals[i] );                if( ++nLineLen > 6 && i < nOrdinalCount-1 )                {                    VSIFPrintf( fpLoader, "\n#" );                    nLineLen = 0;                }            }            VSIFPrintf( fpLoader, "/" );        }        else        {            VSIFPrintf( fpLoader, "0|/|/" );        }    }    else    {        VSIFPrintf( fpLoader, "0|/|/" );    }/* -------------------------------------------------------------------- *//*      Set the other fields.                                           *//* -------------------------------------------------------------------- */    int i;    nLineLen = 0;    VSIFPrintf( fpLoader, "\n#" );    for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ )    {        OGRFieldDefn *poFldDefn = poFeatureDefn->GetFieldDefn(i);        if( !poFeature->IsFieldSet( i ) )        {            if( poFldDefn->GetType() != OFTInteger                 && poFldDefn->GetType() != OFTReal )                VSIFPrintf( fpLoader, "%04d", 0 );            continue;        }        const char *pszStrValue = poFeature->GetFieldAsString(i);        if( nLineLen > 70 )        {

⌨️ 快捷键说明

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