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

📄 ogrociwritablelayer.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************//*                            CreateField()                             *//************************************************************************/OGRErr OGROCIWritableLayer::CreateField( OGRFieldDefn *poFieldIn, int bApproxOK ){    OGROCISession      *poSession = poDS->GetSession();    char                szFieldType[256];    OGRFieldDefn        oField( poFieldIn );/* -------------------------------------------------------------------- *//*      Do we want to "launder" the column names into Postgres          *//*      friendly format?                                                *//* -------------------------------------------------------------------- */    if( bLaunderColumnNames )    {        char    *pszSafeName = CPLStrdup( oField.GetNameRef() );        poSession->CleanName( pszSafeName );        oField.SetName( pszSafeName );        CPLFree( pszSafeName );    }    /* -------------------------------------------------------------------- *//*      Work out the PostgreSQL type.                                   *//* -------------------------------------------------------------------- */    if( oField.GetType() == OFTInteger )    {        if( bPreservePrecision && oField.GetWidth() != 0 )            sprintf( szFieldType, "NUMBER(%d)", oField.GetWidth() );        else            strcpy( szFieldType, "INTEGER" );    }    else if( oField.GetType() == OFTReal )    {        if( bPreservePrecision && oField.GetWidth() != 0 )            sprintf( szFieldType, "NUMBER(%d,%d)",                      oField.GetWidth(), oField.GetPrecision() );        else            strcpy( szFieldType, "FLOAT(126)" );    }    else if( oField.GetType() == OFTString )    {        if( oField.GetWidth() == 0 || !bPreservePrecision )            strcpy( szFieldType, "VARCHAR(2047)" );        else            sprintf( szFieldType, "CHAR(%d)", oField.GetWidth() );    }    else if( bApproxOK )    {        CPLError( CE_Warning, CPLE_NotSupported,                  "Can't create field %s with type %s on Oracle layers.  Creating as VARCHAR.",                  oField.GetNameRef(),                  OGRFieldDefn::GetFieldTypeName(oField.GetType()) );        strcpy( szFieldType, "VARCHAR(2047)" );    }    else    {        CPLError( CE_Failure, CPLE_NotSupported,                  "Can't create field %s with type %s on Oracle layers.",                  oField.GetNameRef(),                  OGRFieldDefn::GetFieldTypeName(oField.GetType()) );        return OGRERR_FAILURE;    }/* -------------------------------------------------------------------- *//*      Create the new field.                                           *//* -------------------------------------------------------------------- */    OGROCIStringBuf     oCommand;    OGROCIStatement     oAddField( poSession );    oCommand.MakeRoomFor( 40 + strlen(poFeatureDefn->GetName())                          + strlen(oField.GetNameRef())                          + strlen(szFieldType) );    sprintf( oCommand.GetString(), "ALTER TABLE %s ADD \"%s\" %s",              poFeatureDefn->GetName(), oField.GetNameRef(), szFieldType );    if( oAddField.Execute( oCommand.GetString() ) != CE_None )        return OGRERR_FAILURE;    poFeatureDefn->AddFieldDefn( &oField );    return OGRERR_NONE;}/************************************************************************//*                            SetDimension()                            *//************************************************************************/void OGROCIWritableLayer::SetDimension( int nNewDim ){    nDimension = nNewDim;}/************************************************************************//*                            ParseDIMINFO()                            *//************************************************************************/void OGROCIWritableLayer::ParseDIMINFO( const char *pszOptionName,                                         double *pdfMin,                                         double *pdfMax,                                        double *pdfRes ){    const char *pszUserDIMINFO;    char **papszTokens;    pszUserDIMINFO = CSLFetchNameValue( papszOptions, pszOptionName );    if( pszUserDIMINFO == NULL )        return;    papszTokens =         CSLTokenizeStringComplex( pszUserDIMINFO, ",", FALSE, FALSE );    if( CSLCount(papszTokens) != 3 )    {        CSLDestroy( papszTokens );        CPLError( CE_Warning, CPLE_AppDefined,                   "Ignoring %s, it does not contain three comma separated values.",                   pszOptionName );        return;    }    *pdfMin = atof(papszTokens[0]);    *pdfMax = atof(papszTokens[1]);    *pdfRes = atof(papszTokens[2]);    CSLDestroy( papszTokens );}/************************************************************************//*                       TranslateToSDOGeometry()                       *//************************************************************************/OGRErr OGROCIWritableLayer::TranslateToSDOGeometry( OGRGeometry * poGeometry,                                                    int *pnGType ){    nOrdinalCount = 0;    nElemInfoCount = 0;    if( poGeometry == NULL )        return OGRERR_FAILURE;/* ==================================================================== *//*      Handle a point geometry.                                        *//* ==================================================================== */    if( wkbFlatten(poGeometry->getGeometryType()) == wkbPoint )    {#ifdef notdef        char szResult[1024];        OGRPoint *poPoint = (OGRPoint *) poGeometry;        if( nDimension == 2 )            sprintf( szResult,                      "%s(%d,%s,MDSYS.SDO_POINT_TYPE(%.16g,%.16g,0.0),NULL,NULL)",                     SDO_GEOMETRY, 2001, szSRID,                      poPoint->getX(), poPoint->getY() );        else            sprintf( szResult,                      "%s(%d,%s,MDSYS.SDO_POINT_TYPE(%.16g,%.16g,%.16g),NULL,NULL)",                     SDO_GEOMETRY, 3001, szSRID,                      poPoint->getX(), poPoint->getY(), poPoint->getZ() );        return CPLStrdup(szResult );#endif    }/* ==================================================================== *//*      Handle a line string geometry.                                  *//* ==================================================================== */    else if( wkbFlatten(poGeometry->getGeometryType()) == wkbLineString )    {        *pnGType = nDimension * 1000 + 2;        TranslateElementGroup( poGeometry );        return OGRERR_NONE;    }/* ==================================================================== *//*      Handle a polygon geometry.                                      *//* ==================================================================== */    else if( wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon )    {        *pnGType = nDimension == 2 ? 2003 : 3003;        TranslateElementGroup( poGeometry );        return OGRERR_NONE;    }/* ==================================================================== *//*      Handle a multi point geometry.                                  *//* ==================================================================== */    else if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPoint )    {        OGRMultiPoint *poMP = (OGRMultiPoint *) poGeometry;        int  iVert;        *pnGType = nDimension*1000 + 5;        PushElemInfo( 1, 1, poMP->getNumGeometries() );                for( iVert = 0; iVert < poMP->getNumGeometries(); iVert++ )        {            OGRPoint *poPoint = (OGRPoint *)poMP->getGeometryRef( iVert );            PushOrdinal( poPoint->getX() );            PushOrdinal( poPoint->getY() );            if( nDimension == 3 )                PushOrdinal( poPoint->getZ() );        }        return OGRERR_NONE;    }/* ==================================================================== *//*      Handle other geometry collections.                              *//* ==================================================================== */    else    {/* -------------------------------------------------------------------- *//*      Identify the GType.                                             *//* -------------------------------------------------------------------- */        if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiLineString )            *pnGType = nDimension * 1000 + 6;        else if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon )            *pnGType = nDimension * 1000 + 7;        else if( wkbFlatten(poGeometry->getGeometryType())                  == wkbGeometryCollection )            *pnGType = nDimension * 1000 + 4;        else         {            CPLError( CE_Failure, CPLE_AppDefined,                      "Unexpected geometry type (%d/%s) in "                      "OGROCIWritableLayer::TranslateToSDOGeometry()",                      poGeometry->getGeometryType(),                       poGeometry->getGeometryName() );            return OGRERR_FAILURE;        }/* -------------------------------------------------------------------- *//*      Translate each child in turn.                                   *//* -------------------------------------------------------------------- */        OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeometry;        int  iChild;        for( iChild = 0; iChild < poGC->getNumGeometries(); iChild++ )            TranslateElementGroup( poGC->getGeometryRef(iChild) );        return OGRERR_NONE;    }    return OGRERR_FAILURE;}

⌨️ 快捷键说明

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