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

📄 ogrocitablelayer.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*                          SetSpatialFilter()                          *//************************************************************************/void OGROCITableLayer::SetSpatialFilter( OGRGeometry * poGeomIn ){    if( !InstallFilter( poGeomIn ) )        return;    BuildWhere();    ResetReading();}/************************************************************************//*                        TestForSpatialIndex()                         *//************************************************************************/void OGROCITableLayer::TestForSpatialIndex( const char *pszSpatWHERE ){    OGROCIStringBuf oTestCmd;    OGROCIStatement oTestStatement( poDS->GetSession() );            oTestCmd.Append( "SELECT COUNT(*) FROM " );    oTestCmd.Append( poFeatureDefn->GetName() );    oTestCmd.Append( pszSpatWHERE );    if( oTestStatement.Execute( oTestCmd.GetString() ) != CE_None )        bHaveSpatialIndex = FALSE;    else        bHaveSpatialIndex = TRUE;}/************************************************************************//*                             BuildWhere()                             *//*                                                                      *//*      Build the WHERE statement appropriate to the current set of     *//*      criteria (spatial and attribute queries).                       *//************************************************************************/void OGROCITableLayer::BuildWhere(){    OGROCIStringBuf oWHERE;    CPLFree( pszWHERE );    pszWHERE = NULL;    if( m_poFilterGeom != NULL && bHaveSpatialIndex )    {        OGREnvelope  sEnvelope;        m_poFilterGeom->getEnvelope( &sEnvelope );        oWHERE.Append( " WHERE sdo_filter(" );        oWHERE.Append( pszGeomName );        oWHERE.Append( ", MDSYS.SDO_GEOMETRY(2003," );        if( nSRID == -1 )            oWHERE.Append( "NULL" );        else            oWHERE.Appendf( 15, "%d", nSRID );        oWHERE.Append( ",NULL," );        oWHERE.Append( "MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,3)," );        oWHERE.Append( "MDSYS.SDO_ORDINATE_ARRAY(" );        oWHERE.Appendf( 200, "%.16g,%.16g,%.16g,%.16g",                         sEnvelope.MinX, sEnvelope.MinY,                        sEnvelope.MaxX, sEnvelope.MaxY );        oWHERE.Append( ")), 'querytype=window') = 'TRUE' " );    }    if( bHaveSpatialIndex == HSI_UNKNOWN )    {        TestForSpatialIndex( oWHERE.GetString() );        if( !bHaveSpatialIndex )            oWHERE.Clear();    }    if( pszQuery != NULL )    {        if( oWHERE.GetLast() == '\0' )            oWHERE.Append( "WHERE " );        else            oWHERE.Append( "AND " );        oWHERE.Append( pszQuery );    }    pszWHERE = oWHERE.StealString();}/************************************************************************//*                      BuildFullQueryStatement()                       *//************************************************************************/void OGROCITableLayer::BuildFullQueryStatement(){    if( pszQueryStatement != NULL )    {        CPLFree( pszQueryStatement );        pszQueryStatement = NULL;    }    OGROCIStringBuf oCmd;    char *pszFields = BuildFields();    oCmd.Append( "SELECT " );    oCmd.Append( pszFields );    oCmd.Append( " FROM " );    oCmd.Append( poFeatureDefn->GetName() );    oCmd.Append( " " );    oCmd.Append( pszWHERE );    pszQueryStatement = oCmd.StealString();    CPLFree( pszFields );}/************************************************************************//*                             GetFeature()                             *//************************************************************************/OGRFeature *OGROCITableLayer::GetFeature( long nFeatureId ){/* -------------------------------------------------------------------- *//*      If we don't have an FID column scan for the desired feature.    *//* -------------------------------------------------------------------- */    if( pszFIDName == NULL )        return OGROCILayer::GetFeature( nFeatureId );/* -------------------------------------------------------------------- *//*      Clear any existing query.                                       *//* -------------------------------------------------------------------- */    ResetReading();/* -------------------------------------------------------------------- *//*      Build query for this specific feature.                          *//* -------------------------------------------------------------------- */    OGROCIStringBuf oCmd;    char *pszFields = BuildFields();    oCmd.Append( "SELECT " );    oCmd.Append( pszFields );    oCmd.Append( " FROM " );    oCmd.Append( poFeatureDefn->GetName() );    oCmd.Append( " " );    oCmd.Appendf( 50+strlen(pszFIDName),                   " WHERE \"%s\" = %ld ",                   pszFIDName, nFeatureId );/* -------------------------------------------------------------------- *//*      Execute the statement.                                          *//* -------------------------------------------------------------------- */    if( !ExecuteQuery( oCmd.GetString() ) )        return NULL;/* -------------------------------------------------------------------- *//*      Get the feature.                                                *//* -------------------------------------------------------------------- */    OGRFeature *poFeature;    poFeature = GetNextRawFeature();        if( poFeature != NULL && poFeature->GetGeometryRef() != NULL )        poFeature->GetGeometryRef()->assignSpatialReference( poSRS );/* -------------------------------------------------------------------- *//*      Cleanup the statement.                                          *//* -------------------------------------------------------------------- */    ResetReading();/* -------------------------------------------------------------------- *//*      verify the FID.                                                 *//* -------------------------------------------------------------------- */    if( poFeature != NULL && poFeature->GetFID() != nFeatureId )    {        CPLError( CE_Failure, CPLE_AppDefined,                   "OGROCITableLayer::GetFeature(%d) ... query returned feature %d instead!",                  nFeatureId, poFeature->GetFID() );        delete poFeature;        return NULL;    }    else        return poFeature;}/************************************************************************//*                           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 *OGROCITableLayer::GetNextFeature(){    for( ; TRUE; )    {        OGRFeature      *poFeature;        poFeature = GetNextRawFeature();        if( poFeature == NULL )        {            CPLDebug( "OCI", "Query complete, got %d hits, and %d discards.",                      nHits, nDiscarded );            nHits = 0;            nDiscarded = 0;            return NULL;        }        if( m_poFilterGeom == NULL            || FilterGeometry( poFeature->GetGeometryRef() ) )        {            nHits++;            if( poFeature->GetGeometryRef() != NULL )                poFeature->GetGeometryRef()->assignSpatialReference( poSRS );            return poFeature;        }        if( m_poFilterGeom != NULL )            nDiscarded++;        delete poFeature;    }}/************************************************************************//*                            ResetReading()                            *//************************************************************************/void OGROCITableLayer::ResetReading(){    nHits = 0;    nDiscarded = 0;    FlushPendingFeatures();    BuildFullQueryStatement();    OGROCILayer::ResetReading();}/************************************************************************//*                            BuildFields()                             *//*                                                                      *//*      Build list of fields to fetch, performing any required          *//*      transformations (such as on geometry).                          *//************************************************************************/char *OGROCITableLayer::BuildFields(){    int         i;    OGROCIStringBuf oFldList;    if( pszGeomName )                                                       {        oFldList.Append( "\"" );        oFldList.Append( pszGeomName );        oFldList.Append( "\"" );        iGeomColumn = 0;    }    for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ )    {        const char *pszName = poFeatureDefn->GetFieldDefn(i)->GetNameRef();        if( oFldList.GetLast() != '\0' )            oFldList.Append( "," );        oFldList.Append( "\"" );        oFldList.Append( pszName );        oFldList.Append( "\"" );    }    if( pszFIDName != NULL )    {        iFIDColumn = poFeatureDefn->GetFieldCount();        oFldList.Append( ",\"" );        oFldList.Append( pszFIDName );        oFldList.Append( "\"" );    }    return oFldList.StealString();}/************************************************************************//*                         SetAttributeFilter()                         *//************************************************************************/OGRErr OGROCITableLayer::SetAttributeFilter( const char *pszQuery ){    if( (pszQuery == NULL && this->pszQuery == NULL)        || (pszQuery != NULL && this->pszQuery != NULL            && strcmp(pszQuery,this->pszQuery) == 0) )        return OGRERR_NONE;        CPLFree( this->pszQuery );    if( pszQuery == NULL )        this->pszQuery = NULL;    else        this->pszQuery = CPLStrdup( pszQuery );    BuildWhere();    ResetReading();    return OGRERR_NONE;}/************************************************************************//*                             SetFeature()                             *//*                                                                      *//*      We implement SetFeature() by deleting the existing row (if      *//*      it exists), and then using CreateFeature() to write it out      *//*      tot he table normally.  CreateFeature() will preserve the       *//*      existing FID if possible.                                       *//************************************************************************/OGRErr OGROCITableLayer::SetFeature( OGRFeature *poFeature ){/* -------------------------------------------------------------------- *//*      Do some validation.                                             *//* -------------------------------------------------------------------- */    if( pszFIDName == NULL )    {        CPLError( CE_Failure, CPLE_AppDefined,                   "OGROCITableLayer::SetFeature(%d) failed because there is "                  "no apparent FID column on table %s.",                  poFeature->GetFID(),                   poFeatureDefn->GetName() );        return OGRERR_FAILURE;    }    if( poFeature->GetFID() == OGRNullFID )    {        CPLError( CE_Failure, CPLE_AppDefined,                   "OGROCITableLayer::SetFeature(%d) failed because the feature "                  "has no FID!", poFeature->GetFID() );        return OGRERR_FAILURE;    }

⌨️ 快捷键说明

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