ogr/ogrsf_frmts/pgeo/ogrpgeolayer.cpp
/************************************************************************/
/*                          BuildFeatureDefn()                          */
/*                                                                      */
/*      Build feature definition from a set of column definitions       */
/*      set on a statement.  Sift out geometry and FID fields.          */
/************************************************************************/
BuildFeatureDefn()
Build feature definition from a set of column definitions
set on a statement.  Sift out geometry and FID fields.
BuildFeatureDefn () Build feature definition from a set of column definitions set on a statement . Sift out geometry and FID fields .
CPLErr OGRPGeoLayer::BuildFeatureDefn( const char *pszLayerName,
                                       CPLODBCStatement *poStmtIn )
{
    poFeatureDefn = new OGRFeatureDefn( pszLayerName );
    SetDescription( poFeatureDefn->GetName() );
    int    nRawColumns = poStmtIn->GetColCount();
    poFeatureDefn->Reference();
    poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(poSRS);
    panFieldOrdinals = (int *) CPLMalloc( sizeof(int) * nRawColumns );
    for( int iCol = 0; iCol < nRawColumns; iCol++ )
    {
        OGRFieldDefn    oField( poStmtIn->GetColName(iCol), OFTString );
        oField.SetWidth(
            std::max(static_cast<short>(0), poStmtIn->GetColSize( iCol )));
        if( pszGeomColumn != NULL
            && EQUAL(poStmtIn->GetColName(iCol),pszGeomColumn) )
            continue;
        if( pszFIDColumn == NULL
            && EQUAL(poStmtIn->GetColName(iCol),"OBJECTID") )
        {
            pszFIDColumn = CPLStrdup(poStmtIn->GetColName(iCol));
        }
        if( pszGeomColumn == NULL
            && EQUAL(poStmtIn->GetColName(iCol),"Shape") )
        {
            pszGeomColumn = CPLStrdup(poStmtIn->GetColName(iCol));
            continue;
        }
        switch( poStmtIn->GetColType(iCol) )
        {
          case SQL_INTEGER:
          case SQL_SMALLINT:
            oField.SetType( OFTInteger );
            break;
          case SQL_BINARY:
          case SQL_VARBINARY:
          case SQL_LONGVARBINARY:
            oField.SetType( OFTBinary );
            break;
          case SQL_DECIMAL:
            oField.SetType( OFTReal );
            oField.SetPrecision( poStmtIn->GetColPrecision(iCol) );
            break;
          case SQL_FLOAT:
          case SQL_REAL:
          case SQL_DOUBLE:
            oField.SetType( OFTReal );
            oField.SetWidth( 0 );
            break;
          case SQL_C_DATE:
            oField.SetType( OFTDate );
            break;
          case SQL_C_TIME:
            oField.SetType( OFTTime );
            break;
          case SQL_C_TIMESTAMP:
            oField.SetType( OFTDateTime );
            break;
          default:
            ;
        }
        if( pszGeomColumn != NULL )
            poFeatureDefn->GetGeomFieldDefn(0)->SetName(pszGeomColumn);
        poFeatureDefn->AddFieldDefn( &oField );
        panFieldOrdinals[poFeatureDefn->GetFieldCount() - 1] = iCol+1;
    }
    return CE_None;
}
CPLErr OGRPGeoLayer :: BuildFeatureDefn ( const char * pszLayerName , CPLODBCStatement * poStmtIn ) { poFeatureDefn = new OGRFeatureDefn ( pszLayerName ) ; SetDescription ( poFeatureDefn -> GetName ( ) ) ; int nRawColumns = poStmtIn -> GetColCount ( ) ; poFeatureDefn -> Reference ( ) ; poFeatureDefn -> GetGeomFieldDefn ( 0 ) -> SetSpatialRef ( poSRS ) ; panFieldOrdinals = ( int * ) CPLMalloc ( sizeof ( int ) * nRawColumns ) ; for ( int iCol = 0 ; iCol < nRawColumns ; iCol ++ ) { OGRFieldDefn oField ( poStmtIn -> GetColName ( iCol ) , OFTString ) ; oField . SetWidth ( std :: max ( static_cast < short > ( 0 ) , poStmtIn -> GetColSize ( iCol ) ) ) ; if ( pszGeomColumn != NULL && EQUAL ( poStmtIn -> GetColName ( iCol ) , pszGeomColumn ) ) continue ; if ( pszFIDColumn == NULL && EQUAL ( poStmtIn -> GetColName ( iCol ) , " " ) ) { pszFIDColumn = CPLStrdup ( poStmtIn -> GetColName ( iCol ) ) ; } if ( pszGeomColumn == NULL && EQUAL ( poStmtIn -> GetColName ( iCol ) , " " ) ) { pszGeomColumn = CPLStrdup ( poStmtIn -> GetColName ( iCol ) ) ; continue ; } switch ( poStmtIn -> GetColType ( iCol ) ) { case SQL_INTEGER : case SQL_SMALLINT : oField . SetType ( OFTInteger ) ; break ; case SQL_BINARY : case SQL_VARBINARY : case SQL_LONGVARBINARY : oField . SetType ( OFTBinary ) ; break ; case SQL_DECIMAL : oField . SetType ( OFTReal ) ; oField . SetPrecision ( poStmtIn -> GetColPrecision ( iCol ) ) ; break ; case SQL_FLOAT : case SQL_REAL : case SQL_DOUBLE : oField . SetType ( OFTReal ) ; oField . SetWidth ( 0 ) ; break ; case SQL_C_DATE : oField . SetType ( OFTDate ) ; break ; case SQL_C_TIME : oField . SetType ( OFTTime ) ; break ; case SQL_C_TIMESTAMP : oField . SetType ( OFTDateTime ) ; break ; default : ; } if ( pszGeomColumn != NULL ) poFeatureDefn -> GetGeomFieldDefn ( 0 ) -> SetName ( pszGeomColumn ) ; poFeatureDefn -> AddFieldDefn ( & oField ) ; panFieldOrdinals [ poFeatureDefn -> GetFieldCount ( ) - 1 ] = iCol + 1 ; } return CE_None ; }
BuildFeatureDefn()
Build feature definition from a set of column definitions
set on a statement.
BuildFeatureDefn () Build feature definition from a set of column definitions set on a statement .
/* leave it as OFTString */