?? ogrocidatasource.cpp
字號(hào):
/* Prepare and execute the geometry validation. *//* -------------------------------------------------------------------- */ OGROCIStringBuf oValidateCmd; OGROCIStatement oValidateStmt( GetSession() ); oValidateCmd.Append( "SELECT c." ); oValidateCmd.Append( poLayer->GetFIDColumn() ); oValidateCmd.Append( ", SDO_GEOM.VALIDATE_GEOMETRY(c." ); oValidateCmd.Append( poLayer->GetGeometryColumn() ); 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->GetGeometryColumn() ); oValidateCmd.Append( "' AND SDO_GEOM.VALIDATE_GEOMETRY(c." ); oValidateCmd.Append( poLayer->GetGeometryColumn() ); 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 ) { CPLDebug( "OCI", "DeleteLayer: %s not found in layer list." \ " Layer * not* deleted.", pszLayerName ); 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. *//* -------------------------------------------------------------------- */ const char *pszExpectedFIDName = CPLGetConfigOption( "OCI_FID", "OGR_FID" ); OGROCIStatement oStatement( poSession ); sprintf( szCommand, "CREATE TABLE \"%s\" ( " "%s INTEGER, " "%s %s )", pszSafeLayerName, pszExpectedFIDName, 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. *//* -------------------------------------------------------------------- */ if( pszDialect != NULL && EQUAL(pszDialect,"OGRSQL") ) return OGRDataSource::ExecuteSQL( pszSQLCommand, poSpatialFilter, pszDialect );/* -------------------------------------------------------------------- *//* Ensure any pending stuff is flushed to the database. *//* -------------------------------------------------------------------- */ SyncToDisk(); CPLDebug( "OCI", "ExecuteSQL(%s)", pszSQLCommand );/* -------------------------------------------------------------------- *//* Special case DELLAYER: command. *//* -------------------------------------------------------------------- */ if( EQUALN(pszSQLCommand,"DELLAYER:",9) ) { const char *pszLayerName = pszSQLCommand + 9; while( *pszLayerName == ' ' ) pszLayerName++; DeleteLayer( pszLayerName ); return NULL; }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -