本文整理汇总了C++中VSIFTellL函数的典型用法代码示例。如果您正苦于以下问题:C++ VSIFTellL函数的具体用法?C++ VSIFTellL怎么用?C++ VSIFTellL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VSIFTellL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
bool OGRDXFWriterDS::TransferUpdateHeader( VSILFILE *fpOut )
{
oHeaderDS.ResetReadPointer( 0 );
/* -------------------------------------------------------------------- */
/* Copy header, inserting in new objects as needed. */
/* -------------------------------------------------------------------- */
char szLineBuf[257];
int nCode = 0;
CPLString osSection;
CPLString osTable;
CPLString osEntity;
while( (nCode = oHeaderDS.ReadValue( szLineBuf, sizeof(szLineBuf) )) != -1
&& osSection != "ENTITIES" )
{
if( nCode == 0 && EQUAL(szLineBuf,"ENDTAB") )
{
// If we are at the end of the LAYER TABLE consider inserting
// missing definitions.
if( osTable == "LAYER" )
{
if( !WriteNewLayerDefinitions( fp ) )
return false;
}
// If at the end of the BLOCK_RECORD TABLE consider inserting
// missing definitions.
if( osTable == "BLOCK_RECORD" && poBlocksLayer )
{
if( !WriteNewBlockRecords( fp ) )
return false;
}
// If at the end of the LTYPE TABLE consider inserting
// missing layer type definitions.
if( osTable == "LTYPE" )
{
if( !WriteNewLineTypeRecords( fp ) )
return false;
}
osTable = "";
}
// If we are at the end of the BLOCKS section, consider inserting
// supplementary blocks.
if( nCode == 0 && osSection == "BLOCKS" && EQUAL(szLineBuf,"ENDSEC")
&& poBlocksLayer != NULL )
{
if( !WriteNewBlockDefinitions( fp ) )
return false;
}
// We need to keep track of where $HANDSEED is so that we can
// come back and fix it up when we have generated all entity ids.
if( nCode == 9 && EQUAL(szLineBuf,"$HANDSEED") )
{
if( !WriteValue( fpOut, nCode, szLineBuf ) )
return false;
nCode = oHeaderDS.ReadValue( szLineBuf, sizeof(szLineBuf) );
// ensure we have room to overwrite with a longer value.
while( strlen(szLineBuf) < 8 )
{
memmove( szLineBuf+1, szLineBuf, strlen(szLineBuf)+1 );
szLineBuf[0] = '0';
}
nHANDSEEDOffset = VSIFTellL( fpOut );
}
// Patch EXTMIN with minx and miny
if( nCode == 9 && EQUAL(szLineBuf,"$EXTMIN") )
{
if( !WriteValue( fpOut, nCode, szLineBuf ) )
return false;
nCode = oHeaderDS.ReadValue( szLineBuf, sizeof(szLineBuf) );
if (nCode == 10)
{
if( !WriteValue( fpOut, nCode, oGlobalEnvelope.MinX ) )
return false;
nCode = oHeaderDS.ReadValue( szLineBuf, sizeof(szLineBuf) );
if (nCode == 20)
{
if( !WriteValue( fpOut, nCode, oGlobalEnvelope.MinY ) )
return false;
continue;
}
}
}
// Patch EXTMAX with maxx and maxy
if( nCode == 9 && EQUAL(szLineBuf,"$EXTMAX") )
{
//.........这里部分代码省略.........
示例2: VSIFOpenL
//.........这里部分代码省略.........
delete poDS;
return NULL;
}
GDALDataType eDT = GDT_Float32;
if (STARTS_WITH_CI(pszLine + E00_INT_SIZE + E00_INT_SIZE, " 1"))
eDT = GDT_Int32;
else if (STARTS_WITH_CI(pszLine + E00_INT_SIZE + E00_INT_SIZE, " 2"))
eDT = GDT_Float32;
else
{
CPLDebug("E00GRID", "Unknown data type : %s", pszLine);
}
const double dfNoData = CPLAtof(pszLine + E00_INT_SIZE + E00_INT_SIZE + 2);
/* read pixel size */
if (e00ReadPtr)
pszLine = E00ReadNextLine(e00ReadPtr);
else
pszLine = CPLReadLine2L(fp, 81, NULL);
if (pszLine == NULL || strlen(pszLine) < 2*E00_DOUBLE_SIZE)
{
CPLDebug("E00GRID", "Bad 4th line");
delete poDS;
return NULL;
}
/*
double dfPixelX = CPLAtof(pszLine);
double dfPixelY = CPLAtof(pszLine + E00_DOUBLE_SIZE);
*/
/* read xmin, ymin */
if (e00ReadPtr)
pszLine = E00ReadNextLine(e00ReadPtr);
else
pszLine = CPLReadLine2L(fp, 81, NULL);
if (pszLine == NULL || strlen(pszLine) < 2*E00_DOUBLE_SIZE)
{
CPLDebug("E00GRID", "Bad 5th line");
delete poDS;
return NULL;
}
const double dfMinX = CPLAtof(pszLine);
const double dfMinY = CPLAtof(pszLine + E00_DOUBLE_SIZE);
/* read xmax, ymax */
if (e00ReadPtr)
pszLine = E00ReadNextLine(e00ReadPtr);
else
pszLine = CPLReadLine2L(fp, 81, NULL);
if (pszLine == NULL || strlen(pszLine) < 2*E00_DOUBLE_SIZE)
{
CPLDebug("E00GRID", "Bad 6th line");
delete poDS;
return NULL;
}
const double dfMaxX = CPLAtof(pszLine);
const double dfMaxY = CPLAtof(pszLine + E00_DOUBLE_SIZE);
poDS->nRasterXSize = nRasterXSize;
poDS->nRasterYSize = nRasterYSize;
poDS->dfNoData = dfNoData;
poDS->adfGeoTransform[0] = dfMinX;
poDS->adfGeoTransform[1] = (dfMaxX - dfMinX) / nRasterXSize;
poDS->adfGeoTransform[2] = 0;
poDS->adfGeoTransform[3] = dfMaxY;
poDS->adfGeoTransform[4] = 0;
poDS->adfGeoTransform[5] = - (dfMaxY - dfMinY) / nRasterYSize;
poDS->nDataStart = VSIFTellL(fp);
if (bCompressed)
{
poDS->panOffsets = (vsi_l_offset*)
VSIMalloc2(sizeof(vsi_l_offset), nRasterYSize);
if (poDS->panOffsets == NULL)
{
delete poDS;
return NULL;
}
}
/* -------------------------------------------------------------------- */
/* Create band information objects. */
/* -------------------------------------------------------------------- */
poDS->nBands = 1;
for( int i = 0; i < poDS->nBands; i++ )
poDS->SetBand( i+1, new E00GRIDRasterBand( poDS, i+1, eDT ) );
/* -------------------------------------------------------------------- */
/* Initialize any PAM information. */
/* -------------------------------------------------------------------- */
poDS->SetDescription( poOpenInfo->pszFilename );
poDS->TryLoadXML();
/* -------------------------------------------------------------------- */
/* Support overviews. */
/* -------------------------------------------------------------------- */
poDS->oOvManager.Initialize( poDS, poOpenInfo->pszFilename );
return poDS;
}
示例3: CPLError
OGRErr OGRCSVLayer::CreateFeature( OGRFeature *poNewFeature )
{
int iField;
if( !bInWriteMode )
{
CPLError( CE_Failure, CPLE_AppDefined,
"The CreateFeature() operation is not permitted on a read-only CSV." );
return OGRERR_FAILURE;
}
/* If we need rewind, it means that we have just written a feature before */
/* so there's no point seeking to the end of the file, as we're already */
/* at the end */
int bNeedSeekEnd = !bNeedRewindBeforeRead;
bNeedRewindBeforeRead = TRUE;
/* -------------------------------------------------------------------- */
/* Write field names if we haven't written them yet. */
/* Write .csvt file if needed */
/* -------------------------------------------------------------------- */
if( bNew )
{
OGRErr eErr = WriteHeader();
if (eErr != OGRERR_NONE)
return eErr;
bNeedSeekEnd = FALSE;
}
if (fpCSV == NULL)
return OGRERR_FAILURE;
/* -------------------------------------------------------------------- */
/* Make sure we are at the end of the file. */
/* -------------------------------------------------------------------- */
if (bNeedSeekEnd)
{
if (bFirstFeatureAppendedDuringSession)
{
/* Add a newline character to the end of the file if necessary */
bFirstFeatureAppendedDuringSession = FALSE;
VSIFSeekL( fpCSV, 0, SEEK_END );
VSIFSeekL( fpCSV, VSIFTellL(fpCSV) - 1, SEEK_SET);
char chLast;
VSIFReadL( &chLast, 1, 1, fpCSV );
VSIFSeekL( fpCSV, 0, SEEK_END );
if (chLast != '\n')
{
if( bUseCRLF )
VSIFPutcL( 13, fpCSV );
VSIFPutcL( '\n', fpCSV );
}
}
else
{
VSIFSeekL( fpCSV, 0, SEEK_END );
}
}
/* -------------------------------------------------------------------- */
/* Write out the geometry */
/* -------------------------------------------------------------------- */
if (eGeometryFormat == OGR_CSV_GEOM_AS_WKT)
{
OGRGeometry *poGeom = poNewFeature->GetGeometryRef();
char* pszWKT = NULL;
if (poGeom && poGeom->exportToWkt(&pszWKT) == OGRERR_NONE)
{
VSIFPrintfL( fpCSV, "\"%s\"", pszWKT);
}
else
{
VSIFPrintfL( fpCSV, "\"\"");
}
CPLFree(pszWKT);
if (poFeatureDefn->GetFieldCount() > 0)
VSIFPrintfL( fpCSV, "%c", chDelimiter);
}
else if (eGeometryFormat == OGR_CSV_GEOM_AS_XYZ ||
eGeometryFormat == OGR_CSV_GEOM_AS_XY ||
eGeometryFormat == OGR_CSV_GEOM_AS_YX)
{
OGRGeometry *poGeom = poNewFeature->GetGeometryRef();
if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint)
{
OGRPoint* poPoint = (OGRPoint*) poGeom;
char szBuffer[75];
if (eGeometryFormat == OGR_CSV_GEOM_AS_XYZ )
OGRMakeWktCoordinate(szBuffer, poPoint->getX(), poPoint->getY(), poPoint->getZ(), 3);
else if (eGeometryFormat == OGR_CSV_GEOM_AS_XY )
OGRMakeWktCoordinate(szBuffer, poPoint->getX(), poPoint->getY(), 0, 2);
else
OGRMakeWktCoordinate(szBuffer, poPoint->getY(), poPoint->getX(), 0, 2);
char* pc = szBuffer;
while(*pc != '\0')
{
if (*pc == ' ')
*pc = chDelimiter;
//.........这里部分代码省略.........
示例4: 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);
}
}
}
示例5: msTransformToGeospatialPDF
static void msTransformToGeospatialPDF(imageObj *img, mapObj *map, cairo_renderer *r)
{
/* We need a GDAL 1.10 PDF driver at runtime, but as far as the C API is concerned, GDAL 1.9 is */
/* largely sufficient. */
#if defined(USE_GDAL) && defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1900
GDALDatasetH hDS = NULL;
const char* pszGEO_ENCODING = NULL;
GDALDriverH hPDFDriver = NULL;
const char* pszVirtualIO = NULL;
int bVirtualIO = FALSE;
char* pszTmpFilename = NULL;
VSILFILE* fp = NULL;
if (map == NULL)
return;
pszGEO_ENCODING = msGetOutputFormatOption(img->format, "GEO_ENCODING", NULL);
if (pszGEO_ENCODING == NULL)
return;
msGDALInitialize();
hPDFDriver = GDALGetDriverByName("PDF");
if (hPDFDriver == NULL)
return;
/* When compiled against libpoppler, the PDF driver is VirtualIO capable */
/* but not, when it is compiled against libpodofo. */
pszVirtualIO = GDALGetMetadataItem( hPDFDriver, GDAL_DCAP_VIRTUALIO, NULL );
if (pszVirtualIO)
bVirtualIO = CSLTestBoolean(pszVirtualIO);
if (bVirtualIO)
pszTmpFilename = msTmpFile(map, NULL, "/vsimem/mscairopdf/", "pdf");
else
pszTmpFilename = msTmpFile(map, map->mappath, NULL, "pdf");
/* Copy content of outputStream buffer into file */
fp = VSIFOpenL(pszTmpFilename, "wb");
if (fp == NULL) {
msFree(pszTmpFilename);
return;
}
VSIFWriteL(r->outputStream->data, 1, r->outputStream->size, fp);
VSIFCloseL(fp);
fp = NULL;
hDS = GDALOpen(pszTmpFilename, GA_Update);
if ( hDS != NULL ) {
char* pszWKT = msProjectionObj2OGCWKT( &(map->projection) );
if( pszWKT != NULL ) {
double adfGeoTransform[6];
int i;
/* Add user-specified options */
for( i = 0; i < img->format->numformatoptions; i++ ) {
const char* pszOption = img->format->formatoptions[i];
if( strncasecmp(pszOption,"METADATA_ITEM:",14) == 0 ) {
char* pszKey = NULL;
const char* pszValue = CPLParseNameValue(pszOption + 14,
&pszKey);
if( pszKey != NULL ) {
GDALSetMetadataItem(hDS, pszKey, pszValue, NULL);
CPLFree(pszKey);
}
}
}
/* We need to rescale the geotransform because GDAL will not necessary */
/* open the PDF with the DPI that was used to generate it */
memcpy(adfGeoTransform, map->gt.geotransform, 6 * sizeof(double));
adfGeoTransform[1] = adfGeoTransform[1] * map->width / GDALGetRasterXSize(hDS);
adfGeoTransform[5] = adfGeoTransform[5] * map->height / GDALGetRasterYSize(hDS);
GDALSetGeoTransform(hDS, adfGeoTransform);
GDALSetProjection(hDS, pszWKT);
msFree( pszWKT );
pszWKT = NULL;
CPLSetThreadLocalConfigOption("GDAL_PDF_GEO_ENCODING", pszGEO_ENCODING);
GDALClose(hDS);
hDS = NULL;
CPLSetThreadLocalConfigOption("GDAL_PDF_GEO_ENCODING", NULL);
/* We need to replace the buffer with the content of the GDAL file */
fp = VSIFOpenL(pszTmpFilename, "rb");
if( fp != NULL ) {
int nFileSize;
VSIFSeekL(fp, 0, SEEK_END);
nFileSize = (int)VSIFTellL(fp);
msBufferResize(r->outputStream, nFileSize);
VSIFSeekL(fp, 0, SEEK_SET);
VSIFReadL(r->outputStream->data, 1, nFileSize, fp);
r->outputStream->size = nFileSize;
//.........这里部分代码省略.........
示例6: Close
//.........这里部分代码省略.........
/* -------------------------------------------------------------------- */
/* If the header is invalid, then clean up, report the error */
/* and return. */
/* -------------------------------------------------------------------- */
if( !bValid )
{
CPL_IGNORE_RET_VAL(VSIFCloseL( fpDDF ));
fpDDF = NULL;
if( !bFailQuietly )
CPLError( CE_Failure, CPLE_AppDefined,
"File `%s' does not appear to have\n"
"a valid ISO 8211 header.\n",
pszFilename );
return FALSE;
}
/* -------------------------------------------------------------------- */
/* Read the whole record info memory. */
/* -------------------------------------------------------------------- */
char *pachRecord;
pachRecord = (char *) CPLMalloc(_recLength);
memcpy( pachRecord, achLeader, nLeaderSize );
if( (int)VSIFReadL( pachRecord+nLeaderSize, 1, _recLength-nLeaderSize, fpDDF )
!= _recLength - nLeaderSize )
{
if( !bFailQuietly )
CPLError( CE_Failure, CPLE_FileIO,
"Header record is short on DDF file `%s'.",
pszFilename );
return FALSE;
}
/* -------------------------------------------------------------------- */
/* First make a pass counting the directory entries. */
/* -------------------------------------------------------------------- */
int nFieldEntryWidth, nFDCount = 0;
nFieldEntryWidth = _sizeFieldLength + _sizeFieldPos + _sizeFieldTag;
for( i = nLeaderSize; i < _recLength; i += nFieldEntryWidth )
{
if( pachRecord[i] == DDF_FIELD_TERMINATOR )
break;
nFDCount++;
}
/* -------------------------------------------------------------------- */
/* Allocate, and read field definitions. */
/* -------------------------------------------------------------------- */
for( i = 0; i < nFDCount; i++ )
{
char szTag[128];
int nEntryOffset = nLeaderSize + i*nFieldEntryWidth;
int nFieldLength, nFieldPos;
DDFFieldDefn *poFDefn;
strncpy( szTag, pachRecord+nEntryOffset, _sizeFieldTag );
szTag[_sizeFieldTag] = '\0';
nEntryOffset += _sizeFieldTag;
nFieldLength = DDFScanInt( pachRecord+nEntryOffset, _sizeFieldLength );
nEntryOffset += _sizeFieldLength;
nFieldPos = DDFScanInt( pachRecord+nEntryOffset, _sizeFieldPos );
if (_fieldAreaStart+nFieldPos < 0 ||
_recLength - (_fieldAreaStart+nFieldPos) < nFieldLength)
{
if( !bFailQuietly )
CPLError( CE_Failure, CPLE_FileIO,
"Header record invalid on DDF file `%s'.",
pszFilename );
CPLFree( pachRecord );
return FALSE;
}
poFDefn = new DDFFieldDefn();
if( poFDefn->Initialize( this, szTag, nFieldLength,
pachRecord+_fieldAreaStart+nFieldPos ) )
AddField( poFDefn );
else
delete poFDefn;
}
CPLFree( pachRecord );
/* -------------------------------------------------------------------- */
/* Record the current file offset, the beginning of the first */
/* data record. */
/* -------------------------------------------------------------------- */
nFirstRecordOffset = (long)VSIFTellL( fpDDF );
return TRUE;
}
示例7: 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 );
}
示例8: VSIFSeekL
//.........这里部分代码省略.........
/* Read the palette. */
/* -------------------------------------------------------------------- */
GByte palette[768];
GUInt16 i;
for( i = 0; i < 256; i++ )
{
VSIFReadL( &palette[i * 3 + 2], 1, 1, poOpenInfo->fpL );
VSIFReadL( &palette[i * 3 + 1], 1, 1, poOpenInfo->fpL );
VSIFReadL( &palette[i * 3 + 0], 1, 1, poOpenInfo->fpL );
}
/* -------------------------------------------------------------------- */
/* Find block offsets. */
/* -------------------------------------------------------------------- */
GUInt32 blocks;
GUInt32 *offsets;
blocks = header.iHorBlocks * header.iVertBlocks;
offsets = (GUInt32 *)CPLMalloc( blocks * sizeof(GUInt32) );
if( !offsets )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"File %s. Unable to allocate offset table.\n",
poOpenInfo->pszFilename );
return NULL;
}
if( header.iOptions == 0x00 )
{
offsets[0] = VSIFTellL( poOpenInfo->fpL );
for( GUInt32 i = 1; i < blocks; i++ )
{
offsets[i] = offsets[i - 1] +
header.iBlockWidth * header.iBlockHeight;
}
}
else
{
for( GUInt32 i = 0; i < blocks; i++ )
{
VSIFReadL( &offsets[i], 1, sizeof(offsets[i]), poOpenInfo->fpL );
#ifdef CPL_MSB
CPL_SWAP32PTR( &offsets[i] );
#endif
if( rik3header )
{
GUInt32 blockSize;
VSIFReadL( &blockSize, 1, sizeof(blockSize), poOpenInfo->fpL );
#ifdef CPL_MSB
CPL_SWAP32PTR( &blockSize );
#endif
}
}
}
/* -------------------------------------------------------------------- */
/* Final checks. */
/* -------------------------------------------------------------------- */
// File size
示例9: GetNoDataValue
//.........这里部分代码省略.........
{
if (!bLastWasSep)
nCol ++;
bLastWasSep = TRUE;
}
else if ((ch == ',' && poGDS->chDecimalSep != ',') || ch == '\t' || ch == ';')
{
nCol ++;
bLastWasSep = TRUE;
}
else
{
bLastWasSep = FALSE;
}
pszPtr ++;
}
/* Skip empty line */
if (nCol == 0 && bLastWasSep)
continue;
poGDS->nDataLineNum ++;
}
}
double dfExpectedY = poGDS->adfGeoTransform[3] + (0.5 + nBlockYOff) * poGDS->adfGeoTransform[5];
int idx = -1;
while(TRUE)
{
int nCol;
int bLastWasSep;
do
{
vsi_l_offset nOffsetBefore = VSIFTellL(poGDS->fp);
const char* pszLine = CPLReadLine2L(poGDS->fp, 100, 0);
if (pszLine == NULL)
{
if( poGDS->bSameNumberOfValuesPerLine )
{
CPLError(CE_Failure, CPLE_AppDefined, "Cannot read line %d", poGDS->nLineNum + 1);
return CE_Failure;
}
else
{
nLastYOff = nBlockYOff;
return CE_None;
}
}
poGDS->nLineNum ++;
const char* pszPtr = pszLine;
char ch;
nCol = 0;
bLastWasSep = TRUE;
double dfX = 0.0, dfY = 0.0, dfZ = 0.0;
int bUsefulColsFound = 0;
while((ch = *pszPtr) != '\0')
{
if (ch == ' ')
{
if (!bLastWasSep)
nCol ++;
bLastWasSep = TRUE;
}
else if ((ch == ',' && poGDS->chDecimalSep != ',') || ch == '\t' || ch == ';')
{
示例10: readUShort
Track* GTM::fetchNextTrack()
{
/* Point to the actual track offset */
if ( VSIFSeekL(pGTMFile, actualTrackOffset, SEEK_SET) != 0)
return nullptr;
/* Read string length */
const unsigned short stringSize = readUShort(pGTMFile);
/* Read name string */
char* pszName = (char*) VSI_MALLOC2_VERBOSE(sizeof(char), stringSize+1);
if( pszName == nullptr )
return nullptr;
if ( stringSize != 0 && !readFile( pszName, 1, sizeof(char) * stringSize ) )
{
CPLFree(pszName);
return nullptr;
}
pszName[stringSize] = '\0';
/* Read type */
const unsigned char type = readUChar(pGTMFile);
/* Read color */
const int color = readInt(pGTMFile);
Track* poTrack = new Track(pszName, type, color);
CPLFree(pszName);
/* Adjust actual Track offset */
actualTrackOffset = VSIFTellL(pGTMFile) + 7;
++trackFetched;
/* Now, We read all trackpoints for this track */
double latitude = 0.0;
double longitude = 0.0;
GIntBig datetime = 0;
unsigned char start = 0;
float altitude = 0.0f;
/* NOTE: Parameters are passed by reference */
if ( !readTrackPoints(latitude, longitude, datetime, start, altitude) )
{
delete poTrack;
return nullptr;
}
/* Check if it is the start, if not we have done something wrong */
if (start != 1)
{
delete poTrack;
return nullptr;
}
poTrack->addPoint(longitude, latitude, datetime, altitude);
do
{
/* NOTE: Parameters are passed by reference */
if ( !readTrackPoints(latitude, longitude, datetime, start, altitude) )
{
delete poTrack;
return nullptr;
}
if (start == 0)
poTrack->addPoint(longitude, latitude, datetime, altitude);
} while(start == 0 && trackpointFetched < ntcks);
/* We have read one more than necessary, so we adjust the offset */
if (trackpointFetched < ntcks)
{
actualTrackpointOffset -= 25;
--trackpointFetched;
}
return poTrack;
}
示例11: CPLError
/**********************************************************************
* TABRawBinBlock::CommitToFile()
*
* Commit the current state of the binary block to the file to which
* it has been previously attached.
*
* Derived classes may want to (optionally) reimplement this method if
* they need to do special processing before committing the block to disk.
*
* For files created with bHardBlockSize=TRUE, a complete block of
* the specified size is always written, otherwise only the number of
* used bytes in the block will be written to disk.
*
* Returns 0 if successful or -1 if an error happened, in which case
* CPLError() will have been called.
**********************************************************************/
int TABRawBinBlock::CommitToFile()
{
int nStatus = 0;
if (m_fp == NULL || m_nBlockSize <= 0 || m_pabyBuf == NULL ||
m_nFileOffset < 0)
{
CPLError(CE_Failure, CPLE_AssertionFailed,
"TABRawBinBlock::CommitToFile(): Block has not been initialized yet!");
return -1;
}
/*----------------------------------------------------------------
* If block has not been modified, then just return... nothing to do.
*---------------------------------------------------------------*/
if (!m_bModified)
return 0;
/*----------------------------------------------------------------
* Move the output file pointer to the right position...
*---------------------------------------------------------------*/
if (VSIFSeekL(m_fp, m_nFileOffset, SEEK_SET) != 0)
{
/*------------------------------------------------------------
* Moving pointer failed... we may need to pad with zeros if
* block destination is beyond current end of file.
*-----------------------------------------------------------*/
int nCurPos = (int)VSIFTellL(m_fp);
if (nCurPos < m_nFileOffset &&
VSIFSeekL(m_fp, 0L, SEEK_END) == 0 &&
(nCurPos = (int)VSIFTellL(m_fp)) < m_nFileOffset)
{
const GByte cZero = 0;
while(nCurPos < m_nFileOffset && nStatus == 0)
{
if (VSIFWriteL(&cZero, 1, 1, m_fp) != 1)
{
CPLError(CE_Failure, CPLE_FileIO,
"Failed writing 1 byte at offset %d.", nCurPos);
nStatus = -1;
break;
}
nCurPos++;
}
}
if (nCurPos != m_nFileOffset)
nStatus = -1; // Error message will follow below
}
/*----------------------------------------------------------------
* At this point we are ready to write to the file.
*
* If m_bHardBlockSize==FALSE, then we do not write a complete block;
* we write only the part of the block that was used.
*---------------------------------------------------------------*/
int numBytesToWrite = m_bHardBlockSize?m_nBlockSize:m_nSizeUsed;
/*CPLDebug("MITAB", "Committing to offset %d", m_nFileOffset);*/
if (nStatus != 0 ||
VSIFWriteL(m_pabyBuf,sizeof(GByte),
numBytesToWrite, m_fp) != (size_t)numBytesToWrite )
{
CPLError(CE_Failure, CPLE_FileIO,
"Failed writing %d bytes at offset %d.",
numBytesToWrite, m_nFileOffset);
return -1;
}
if( m_nFileOffset + numBytesToWrite > m_nFileSize )
{
m_nFileSize = m_nFileOffset + numBytesToWrite;
}
VSIFFlushL(m_fp);
m_bModified = FALSE;
return 0;
}
示例12: CPLError
//.........这里部分代码省略.........
memcpy( achHeader + 5*16+8, pszValue, MIN(16,strlen(pszValue)) );
memcpy( achHeader + 6*16, "SYSTEM_T ", 16 );
pszValue = CSLFetchNameValueDef( papszOptions, "SYSTEM_T", "" );
memcpy( achHeader + 6*16+8, pszValue, MIN(16,strlen(pszValue)) );
memcpy( achHeader + 7*16, "MAJOR_F ", 8);
memcpy( achHeader + 8*16, "MINOR_F ", 8 );
memcpy( achHeader + 9*16, "MAJOR_T ", 8 );
memcpy( achHeader + 10*16, "MINOR_T ", 8 );
VSIFWriteL( achHeader, 1, sizeof(achHeader), fp );
}
/* -------------------------------------------------------------------- */
/* Otherwise update the header with an increased subfile count, */
/* and advanced to the last record of the file. */
/* -------------------------------------------------------------------- */
else
{
VSIFSeekL( fp, 2*16 + 8, SEEK_SET );
VSIFReadL( &nNumFile, 1, 4, fp );
CPL_LSBPTR32( &nNumFile );
nNumFile++;
CPL_LSBPTR32( &nNumFile );
VSIFSeekL( fp, 2*16 + 8, SEEK_SET );
VSIFWriteL( &nNumFile, 1, 4, fp );
vsi_l_offset nEnd;
VSIFSeekL( fp, 0, SEEK_END );
nEnd = VSIFTellL( fp );
VSIFSeekL( fp, nEnd-16, SEEK_SET );
}
/* -------------------------------------------------------------------- */
/* Write the grid header. */
/* -------------------------------------------------------------------- */
memset( achHeader, 0, sizeof(achHeader) );
memcpy( achHeader + 0*16, "SUB_NAME ", 16 );
pszValue = CSLFetchNameValueDef( papszOptions, "SUB_NAME", "" );
memcpy( achHeader + 0*16+8, pszValue, MIN(16,strlen(pszValue)) );
memcpy( achHeader + 1*16, "PARENT ", 16 );
pszValue = CSLFetchNameValueDef( papszOptions, "PARENT", "NONE" );
memcpy( achHeader + 1*16+8, pszValue, MIN(16,strlen(pszValue)) );
memcpy( achHeader + 2*16, "CREATED ", 16 );
pszValue = CSLFetchNameValueDef( papszOptions, "CREATED", "" );
memcpy( achHeader + 2*16+8, pszValue, MIN(16,strlen(pszValue)) );
memcpy( achHeader + 3*16, "UPDATED ", 16 );
pszValue = CSLFetchNameValueDef( papszOptions, "UPDATED", "" );
memcpy( achHeader + 3*16+8, pszValue, MIN(16,strlen(pszValue)) );
double dfValue;
memcpy( achHeader + 4*16, "S_LAT ", 8 );
dfValue = 0;
CPL_LSBPTR64( &dfValue );
memcpy( achHeader + 4*16 + 8, &dfValue, 8 );
memcpy( achHeader + 5*16, "N_LAT ", 8 );
示例13: CPLStrdup
int OGRBNADataSource::Open( const char * pszFilename, int bUpdateIn)
{
int ok = FALSE;
pszName = CPLStrdup( pszFilename );
bUpdate = bUpdateIn;
/* -------------------------------------------------------------------- */
/* Determine what sort of object this is. */
/* -------------------------------------------------------------------- */
VSIStatBufL sStatBuf;
if( VSIStatL( pszFilename, &sStatBuf ) != 0 )
return FALSE;
// --------------------------------------------------------------------
// Does this appear to be a .bna file?
// --------------------------------------------------------------------
if( !(EQUAL( CPLGetExtension(pszFilename), "bna" )
|| ((EQUALN( pszFilename, "/vsigzip/", 9) || EQUALN( pszFilename, "/vsizip/", 8)) &&
(strstr( pszFilename, ".bna") || strstr( pszFilename, ".BNA")))) )
return FALSE;
VSILFILE* fp = VSIFOpenL(pszFilename, "rb");
if (fp)
{
BNARecord* record;
int curLine = 0;
const char* layerRadixName[] = { "points", "polygons", "lines", "ellipses"};
OGRwkbGeometryType wkbGeomTypes[] = { wkbPoint, wkbMultiPolygon, wkbLineString, wkbPolygon };
int i;
#if defined(BNA_FAST_DS_OPEN)
record = BNA_GetNextRecord(fp, &ok, &curLine, FALSE, BNA_READ_NONE);
BNA_FreeRecord(record);
if (ok)
{
nLayers = 4;
papoLayers = (OGRBNALayer **) CPLMalloc(nLayers * sizeof(OGRBNALayer*));
for(i=0;i<4;i++)
papoLayers[i] = new OGRBNALayer( pszFilename,
layerRadixName[i],
(BNAFeatureType)i, wkbGeomTypes[i], FALSE, this );
}
#else
int nFeatures[4] = { 0, 0, 0, 0 };
OffsetAndLine* offsetAndLineFeaturesTable[4] = { NULL, NULL, NULL, NULL };
int nIDs[4] = {0, 0, 0, 0};
int partialIndexTable = TRUE;
while(1)
{
int offset = VSIFTellL(fp);
int line = curLine;
record = BNA_GetNextRecord(fp, &ok, &curLine, FALSE, BNA_READ_NONE);
if (ok == FALSE)
{
BNA_FreeRecord(record);
if (line != 0)
ok = TRUE;
break;
}
if (record == NULL)
{
/* end of file */
ok = TRUE;
/* and we have finally build the whole index table */
partialIndexTable = FALSE;
break;
}
if (record->nIDs > nIDs[record->featureType])
nIDs[record->featureType] = record->nIDs;
nFeatures[record->featureType]++;
offsetAndLineFeaturesTable[record->featureType] =
(OffsetAndLine*)CPLRealloc(offsetAndLineFeaturesTable[record->featureType],
nFeatures[record->featureType] * sizeof(OffsetAndLine));
offsetAndLineFeaturesTable[record->featureType][nFeatures[record->featureType]-1].offset = offset;
offsetAndLineFeaturesTable[record->featureType][nFeatures[record->featureType]-1].line = line;
BNA_FreeRecord(record);
}
nLayers = (nFeatures[0] != 0) + (nFeatures[1] != 0) + (nFeatures[2] != 0) + (nFeatures[3] != 0);
papoLayers = (OGRBNALayer **) CPLMalloc(nLayers * sizeof(OGRBNALayer*));
int iLayer = 0;
for(i=0;i<4;i++)
{
if (nFeatures[i])
{
papoLayers[iLayer] = new OGRBNALayer( pszFilename,
layerRadixName[i],
(BNAFeatureType)i,
wkbGeomTypes[i],
FALSE,
this,
//.........这里部分代码省略.........
示例14: VSIIngestFile
int VSIIngestFile( VSILFILE* fp,
const char* pszFilename,
GByte** ppabyRet,
vsi_l_offset* pnSize,
GIntBig nMaxSize)
{
vsi_l_offset nDataLen = 0;
int bFreeFP = FALSE;
if( fp == NULL && pszFilename == NULL )
return FALSE;
if( ppabyRet == NULL )
return FALSE;
*ppabyRet = NULL;
if( pnSize != NULL )
*pnSize = 0;
if( NULL == fp )
{
fp = VSIFOpenL( pszFilename, "rb" );
if( NULL == fp )
{
CPLError( CE_Failure, CPLE_FileIO,
"Cannot open file '%s'", pszFilename );
return FALSE;
}
bFreeFP = TRUE;
}
else
VSIFSeekL(fp, 0, SEEK_SET);
if( pszFilename == NULL ||
strcmp(pszFilename, "/vsistdin/") == 0 )
{
vsi_l_offset nDataAlloc = 0;
VSIFSeekL( fp, 0, SEEK_SET );
while(TRUE)
{
if( nDataLen + 8192 + 1 > nDataAlloc )
{
nDataAlloc = (nDataAlloc * 4) / 3 + 8192 + 1;
if( nDataAlloc > (vsi_l_offset)(size_t)nDataAlloc )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Input file too large to be opened" );
VSIFree( *ppabyRet );
*ppabyRet = NULL;
if( bFreeFP )
VSIFCloseL( fp );
return FALSE;
}
GByte* pabyNew = (GByte*)VSIRealloc(*ppabyRet, (size_t)nDataAlloc);
if( pabyNew == NULL )
{
CPLError( CE_Failure, CPLE_OutOfMemory,
"Cannot allocated " CPL_FRMT_GIB " bytes",
nDataAlloc );
VSIFree( *ppabyRet );
*ppabyRet = NULL;
if( bFreeFP )
VSIFCloseL( fp );
return FALSE;
}
*ppabyRet = pabyNew;
}
int nRead = (int)VSIFReadL( *ppabyRet + nDataLen, 1, 8192, fp );
nDataLen += nRead;
if ( nMaxSize >= 0 && nDataLen > (vsi_l_offset)nMaxSize )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Input file too large to be opened" );
VSIFree( *ppabyRet );
*ppabyRet = NULL;
if( pnSize != NULL )
*pnSize = 0;
if( bFreeFP )
VSIFCloseL( fp );
return FALSE;
}
if( pnSize != NULL )
*pnSize += nRead;
(*ppabyRet)[nDataLen] = '\0';
if( nRead == 0 )
break;
}
}
else
{
VSIFSeekL( fp, 0, SEEK_END );
nDataLen = VSIFTellL( fp );
// With "large" VSI I/O API we can read data chunks larger than VSIMalloc
// could allocate. Catch it here.
if ( nDataLen > (vsi_l_offset)(size_t)nDataLen ||
(nMaxSize >= 0 && nDataLen > (vsi_l_offset)nMaxSize) )
{
CPLError( CE_Failure, CPLE_AppDefined,
//.........这里部分代码省略.........
示例15: USGSDEMGetCurrentFilePos
static vsi_l_offset USGSDEMGetCurrentFilePos( const Buffer* psBuffer )
{
return VSIFTellL(psBuffer->fp) - psBuffer->buffer_size + psBuffer->cur_index;
}