本文整理汇总了C++中CPLAssert函数的典型用法代码示例。如果您正苦于以下问题:C++ CPLAssert函数的具体用法?C++ CPLAssert怎么用?C++ CPLAssert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CPLAssert函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: DB2_V72_FIX_BYTE_ORDER
OGRErr OGRGeometryCollection::importFromWkb( unsigned char * pabyData,
int nSize )
{
OGRwkbByteOrder eByteOrder;
int nDataOffset;
if( nSize < 9 && nSize != -1 )
return OGRERR_NOT_ENOUGH_DATA;
/* -------------------------------------------------------------------- */
/* Get the byte order byte. */
/* -------------------------------------------------------------------- */
eByteOrder = DB2_V72_FIX_BYTE_ORDER((OGRwkbByteOrder) *pabyData);
CPLAssert( eByteOrder == wkbXDR || eByteOrder == wkbNDR );
/* -------------------------------------------------------------------- */
/* Get the geometry feature type. For now we assume that */
/* geometry type is between 0 and 255 so we only have to fetch */
/* one byte. */
/* -------------------------------------------------------------------- */
#ifdef DEBUG
OGRwkbGeometryType eGeometryType;
if( eByteOrder == wkbNDR )
{
eGeometryType = (OGRwkbGeometryType) pabyData[1];
}
else
{
eGeometryType = (OGRwkbGeometryType) pabyData[4];
}
CPLAssert( eGeometryType == wkbGeometryCollection
|| eGeometryType == wkbMultiPolygon
|| eGeometryType == wkbMultiLineString
|| eGeometryType == wkbMultiPoint );
#endif
/* -------------------------------------------------------------------- */
/* Clear existing Geoms. */
/* -------------------------------------------------------------------- */
empty();
/* -------------------------------------------------------------------- */
/* Get the geometry count. */
/* -------------------------------------------------------------------- */
memcpy( &nGeomCount, pabyData + 5, 4 );
if( OGR_SWAP( eByteOrder ) )
nGeomCount = CPL_SWAP32(nGeomCount);
papoGeoms = (OGRGeometry **) OGRMalloc(sizeof(void*) * nGeomCount);
nDataOffset = 9;
if( nSize != -1 )
nSize -= nDataOffset;
/* -------------------------------------------------------------------- */
/* Get the Geoms. */
/* -------------------------------------------------------------------- */
for( int iGeom = 0; iGeom < nGeomCount; iGeom++ )
{
OGRErr eErr;
eErr = OGRGeometryFactory::
createFromWkb( pabyData + nDataOffset, NULL,
papoGeoms + iGeom, nSize );
if( eErr != OGRERR_NONE )
{
nGeomCount = iGeom;
return eErr;
}
if (papoGeoms[iGeom]->getCoordinateDimension() == 3)
nCoordDimension = 3;
if( nSize != -1 )
nSize -= papoGeoms[iGeom]->WkbSize();
nDataOffset += papoGeoms[iGeom]->WkbSize();
}
return OGRERR_NONE;
}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:86,代码来源:ogrgeometrycollection.cpp
示例2: cln_GetNextObject
OGRFeature *OGROGDILayer::GetNextRawFeature()
{
ecs_Result *psResult;
int i;
OGRFeature *poFeature;
/* -------------------------------------------------------------------- */
/* Retrieve object from OGDI server and create new feature */
/* -------------------------------------------------------------------- */
psResult = cln_GetNextObject(m_nClientID);
if (! ECSSUCCESS(psResult))
{
// We probably reached EOF... keep track of shape count.
m_nTotalShapeCount = m_iNextShapeId - m_nFilteredOutShapes;
return NULL;
}
poFeature = new OGRFeature(m_poFeatureDefn);
poFeature->SetFID( m_iNextShapeId++ );
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Process geometry */
/* -------------------------------------------------------------------- */
if (m_eFamily == Point)
{
ecs_Point *psPoint = &(ECSGEOM(psResult).point);
OGRPoint *poOGRPoint = new OGRPoint(psPoint->c.x, psPoint->c.y);
poOGRPoint->assignSpatialReference(m_poSpatialRef);
poFeature->SetGeometryDirectly(poOGRPoint);
}
else if (m_eFamily == Line)
{
ecs_Line *psLine = &(ECSGEOM(psResult).line);
OGRLineString *poOGRLine = new OGRLineString();
poOGRLine->setNumPoints( psLine->c.c_len );
for( i=0; i < (int) psLine->c.c_len; i++ )
{
poOGRLine->setPoint(i, psLine->c.c_val[i].x, psLine->c.c_val[i].y);
}
poOGRLine->assignSpatialReference(m_poSpatialRef);
poFeature->SetGeometryDirectly(poOGRLine);
}
else if (m_eFamily == Area)
{
ecs_Area *psArea = &(ECSGEOM(psResult).area);
OGRPolygon *poOGRPolygon = new OGRPolygon();
for(int iRing=0; iRing < (int) psArea->ring.ring_len; iRing++)
{
ecs_FeatureRing *psRing = &(psArea->ring.ring_val[iRing]);
OGRLinearRing *poOGRRing = new OGRLinearRing();
poOGRRing->setNumPoints( psRing->c.c_len );
for( i=0; i < (int) psRing->c.c_len; i++ )
{
poOGRRing->setPoint(i, psRing->c.c_val[i].x,
psRing->c.c_val[i].y);
}
poOGRPolygon->addRingDirectly(poOGRRing);
}
// __TODO__
// When OGR supports polygon centroids then we should carry them here
poOGRPolygon->assignSpatialReference(m_poSpatialRef);
poFeature->SetGeometryDirectly(poOGRPolygon);
}
else if (m_eFamily == Text)
{
// __TODO__
// For now text is treated as a point and string is lost
//
ecs_Text *psText = &(ECSGEOM(psResult).text);
OGRPoint *poOGRPoint = new OGRPoint(psText->c.x, psText->c.y);
poOGRPoint->assignSpatialReference(m_poSpatialRef);
poFeature->SetGeometryDirectly(poOGRPoint);
}
else
{
CPLAssert(FALSE);
}
/* -------------------------------------------------------------------- */
/* Set attributes */
/* -------------------------------------------------------------------- */
char *pszAttrList = ECSOBJECTATTR(psResult);
for( int iField = 0; iField < m_poFeatureDefn->GetFieldCount(); iField++ )
{
char *pszFieldStart;
int nNameLen;
//.........这里部分代码省略.........
开发者ID:samalone,项目名称:gdal-ios,代码行数:101,代码来源:ogrogdilayer.cpp
示例3: DB2_V72_FIX_BYTE_ORDER
OGRErr OGRLineString::importFromWkb( unsigned char * pabyData,
int nSize )
{
OGRwkbByteOrder eByteOrder;
if( nSize < 21 && nSize != -1 )
return OGRERR_NOT_ENOUGH_DATA;
/* -------------------------------------------------------------------- */
/* Get the byte order byte. */
/* -------------------------------------------------------------------- */
eByteOrder = DB2_V72_FIX_BYTE_ORDER((OGRwkbByteOrder) *pabyData);
assert( eByteOrder == wkbXDR || eByteOrder == wkbNDR );
/* -------------------------------------------------------------------- */
/* Get the geometry feature type. For now we assume that */
/* geometry type is between 0 and 255 so we only have to fetch */
/* one byte. */
/* -------------------------------------------------------------------- */
OGRwkbGeometryType eGeometryType;
int bIs3D;
if( eByteOrder == wkbNDR )
{
eGeometryType = (OGRwkbGeometryType) pabyData[1];
bIs3D = pabyData[4] & 0x80 || pabyData[2] & 0x80;
}
else
{
eGeometryType = (OGRwkbGeometryType) pabyData[4];
bIs3D = pabyData[1] & 0x80 || pabyData[3] & 0x80;
}
#ifdef __WXOSX__
assert( eGeometryType == wkbLineString );
#else
CPLAssert( eGeometryType == wkbLineString );
#endif
/* -------------------------------------------------------------------- */
/* Get the vertex count. */
/* -------------------------------------------------------------------- */
int nNewNumPoints;
memcpy( &nNewNumPoints, pabyData + 5, 4 );
if( OGR_SWAP( eByteOrder ) )
nNewNumPoints = CPL_SWAP32(nNewNumPoints);
setNumPoints( nNewNumPoints );
if( bIs3D )
Make3D();
else
Make2D();
/* -------------------------------------------------------------------- */
/* Get the vertex. */
/* -------------------------------------------------------------------- */
int i;
if( bIs3D )
{
for( i = 0; i < nPointCount; i++ )
{
memcpy( paoPoints + i, pabyData + 9 + i*24, 16 );
memcpy( padfZ + i, pabyData + 9 + 16 + i*24, 8 );
}
}
else
{
memcpy( paoPoints, pabyData + 9, 16 * nPointCount );
}
/* -------------------------------------------------------------------- */
/* Byte swap if needed. */
/* -------------------------------------------------------------------- */
if( OGR_SWAP( eByteOrder ) )
{
for( i = 0; i < nPointCount; i++ )
{
CPL_SWAPDOUBLE( &(paoPoints[i].x) );
CPL_SWAPDOUBLE( &(paoPoints[i].y) );
}
if( bIs3D )
{
for( i = 0; i < nPointCount; i++ )
{
CPL_SWAPDOUBLE( padfZ + i );
}
}
}
return OGRERR_NONE;
}
开发者ID:CarCode,项目名称:Cocoa-OCPN,代码行数:95,代码来源:ogrlinestring.cpp
示例4: CPLAssert
int OGRTABDataSource::Open( const char * pszName, int bTestOpen )
{
VSIStatBuf stat;
CPLAssert( m_pszName == NULL );
m_pszName = CPLStrdup( pszName );
/* -------------------------------------------------------------------- */
/* Is this a file or directory? */
/* -------------------------------------------------------------------- */
if( VSIStat( pszName, &stat ) != 0
|| (!VSI_ISDIR(stat.st_mode) && !VSI_ISREG(stat.st_mode)) )
{
if( !bTestOpen )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"%s is not a file or directory.\n"
"Unable to open as a Mapinfo dataset.\n",
pszName );
}
return FALSE;
}
/* -------------------------------------------------------------------- */
/* If it is a file, try to open as a Mapinfo file. */
/* -------------------------------------------------------------------- */
if( VSI_ISREG(stat.st_mode) )
{
IMapInfoFile *poFile;
poFile = IMapInfoFile::SmartOpen( pszName, bTestOpen );
if( poFile == NULL )
return FALSE;
m_nLayerCount = 1;
m_papoLayers = (IMapInfoFile **) CPLMalloc(sizeof(void*));
m_papoLayers[0] = poFile;
m_pszDirectory = CPLStrdup( CPLGetPath(pszName) );
}
/* -------------------------------------------------------------------- */
/* Otherwise, we need to scan the whole directory for files */
/* ending in .tab or .mif. */
/* -------------------------------------------------------------------- */
else
{
char **papszFileList = CPLReadDir( pszName );
m_pszDirectory = CPLStrdup( pszName );
for( int iFile = 0;
papszFileList != NULL && papszFileList[iFile] != NULL;
iFile++ )
{
IMapInfoFile *poFile;
const char *pszExtension = CPLGetExtension(papszFileList[iFile]);
char *pszSubFilename;
if( !EQUAL(pszExtension,"tab") && !EQUAL(pszExtension,"mif") )
continue;
pszSubFilename = CPLStrdup(
CPLFormFilename( m_pszDirectory, papszFileList[iFile], NULL ));
poFile = IMapInfoFile::SmartOpen( pszSubFilename, bTestOpen );
CPLFree( pszSubFilename );
if( poFile == NULL )
{
CSLDestroy( papszFileList );
return FALSE;
}
m_nLayerCount++;
m_papoLayers = (IMapInfoFile **)
CPLRealloc(m_papoLayers,sizeof(void*)*m_nLayerCount);
m_papoLayers[m_nLayerCount-1] = poFile;
}
CSLDestroy( papszFileList );
if( m_nLayerCount == 0 )
{
if( !bTestOpen )
CPLError( CE_Failure, CPLE_OpenFailed,
"No mapinfo files found in directory %s.\n",
m_pszDirectory );
return FALSE;
}
}
return TRUE;
}
开发者ID:Chaduke,项目名称:bah.mod,代码行数:98,代码来源:mitab_ogr_datasource.cpp
示例5: GetState
void NASReader::SetFeaturePropertyDirectly( const char *pszElement,
char *pszValue )
{
GMLFeature *poFeature = GetState()->m_poFeature;
CPLAssert( poFeature != NULL );
/* -------------------------------------------------------------------- */
/* Does this property exist in the feature class? If not, add */
/* it. */
/* -------------------------------------------------------------------- */
GMLFeatureClass *poClass = poFeature->GetClass();
int iProperty;
for( iProperty=0; iProperty < poClass->GetPropertyCount(); iProperty++ )
{
if( EQUAL(poClass->GetProperty( iProperty )->GetSrcElement(),
pszElement ) )
break;
}
if( iProperty == poClass->GetPropertyCount() )
{
if( poClass->IsSchemaLocked() )
{
CPLDebug("NAS","Encountered property missing from class schema.");
CPLFree(pszValue);
return;
}
CPLString osFieldName;
if( strchr(pszElement,'|') == NULL )
osFieldName = pszElement;
else
{
osFieldName = strrchr(pszElement,'|') + 1;
if( poClass->GetPropertyIndex(osFieldName) != -1 )
osFieldName = pszElement;
}
// Does this conflict with an existing property name?
while( poClass->GetProperty(osFieldName) != NULL )
{
osFieldName += "_";
}
GMLPropertyDefn *poPDefn = new GMLPropertyDefn(osFieldName,pszElement);
if( EQUAL(CPLGetConfigOption( "GML_FIELDTYPES", ""), "ALWAYS_STRING") )
poPDefn->SetType( GMLPT_String );
poClass->AddProperty( poPDefn );
}
/* -------------------------------------------------------------------- */
/* We want to handle <lage> specially to ensure it is zero */
/* filled, and treated as a string depspite the numeric */
/* content. https://trac.wheregroup.com/PostNAS/ticket/9 */
/* -------------------------------------------------------------------- */
if( strcmp(poClass->GetProperty(iProperty)->GetName(),"lage") == 0 )
{
if( strlen(pszValue) < 5 )
{
CPLString osValue = "00000";
osValue += pszValue;
poFeature->SetPropertyDirectly( iProperty, CPLStrdup(osValue + osValue.size() - 5) );
CPLFree(pszValue);
}
else
poFeature->SetPropertyDirectly( iProperty, pszValue );
if( !poClass->IsSchemaLocked() )
{
poClass->GetProperty(iProperty)->SetWidth( 5 );
poClass->GetProperty(iProperty)->SetType( GMLPT_String );
}
return;
}
/* -------------------------------------------------------------------- */
/* Set the property */
/* -------------------------------------------------------------------- */
poFeature->SetPropertyDirectly( iProperty, pszValue );
/* -------------------------------------------------------------------- */
/* Do we need to update the property type? */
/* -------------------------------------------------------------------- */
if( !poClass->IsSchemaLocked() )
{
// Special handling for punktkennung per NAS #12
if( strcmp(poClass->GetProperty(iProperty)->GetName(),
"punktkennung") == 0)
{
poClass->GetProperty(iProperty)->SetWidth( 15 );
poClass->GetProperty(iProperty)->SetType( GMLPT_String );
}
// Special handling for artDerFlurstuecksgrenze per http://trac.osgeo.org/gdal/ticket/4255
//.........这里部分代码省略.........
开发者ID:afarnham,项目名称:gdal,代码行数:101,代码来源:nasreader.cpp
示例6: CPLGetConfigOption
//.........这里部分代码省略.........
if( !FindFile( szTargetFile, pszDirectory, bReportErr, &fp ) )
return FALSE;
/* -------------------------------------------------------------------- */
/* Skip the line defining the column titles. */
/* -------------------------------------------------------------------- */
pszLine = ReadLine( fp );
if( !EQUAL(pszLine,
"\"Code\",\"Attribute\",\"Acronym\",\"Attributetype\",\"Class\"") )
{
CPLError( CE_Failure, CPLE_AppDefined,
"s57attributes columns don't match expected format!\n" );
return FALSE;
}
/* -------------------------------------------------------------------- */
/* Prepare arrays for the per-attribute information. */
/* -------------------------------------------------------------------- */
nAttrMax = MAX_ATTRIBUTES-1;
papszAttrNames = (char **) CPLCalloc(sizeof(char *),MAX_ATTRIBUTES);
papszAttrAcronym = (char **) CPLCalloc(sizeof(char *),MAX_ATTRIBUTES);
//papapszAttrValues = (char ***) CPLCalloc(sizeof(char **),MAX_ATTRIBUTES);
pachAttrType = (char *) CPLCalloc(sizeof(char),MAX_ATTRIBUTES);
pachAttrClass = (char *) CPLCalloc(sizeof(char),MAX_ATTRIBUTES);
panAttrIndex = (int *) CPLCalloc(sizeof(int),MAX_ATTRIBUTES);
/* -------------------------------------------------------------------- */
/* Read and form string list. */
/* -------------------------------------------------------------------- */
int iAttr;
while( (pszLine = ReadLine(fp)) != NULL )
{
char **papszTokens = CSLTokenizeStringComplex( pszLine, ",",
TRUE, TRUE );
if( CSLCount(papszTokens) < 5 )
{
CPLAssert( FALSE );
continue;
}
iAttr = atoi(papszTokens[0]);
if( iAttr < 0 || iAttr >= nAttrMax
|| papszAttrNames[iAttr] != NULL )
{
CPLDebug( "S57", "Duplicate definition for attribute %d:%s",
iAttr, papszTokens[2] );
continue;
}
papszAttrNames[iAttr] = CPLStrdup(papszTokens[1]);
papszAttrAcronym[iAttr] = CPLStrdup(papszTokens[2]);
pachAttrType[iAttr] = papszTokens[3][0];
pachAttrClass[iAttr] = papszTokens[4][0];
CSLDestroy( papszTokens );
}
if( fp != NULL )
VSIFClose( fp );
/* -------------------------------------------------------------------- */
/* Build unsorted index of attributes. */
/* -------------------------------------------------------------------- */
nAttrCount = 0;
for( iAttr = 0; iAttr < nAttrMax; iAttr++ )
{
if( papszAttrAcronym[iAttr] != NULL )
panAttrIndex[nAttrCount++] = iAttr;
}
/* -------------------------------------------------------------------- */
/* Sort index by acronym. */
/* -------------------------------------------------------------------- */
int bModified;
do
{
bModified = FALSE;
for( iAttr = 0; iAttr < nAttrCount-1; iAttr++ )
{
if( strcmp(papszAttrAcronym[panAttrIndex[iAttr]],
papszAttrAcronym[panAttrIndex[iAttr+1]]) > 0 )
{
int nTemp;
nTemp = panAttrIndex[iAttr];
panAttrIndex[iAttr] = panAttrIndex[iAttr+1];
panAttrIndex[iAttr+1] = nTemp;
bModified = TRUE;
}
}
} while( bModified );
return TRUE;
}
开发者ID:Chaduke,项目名称:bah.mod,代码行数:101,代码来源:s57classregistrar.cpp
示例7: CPLAssert
int OGRMySQLDataSource::FetchSRSId( OGRSpatialReference * poSRS )
{
char **papszRow;
MYSQL_RES *hResult=NULL;
char szCommand[10000];
char *pszWKT = NULL;
int nSRSId;
if( poSRS == NULL )
return -1;
/* -------------------------------------------------------------------- */
/* Translate SRS to WKT. */
/* -------------------------------------------------------------------- */
if( poSRS->exportToWkt( &pszWKT ) != OGRERR_NONE )
return -1;
CPLAssert( strlen(pszWKT) < sizeof(szCommand) - 500 );
/* -------------------------------------------------------------------- */
/* Try to find in the existing table. */
/* -------------------------------------------------------------------- */
sprintf( szCommand,
"SELECT srid FROM spatial_ref_sys WHERE srtext = '%s'",
pszWKT );
if( !mysql_query( GetConn(), szCommand ) )
hResult = mysql_store_result( GetConn() );
if (!mysql_num_rows(hResult))
{
CPLDebug("MYSQL", "No rows exist currently exist in spatial_ref_sys");
mysql_free_result( hResult );
hResult = NULL;
}
papszRow = NULL;
if( hResult != NULL )
papszRow = mysql_fetch_row( hResult );
if( papszRow != NULL && papszRow[0] != NULL )
{
nSRSId = atoi(papszRow[0]);
if( hResult != NULL )
mysql_free_result( hResult );
hResult = NULL;
CPLFree(pszWKT);
return nSRSId;
}
// make sure to attempt to free results of successful queries
hResult = mysql_store_result( GetConn() );
if( hResult != NULL )
mysql_free_result( hResult );
hResult = NULL;
/* -------------------------------------------------------------------- */
/* Get the current maximum srid in the srs table. */
/* -------------------------------------------------------------------- */
sprintf( szCommand,
"SELECT MAX(srid) FROM spatial_ref_sys");
if( !mysql_query( GetConn(), szCommand ) )
{
hResult = mysql_store_result( GetConn() );
papszRow = mysql_fetch_row( hResult );
}
if( papszRow != NULL && papszRow[0] != NULL )
{
nSRSId = atoi(papszRow[0]) + 1;
}
else
nSRSId = 1;
if( hResult != NULL )
mysql_free_result( hResult );
hResult = NULL;
/* -------------------------------------------------------------------- */
/* Try adding the SRS to the SRS table. */
/* -------------------------------------------------------------------- */
sprintf( szCommand,
"INSERT INTO spatial_ref_sys (srid,srtext) VALUES (%d,'%s')",
nSRSId, pszWKT );
if( !mysql_query( GetConn(), szCommand ) )
hResult = mysql_store_result( GetConn() );
// make sure to attempt to free results of successful queries
hResult = mysql_store_result( GetConn() );
if( hResult != NULL )
mysql_free_result( hResult );
hResult = NULL;
CPLFree(pszWKT);
return nSRSId;
}
开发者ID:469447793,项目名称:World-Wind-Java,代码行数:99,代码来源:ogrmysqldatasource.cpp
示例8: memcpy
//.........这里部分代码省略.........
GDALRasterBand * poBaseMask = poBaseBand != nullptr ?
poBaseBand->GetMaskBand() : nullptr;
const int nOverviewCount = poBaseMask != nullptr ?
poBaseMask->GetOverviewCount() : 0;
GDALDataset* poMaskDSTemp = nullptr;
for( int iOver = 0; iOver < nOverviewCount; iOver++ )
{
GDALRasterBand * const poOverBand =
poBaseMask->GetOverview( iOver );
if( poOverBand == nullptr )
continue;
if( poOverBand->GetXSize() == poDS->GetRasterXSize()
&& poOverBand->GetYSize() == poDS->GetRasterYSize() )
{
poMaskDSTemp = poOverBand->GetDataset();
break;
}
}
if( poMaskDSTemp != poDS )
{
poMaskDS = poMaskDSTemp;
bCheckedForMask = true;
bOwnMaskDS = false;
return poMaskDS != nullptr;
}
}
/* -------------------------------------------------------------------- */
/* Are we even initialized? If not, we apparently don't want */
/* to support overviews and masks. */
/* -------------------------------------------------------------------- */
if( poDS == nullptr )
return FALSE;
/* -------------------------------------------------------------------- */
/* Check for .msk file. */
/* -------------------------------------------------------------------- */
bCheckedForMask = true;
if( pszBasename == nullptr )
pszBasename = poDS->GetDescription();
// Don't bother checking for masks of masks.
if( EQUAL(CPLGetExtension(pszBasename),"msk") )
return FALSE;
if( !GDALCanFileAcceptSidecarFile(pszBasename) )
return FALSE;
CPLString osMskFilename;
osMskFilename.Printf( "%s.msk", pszBasename );
std::vector<char> achMskFilename;
achMskFilename.resize(osMskFilename.size() + 1);
memcpy(&(achMskFilename[0]),
osMskFilename.c_str(),
osMskFilename.size() + 1);
bool bExists = CPL_TO_BOOL(
CPLCheckForFile( &achMskFilename[0],
papszSiblingFiles ) );
osMskFilename = &achMskFilename[0];
#if !defined(WIN32)
if( !bExists && !papszSiblingFiles )
{
osMskFilename.Printf( "%s.MSK", pszBasename );
memcpy(&(achMskFilename[0]),
osMskFilename.c_str(),
osMskFilename.size() + 1);
bExists = CPL_TO_BOOL(
CPLCheckForFile( &achMskFilename[0],
papszSiblingFiles ) );
osMskFilename = &achMskFilename[0];
}
#endif
if( !bExists )
return FALSE;
/* -------------------------------------------------------------------- */
/* Open the file. */
/* -------------------------------------------------------------------- */
poMaskDS = GDALDataset::Open(
osMskFilename,
GDAL_OF_RASTER |
(poDS->GetAccess() == GA_Update ? GDAL_OF_UPDATE : 0),
nullptr, nullptr, papszInitSiblingFiles );
CPLAssert( poMaskDS != poDS );
if( poMaskDS == nullptr )
return FALSE;
bOwnMaskDS = true;
return TRUE;
}
开发者ID:OSGeo,项目名称:gdal,代码行数:101,代码来源:gdaldefaultoverviews.cpp
示例9: CleanOverviews
//.........这里部分代码省略.........
for( int i = 0; i < nOverviews; i++ )
{
if( !abValidLevel[i] || !abRequireRefresh[i] )
continue;
for( int j = 0; j < poBand->GetOverviewCount(); j++ )
{
if( abAlreadyUsedOverviewBand[j] )
continue;
GDALRasterBand * poOverview = poBand->GetOverview( j );
if( poOverview == nullptr )
continue;
int bHasNoData = FALSE;
double noDataValue = poBand->GetNoDataValue(&bHasNoData);
if( bHasNoData )
poOverview->SetNoDataValue(noDataValue);
const int nOvFactor =
GDALComputeOvFactor(poOverview->GetXSize(),
poBand->GetXSize(),
poOverview->GetYSize(),
poBand->GetYSize());
if( nOvFactor == panOverviewList[i] ||
nOvFactor == GDALOvLevelAdjust2( panOverviewList[i],
poBand->GetXSize(),
poBand->GetYSize() ))
{
abAlreadyUsedOverviewBand[j] = true;
CPLAssert(nNewOverviews < poBand->GetOverviewCount());
papoOverviewBands[nNewOverviews++] = poOverview;
break;
}
}
}
if( nNewOverviews > 0 )
{
const double dfOffset = dfAreaNewOverviews / dfAreaRefreshedOverviews;
const double dfScale = 1.0 - dfOffset;
pScaledProgress = GDALCreateScaledProgress(
dfOffset + dfScale * iBand / nBands,
dfOffset + dfScale * (iBand+1) / nBands,
pfnProgress, pProgressData );
eErr = GDALRegenerateOverviews( GDALRasterBand::ToHandle(poBand),
nNewOverviews,
reinterpret_cast<GDALRasterBandH*>(papoOverviewBands),
pszResampling,
GDALScaledProgress, pScaledProgress );
GDALDestroyScaledProgress( pScaledProgress );
}
}
/* -------------------------------------------------------------------- */
/* Cleanup */
/* -------------------------------------------------------------------- */
CPLFree( papoOverviewBands );
CPLFree( panNewOverviewList );
CPLFree( pahBands );
/* -------------------------------------------------------------------- */
/* If we have a mask file, we need to build its overviews too. */
开发者ID:OSGeo,项目名称:gdal,代码行数:67,代码来源:gdaldefaultoverviews.cpp
示例10: CPLAssert
void OGRCompoundCurve::EndPoint(OGRPoint *p) const
{
CPLAssert(oCC.nCurveCount > 0);
oCC.papoCurves[oCC.nCurveCount-1]->EndPoint(p);
}
开发者ID:drownedout,项目名称:datamap,代码行数:5,代码来源:ogrcompoundcurve.cpp
示例11: CPLError
//.........这里部分代码省略.........
break;
if (eReqDT == GDT_Int16)
{
WriteFloat(fp, 1); /* scale */
WriteFloat(fp, 0); /* offset */
for(k=0;k<nReqYSize;k++)
{
int nLastVal = ((short*)pTileBuffer)[(nReqYSize - k - 1) * nReqXSize + 0];
GByte nWordSize = 1;
for(l=1;l<nReqXSize;l++)
{
int nVal = ((short*)pTileBuffer)[(nReqYSize - k - 1) * nReqXSize + l];
int nDiff = nVal - nLastVal;
if (nDiff < -32768 || nDiff > 32767)
{
nWordSize = 4;
break;
}
if (nDiff < -128 || nDiff > 127)
nWordSize = 2;
nLastVal = nVal;
}
VSIFWriteL(&nWordSize, 1, 1, fp);
nLastVal = ((short*)pTileBuffer)[(nReqYSize - k - 1) * nReqXSize + 0];
WriteInt(fp, nLastVal);
for(l=1;l<nReqXSize;l++)
{
int nVal = ((short*)pTileBuffer)[(nReqYSize - k - 1) * nReqXSize + l];
int nDiff = nVal - nLastVal;
if (nWordSize == 1)
{
CPLAssert(nDiff >= -128 && nDiff <= 127);
char chDiff = (char)nDiff;
VSIFWriteL(&chDiff, 1, 1, fp);
}
else if (nWordSize == 2)
{
CPLAssert(nDiff >= -32768 && nDiff <= 32767);
WriteShort(fp, (short)nDiff);
}
else
{
WriteInt(fp, nDiff);
}
nLastVal = nVal;
}
}
}
else
{
float fMinVal = ((float*)pTileBuffer)[0];
float fMaxVal = fMinVal;
for(k=1;k<nReqYSize*nReqXSize;k++)
{
float fVal = ((float*)pTileBuffer)[k];
if (fVal < fMinVal) fMinVal = fVal;
if (fVal > fMaxVal) fMaxVal = fVal;
}
float fIntRange = (fMaxVal - fMinVal) / fVertPres;
float fScale = (fMinVal == fMaxVal) ? 1 : (fMaxVal - fMinVal) / fIntRange;
float fOffset = fMinVal;
WriteFloat(fp, fScale); /* scale */
WriteFloat(fp, fOffset); /* offset */
开发者ID:0004c,项目名称:node-gdal,代码行数:67,代码来源:hf2dataset.cpp
示例12: CPLAssert
int OGRMySQLDataSource::Open( const char * pszNewName, int bUpdate,
int bTestOpen )
{
CPLAssert( nLayers == 0 );
/* -------------------------------------------------------------------- */
/* Verify MySQL prefix. */
/* -------------------------------------------------------------------- */
if( !EQUALN(pszNewName,"MYSQL:",6) )
{
if( !bTestOpen )
CPLError( CE_Failure, CPLE_AppDefined,
"%s does not conform to MySQL naming convention,"
" MYSQL:dbname[, user=..][,password=..][,host=..][,port=..][tables=table;table;...]",
pszNewName );
return FALSE;
}
/* -------------------------------------------------------------------- */
/* Use options process to get .my.cnf file contents. */
/* -------------------------------------------------------------------- */
int nPort = 0, i;
char **papszTableNames=NULL;
std::string oHost, oPassword, oUser, oDB;
char *apszArgv[2] = { (char*) "org", NULL };
char **papszArgv = apszArgv;
int nArgc = 1;
const char *client_groups[] = {"client", "ogr", NULL };
my_init(); // I hope there is no problem with calling this multiple times!
load_defaults( "my", client_groups, &nArgc, &papszArgv );
for( i = 0; i < nArgc; i++ )
{
if( EQUALN(papszArgv[i],"--user=",7) )
oUser = papszArgv[i] + 7;
else if( EQUALN(papszArgv[i],"--host=",7) )
oHost = papszArgv[i] + 7;
else if( EQUALN(papszArgv[i],"--password=",11) )
oPassword = papszArgv[i] + 11;
else if( EQUALN(papszArgv[i],"--port=",7) )
nPort = atoi(papszArgv[i] + 7);
}
// cleanup
free_defaults( papszArgv );
/* -------------------------------------------------------------------- */
/* Parse out connection information. */
/* -------------------------------------------------------------------- */
char **papszItems = CSLTokenizeString2( pszNewName+6, ",",
CSLT_HONOURSTRINGS );
if( CSLCount(papszItems) < 1 )
{
CSLDestroy( papszItems );
CPLError( CE_Failure, CPLE_AppDefined,
"MYSQL: request missing databasename." );
return FALSE;
}
oDB = papszItems[0];
for( i = 1; papszItems[i] != NULL; i++ )
{
if( EQUALN(papszItems[i],"user=",5) )
oUser = papszItems[i] + 5;
else if( EQUALN(papszItems[i],"password=",9) )
oPassword = papszItems[i] + 9;
else if( EQUALN(papszItems[i],"host=",5) )
oHost = papszItems[i] + 5;
else if( EQUALN(papszItems[i],"port=",5) )
nPort = atoi(papszItems[i] + 5);
else if( EQUALN(papszItems[i],"tables=",7) )
{
papszTableNames = CSLTokenizeStringComplex(
papszItems[i] + 7, ";", FALSE, FALSE );
}
else
CPLError( CE_Warning, CPLE_AppDefined,
"'%s' in MYSQL datasource definition not recognised and ignored.", papszItems[i] );
}
CSLDestroy( papszItems );
/* -------------------------------------------------------------------- */
/* Try to establish connection. */
/* -------------------------------------------------------------------- */
hConn = mysql_init( NULL );
if( hConn == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
"mysql_init() failed." );
}
/* -------------------------------------------------------------------- */
/* Set desired options on the connection: charset and timeout. */
/* -------------------------------------------------------------------- */
//.........这里部分代码省略.........
开发者ID:actian-geospatial,项目名称:ogr-ingres,代码行数:101,代码来源:ogrmysqldatasource.cpp
示例13: VRTCreateCopy
static GDALDataset *
VRTCreateCopy( const char * pszFilename,
GDALDataset *poSrcDS,
int bStrict,
char ** papszOptions,
CPL_UNUSED GDALProgressFunc pfnProgress,
CPL_UNUSED void * pProgressData )
{
VRTDataset *poVRTDS = NULL;
(void) bStrict;
(void) papszOptions;
CPLAssert( NULL != poSrcDS );
/* -------------------------------------------------------------------- */
/* If the source dataset is a virtual dataset then just write */
/* it to disk as a special case to avoid extra layers of */
/* indirection. */
/* -------------------------------------------------------------------- */
if( poSrcDS->GetDriver() != NULL &&
EQUAL(poSrcDS->GetDriver()->GetDescription(),"VRT") )
{
/* -------------------------------------------------------------------- */
/* Convert tree to a single block of XML text. */
/* -------------------------------------------------------------------- */
char *pszVRTPath = CPLStrdup(CPLGetPath(pszFilename));
((VRTDataset *) poSrcDS)->UnsetPreservedRelativeFilenames();
CPLXMLNode *psDSTree = ((VRTDataset *) poSrcDS)->SerializeToXML( pszVRTPath );
char *pszXML = CPLSerializeXMLTree( psDSTree );
CPLDestroyXMLNode( psDSTree );
CPLFree( pszVRTPath );
/* -------------------------------------------------------------------- */
/* Write to disk. */
/* -------------------------------------------------------------------- */
GDALDataset* pCopyDS = NULL;
if( 0 != strlen( pszFilename ) )
{
VSILFILE *fpVRT = NULL;
fpVRT = VSIFOpenL( pszFilename, "wb" );
if (fpVRT == NULL)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot create %s", pszFilename);
CPLFree( pszXML );
return NULL;
}
VSIFWriteL( pszXML, 1, strlen(pszXML), fpVRT );
VSIFCloseL( fpVRT );
pCopyDS = (GDALDataset *) GDALOpen( pszFilename, GA_Update );
}
else
{
/* No destination file is given, so pass serialized XML directly. */
pCopyDS = (GDALDataset *) GDALOpen( pszXML, GA_Update );
}
CPLFree( pszXML );
return pCopyDS;
}
/* -------------------------------------------------------------------- */
/* Create the virtual dataset. */
/* -------------------------------------------------------------------- */
poVRTDS = (VRTDataset *)
VRTDataset::Create( pszFilename,
poSrcDS->GetRasterXSize(),
poSrcDS->GetRasterYSize(),
0, GDT_Byte, NULL );
if (poVRTDS == NULL)
return NULL;
/* -------------------------------------------------------------------- */
/* Do we have a geotransform? */
/* -------------------------------------------------------------------- */
double adfGeoTransform[6];
if( poSrcDS->GetGeoTransform( adfGeoTransform ) == CE_None )
{
poVRTDS->SetGeoTransform( adfGeoTransform );
}
/* -------------------------------------------------------------------- */
/* Copy projection */
/* -------------------------------------------------------------------- */
poVRTDS->SetProjection( poSrcDS->GetProjectionRef() );
/* -------------------------------------------------------------------- */
/* Emit dataset level metadata. */
//.........这里部分代码省略.........
开发者ID:drownedout,项目名称:datamap,代码行数:101,代码来源:vrtdriver.cpp
示例14: CPLAssert
CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,
int nBlockYOff, void * pImage)
{
EpsilonDataset* poGDS = (EpsilonDataset*) poDS;
//CPLDebug("EPSILON", "IReadBlock(nBand=%d,nBlockXOff=%d,nBlockYOff=%d)",
// nBand, nBlockXOff, nBlockYOff);
int nBlocksPerRow = (poGDS->nRasterXSize + nBlockXSize - 1) / nBlockXSize;
int nBlock = nBlockXOff + nBlockYOff * nBlocksPerRow;
BlockDesc* psDesc = &poGDS->pasBlocks[nBlock];
#ifdef DEBUG
int nBlocksPerColumn = (poGDS->nRasterYSize + nBlockYSize - 1) / nBlockYSize;
CPLAssert(psDesc->x == nBlockXOff * nBlockXSize);
CPLAssert(psDesc->y == nBlockYOff * nBlockYSize);
CPLAssert(psDesc->w == (nBlockXOff < nBlocksPerRow - 1) ?
nBlockXSize : poGDS->nRasterXSize - psDesc->x);
CPLAssert(psDesc->h == (nBlockYOff < nBlocksPerColumn - 1) ?
nBlockYSize : poGDS->nRasterYSize - psDesc->y);
#endif
poGDS->Seek(psDesc->offset);
if (!poGDS->GetNextBlockData())
{
memset(pImage, 0, nBlockXSize * nBlockYSize);
return CE_Failure;
}
eps_block_header hdr;
if (eps_read_block_header (poGDS->pabyBlockData,
poGDS->nBlockDataSize, &hdr) != EPS_OK)
{
CPLError(CE_Warning, CPLE_AppDefined, "cannot read block header");
memset(pImage, 0, nBlockXSize * nBlockYSize);
return CE_Failure;
}
if (hdr.chk_flag == EPS_BAD_CRC ||
hdr.crc_flag == EPS_BAD_CRC)
{
CPLError(CE_Warning, CPLE_AppDefined, "bad CRC");
memset(pImage, 0, nBlockXSize * nBlockYSize);
return CE_Failure;
}
int w = (hdr.block_type == EPS_GRAYSCALE_BLOCK) ? hdr.gs.w : hdr.tc.w;
int h = (hdr.block_type == EPS_GRAYSCALE_BLOCK) ? hdr.gs.h : hdr.tc.h;
int i;
if (poGDS->nBands == 1)
{
unsigned char ** pTempData =
(unsigned char **) CPLMalloc(h * sizeof(unsigned char*));
for(i=0;i<h;i++)
pTempData[i] = ((GByte*)pImage) + i * nBlockXSize;
if (w != nBlockXSize || h != nBlockYSize)
memset(pImage, 0, nBlockXSize * nBlockYSize);
if (eps_decode_grayscale_block (pTempData,
poGDS->pabyBlockData, &hdr) != EPS_OK)
{
CPLFree(pTempData);
memset(pImage, 0, nBlockXSize * nBlockYSize);
return CE_Failure;
}
CPLFree(pTempData);
}
else
{
if (poGDS->pabyRGBData == NULL)
{
poGDS->pabyRGBData =
(GByte*) VSIMalloc3(nBlock
|
请发表评论