📄 ogrociloaderlayer.cpp
字号:
VSIFPrintf( fpLoader, "\n#" ); nLineLen = 0; } nLineLen += strlen(pszStrValue); if( poFldDefn->GetType() == OFTInteger || poFldDefn->GetType() == OFTReal ) { if( poFldDefn->GetWidth() > 0 && bPreservePrecision && (int) strlen(pszStrValue) > poFldDefn->GetWidth() ) { ReportTruncation( poFldDefn ); VSIFPrintf( fpLoader, "|" ); } else VSIFPrintf( fpLoader, "%s|", pszStrValue ); } else { int nLength = strlen(pszStrValue); if( poFldDefn->GetWidth() > 0 && nLength > poFldDefn->GetWidth() ) { ReportTruncation( poFldDefn ); nLength = poFldDefn->GetWidth(); } VSIFPrintf( fpLoader, "%04d", nLength ); VSIFWrite( (void *) pszStrValue, 1, nLength, fpLoader ); } } if( VSIFPrintf( fpLoader, "\n" ) == 0 ) { CPLError( CE_Failure, CPLE_FileIO, "Write to loader file failed, likely out of disk space." ); return OGRERR_FAILURE; } else return OGRERR_NONE;}/************************************************************************//* WriteFeatureVariableMode() *//************************************************************************/OGRErr OGROCILoaderLayer::WriteFeatureVariableMode( OGRFeature *poFeature ){ OGROCIStringBuf oLine; if( fpData == NULL ) return OGRERR_FAILURE;/* -------------------------------------------------------------------- *//* Write the FID. *//* -------------------------------------------------------------------- */ oLine.Append( "00000000" ); oLine.Appendf( 32, " %d|", poFeature->GetFID() );/* -------------------------------------------------------------------- *//* Set the geometry *//* -------------------------------------------------------------------- */ if( poFeature->GetGeometryRef() != NULL) { char szSRID[128]; int nGType; int i; if( nSRID == -1 ) strcpy( szSRID, "NULL" ); else sprintf( szSRID, "%d", nSRID ); if( TranslateToSDOGeometry( poFeature->GetGeometryRef(), &nGType ) == OGRERR_NONE ) { oLine.Appendf( 32, "%d|", nGType ); for( i = 0; i < nElemInfoCount; i++ ) { oLine.Appendf( 32, "%d|", panElemInfo[i] ); } oLine.Append( "/" ); for( i = 0; i < nOrdinalCount; i++ ) { oLine.Appendf( 32, "%.16g|", padfOrdinals[i] ); } oLine.Append( "/" ); } else { oLine.Append( "0|/|/" ); } } else { oLine.Append( "0|/|/" ); }/* -------------------------------------------------------------------- *//* Set the other fields. *//* -------------------------------------------------------------------- */ int i; for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { OGRFieldDefn *poFldDefn = poFeatureDefn->GetFieldDefn(i); if( !poFeature->IsFieldSet( i ) ) { if( poFldDefn->GetType() != OFTInteger && poFldDefn->GetType() != OFTReal ) oLine.Append( "0000" ); else oLine.Append( "|" ); continue; } const char *pszStrValue = poFeature->GetFieldAsString(i); if( poFldDefn->GetType() == OFTInteger || poFldDefn->GetType() == OFTReal ) { if( poFldDefn->GetWidth() > 0 && bPreservePrecision && (int) strlen(pszStrValue) > poFldDefn->GetWidth() ) { ReportTruncation( poFldDefn ); oLine.Append( "|" ); } else { oLine.Append( pszStrValue ); oLine.Append( "|" ); } } else { int nLength = strlen(pszStrValue); if( poFldDefn->GetWidth() > 0 && nLength > poFldDefn->GetWidth() ) { ReportTruncation( poFldDefn ); nLength = poFldDefn->GetWidth(); ((char *) pszStrValue)[nLength] = '\0'; } oLine.Appendf( 5, "%04d", nLength ); oLine.Append( pszStrValue ); } } oLine.Appendf( 3, "\n" );/* -------------------------------------------------------------------- *//* Update the line's length, and write to disk. *//* -------------------------------------------------------------------- */ char szLength[9]; size_t nStringLen = strlen(oLine.GetString()); sprintf( szLength, "%08d", nStringLen-8 ); strncpy( oLine.GetString(), szLength, 8 ); if( VSIFWrite( oLine.GetString(), 1, nStringLen, fpData ) != nStringLen ) { CPLError( CE_Failure, CPLE_FileIO, "Write to loader file failed, likely out of disk space." ); return OGRERR_FAILURE; } else return OGRERR_NONE;}/************************************************************************//* WriteFeatureBinaryMode() *//************************************************************************/OGRErr OGROCILoaderLayer::WriteFeatureBinaryMode( OGRFeature *poFeature ){ return OGRERR_UNSUPPORTED_OPERATION;}/************************************************************************//* CreateFeature() *//************************************************************************/OGRErr OGROCILoaderLayer::CreateFeature( OGRFeature *poFeature ){ WriteLoaderHeader();/* -------------------------------------------------------------------- *//* Set the FID. *//* -------------------------------------------------------------------- */ if( poFeature->GetFID() == OGRNullFID ) poFeature->SetFID( iNextFIDToWrite++ );/* -------------------------------------------------------------------- *//* Add extents of this geometry to the existing layer extents. *//* -------------------------------------------------------------------- */ if( poFeature->GetGeometryRef() != NULL ) { OGREnvelope sThisExtent; poFeature->GetGeometryRef()->getEnvelope( &sThisExtent ); sExtent.Merge( sThisExtent ); }/* -------------------------------------------------------------------- *//* Call the mode specific write function. *//* -------------------------------------------------------------------- */ if( nLDRMode == LDRM_STREAM ) return WriteFeatureStreamMode( poFeature ); else if( nLDRMode == LDRM_VARIABLE ) return WriteFeatureVariableMode( poFeature ); else if( nLDRMode == LDRM_BINARY ) return WriteFeatureBinaryMode( poFeature ); else return OGRERR_UNSUPPORTED_OPERATION;}/************************************************************************//* TestCapability() *//************************************************************************/int OGROCILoaderLayer::TestCapability( const char * pszCap ){ if( EQUAL(pszCap,OLCSequentialWrite) ) return TRUE; else if( EQUAL(pszCap,OLCCreateField) ) return TRUE; else return OGROCILayer::TestCapability( pszCap );}/************************************************************************//* GetFeatureCount() *//* *//* If a spatial filter is in effect, we turn control over to *//* the generic counter. Otherwise we return the total count. *//* Eventually we should consider implementing a more efficient *//* way of counting features matching a spatial query. *//************************************************************************/int OGROCILoaderLayer::GetFeatureCount( int bForce ){ return iNextFIDToWrite - 1;}/************************************************************************//* FinalizeNewLayer() *//* *//* Our main job here is to update the USER_SDO_GEOM_METADATA *//* table to include the correct array of dimension object with *//* the appropriate extents for this layer. We may also do *//* spatial indexing at this point. *//************************************************************************/void OGROCILoaderLayer::FinalizeNewLayer(){ OGROCIStringBuf sDimUpdate;/* -------------------------------------------------------------------- *//* If the dimensions are degenerate (all zeros) then we assume *//* there were no geometries, and we don't bother setting the *//* dimensions. *//* -------------------------------------------------------------------- */ if( sExtent.MaxX == 0 && sExtent.MinX == 0 && sExtent.MaxY == 0 && sExtent.MinY == 0 ) { CPLError( CE_Warning, CPLE_AppDefined, "Layer %s appears to have no geometry ... not setting SDO DIMINFO metadata.", poFeatureDefn->GetName() ); return; }/* -------------------------------------------------------------------- *//* Establish the extents and resolution to use. *//* -------------------------------------------------------------------- */ double dfResSize; double dfXMin, dfXMax, dfXRes; double dfYMin, dfYMax, dfYRes; double dfZMin, dfZMax, dfZRes; if( sExtent.MaxX - sExtent.MinX > 400 ) dfResSize = 0.001; else dfResSize = 0.0000001; dfXMin = sExtent.MinX - dfResSize * 3; dfXMax = sExtent.MaxX + dfResSize * 3; dfXRes = dfResSize; ParseDIMINFO( "DIMINFO_X", &dfXMin, &dfXMax, &dfXRes ); dfYMin = sExtent.MinY - dfResSize * 3; dfYMax = sExtent.MaxY + dfResSize * 3; dfYRes = dfResSize; ParseDIMINFO( "DIMINFO_Y", &dfYMin, &dfYMax, &dfYRes ); dfZMin = -100000.0; dfZMax = 100000.0; dfZRes = 0.002; ParseDIMINFO( "DIMINFO_Z", &dfZMin, &dfZMax, &dfZRes ); /* -------------------------------------------------------------------- *//* Prepare dimension update statement. *//* -------------------------------------------------------------------- */ sDimUpdate.Append( "UPDATE USER_SDO_GEOM_METADATA SET DIMINFO = " ); sDimUpdate.Append( "MDSYS.SDO_DIM_ARRAY(" ); sDimUpdate.Appendf(200, "MDSYS.SDO_DIM_ELEMENT('X',%.16g,%.16g,%.12g)", dfXMin, dfXMax, dfXRes ); sDimUpdate.Appendf(200, ",MDSYS.SDO_DIM_ELEMENT('Y',%.16g,%.16g,%.12g)", dfYMin, dfYMax, dfYRes ); if( nDimension == 3 ) { sDimUpdate.Appendf(200, ",MDSYS.SDO_DIM_ELEMENT('Z',%.16g,%.16g,%.12g)", dfZMin, dfZMax, dfZRes ); } sDimUpdate.Append( ")" ); sDimUpdate.Appendf( strlen(poFeatureDefn->GetName()) + 100, " WHERE table_name = '%s'", poFeatureDefn->GetName() );/* -------------------------------------------------------------------- *//* Execute the metadata update. *//* -------------------------------------------------------------------- */ OGROCIStatement oExecStatement( poDS->GetSession() ); if( oExecStatement.Execute( sDimUpdate.GetString() ) != CE_None ) return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -