?? ogrocidatasource.cpp
字號:
/* -------------------------------------------------------------------- *//* Special case VALLAYER: command. *//* -------------------------------------------------------------------- */ if( EQUALN(pszSQLCommand,"VALLAYER:",9) ) { const char *pszLayerName = pszSQLCommand + 9; while( *pszLayerName == ' ' ) pszLayerName++; ValidateLayer( pszLayerName ); return NULL; }/* -------------------------------------------------------------------- *//* Just execute simple command. *//* -------------------------------------------------------------------- */ if( !EQUALN(pszSQLCommand,"SELECT",6) ) { OGROCIStatement oCommand( poSession ); oCommand.Execute( pszSQLCommand, OCI_COMMIT_ON_SUCCESS ); return NULL; }/* -------------------------------------------------------------------- *//* Otherwise instantiate a layer. *//* -------------------------------------------------------------------- */ else { OGROCIStatement oCommand( poSession ); if( oCommand.Execute( pszSQLCommand, OCI_DESCRIBE_ONLY ) == CE_None ) return new OGROCISelectLayer( this, pszSQLCommand, &oCommand ); else return NULL; }}/************************************************************************//* ReleaseResultSet() *//************************************************************************/void OGROCIDataSource::ReleaseResultSet( OGRLayer * poLayer ){ delete poLayer;}/************************************************************************//* FetchSRS() *//* *//* Return a SRS corresponding to a particular id. Note that *//* reference counting should be honoured on the returned *//* OGRSpatialReference, as handles may be cached. *//************************************************************************/OGRSpatialReference *OGROCIDataSource::FetchSRS( int nId ){ if( nId < 0 ) return NULL;/* -------------------------------------------------------------------- *//* First, we look through our SRID cache, is it there? *//* -------------------------------------------------------------------- */ int i; for( i = 0; i < nKnownSRID; i++ ) { if( panSRID[i] == nId ) return papoSRS[i]; }/* -------------------------------------------------------------------- *//* Try looking up in MDSYS.CS_SRS table. *//* -------------------------------------------------------------------- */ OGROCIStatement oStatement( GetSession() ); char szSelect[200], **papszResult; sprintf( szSelect, "SELECT WKTEXT, AUTH_SRID, AUTH_NAME FROM MDSYS.CS_SRS WHERE SRID = %d", nId ); if( oStatement.Execute( szSelect ) != CE_None ) return NULL; papszResult = oStatement.SimpleFetchRow(); if( CSLCount(papszResult) < 1 ) return NULL;/* -------------------------------------------------------------------- *//* Turn into a spatial reference. *//* -------------------------------------------------------------------- */ char *pszWKT = papszResult[0]; OGRSpatialReference *poSRS = NULL; poSRS = new OGRSpatialReference(); if( poSRS->importFromWkt( &pszWKT ) != OGRERR_NONE ) { delete poSRS; poSRS = NULL; }/* -------------------------------------------------------------------- *//* If we have a corresponding EPSG code for this SRID, use that *//* authority. *//* -------------------------------------------------------------------- */ int bGotEPSGMapping = FALSE; for( i = 0; anEPSGOracleMapping[i] != 0; i += 2 ) { if( anEPSGOracleMapping[i] == nId ) { poSRS->SetAuthority( poSRS->GetRoot()->GetValue(), "EPSG", anEPSGOracleMapping[i+1] ); bGotEPSGMapping = TRUE; break; } }/* -------------------------------------------------------------------- *//* Insert authority information, if it is available. *//* -------------------------------------------------------------------- */ if( papszResult[1] != NULL && atoi(papszResult[1]) != 0 && papszResult[2] != NULL && strlen(papszResult[1]) != 0 && poSRS->GetRoot() != NULL && !bGotEPSGMapping ) { poSRS->SetAuthority( poSRS->GetRoot()->GetValue(), papszResult[2], atoi(papszResult[1]) ); }/* -------------------------------------------------------------------- *//* Add to the cache. *//* -------------------------------------------------------------------- */ panSRID = (int *) CPLRealloc(panSRID,sizeof(int) * (nKnownSRID+1) ); papoSRS = (OGRSpatialReference **) CPLRealloc(papoSRS, sizeof(void*) * (nKnownSRID + 1) ); panSRID[nKnownSRID] = nId; papoSRS[nKnownSRID] = poSRS; nKnownSRID++; return poSRS;}/************************************************************************//* FetchSRSId() *//* *//* Fetch the id corresponding to an SRS, and if not found, add *//* it to the table. *//************************************************************************/int OGROCIDataSource::FetchSRSId( OGRSpatialReference * poSRS ){ char *pszWKT = NULL; int nSRSId; if( poSRS == NULL ) return -1; if( !poSRS->IsProjected() && !poSRS->IsGeographic() ) return -1;/* ==================================================================== *//* The first strategy is to see if we can identify it by *//* authority information within the SRS. Either using ORACLE *//* authority values directly, or check if there is a known *//* translation for an EPSG authority code. *//* ==================================================================== */ const char *pszAuthName = NULL, *pszAuthCode = NULL; if( poSRS->IsGeographic() ) { pszAuthName = poSRS->GetAuthorityName( "GEOGCS" ); pszAuthCode = poSRS->GetAuthorityCode( "GEOGCS" ); } else if( poSRS->IsProjected() ) { pszAuthName = poSRS->GetAuthorityName( "PROJCS" ); pszAuthCode = poSRS->GetAuthorityCode( "PROJCS" ); } if( pszAuthName != NULL && pszAuthCode != NULL ) { if( EQUAL(pszAuthName,"Oracle") && atoi(pszAuthCode) != 0 ) return atoi(pszAuthCode); if( EQUAL(pszAuthName,"EPSG") ) { int i, nEPSGCode = atoi(pszAuthCode); for( i = 0; anEPSGOracleMapping[i] != 0; i += 2 ) { if( nEPSGCode == anEPSGOracleMapping[i+1] ) return anEPSGOracleMapping[i]; } } }/* ==================================================================== *//* We need to lookup the SRS in the existing Oracle CS_SRS *//* table. *//* ==================================================================== *//* -------------------------------------------------------------------- *//* Convert SRS into old style format (SF-SQL 1.0). *//* -------------------------------------------------------------------- */ OGRSpatialReference *poSRS2 = poSRS->Clone(); poSRS2->StripCTParms();/* -------------------------------------------------------------------- *//* Convert any degree type unit names to "Decimal Degree". *//* -------------------------------------------------------------------- */ double dfAngularUnits = poSRS2->GetAngularUnits( NULL ); if( fabs(dfAngularUnits - 0.0174532925199433) < 0.0000000000000010 ) poSRS2->SetAngularUnits( "Decimal Degree", 0.0174532925199433 );/* -------------------------------------------------------------------- *//* Translate SRS to WKT. *//* -------------------------------------------------------------------- */ if( poSRS2->exportToWkt( &pszWKT ) != OGRERR_NONE ) { delete poSRS2; return -1; } delete poSRS2; /* -------------------------------------------------------------------- *//* Try to find in the existing table. *//* -------------------------------------------------------------------- */ OGROCIStringBuf oCmdText; OGROCIStatement oCmdStatement( GetSession() ); char **papszResult = NULL; oCmdText.Append( "SELECT SRID FROM MDSYS.CS_SRS WHERE WKTEXT = '" ); oCmdText.Append( pszWKT ); oCmdText.Append( "'" ); if( oCmdStatement.Execute( oCmdText.GetString() ) == CE_None ) papszResult = oCmdStatement.SimpleFetchRow() ;/* -------------------------------------------------------------------- *//* We got it! Return it. *//* -------------------------------------------------------------------- */ if( CSLCount(papszResult) == 1 ) { CPLFree( pszWKT ); return atoi( papszResult[0] ); } /* ==================================================================== *//* We didn't find it, so we need to define it as a new SRID at *//* the end of the list of known values. *//* ==================================================================== *//* -------------------------------------------------------------------- *//* Get the current maximum srid in the srs table. *//* -------------------------------------------------------------------- */ if( oCmdStatement.Execute("SELECT MAX(SRID) FROM MDSYS.CS_SRS") == CE_None ) papszResult = oCmdStatement.SimpleFetchRow(); else papszResult = NULL; if( CSLCount(papszResult) == 1 ) nSRSId = atoi(papszResult[0]) + 1; else nSRSId = 1;/* -------------------------------------------------------------------- *//* Try adding the SRS to the SRS table. *//* -------------------------------------------------------------------- */ oCmdText.Clear(); oCmdText.Append( "INSERT INTO MDSYS.CS_SRS (SRID, WKTEXT, CS_NAME) " ); oCmdText.Appendf( 100, " VALUES (%d,'", nSRSId ); oCmdText.Append( pszWKT ); oCmdText.Append( "', '" ); oCmdText.Append( poSRS->GetRoot()->GetChild(0)->GetValue() ); oCmdText.Append( "' )" ); CPLFree( pszWKT ); if( oCmdStatement.Execute( oCmdText.GetString() ) != CE_None ) return -1; else return nSRSId;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -