本文整理汇总了C++中VSIFSeekL函数的典型用法代码示例。如果您正苦于以下问题:C++ VSIFSeekL函数的具体用法?C++ VSIFSeekL怎么用?C++ VSIFSeekL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VSIFSeekL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
NITFDES *NITFDESAccess( NITFFile *psFile, int iSegment )
{
NITFDES *psDES;
char *pachHeader;
NITFSegmentInfo *psSegInfo;
char szDESID[26];
char szTemp[128];
int nOffset;
int bHasDESOFLW;
int nDESSHL;
/* -------------------------------------------------------------------- */
/* Verify segment, and return existing DES accessor if there */
/* is one. */
/* -------------------------------------------------------------------- */
if( iSegment < 0 || iSegment >= psFile->nSegmentCount )
return NULL;
psSegInfo = psFile->pasSegmentInfo + iSegment;
if( !EQUAL(psSegInfo->szSegmentType,"DE") )
return NULL;
if( psSegInfo->hAccess != NULL )
return (NITFDES *) psSegInfo->hAccess;
/* -------------------------------------------------------------------- */
/* Read the DES subheader. */
/* -------------------------------------------------------------------- */
if (psSegInfo->nSegmentHeaderSize < 200)
{
CPLError(CE_Failure, CPLE_AppDefined,
"DES header too small");
return NULL;
}
pachHeader = (char*) VSIMalloc(psSegInfo->nSegmentHeaderSize);
if (pachHeader == NULL)
{
CPLError(CE_Failure, CPLE_OutOfMemory,
"Cannot allocate memory for segment header");
return NULL;
}
retry:
if( VSIFSeekL( psFile->fp, psSegInfo->nSegmentHeaderStart,
SEEK_SET ) != 0
|| VSIFReadL( pachHeader, 1, psSegInfo->nSegmentHeaderSize,
psFile->fp ) != psSegInfo->nSegmentHeaderSize )
{
CPLError( CE_Failure, CPLE_FileIO,
"Failed to read %u byte DES subheader from " CPL_FRMT_GUIB ".",
psSegInfo->nSegmentHeaderSize,
psSegInfo->nSegmentHeaderStart );
CPLFree(pachHeader);
return NULL;
}
if (!EQUALN(pachHeader, "DE", 2))
{
if (EQUALN(pachHeader + 4, "DERegistered", 12))
{
/* BAO_46_Ed1/rpf/conc/concz10/000fz010.ona and cie are buggy */
CPLDebug("NITF", "Patching nSegmentHeaderStart and nSegmentStart for DE segment %d", iSegment);
psSegInfo->nSegmentHeaderStart += 4;
psSegInfo->nSegmentStart += 4;
goto retry;
}
CPLError(CE_Failure, CPLE_AppDefined,
"Invalid segment prefix for DE segment %d", iSegment);
CPLFree(pachHeader);
return NULL;
}
/* -------------------------------------------------------------------- */
/* Initialize DES object. */
/* -------------------------------------------------------------------- */
psDES = (NITFDES *) CPLCalloc(sizeof(NITFDES),1);
psDES->psFile = psFile;
psDES->iSegment = iSegment;
psDES->pachHeader = pachHeader;
psSegInfo->hAccess = psDES;
/* -------------------------------------------------------------------- */
/* Collect a variety of information as metadata. */
/* -------------------------------------------------------------------- */
#define GetMD( length, name ) \
do { NITFExtractMetadata( &(psDES->papszMetadata), pachHeader, \
nOffset, length, \
"NITF_" #name ); \
nOffset += length; } while(0)
nOffset = 2;
GetMD( 25, DESID );
GetMD( 2, DESVER );
//.........这里部分代码省略.........
示例2: while
OGRFeature *OGRIdrisiLayer::GetNextRawFeature()
{
while(TRUE)
{
if (eGeomType == wkbPoint)
{
double dfId;
double dfX, dfY;
if (VSIFReadL(&dfId, sizeof(double), 1, fp) != 1 ||
VSIFReadL(&dfX, sizeof(double), 1, fp) != 1 ||
VSIFReadL(&dfY, sizeof(double), 1, fp) != 1)
{
return NULL;
}
CPL_LSBPTR64(&dfId);
CPL_LSBPTR64(&dfX);
CPL_LSBPTR64(&dfY);
if (m_poFilterGeom != NULL &&
(dfX < m_sFilterEnvelope.MinX ||
dfX > m_sFilterEnvelope.MaxX ||
dfY < m_sFilterEnvelope.MinY ||
dfY > m_sFilterEnvelope.MaxY))
{
nNextFID ++;
continue;
}
OGRPoint* poGeom = new OGRPoint(dfX, dfY);
if (poSRS)
poGeom->assignSpatialReference(poSRS);
OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
poFeature->SetField(0, dfId);
poFeature->SetFID(nNextFID ++);
poFeature->SetGeometryDirectly(poGeom);
ReadAVLLine(poFeature);
return poFeature;
}
else if (eGeomType == wkbLineString)
{
double dfId;
double dfMinXShape, dfMaxXShape, dfMinYShape, dfMaxYShape;
unsigned int nNodes;
if (VSIFReadL(&dfId, sizeof(double), 1, fp) != 1 ||
VSIFReadL(&dfMinXShape, sizeof(double), 1, fp) != 1 ||
VSIFReadL(&dfMaxXShape, sizeof(double), 1, fp) != 1 ||
VSIFReadL(&dfMinYShape, sizeof(double), 1, fp) != 1 ||
VSIFReadL(&dfMaxYShape, sizeof(double), 1, fp) != 1)
{
return NULL;
}
CPL_LSBPTR64(&dfId);
CPL_LSBPTR64(&dfMinXShape);
CPL_LSBPTR64(&dfMaxXShape);
CPL_LSBPTR64(&dfMinYShape);
CPL_LSBPTR64(&dfMaxYShape);
if (VSIFReadL(&nNodes, sizeof(unsigned int), 1, fp) != 1)
{
return NULL;
}
CPL_LSBPTR32(&nNodes);
if (nNodes > 100 * 1000 * 1000)
return NULL;
if (m_poFilterGeom != NULL &&
(dfMaxXShape < m_sFilterEnvelope.MinX ||
dfMinXShape > m_sFilterEnvelope.MaxX ||
dfMaxYShape < m_sFilterEnvelope.MinY ||
dfMinYShape > m_sFilterEnvelope.MaxY))
{
nNextFID ++;
VSIFSeekL(fp, sizeof(OGRRawPoint) * nNodes, SEEK_CUR);
continue;
}
OGRRawPoint* poRawPoints = (OGRRawPoint*)VSIMalloc2(sizeof(OGRRawPoint), nNodes);
if (poRawPoints == NULL)
{
return NULL;
}
if ((unsigned int)VSIFReadL(poRawPoints, sizeof(OGRRawPoint), nNodes, fp) != nNodes)
{
VSIFree(poRawPoints);
return NULL;
}
#if defined(CPL_MSB)
for(unsigned int iNode=0; iNode<nNodes; iNode++)
{
CPL_LSBPTR64(&poRawPoints[iNode].x);
CPL_LSBPTR64(&poRawPoints[iNode].y);
}
#endif
OGRLineString* poGeom = new OGRLineString();
poGeom->setPoints(nNodes, poRawPoints, NULL);
//.........这里部分代码省略.........
示例3: VSIFTellL
int GDALJP2Box::ReadBox()
{
GUInt32 nLBox;
GUInt32 nTBox;
nBoxOffset = VSIFTellL( fpVSIL );
if( VSIFReadL( &nLBox, 4, 1, fpVSIL ) != 1
|| VSIFReadL( &nTBox, 4, 1, fpVSIL ) != 1 )
{
return FALSE;
}
memcpy( szBoxType, &nTBox, 4 );
szBoxType[4] = '\0';
nLBox = CPL_MSBWORD32( nLBox );
if( nLBox != 1 )
{
nBoxLength = nLBox;
nDataOffset = nBoxOffset + 8;
}
else
{
GByte abyXLBox[8];
if( VSIFReadL( abyXLBox, 8, 1, fpVSIL ) != 1 )
return FALSE;
if( sizeof(nBoxLength) == 8 )
{
CPL_MSBPTR64( abyXLBox );
memcpy( &nBoxLength, abyXLBox, 8 );
}
else
{
CPL_MSBPTR32( abyXLBox+4 );
memcpy( &nBoxLength, abyXLBox+4, 4 );
}
nDataOffset = nBoxOffset + 16;
}
if( nBoxLength == 0 )
{
VSIFSeekL( fpVSIL, 0, SEEK_END );
nBoxLength = VSIFTellL( fpVSIL ) - nBoxOffset;
VSIFSeekL( fpVSIL, nDataOffset, SEEK_SET );
}
if( EQUAL(szBoxType,"uuid") )
{
if( VSIFReadL( abyUUID, 16, 1, fpVSIL ) != 1 )
return FALSE;
nDataOffset += 16;
}
if( GetDataLength() < 0 )
{
CPLDebug("GDALJP2", "Invalid length for box %s", szBoxType);
return FALSE;
}
return TRUE;
}
示例4: osOriginalFilename
GDALDataset *HF2Dataset::Open( GDALOpenInfo * poOpenInfo )
{
CPLString osOriginalFilename(poOpenInfo->pszFilename);
if (!Identify(poOpenInfo))
return NULL;
GDALOpenInfo* poOpenInfoToDelete = NULL;
/* GZipped .hf2 files are common, so automagically open them */
/* if the /vsigzip/ has not been explicitly passed */
CPLString osFilename(poOpenInfo->pszFilename);
if ((EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "hfz") ||
(strlen(poOpenInfo->pszFilename) > 6 &&
EQUAL(poOpenInfo->pszFilename + strlen(poOpenInfo->pszFilename) - 6, "hf2.gz"))) &&
!EQUALN(poOpenInfo->pszFilename, "/vsigzip/", 9))
{
osFilename = "/vsigzip/";
osFilename += poOpenInfo->pszFilename;
poOpenInfo = poOpenInfoToDelete =
new GDALOpenInfo(osFilename.c_str(), GA_ReadOnly,
poOpenInfo->GetSiblingFiles());
}
/* -------------------------------------------------------------------- */
/* Parse header */
/* -------------------------------------------------------------------- */
int nXSize, nYSize;
memcpy(&nXSize, poOpenInfo->pabyHeader + 6, 4);
CPL_LSBPTR32(&nXSize);
memcpy(&nYSize, poOpenInfo->pabyHeader + 10, 4);
CPL_LSBPTR32(&nYSize);
GUInt16 nTileSize;
memcpy(&nTileSize, poOpenInfo->pabyHeader + 14, 2);
CPL_LSBPTR16(&nTileSize);
float fVertPres, fHorizScale;
memcpy(&fVertPres, poOpenInfo->pabyHeader + 16, 4);
CPL_LSBPTR32(&fVertPres);
memcpy(&fHorizScale, poOpenInfo->pabyHeader + 20, 4);
CPL_LSBPTR32(&fHorizScale);
GUInt32 nExtendedHeaderLen;
memcpy(&nExtendedHeaderLen, poOpenInfo->pabyHeader + 24, 4);
CPL_LSBPTR32(&nExtendedHeaderLen);
delete poOpenInfoToDelete;
poOpenInfoToDelete = NULL;
if (nTileSize < 8)
return NULL;
if (nXSize <= 0 || nXSize > INT_MAX - nTileSize ||
nYSize <= 0 || nYSize > INT_MAX - nTileSize)
return NULL;
/* To avoid later potential int overflows */
if (nExtendedHeaderLen > 1024 * 65536)
return NULL;
if (!GDALCheckDatasetDimensions(nXSize, nYSize))
{
return NULL;
}
/* -------------------------------------------------------------------- */
/* Parse extended blocks */
/* -------------------------------------------------------------------- */
VSILFILE* fp = VSIFOpenL(osFilename.c_str(), "rb");
if (fp == NULL)
return NULL;
VSIFSeekL(fp, 28, SEEK_SET);
int bHasExtent = FALSE;
double dfMinX = 0, dfMaxX = 0, dfMinY = 0, dfMaxY = 0;
int bHasUTMZone = FALSE;
GInt16 nUTMZone = 0;
int bHasEPSGDatumCode = FALSE;
GInt16 nEPSGDatumCode = 0;
int bHasEPSGCode = FALSE;
GInt16 nEPSGCode = 0;
int bHasRelativePrecision = FALSE;
float fRelativePrecision = 0;
char szApplicationName[256];
szApplicationName[0] = 0;
GUInt32 nExtendedHeaderOff = 0;
while(nExtendedHeaderOff < nExtendedHeaderLen)
{
char pabyBlockHeader[24];
VSIFReadL(pabyBlockHeader, 24, 1, fp);
char szBlockName[16 + 1];
memcpy(szBlockName, pabyBlockHeader + 4, 16);
szBlockName[16] = 0;
GUInt32 nBlockSize;
memcpy(&nBlockSize, pabyBlockHeader + 20, 4);
CPL_LSBPTR32(&nBlockSize);
//.........这里部分代码省略.........
示例5: GTXDataset
GDALDataset *GTXDataset::Open( GDALOpenInfo * poOpenInfo )
{
if( !Identify( poOpenInfo ) )
return NULL;
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
GTXDataset *poDS = new GTXDataset();
poDS->eAccess = poOpenInfo->eAccess;
/* -------------------------------------------------------------------- */
/* Open the file. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_ReadOnly )
poDS->fpImage = VSIFOpenL( poOpenInfo->pszFilename, "rb" );
else
poDS->fpImage = VSIFOpenL( poOpenInfo->pszFilename, "rb+" );
if( poDS->fpImage == NULL )
{
delete poDS;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Read the header. */
/* -------------------------------------------------------------------- */
poDS->adfGeoTransform[2] = 0.0;
poDS->adfGeoTransform[4] = 0.0;
CPL_IGNORE_RET_VAL(VSIFReadL( poDS->adfGeoTransform+3, 8, 1,
poDS->fpImage ));
CPL_IGNORE_RET_VAL(VSIFReadL( poDS->adfGeoTransform+0, 8, 1,
poDS->fpImage ));
CPL_IGNORE_RET_VAL(VSIFReadL( poDS->adfGeoTransform+5, 8, 1,
poDS->fpImage ));
CPL_IGNORE_RET_VAL(VSIFReadL( poDS->adfGeoTransform+1, 8, 1,
poDS->fpImage ));
CPL_IGNORE_RET_VAL(VSIFReadL( &(poDS->nRasterYSize), 4, 1, poDS->fpImage ));
CPL_IGNORE_RET_VAL(VSIFReadL( &(poDS->nRasterXSize), 4, 1, poDS->fpImage ));
CPL_MSBPTR32( &(poDS->nRasterYSize) );
CPL_MSBPTR32( &(poDS->nRasterXSize) );
CPL_MSBPTR64( poDS->adfGeoTransform + 0 );
CPL_MSBPTR64( poDS->adfGeoTransform + 1 );
CPL_MSBPTR64( poDS->adfGeoTransform + 3 );
CPL_MSBPTR64( poDS->adfGeoTransform + 5 );
poDS->adfGeoTransform[3] +=
poDS->adfGeoTransform[5] * (poDS->nRasterYSize-1);
poDS->adfGeoTransform[0] -= poDS->adfGeoTransform[1] * 0.5;
poDS->adfGeoTransform[3] += poDS->adfGeoTransform[5] * 0.5;
poDS->adfGeoTransform[5] *= -1;
if (!GDALCheckDatasetDimensions(poDS->nRasterXSize, poDS->nRasterYSize))
{
delete poDS;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Guess the data type. Since October 1, 2009, it should be */
/* Float32. Before it was double. */
/* -------------------------------------------------------------------- */
CPL_IGNORE_RET_VAL(VSIFSeekL(poDS->fpImage, 0, SEEK_END));
const vsi_l_offset nSize = VSIFTellL(poDS->fpImage);
GDALDataType eDT = GDT_Float32;
if( nSize == 40 + 8 * static_cast<vsi_l_offset>(poDS->nRasterXSize) *
poDS->nRasterYSize )
eDT = GDT_Float64;
const int nDTSize = GDALGetDataTypeSizeBytes(eDT);
/* -------------------------------------------------------------------- */
/* Create band information object. */
/* -------------------------------------------------------------------- */
RawRasterBand *poBand = new RawRasterBand(
poDS, 1, poDS->fpImage,
(poDS->nRasterYSize-1) * poDS->nRasterXSize*nDTSize + 40,
nDTSize, poDS->nRasterXSize * -nDTSize,
eDT,
!CPL_IS_LSB, TRUE, FALSE );
poBand->SetNoDataValue( -88.8888 );
poDS->SetBand( 1, poBand );
/* -------------------------------------------------------------------- */
/* Initialize any PAM information. */
/* -------------------------------------------------------------------- */
poDS->SetDescription( poOpenInfo->pszFilename );
poDS->TryLoadXML();
/* -------------------------------------------------------------------- */
/* Check for overviews. */
//.........这里部分代码省略.........
示例6: GetShapeRecordId
int TigerCompleteChain::AddShapePoints( int nTLID, int nRecordId,
OGRLineString * poLine, CPL_UNUSED int nSeqNum )
{
int nShapeRecId;
nShapeRecId = GetShapeRecordId( nRecordId, nTLID );
// -2 means an error occured.
if( nShapeRecId == -2 )
return FALSE;
// -1 means there are no extra shape vertices, but things worked fine.
if( nShapeRecId == -1 )
return TRUE;
/* -------------------------------------------------------------------- */
/* Read all the sequential records with the same TLID. */
/* -------------------------------------------------------------------- */
char achShapeRec[OGR_TIGER_RECBUF_LEN];
int nShapeRecLen = psRT2Info->nRecordLength + nRecordLength - psRT1Info->nRecordLength;
for( ; TRUE; nShapeRecId++ )
{
int nBytesRead = 0;
if( VSIFSeekL( fpShape, (nShapeRecId-1) * nShapeRecLen,
SEEK_SET ) != 0 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Failed to seek to %d of %s2",
(nShapeRecId-1) * nShapeRecLen, pszModule );
return FALSE;
}
nBytesRead = VSIFReadL( achShapeRec, 1, psRT2Info->nRecordLength,
fpShape );
/*
** Handle case where the last record in the file is full. We will
** try to read another record but not find it. We require that we
** have found at least one shape record for this case though.
*/
if( nBytesRead <= 0 && VSIFEofL( fpShape )
&& poLine->getNumPoints() > 0 )
break;
if( nBytesRead != psRT2Info->nRecordLength )
{
CPLError( CE_Failure, CPLE_FileIO,
"Failed to read %d bytes of record %d of %s2 at offset %d",
psRT2Info->nRecordLength, nShapeRecId, pszModule,
(nShapeRecId-1) * nShapeRecLen );
return FALSE;
}
if( atoi(GetField(achShapeRec,6,15)) != nTLID )
break;
/* -------------------------------------------------------------------- */
/* Translate the locations into OGRLineString vertices. */
/* -------------------------------------------------------------------- */
int iVertex;
for( iVertex = 0; iVertex < 10; iVertex++ )
{
int iStart = 19 + 19*iVertex;
int nX = atoi(GetField(achShapeRec,iStart,iStart+9));
int nY = atoi(GetField(achShapeRec,iStart+10,iStart+18));
if( nX == 0 && nY == 0 )
break;
poLine->addPoint( nX / 1000000.0, nY / 1000000.0 );
}
/* -------------------------------------------------------------------- */
/* Don't get another record if this one was incomplete. */
/* -------------------------------------------------------------------- */
if( iVertex < 10 )
break;
}
return TRUE;
}
示例7: CPL_LSBWORD32
GDALDataset *GSCDataset::Open( GDALOpenInfo * poOpenInfo )
{
int nPixels, nLines, i, nRecordLen;
/* -------------------------------------------------------------------- */
/* Does this plausible look like a GSC Geogrid file? */
/* -------------------------------------------------------------------- */
if( poOpenInfo->nHeaderBytes < 20 )
return NULL;
if( poOpenInfo->pabyHeader[12] != 0x02
|| poOpenInfo->pabyHeader[13] != 0x00
|| poOpenInfo->pabyHeader[14] != 0x00
|| poOpenInfo->pabyHeader[15] != 0x00 )
return NULL;
nRecordLen = CPL_LSBWORD32(((GInt32 *) poOpenInfo->pabyHeader)[0]);
nPixels = CPL_LSBWORD32(((GInt32 *) poOpenInfo->pabyHeader)[1]);
nLines = CPL_LSBWORD32(((GInt32 *) poOpenInfo->pabyHeader)[2]);
if( nPixels < 1 || nLines < 1 || nPixels > 100000 || nLines > 100000 )
return NULL;
if( nRecordLen != nPixels * 4 )
return NULL;
/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The GSC driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
nRecordLen += 8; /* for record length markers */
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
GSCDataset *poDS;
poDS = new GSCDataset();
poDS->nRasterXSize = nPixels;
poDS->nRasterYSize = nLines;
/* -------------------------------------------------------------------- */
/* Assume ownership of the file handled from the GDALOpenInfo. */
/* -------------------------------------------------------------------- */
poDS->fpImage = VSIFOpenL(poOpenInfo->pszFilename, "rb");
if (poDS->fpImage == NULL)
{
delete poDS;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Read the header information in the second record. */
/* -------------------------------------------------------------------- */
float afHeaderInfo[8];
if( VSIFSeekL( poDS->fpImage, nRecordLen + 12, SEEK_SET ) != 0
|| VSIFReadL( afHeaderInfo, sizeof(float), 8, poDS->fpImage ) != 8 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Failure reading second record of GSC file with %d record length.",
nRecordLen );
delete poDS;
return NULL;
}
for( i = 0; i < 8; i++ )
{
CPL_LSBPTR32( afHeaderInfo + i );
}
poDS->adfGeoTransform[0] = afHeaderInfo[2];
poDS->adfGeoTransform[1] = afHeaderInfo[0];
poDS->adfGeoTransform[2] = 0.0;
poDS->adfGeoTransform[3] = afHeaderInfo[5];
poDS->adfGeoTransform[4] = 0.0;
poDS->adfGeoTransform[5] = -afHeaderInfo[1];
/* -------------------------------------------------------------------- */
/* Create band information objects. */
/* -------------------------------------------------------------------- */
RawRasterBand *poBand;
#ifdef CPL_LSB
int bNative = TRUE;
#else
int bNative = FALSE;
#endif
poBand = new RawRasterBand( poDS, 1, poDS->fpImage,
nRecordLen * 2 + 4,
sizeof(float), nRecordLen,
//.........这里部分代码省略.........
示例8: CPLError
CPLErr GS7BGDataset::WriteHeader( VSILFILE *fp, GInt32 nXSize, GInt32 nYSize,
double dfMinX, double dfMaxX,
double dfMinY, double dfMaxY,
double dfMinZ, double dfMaxZ )
{
if( VSIFSeekL( fp, 0, SEEK_SET ) != 0 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to seek to start of grid file.\n" );
return CE_Failure;
}
GInt32 nTemp = CPL_LSBWORD32(nHEADER_TAG);
if( VSIFWriteL( (void *)&nTemp, sizeof(GInt32), 1, fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to write header tag to grid file.\n" );
return CE_Failure;
}
nTemp = CPL_LSBWORD32(sizeof(GInt32)); // Size of version section.
if( VSIFWriteL( (void *)&nTemp, sizeof(GInt32), 1, fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to write size to grid file.\n" );
return CE_Failure;
}
nTemp = CPL_LSBWORD32(1); // Version
if( VSIFWriteL( (void *)&nTemp, sizeof(GInt32), 1, fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to write size to grid file.\n" );
return CE_Failure;
}
nTemp = CPL_LSBWORD32(nGRID_TAG); // Mark start of grid
if( VSIFWriteL( (void *)&nTemp, sizeof(GInt32), 1, fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to write size to grid file.\n" );
return CE_Failure;
}
nTemp = CPL_LSBWORD32(72); // Grid info size (the remainder of the header)
if( VSIFWriteL( (void *)&nTemp, sizeof(GInt32), 1, fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to write size to grid file.\n" );
return CE_Failure;
}
nTemp = CPL_LSBWORD32(nYSize);
if( VSIFWriteL( (void *)&nTemp, sizeof(GInt32), 1, fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to write Y size to grid file.\n" );
return CE_Failure;
}
nTemp = CPL_LSBWORD32(nXSize);
if( VSIFWriteL( (void *)&nTemp, sizeof(GInt32), 1, fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to write X size to grid file.\n" );
return CE_Failure;
}
double dfTemp = dfMinX;
CPL_LSBPTR64(&dfTemp);
if( VSIFWriteL( (void *)&dfTemp, sizeof(double), 1, fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to write minimum X value to grid file.\n" );
return CE_Failure;
}
dfTemp = dfMinY;
CPL_LSBPTR64( &dfTemp );
if( VSIFWriteL( (void *)&dfTemp, sizeof(double), 1, fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to write minimum Y value to grid file.\n" );
return CE_Failure;
}
// Write node spacing in x direction
dfTemp = (dfMaxX - dfMinX) / (nXSize - 1);
CPL_LSBPTR64(&dfTemp);
if( VSIFWriteL( (void *)&dfTemp, sizeof(double), 1, fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Unable to write spacing in X value.\n" );
return CE_Failure;
}
// Write node spacing in y direction
dfTemp = (dfMaxY - dfMinY) / (nYSize -1);
CPL_LSBPTR64( &dfTemp );
//.........这里部分代码省略.........
示例9: RPFTOCReadFromBuffer
RPFToc* RPFTOCReadFromBuffer(const char* pszFilename, VSILFILE* fp, const char* tocHeader)
{
tocHeader += 1; /* skip endian */
tocHeader += 2; /* skip header length */
tocHeader += 12; /* skip file name : this should be A.TOC (padded) */
tocHeader += 1; /* skip new */
tocHeader += 15; /* skip standard_num */
tocHeader += 8; /* skip standard_date */
tocHeader += 1; /* skip classification */
tocHeader += 2; /* skip country */
tocHeader += 2; /* skip release */
unsigned int locationSectionPhysicalLocation;
memcpy(&locationSectionPhysicalLocation, tocHeader, sizeof(unsigned int));
CPL_MSBPTR32(&locationSectionPhysicalLocation);
if( VSIFSeekL( fp, locationSectionPhysicalLocation, SEEK_SET ) != 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Invalid TOC file. Unable to seek to locationSectionPhysicalLocation at offset %d.",
locationSectionPhysicalLocation );
return nullptr;
}
int nSections;
NITFLocation* pasLocations = NITFReadRPFLocationTable(fp, &nSections);
unsigned int boundaryRectangleSectionSubHeaderPhysIndex = 0;
unsigned int boundaryRectangleTablePhysIndex = 0;
unsigned int frameFileIndexSectionSubHeaderPhysIndex = 0;
unsigned int frameFileIndexSubsectionPhysIndex = 0;
for( int i = 0; i < nSections; i++ )
{
if (pasLocations[i].nLocId == LID_BoundaryRectangleSectionSubheader)
{
boundaryRectangleSectionSubHeaderPhysIndex = pasLocations[i].nLocOffset;
}
else if (pasLocations[i].nLocId == LID_BoundaryRectangleTable)
{
boundaryRectangleTablePhysIndex = pasLocations[i].nLocOffset;
}
else if (pasLocations[i].nLocId == LID_FrameFileIndexSectionSubHeader)
{
frameFileIndexSectionSubHeaderPhysIndex = pasLocations[i].nLocOffset;
}
else if (pasLocations[i].nLocId == LID_FrameFileIndexSubsection)
{
frameFileIndexSubsectionPhysIndex = pasLocations[i].nLocOffset;
}
}
CPLFree(pasLocations);
if (boundaryRectangleSectionSubHeaderPhysIndex == 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Invalid TOC file. Can't find LID_BoundaryRectangleSectionSubheader." );
return nullptr;
}
if (boundaryRectangleTablePhysIndex == 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Invalid TOC file. Can't find LID_BoundaryRectangleTable." );
return nullptr;
}
if (frameFileIndexSectionSubHeaderPhysIndex == 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Invalid TOC file. Can't find LID_FrameFileIndexSectionSubHeader." );
return nullptr;
}
if (frameFileIndexSubsectionPhysIndex == 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Invalid TOC file. Can't find LID_FrameFileIndexSubsection." );
return nullptr;
}
if( VSIFSeekL( fp, boundaryRectangleSectionSubHeaderPhysIndex, SEEK_SET ) != 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Invalid TOC file. Unable to seek to boundaryRectangleSectionSubHeaderPhysIndex at offset %d.",
boundaryRectangleSectionSubHeaderPhysIndex );
return nullptr;
}
unsigned int boundaryRectangleTableOffset;
bool bOK = VSIFReadL( &boundaryRectangleTableOffset, sizeof(boundaryRectangleTableOffset), 1, fp) == 1;
CPL_MSBPTR32( &boundaryRectangleTableOffset );
unsigned short boundaryRectangleCount;
bOK &= VSIFReadL( &boundaryRectangleCount, sizeof(boundaryRectangleCount), 1, fp) == 1;
CPL_MSBPTR16( &boundaryRectangleCount );
if( !bOK || VSIFSeekL( fp, boundaryRectangleTablePhysIndex, SEEK_SET ) != 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Invalid TOC file. Unable to seek to boundaryRectangleTablePhysIndex at offset %d.",
boundaryRectangleTablePhysIndex );
//.........这里部分代码省略.........
示例10: GS7BGDataset
GDALDataset *GS7BGDataset::Open( GDALOpenInfo * poOpenInfo )
{
if( !Identify(poOpenInfo) )
{
return NULL;
}
/* ------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* ------------------------------------------------------------------- */
GS7BGDataset *poDS = new GS7BGDataset();
/* ------------------------------------------------------------------- */
/* Open file with large file API. */
/* ------------------------------------------------------------------- */
poDS->eAccess = poOpenInfo->eAccess;
if( poOpenInfo->eAccess == GA_ReadOnly )
poDS->fp = VSIFOpenL( poOpenInfo->pszFilename, "rb" );
else
poDS->fp = VSIFOpenL( poOpenInfo->pszFilename, "r+b" );
if( poDS->fp == NULL )
{
delete poDS;
CPLError( CE_Failure, CPLE_OpenFailed,
"VSIFOpenL(%s) failed unexpectedly.",
poOpenInfo->pszFilename );
return NULL;
}
/* ------------------------------------------------------------------- */
/* Read the header. The Header section must be the first section */
/* in the file. */
/* ------------------------------------------------------------------- */
if( VSIFSeekL( poDS->fp, 0, SEEK_SET ) != 0 )
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO,
"Unable to seek to start of grid file header.\n" );
return NULL;
}
GInt32 nTag;
if( VSIFReadL( (void *)&nTag, sizeof(GInt32), 1, poDS->fp ) != 1 )
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO, "Unable to read Tag.\n" );
return NULL;
}
CPL_LSBPTR32( &nTag );
if(nTag != nHEADER_TAG)
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO, "Header tag not found.\n" );
return NULL;
}
GUInt32 nSize;
if( VSIFReadL( (void *)&nSize, sizeof(GUInt32), 1, poDS->fp ) != 1 )
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO,
"Unable to read file section size.\n" );
return NULL;
}
CPL_LSBPTR32( &nSize );
GInt32 nVersion;
if( VSIFReadL( (void *)&nVersion, sizeof(GInt32), 1, poDS->fp ) != 1 )
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO,
"Unable to read file version.\n" );
return NULL;
}
CPL_LSBPTR32( &nVersion );
if(nVersion != 1 && nVersion != 2)
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO,
"Incorrect file version (%d).", nVersion );
return NULL;
}
// advance until the grid tag is found
while(nTag != nGRID_TAG)
{
if( VSIFReadL( (void *)&nTag, sizeof(GInt32), 1, poDS->fp ) != 1 )
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO, "Unable to read Tag.\n" );
return NULL;
}
//.........这里部分代码省略.........
示例11: CPLFormFilename
void GDALPamProxyDB::LoadDB()
{
/* -------------------------------------------------------------------- */
/* Open the database relating original names to proxy .aux.xml */
/* file names. */
/* -------------------------------------------------------------------- */
CPLString osDBName =
CPLFormFilename( osProxyDBDir, "gdal_pam_proxy", "dat" );
FILE *fpDB = VSIFOpenL( osDBName, "r" );
nUpdateCounter = 0;
if( fpDB == NULL )
return;
/* -------------------------------------------------------------------- */
/* Read header, verify and extract update counter. */
/* -------------------------------------------------------------------- */
GByte abyHeader[100];
if( VSIFReadL( abyHeader, 1, 100, fpDB ) != 100
|| strncmp( (const char *) abyHeader, "GDAL_PROXY", 10 ) != 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Problem reading %s header - short or corrupt?",
osDBName.c_str() );
return;
}
nUpdateCounter = atoi((const char *) abyHeader + 10);
/* -------------------------------------------------------------------- */
/* Read the file in one gulp. */
/* -------------------------------------------------------------------- */
int nBufLength;
char *pszDBData;
VSIFSeekL( fpDB, 0, SEEK_END );
nBufLength = (int) (VSIFTellL(fpDB) - 100);
pszDBData = (char *) CPLCalloc(1,nBufLength+1);
VSIFSeekL( fpDB, 100, SEEK_SET );
VSIFReadL( pszDBData, 1, nBufLength, fpDB );
VSIFCloseL( fpDB );
/* -------------------------------------------------------------------- */
/* Parse the list of in/out names. */
/* -------------------------------------------------------------------- */
int iNext = 0;
while( iNext < nBufLength )
{
CPLString osOriginal, osProxy;
osOriginal.assign( pszDBData + iNext );
for( ; iNext < nBufLength && pszDBData[iNext] != '\0'; iNext++ ) {}
if( iNext == nBufLength )
break;
iNext++;
osProxy = osProxyDBDir;
osProxy += "/";
osProxy += pszDBData + iNext;
for( ; iNext < nBufLength && pszDBData[iNext] != '\0'; iNext++ ) {}
iNext++;
aosOriginalFiles.push_back( osOriginal );
aosProxyFiles.push_back( osProxy );
}
CPLFree( pszDBData );
}
示例12: RPFTOCReadFromBuffer
RPFToc* RPFTOCReadFromBuffer(const char* pszFilename, FILE* fp, const char* tocHeader)
{
int i, j;
unsigned int locationSectionPhysicalLocation;
unsigned short nSections;
unsigned int boundaryRectangleSectionSubHeaderPhysIndex = 0, boundaryRectangleSectionSubHeaderLength = 0;
unsigned int boundaryRectangleTablePhysIndex = 0, boundaryRectangleTableLength = 0;
unsigned int frameFileIndexSectionSubHeaderPhysIndex = 0, frameFileIndexSectionSubHeaderLength = 0;
unsigned int frameFileIndexSubsectionPhysIndex = 0, frameFileIndexSubsectionLength = 0;
unsigned int boundaryRectangleTableOffset;
unsigned short boundaryRectangleCount;
unsigned int frameIndexTableOffset;
unsigned int nFrameFileIndexRecords;
unsigned short nFrameFilePathnameRecords;
unsigned short frameFileIndexRecordLength;
int newBoundaryId = 0;
RPFToc* toc;
tocHeader += 1; /* skip endian */
tocHeader += 2; /* skip header length */
tocHeader += 12; /* skip file name : this should be A.TOC (padded) */
tocHeader += 1; /* skip new */
tocHeader += 15; /* skip standard_num */
tocHeader += 8; /* skip standard_date */
tocHeader += 1; /* skip classification */
tocHeader += 2; /* skip country */
tocHeader += 2; /* skip release */
memcpy(&locationSectionPhysicalLocation, tocHeader, sizeof(unsigned int));
CPL_MSBPTR32(&locationSectionPhysicalLocation);
if( VSIFSeekL( fp, locationSectionPhysicalLocation, SEEK_SET ) != 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Invalid TOC file. Unable to seek to locationSectionPhysicalLocation at offset %d.",
locationSectionPhysicalLocation );
return NULL;
}
/* Skip location section length (4) and component location table offset (2)*/
VSIFSeekL( fp, 4 + 2, SEEK_CUR);
/* How many sections: # of section location records */
VSIFReadL( &nSections, 1, sizeof(nSections), fp);
CPL_MSBPTR16( &nSections );
/* Skip location record length(2) + component aggregate length(4) */
VSIFSeekL( fp, 2 + 4, SEEK_CUR);
for (i = 0; i < nSections; i++)
{
unsigned short id;
unsigned int sectionLength, physIndex;
VSIFReadL( &id, 1, sizeof(id), fp);
CPL_MSBPTR16( &id );
VSIFReadL( §ionLength, 1, sizeof(sectionLength), fp);
CPL_MSBPTR32( §ionLength );
VSIFReadL( &physIndex, 1, sizeof(physIndex), fp);
CPL_MSBPTR32( &physIndex );
if (id == LID_BoundaryRectangleSectionSubheader)
{
boundaryRectangleSectionSubHeaderPhysIndex = physIndex;
boundaryRectangleSectionSubHeaderLength = sectionLength;
}
else if (id == LID_BoundaryRectangleTable)
{
boundaryRectangleTablePhysIndex = physIndex;
boundaryRectangleTableLength = sectionLength;
}
else if (id == LID_FrameFileIndexSectionSubHeader)
{
frameFileIndexSectionSubHeaderPhysIndex = physIndex;
frameFileIndexSectionSubHeaderLength = sectionLength;
}
else if (id == LID_FrameFileIndexSubsection)
{
frameFileIndexSubsectionPhysIndex = physIndex;
frameFileIndexSubsectionLength = sectionLength;
}
}
if (boundaryRectangleSectionSubHeaderPhysIndex == 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Invalid TOC file. Can't find LID_BoundaryRectangleSectionSubheader." );
return NULL;
}
if (boundaryRectangleTablePhysIndex == 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Invalid TOC file. Can't find LID_BoundaryRectangleTable." );
return NULL;
//.........这里部分代码省略.........
示例13: CPLAssert
CPLErr LevellerRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void* pImage )
{
CPLAssert( sizeof(float) == sizeof(GInt32) );
CPLAssert( nBlockXOff == 0 );
CPLAssert( pImage != NULL );
LevellerDataset *poGDS = (LevellerDataset *) poDS;
/* -------------------------------------------------------------------- */
/* Seek to scanline. */
/* -------------------------------------------------------------------- */
const size_t rowbytes = nBlockXSize * sizeof(float);
if(0 != VSIFSeekL(
poGDS->m_fp,
poGDS->m_nDataOffset + nBlockYOff * rowbytes,
SEEK_SET))
{
CPLError( CE_Failure, CPLE_FileIO,
".bt Seek failed:%s", VSIStrerror( errno ) );
return CE_Failure;
}
/* -------------------------------------------------------------------- */
/* Read the scanline into the image buffer. */
/* -------------------------------------------------------------------- */
if( VSIFReadL( pImage, rowbytes, 1, poGDS->m_fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Leveller read failed:%s", VSIStrerror( errno ) );
return CE_Failure;
}
/* -------------------------------------------------------------------- */
/* Swap on MSB platforms. */
/* -------------------------------------------------------------------- */
#ifdef CPL_MSB
GDALSwapWords( pImage, 4, nRasterXSize, 4 );
#endif
/* -------------------------------------------------------------------- */
/* Convert from legacy-format fixed-point if necessary. */
/* -------------------------------------------------------------------- */
float* pf = (float*)pImage;
if(poGDS->m_version < 6)
{
GInt32* pi = (int*)pImage;
for(size_t i = 0; i < (size_t)nBlockXSize; i++)
pf[i] = (float)pi[i] / 65536;
}
#if 0
/* -------------------------------------------------------------------- */
/* Convert raw elevations to realworld elevs. */
/* -------------------------------------------------------------------- */
for(size_t i = 0; i < nBlockXSize; i++)
pf[i] *= poGDS->m_dWorldscale; //this->GetScale();
#endif
return CE_None;
}
示例14: EstablishFeatureCount
int TigerCompleteChain::SetModule( const char * pszModule )
{
if( !OpenFile( pszModule, "1" ) )
return FALSE;
EstablishFeatureCount();
/* -------------------------------------------------------------------- */
/* Is this a copyright record inserted at the beginning of the */
/* RT1 file by the folks at GDT? If so, setup to ignore the */
/* first record. */
/* -------------------------------------------------------------------- */
nRT1RecOffset = 0;
if( pszModule )
{
char achHeader[10];
VSIFSeekL( fpPrimary, 0, SEEK_SET );
VSIFReadL( achHeader, sizeof(achHeader), 1, fpPrimary );
if( EQUALN(achHeader,"Copyright",8) )
{
nRT1RecOffset = 1;
nFeatures--;
}
}
/* -------------------------------------------------------------------- */
/* Open the RT3 file */
/* -------------------------------------------------------------------- */
if( bUsingRT3 )
{
if( fpRT3 != NULL )
{
VSIFCloseL( fpRT3 );
fpRT3 = NULL;
}
if( pszModule )
{
char *pszFilename;
pszFilename = poDS->BuildFilename( pszModule, "3" );
fpRT3 = VSIFOpenL( pszFilename, "rb" );
CPLFree( pszFilename );
}
}
/* -------------------------------------------------------------------- */
/* Close the shape point file, if open and free the list of */
/* record ids. */
/* -------------------------------------------------------------------- */
if( fpShape != NULL )
{
VSIFCloseL( fpShape );
fpShape = NULL;
}
CPLFree( panShapeRecordId );
panShapeRecordId = NULL;
/* -------------------------------------------------------------------- */
/* Try to open the RT2 file corresponding to this RT1 file. */
/* -------------------------------------------------------------------- */
if( pszModule != NULL )
{
char *pszFilename;
pszFilename = poDS->BuildFilename( pszModule, "2" );
fpShape = VSIFOpenL( pszFilename, "rb" );
if( fpShape == NULL )
{
if( nRT1RecOffset == 0 )
CPLError( CE_Warning, CPLE_OpenFailed,
"Failed to open %s, intermediate shape arcs will not be available.\n",
pszFilename );
}
else
panShapeRecordId = (int *)CPLCalloc(sizeof(int),GetFeatureCount());
CPLFree( pszFilename );
}
return TRUE;
}
示例15: while
OGRFeature *OGRBNALayer::GetNextFeature()
{
OGRFeature *poFeature;
BNARecord* record;
int offset, line;
if (failed || eof) return NULL;
while(1)
{
int ok = FALSE;
offset = (int) VSIFTellL(fpBNA);
line = curLine;
if (nNextFID < nFeatures)
{
VSIFSeekL( fpBNA, offsetAndLineFeaturesTable[nNextFID].offset, SEEK_SET );
curLine = offsetAndLineFeaturesTable[nNextFID].line;
}
record = BNA_GetNextRecord(fpBNA, &ok, &curLine, TRUE, bnaFeatureType);
if (ok == FALSE)
{
BNA_FreeRecord(record);
failed = TRUE;
return NULL;
}
if (record == NULL)
{
/* end of file */
eof = TRUE;
/* and we have finally build the whole index table */
partialIndexTable = FALSE;
return NULL;
}
if (record->featureType == bnaFeatureType)
{
if (nNextFID >= nFeatures)
{
nFeatures++;
offsetAndLineFeaturesTable =
(OffsetAndLine*)CPLRealloc(offsetAndLineFeaturesTable, nFeatures * sizeof(OffsetAndLine));
offsetAndLineFeaturesTable[nFeatures-1].offset = offset;
offsetAndLineFeaturesTable[nFeatures-1].line = line;
}
poFeature = BuildFeatureFromBNARecord(record, nNextFID++);
BNA_FreeRecord(record);
if( (m_poFilterGeom == NULL
|| FilterGeometry( poFeature->GetGeometryRef() ) )
&& (m_poAttrQuery == NULL
|| m_poAttrQuery->Evaluate( poFeature )) )
{
return poFeature;
}
delete poFeature;
}
else
{
BNA_FreeRecord(record);
}
}
}