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

📄 ogrocidatasource.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    {        delete poLayer;        return FALSE;    }/* -------------------------------------------------------------------- *//*      Add layer to data source layer list.                            *//* -------------------------------------------------------------------- */    papoLayers = (OGROCILayer **)        CPLRealloc( papoLayers,  sizeof(OGROCILayer *) * (nLayers+1) );    papoLayers[nLayers++] = poLayer;    return TRUE;}/************************************************************************//*                           ValidateLayer()                            *//************************************************************************/void OGROCIDataSource::ValidateLayer( const char *pszLayerName ){    int iLayer;/* -------------------------------------------------------------------- *//*      Try to find layer.                                              *//* -------------------------------------------------------------------- */    for( iLayer = 0; iLayer < nLayers; iLayer++ )    {        if( EQUAL(pszLayerName,papoLayers[iLayer]->GetLayerDefn()->GetName()) )            break;    }    if( iLayer == nLayers )    {        CPLError( CE_Failure, CPLE_AppDefined,                   "ValidateLayer(): %s is not a recognised layer.",                   pszLayerName );        return;    }/* -------------------------------------------------------------------- *//*      Verify we have an FID and geometry column for this table.       *//* -------------------------------------------------------------------- */    OGROCITableLayer *poLayer = (OGROCITableLayer *) papoLayers[iLayer];    if( poLayer->GetFIDName() == NULL || poLayer->GetGeomName() == NULL )    {        CPLError( CE_Failure, CPLE_AppDefined,                   "ValidateLayer(): %s lacks a geometry or fid column.",                   pszLayerName );        return;    }/* -------------------------------------------------------------------- *//*      Prepare and execute the geometry validation.                    *//* -------------------------------------------------------------------- */    OGROCIStringBuf oValidateCmd;    OGROCIStatement oValidateStmt( GetSession() );    oValidateCmd.Append( "SELECT c." );    oValidateCmd.Append( poLayer->GetFIDName() );    oValidateCmd.Append( ", SDO_GEOM.VALIDATE_GEOMETRY(c." );    oValidateCmd.Append( poLayer->GetGeomName() );    oValidateCmd.Append( ", m.diminfo) from " );    oValidateCmd.Append( poLayer->GetLayerDefn()->GetName() );    oValidateCmd.Append( " c, user_sdo_geom_metadata m WHERE m.table_name= '");    oValidateCmd.Append( poLayer->GetLayerDefn()->GetName() );    oValidateCmd.Append( "' AND m.column_name = '" );    oValidateCmd.Append( poLayer->GetGeomName() );    oValidateCmd.Append( "' AND SDO_GEOM.VALIDATE_GEOMETRY(c." );    oValidateCmd.Append( poLayer->GetGeomName() );    oValidateCmd.Append( ", m.diminfo ) <> 'TRUE'" );    oValidateStmt.Execute( oValidateCmd.GetString() );/* -------------------------------------------------------------------- *//*      Report results to debug stream.                                 *//* -------------------------------------------------------------------- */    char **papszRow;    while( (papszRow = oValidateStmt.SimpleFetchRow()) != NULL )    {        const char *pszReason = papszRow[1];        if( EQUAL(pszReason,"13011") )            pszReason = "13011: value is out of range";        else if( EQUAL(pszReason,"13050") )            pszReason = "13050: unable to construct spatial object";        else if( EQUAL(pszReason,"13349") )            pszReason = "13349: polygon boundary crosses itself";        CPLDebug( "OCI", "Validation failure for FID=%s: %s",                   papszRow[0], pszReason );    }}/************************************************************************//*                            DeleteLayer()                             *//************************************************************************/void OGROCIDataSource::DeleteLayer( const char *pszLayerName ){    int iLayer;/* -------------------------------------------------------------------- *//*      Try to find layer.                                              *//* -------------------------------------------------------------------- */    for( iLayer = 0; iLayer < nLayers; iLayer++ )    {        if( EQUAL(pszLayerName,papoLayers[iLayer]->GetLayerDefn()->GetName()) )        {            pszLayerName = CPLStrdup(papoLayers[iLayer]->GetLayerDefn()->GetName());            break;        }    }    if( iLayer == nLayers )        return;/* -------------------------------------------------------------------- *//*      Blow away our OGR structures related to the layer.  This is     *//*      pretty dangerous if anything has a reference to this layer!     *//* -------------------------------------------------------------------- */    CPLDebug( "OCI", "DeleteLayer(%s)", pszLayerName );    delete papoLayers[iLayer];    memmove( papoLayers + iLayer, papoLayers + iLayer + 1,              sizeof(void *) * (nLayers - iLayer - 1) );    nLayers--;/* -------------------------------------------------------------------- *//*      Remove from the database.                                       *//* -------------------------------------------------------------------- */    OGROCIStatement oCommand( poSession );    char            szCommand[1024];    sprintf( szCommand, "DROP TABLE \"%s\"", pszLayerName );    oCommand.Execute( szCommand );    sprintf( szCommand,              "DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = '%s'",              pszLayerName );    oCommand.Execute( szCommand );    CPLFree( (char *) pszLayerName );}/************************************************************************//*                            CreateLayer()                             *//************************************************************************/OGRLayer *OGROCIDataSource::CreateLayer( const char * pszLayerName,                               OGRSpatialReference *poSRS,                               OGRwkbGeometryType eType,                               char ** papszOptions ){    char                szCommand[1024];    char               *pszSafeLayerName = CPLStrdup(pszLayerName);    poSession->CleanName( pszSafeLayerName );/* -------------------------------------------------------------------- *//*      Do we already have this layer?  If so, should we blow it        *//*      away?                                                           *//* -------------------------------------------------------------------- */    int iLayer;    for( iLayer = 0; iLayer < nLayers; iLayer++ )    {        if( EQUAL(pszSafeLayerName,                  papoLayers[iLayer]->GetLayerDefn()->GetName()) )        {            if( CSLFetchNameValue( papszOptions, "OVERWRITE" ) != NULL                && !EQUAL(CSLFetchNameValue(papszOptions,"OVERWRITE"),"NO") )            {                DeleteLayer( pszSafeLayerName );            }            else            {                CPLError( CE_Failure, CPLE_AppDefined,                           "Layer %s already exists, CreateLayer failed.\n"                          "Use the layer creation option OVERWRITE=YES to "                          "replace it.",                          pszSafeLayerName );                CPLFree( pszSafeLayerName );                return NULL;            }        }    }/* -------------------------------------------------------------------- *//*      Try to get the SRS Id of this spatial reference system,         *//*      adding tot the srs table if needed.                             *//* -------------------------------------------------------------------- */    char szSRSId[100];    if( CSLFetchNameValue( papszOptions, "SRID" ) != NULL )        strcpy( szSRSId, CSLFetchNameValue( papszOptions, "SRID" ) );         else if( poSRS != NULL )        sprintf( szSRSId, "%d", FetchSRSId( poSRS ) );    else        strcpy( szSRSId, "NULL" );/* -------------------------------------------------------------------- *//*      Determine name of geometry column to use.                       *//* -------------------------------------------------------------------- */    const char *pszGeometryName =         CSLFetchNameValue( papszOptions, "GEOMETRY_NAME" );    if( pszGeometryName == NULL )        pszGeometryName = "ORA_GEOMETRY";/* -------------------------------------------------------------------- *//*      Create a basic table with the FID.  Also include the            *//*      geometry if this is not a PostGIS enabled table.                *//* -------------------------------------------------------------------- */       OGROCIStatement oStatement( poSession );        sprintf( szCommand,              "CREATE TABLE \"%s\" ( "             "OGR_FID INTEGER, "             "%s %s )",             pszSafeLayerName, pszGeometryName, SDO_GEOMETRY );    if( oStatement.Execute( szCommand ) != CE_None )    {        CPLFree( pszSafeLayerName );        return NULL;    }/* -------------------------------------------------------------------- *//*      Create the layer object.                                        *//* -------------------------------------------------------------------- */    const char *pszLoaderFile = CSLFetchNameValue(papszOptions,"LOADER_FILE");    OGROCIWritableLayer *poLayer;    if( pszLoaderFile == NULL )        poLayer = new OGROCITableLayer( this, pszSafeLayerName,                                         EQUAL(szSRSId,"NULL") ? -1 : atoi(szSRSId),                                        TRUE, TRUE );    else        poLayer =             new OGROCILoaderLayer( this, pszSafeLayerName,                                    pszGeometryName,                                   EQUAL(szSRSId,"NULL") ? -1 : atoi(szSRSId),                                   pszLoaderFile );/* -------------------------------------------------------------------- *//*      Set various options on the layer.                               *//* -------------------------------------------------------------------- */    poLayer->SetLaunderFlag( CSLFetchBoolean(papszOptions,"LAUNDER",FALSE) );    poLayer->SetPrecisionFlag( CSLFetchBoolean(papszOptions,"PRECISION",TRUE));    if( CSLFetchNameValue(papszOptions,"DIM") != NULL )        poLayer->SetDimension( atoi(CSLFetchNameValue(papszOptions,"DIM")) );    poLayer->SetOptions( papszOptions );/* -------------------------------------------------------------------- *//*      Add layer to data source layer list.                            *//* -------------------------------------------------------------------- */    papoLayers = (OGROCILayer **)        CPLRealloc( papoLayers,  sizeof(OGROCILayer *) * (nLayers+1) );        papoLayers[nLayers++] = poLayer;    CPLFree( pszSafeLayerName );    return poLayer;}/************************************************************************//*                           TestCapability()                           *//************************************************************************/int OGROCIDataSource::TestCapability( const char * pszCap ){    if( EQUAL(pszCap,ODsCCreateLayer) && bDSUpdate )        return TRUE;    else        return FALSE;}/************************************************************************//*                              GetLayer()                              *//************************************************************************/OGRLayer *OGROCIDataSource::GetLayer( int iLayer ){    if( iLayer < 0 || iLayer >= nLayers )        return NULL;    else        return papoLayers[iLayer];}/************************************************************************//*                             ExecuteSQL()                             *//************************************************************************/OGRLayer * OGROCIDataSource::ExecuteSQL( const char *pszSQLCommand,                                        OGRGeometry *poSpatialFilter,                                        const char *pszDialect ){/* -------------------------------------------------------------------- *//*      Use generic implementation for OGRSQL dialect.                  *//* -------------------------------------------------------------------- */

⌨️ 快捷键说明

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