本文整理汇总了C++中VSIFSeek函数的典型用法代码示例。如果您正苦于以下问题:C++ VSIFSeek函数的具体用法?C++ VSIFSeek怎么用?C++ VSIFSeek使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VSIFSeek函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CPLAssert
OGRErr OGRMILayerAttrIndex::LoadConfigFromXML()
{
FILE *fp;
int nXMLSize;
char *pszRawXML;
CPLAssert( poINDFile == NULL );
/* -------------------------------------------------------------------- */
/* Read the XML file. */
/* -------------------------------------------------------------------- */
fp = VSIFOpen( pszMetadataFilename, "rb" );
if( fp == NULL )
return OGRERR_NONE;
VSIFSeek( fp, 0, SEEK_END );
nXMLSize = VSIFTell( fp );
VSIFSeek( fp, 0, SEEK_SET );
pszRawXML = (char *) CPLMalloc(nXMLSize+1);
pszRawXML[nXMLSize] = '\0';
VSIFRead( pszRawXML, nXMLSize, 1, fp );
VSIFClose( fp );
OGRErr eErr = LoadConfigFromXML(pszRawXML);
CPLFree(pszRawXML);
return eErr;
}
示例2: VSIFOpen
/*!
\brief Read the file & load the data
\param pszFile pointer to a filename
\return TRUE on success
\return FALSE on error
*/
int VFKReader::LoadData()
{
FILE *fp;
long nLength;
if (m_pszFilename == NULL)
return FALSE;
/* load vfk file */
fp = VSIFOpen(m_pszFilename, "rb");
if (fp == NULL) {
CPLError(CE_Failure, CPLE_OpenFailed,
"Failed to open file %s.", m_pszFilename);
return FALSE;
}
/* get file length */
VSIFSeek(fp, 0, SEEK_END);
nLength = VSIFTell(fp);
VSIFSeek(fp, 0, SEEK_SET);
/* read file - is necessary to read the whole file? */
m_pszWholeText = (char *) VSIMalloc(nLength+1);
if (m_pszWholeText == NULL) {
CPLError(CE_Failure, CPLE_AppDefined,
"Failed to allocate %ld byte buffer for %s,\n"
"is this really a VFK file?",
nLength, m_pszFilename);
VSIFClose(fp);
return FALSE;
}
if (VSIFRead(m_pszWholeText, nLength, 1, fp) != 1) {
VSIFree(m_pszWholeText);
m_pszWholeText = NULL;
VSIFClose(fp);
CPLError(CE_Failure, CPLE_AppDefined,
"Read failed on %s.", m_pszFilename);
return FALSE;
}
m_pszWholeText[nLength] = '\0';
VSIFClose(fp);
/* split lines */
/* TODO: reduce chars */
for (char *poChar = m_pszWholeText; *poChar != '\0'; poChar++) {
if (*poChar == '\244' && *(poChar+1) != '\0' && *(poChar+2) != '\0') {
*(poChar++) = ' '; // \r
*(poChar++) = ' '; // \n
*poChar = ' ';
}
}
CPLDebug("OGR_VFK", "VFKReader::LoadData(): length=%ld", nLength);
return TRUE;
}
示例3: VSIFSeek
CPLErr COSARRasterBand::IReadBlock(CPL_UNUSED int nBlockXOff, int nBlockYOff,
void *pImage) {
unsigned long nRSFV = 0;
unsigned long nRSLV = 0;
COSARDataset *pCDS = (COSARDataset *) poDS;
/* Find the line we want to be at */
/* To explain some magic numbers:
* 4 bytes for an entire sample (2 I, 2 Q)
* nBlockYOff + 4 = Y offset + 4 annotation lines at beginning
* of file
*/
VSIFSeek(pCDS->fp,(this->nRTNB * (nBlockYOff + 4)), SEEK_SET);
/* Read RSFV and RSLV (TX-GS-DD-3307) */
VSIFRead(&nRSFV,1,4,pCDS->fp);
VSIFRead(&nRSLV,1,4,pCDS->fp);
#ifdef CPL_LSB
nRSFV = CPL_SWAP32(nRSFV);
nRSLV = CPL_SWAP32(nRSLV);
#endif
if (nRSLV < nRSFV || nRSFV == 0
|| nRSFV - 1 >= ((unsigned long) nBlockXSize)
|| nRSLV - nRSFV > ((unsigned long) nBlockXSize)
|| nRSFV >= this->nRTNB || nRSLV > this->nRTNB)
{
/* throw an error */
CPLError(CE_Failure, CPLE_AppDefined,
"RSLV/RSFV values are not sane... oh dear.\n");
return CE_Failure;
}
/* zero out the range line */
for (int i = 0; i < this->nRasterXSize; i++)
{
((GUInt32 *)pImage)[i] = 0;
}
/* properly account for validity mask */
if (nRSFV > 1)
{
VSIFSeek(pCDS->fp,(this->nRTNB*(nBlockYOff+4)+(nRSFV+1)*4), SEEK_SET);
}
/* Read the valid samples: */
VSIFRead(((char *)pImage)+((nRSFV - 1)*4),1,((nRSLV-1)*4)-((nRSFV-1)*4),pCDS->fp);
#ifdef CPL_LSB
// GDALSwapWords( pImage, 4, nBlockXSize * nBlockYSize, 4 );
GDALSwapWords( pImage, 2, nBlockXSize * nBlockYSize * 2, 2 );
#endif
return CE_None;
}
示例4: CPLDestroyXMLNode
int OGRFMECacheIndex::Load()
{
/* -------------------------------------------------------------------- */
/* Lock the cache index file if not already locked. */
/* -------------------------------------------------------------------- */
if( hLock == NULL && !Lock() )
return FALSE;
if( psTree != NULL )
{
CPLDestroyXMLNode( psTree );
psTree = NULL;
}
/* -------------------------------------------------------------------- */
/* Open the index file. If we don't get it, we assume it is */
/* because it doesn't exist, and we create a "stub" tree in */
/* memory. */
/* -------------------------------------------------------------------- */
FILE *fpIndex;
int nLength;
char *pszIndexBuffer;
fpIndex = VSIFOpen( GetPath(), "rb" );
if( fpIndex == NULL )
{
psTree = CPLCreateXMLNode( NULL, CXT_Element, "OGRFMECacheIndex" );
return TRUE;
}
/* -------------------------------------------------------------------- */
/* Load the data from the file. */
/* -------------------------------------------------------------------- */
VSIFSeek( fpIndex, 0, SEEK_END );
nLength = VSIFTell( fpIndex );
VSIFSeek( fpIndex, 0, SEEK_SET );
pszIndexBuffer = (char *) CPLMalloc(nLength+1);
if( (int) VSIFRead( pszIndexBuffer, 1, nLength, fpIndex ) != nLength )
{
CPLError( CE_Failure, CPLE_FileIO,
"Read of %d byte index file failed.", nLength );
return FALSE;
}
VSIFClose( fpIndex );
/* -------------------------------------------------------------------- */
/* Parse the result into an inmemory XML tree. */
/* -------------------------------------------------------------------- */
pszIndexBuffer[nLength] = '\0';
psTree = CPLParseXMLString( pszIndexBuffer );
CPLFree( pszIndexBuffer );
return psTree != NULL;
}
示例5: CPLError
GDALDataset *COSARDataset::Open( GDALOpenInfo * pOpenInfo ) {
long nRTNB;
/* Check if we're actually a COSAR data set. */
if( pOpenInfo->nHeaderBytes < 4 )
return NULL;
if (!EQUALN((char *)pOpenInfo->pabyHeader+MAGIC1_OFFSET, "CSAR",4))
return NULL;
/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( pOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The COSAR driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* this is a cosar dataset */
COSARDataset *pDS;
pDS = new COSARDataset();
/* steal fp */
pDS->fp = pOpenInfo->fp;
pOpenInfo->fp = NULL;
/* Calculate the file size */
VSIFSeek(pDS->fp,0,SEEK_END);
pDS->nSize = VSIFTell(pDS->fp);
VSIFSeek(pDS->fp, RS_OFFSET, SEEK_SET);
VSIFRead(&pDS->nRasterXSize, 1, 4, pDS->fp);
#ifdef CPL_LSB
pDS->nRasterXSize = CPL_SWAP32(pDS->nRasterXSize);
#endif
VSIFRead(&pDS->nRasterYSize, 1, 4, pDS->fp);
#ifdef CPL_LSB
pDS->nRasterYSize = CPL_SWAP32(pDS->nRasterYSize);
#endif
VSIFSeek(pDS->fp, RTNB_OFFSET, SEEK_SET);
VSIFRead(&nRTNB, 1, 4, pDS->fp);
#ifdef CPL_LSB
nRTNB = CPL_SWAP32(nRTNB);
#endif
/* Add raster band */
pDS->SetBand(1, new COSARRasterBand(pDS, nRTNB));
return pDS;
}
示例6: WCTSGetCapabilities
void WCTSGetCapabilities( CPLXMLNode *psOperation )
{
/* -------------------------------------------------------------------- */
/* Verify the service. */
/* -------------------------------------------------------------------- */
if( !EQUAL(CPLGetXMLValue(psOperation,"service","WCTS"),"WCTS") )
{
WCTSEmitServiceException(
CPLSPrintf( "Attempt to GetCapabilities for unsupported '%.500s'\n"
"service. Only WCTS supported.",
CPLGetXMLValue(psOperation,"service","WCTS") ) );
}
/* -------------------------------------------------------------------- */
/* Search for our capabilities document. */
/* -------------------------------------------------------------------- */
const char *pszCapFilename;
FILE *fp;
pszCapFilename = CPLFindFile( "gdal", "wcts_capabilities.xml.0.1.0" );
if( pszCapFilename == NULL
|| (fp = VSIFOpen( pszCapFilename, "rt")) == NULL )
{
WCTSEmitServiceException( "WCTS server misconfigured, "
"unable to find capabilities document." );
}
/* -------------------------------------------------------------------- */
/* Emit the document. */
/* -------------------------------------------------------------------- */
int nLen;
char *pszDoc;
VSIFSeek( fp, 0, SEEK_END );
nLen = VSIFTell( fp );
VSIFSeek( fp, 0, SEEK_SET );
pszDoc = (char *) CPLMalloc(nLen);
VSIFRead( pszDoc, 1, nLen, fp );
VSIFClose( fp );
printf( "Content-type: text/xml%c%c", 10, 10 );
VSIFWrite( pszDoc, 1, nLen, stdout );
fflush( stdout );
CPLFree( pszDoc );
exit( 0 );
}
示例7: VSIFSeek
void TigerFileBase::SetupVersion()
{
char aszRecordHead[6];
VSIFSeek( fpPrimary, 0, SEEK_SET );
VSIFRead( aszRecordHead, 1, 5, fpPrimary );
aszRecordHead[5] = '\0';
nVersionCode = atoi(aszRecordHead+1);
VSIFSeek( fpPrimary, 0, SEEK_SET );
nVersion = TigerClassifyVersion( nVersionCode );
}
示例8: CPLMalloc
void HFAEntry::LoadData()
{
if( pabyData != NULL || nDataSize == 0 )
return;
/* -------------------------------------------------------------------- */
/* Allocate buffer, and read data. */
/* -------------------------------------------------------------------- */
pabyData = (GByte *) CPLMalloc(nDataSize);
if( VSIFSeek( psHFA->fp, nDataPos, SEEK_SET ) < 0 )
{
CPLError( CE_Failure, CPLE_FileIO,
"VSIFSeek() failed in HFAEntry::LoadData()." );
return;
}
if( VSIFRead( pabyData, 1, nDataSize, psHFA->fp ) < 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"VSIFRead() failed in HFAEntry::LoadData()." );
return;
}
/* -------------------------------------------------------------------- */
/* Get the type corresponding to this entry. */
/* -------------------------------------------------------------------- */
poType = psHFA->poDictionary->FindType( szType );
if( poType == NULL )
return;
}
示例9: return
CPLErr HFABand::GetPCT( int * pnColors,
double **ppadfRed,
double **ppadfGreen,
double **ppadfBlue )
{
*pnColors = 0;
*ppadfRed = NULL;
*ppadfGreen = NULL;
*ppadfBlue = NULL;
/* -------------------------------------------------------------------- */
/* If we haven't already tried to load the colors, do so now. */
/* -------------------------------------------------------------------- */
if( nPCTColors == -1 )
{
HFAEntry *poColumnEntry;
int i, iColumn;
nPCTColors = 0;
poColumnEntry = poNode->GetNamedChild("Descriptor_Table.Red");
if( poColumnEntry == NULL )
return( CE_Failure );
nPCTColors = poColumnEntry->GetIntField( "numRows" );
for( iColumn = 0; iColumn < 3; iColumn++ )
{
apadfPCT[iColumn] = (double *)CPLMalloc(sizeof(double)*nPCTColors);
if( iColumn == 0 )
poColumnEntry = poNode->GetNamedChild("Descriptor_Table.Red");
else if( iColumn == 1 )
poColumnEntry= poNode->GetNamedChild("Descriptor_Table.Green");
else if( iColumn == 2 )
poColumnEntry = poNode->GetNamedChild("Descriptor_Table.Blue");
VSIFSeek( psInfo->fp, poColumnEntry->GetIntField("columnDataPtr"),
SEEK_SET );
VSIFRead( apadfPCT[iColumn], sizeof(double), nPCTColors,
psInfo->fp);
for( i = 0; i < nPCTColors; i++ )
HFAStandard( 8, apadfPCT[iColumn] + i );
}
}
/* -------------------------------------------------------------------- */
/* Return the values. */
/* -------------------------------------------------------------------- */
if( nPCTColors == 0 )
return( CE_Failure );
*pnColors = nPCTColors;
*ppadfRed = apadfPCT[0];
*ppadfGreen = apadfPCT[1];
*ppadfBlue = apadfPCT[2];
return( CE_None );
}
示例10: HFAGetDictionary
static char * HFAGetDictionary( HFAHandle hHFA )
{
char *pszDictionary = (char *) CPLMalloc(100);
int nDictMax = 100;
int nDictSize = 0;
VSIFSeek( hHFA->fp, hHFA->nDictionaryPos, SEEK_SET );
while( TRUE )
{
if( nDictSize >= nDictMax-1 )
{
nDictMax = nDictSize * 2 + 100;
pszDictionary = (char *) CPLRealloc(pszDictionary, nDictMax );
}
if( VSIFRead( pszDictionary + nDictSize, 1, 1, hHFA->fp ) < 1
|| pszDictionary[nDictSize] == '\0'
|| (nDictSize > 2 && pszDictionary[nDictSize-2] == ','
&& pszDictionary[nDictSize-1] == '.') )
break;
nDictSize++;
}
pszDictionary[nDictSize] = '\0';
return( pszDictionary );
}
示例11: EstablishRecordLength
void TigerFileBase::EstablishFeatureCount()
{
if( fpPrimary == NULL )
return;
nRecordLength = EstablishRecordLength( fpPrimary );
if( nRecordLength == -1 )
{
nRecordLength = 1;
nFeatures = 0;
return;
}
/* -------------------------------------------------------------------- */
/* Now we think we know the fixed record length for the file */
/* (including line terminators). Get the total file size, and */
/* divide by this length to get the presumed number of records. */
/* -------------------------------------------------------------------- */
long nFileSize;
VSIFSeek( fpPrimary, 0, SEEK_END );
nFileSize = VSIFTell( fpPrimary );
if( (nFileSize % nRecordLength) != 0 )
{
CPLError( CE_Warning, CPLE_FileIO,
"TigerFileBase::EstablishFeatureCount(): "
"File length %d doesn't divide by record length %d.\n",
(int) nFileSize, (int) nRecordLength );
}
nFeatures = nFileSize / nRecordLength;
}
示例12: NWT_GRDDataset
GDALDataset *NWT_GRDDataset::Open( GDALOpenInfo * poOpenInfo )
{
/* -------------------------------------------------------------------- */
/* Look for the header */
/* -------------------------------------------------------------------- */
if( poOpenInfo->fp == NULL || poOpenInfo->nHeaderBytes < 50 )
return NULL;
if( poOpenInfo->pabyHeader[0] != 'H' ||
poOpenInfo->pabyHeader[1] != 'G' ||
poOpenInfo->pabyHeader[2] != 'P' ||
poOpenInfo->pabyHeader[3] != 'C' || poOpenInfo->pabyHeader[4] != '1' )
return NULL;
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
NWT_GRDDataset *poDS;
poDS = new NWT_GRDDataset();
poDS->fp = poOpenInfo->fp;
poOpenInfo->fp = NULL;
/* -------------------------------------------------------------------- */
/* Read the header. */
/* -------------------------------------------------------------------- */
VSIFSeek( poDS->fp, 0, SEEK_SET );
VSIFRead( poDS->abyHeader, 1, 1024, poDS->fp );
poDS->pGrd = (NWT_GRID *) malloc(sizeof(NWT_GRID));
if (!nwt_ParseHeader( poDS->pGrd, (char *) poDS->abyHeader ) ||
!GDALCheckDatasetDimensions(poDS->pGrd->nXSide, poDS->pGrd->nYSide) )
{
delete poDS;
return NULL;
}
poDS->nRasterXSize = poDS->pGrd->nXSide;
poDS->nRasterYSize = poDS->pGrd->nYSide;
// create a colorTable
// if( poDS->pGrd->iNumColorInflections > 0 )
// poDS->CreateColorTable();
nwt_LoadColors( poDS->ColorMap, 4096, poDS->pGrd );
/* -------------------------------------------------------------------- */
/* Create band information objects. */
/* -------------------------------------------------------------------- */
poDS->SetBand( 1, new NWT_GRDRasterBand( poDS, 1 ) ); //r
poDS->SetBand( 2, new NWT_GRDRasterBand( poDS, 2 ) ); //g
poDS->SetBand( 3, new NWT_GRDRasterBand( poDS, 3 ) ); //b
poDS->SetBand( 4, new NWT_GRDRasterBand( poDS, 4 ) ); //z
/* -------------------------------------------------------------------- */
/* Initialize any PAM information. */
/* -------------------------------------------------------------------- */
poDS->SetDescription( poOpenInfo->pszFilename );
poDS->TryLoadXML();
return (poDS);
}
示例13: HFAGetDataTypeBits
CPLErr HFABand::GetRasterBlock( int nXBlock, int nYBlock, void * pData )
{
int iBlock;
if( LoadBlockInfo() != CE_None )
return CE_Failure;
iBlock = nXBlock + nYBlock * nBlocksPerRow;
/* -------------------------------------------------------------------- */
/* If the block isn't valid, or is compressed we just return */
/* all zeros, and an indication of failure. */
/* -------------------------------------------------------------------- */
if( !(panBlockFlag[iBlock] & (BFLG_VALID|BFLG_COMPRESSED)) )
{
int nBytes;
nBytes = HFAGetDataTypeBits(nDataType)*nBlockXSize*nBlockYSize/8;
while( nBytes > 0 )
((GByte *) pData)[--nBytes] = 0;
return( CE_Failure );
}
/* -------------------------------------------------------------------- */
/* Otherwise we really read the data. */
/* -------------------------------------------------------------------- */
if( VSIFSeek( psInfo->fp, panBlockStart[iBlock], SEEK_SET ) != 0 )
return CE_Failure;
if( VSIFRead( pData, panBlockSize[iBlock], 1, psInfo->fp ) == 0 )
return CE_Failure;
/* -------------------------------------------------------------------- */
/* Byte swap to local byte order if required. It appears that */
/* raster data is always stored in Intel byte order in Imagine */
/* files. */
/* -------------------------------------------------------------------- */
#ifdef CPL_MSB
if( HFAGetDataTypeBits(nDataType) == 16 )
{
int ii;
for( ii = 0; ii < nBlockXSize*nBlockYSize; ii++ )
{
unsigned char *pabyData = (unsigned char *) pData;
int nTemp;
nTemp = pabyData[ii*2];
pabyData[ii*2] = pabyData[ii*2+1];
pabyData[ii*2+1] = nTemp;
}
}
#endif /* def CPL_MSB */
return( CE_None );
}
示例14: VSIFRead
HFAEntry::HFAEntry( HFAInfo_t * psHFAIn, GUInt32 nPos,
HFAEntry * poParentIn, HFAEntry * poPrevIn )
{
psHFA = psHFAIn;
nFilePos = nPos;
poParent = poParentIn;
poPrev = poPrevIn;
/* -------------------------------------------------------------------- */
/* Initialize fields to null values in case there is a read */
/* error, so the entry will be in a harmless state. */
/* -------------------------------------------------------------------- */
poNext = poChild = NULL;
nDataPos = nDataSize = 0;
nNextPos = nChildPos = 0;
szName[0] = szType[0] = '\0';
pabyData = NULL;
poType = NULL;
/* -------------------------------------------------------------------- */
/* Read the entry information from the file. */
/* -------------------------------------------------------------------- */
GInt32 anEntryNums[6];
int i;
if( VSIFSeek( psHFA->fp, nFilePos, SEEK_SET ) == -1
|| VSIFRead( anEntryNums, sizeof(GInt32), 6, psHFA->fp ) < 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"VSIFRead() failed in HFAEntry()." );
return;
}
for( i = 0; i < 6; i++ )
HFAStandard( 4, anEntryNums + i );
nNextPos = anEntryNums[0];
nChildPos = anEntryNums[3];
nDataPos = anEntryNums[4];
nDataSize = anEntryNums[5];
/* -------------------------------------------------------------------- */
/* Read the name, and type. */
/* -------------------------------------------------------------------- */
if( VSIFRead( szName, 1, 64, psHFA->fp ) < 1
|| VSIFRead( szType, 1, 32, psHFA->fp ) < 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"VSIFRead() failed in HFAEntry()." );
return;
}
}
示例15: VSIFSeekL
int RawRasterBand::Seek( vsi_l_offset nOffset, int nSeekMode )
{
if( bIsVSIL )
return VSIFSeekL( fpRawL, nOffset, nSeekMode );
else
return VSIFSeek( fpRaw, (long) nOffset, nSeekMode );
}