本文整理汇总了C++中CPLPopErrorHandler函数的典型用法代码示例。如果您正苦于以下问题:C++ CPLPopErrorHandler函数的具体用法?C++ CPLPopErrorHandler怎么用?C++ CPLPopErrorHandler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CPLPopErrorHandler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CPLPushErrorHandler
CPLErr GS7BGDataset::GetGeoTransform( double *padfGeoTransform )
{
if( padfGeoTransform == NULL )
return CE_Failure;
GS7BGRasterBand *poGRB = (GS7BGRasterBand *)GetRasterBand( 1 );
if( poGRB == NULL )
{
padfGeoTransform[0] = 0;
padfGeoTransform[1] = 1;
padfGeoTransform[2] = 0;
padfGeoTransform[3] = 0;
padfGeoTransform[4] = 0;
padfGeoTransform[5] = 1;
return CE_Failure;
}
/* check if we have a PAM GeoTransform stored */
CPLPushErrorHandler( CPLQuietErrorHandler );
CPLErr eErr = GDALPamDataset::GetGeoTransform( padfGeoTransform );
CPLPopErrorHandler();
if( eErr == CE_None )
return CE_None;
/* calculate pixel size first */
padfGeoTransform[1] = (poGRB->dfMaxX - poGRB->dfMinX)/(nRasterXSize - 1);
padfGeoTransform[5] = (poGRB->dfMinY - poGRB->dfMaxY)/(nRasterYSize - 1);
/* then calculate image origin */
padfGeoTransform[0] = poGRB->dfMinX - padfGeoTransform[1] / 2;
padfGeoTransform[3] = poGRB->dfMaxY - padfGeoTransform[5] / 2;
/* tilt/rotation does not supported by the GS grids */
padfGeoTransform[4] = 0.0;
padfGeoTransform[2] = 0.0;
return CE_None;
}
示例2: main
int main( int argc, char ** argv )
{
QCoreApplication app( argc, argv );
QgsApplication::init();
if ( !QgsApplication::isRunningFromBuildDir() )
{
char* prefixPath = getenv( "QGIS_PREFIX_PATH" );
QgsApplication::setPrefixPath( prefixPath ? prefixPath : CMAKE_INSTALL_PREFIX, TRUE );
}
std::cout << "Synchronizing CRS database with GDAL/PROJ definitions." << std::endl;
CPLPushErrorHandler( showError );
int res = QgsCoordinateReferenceSystem::syncDb();
CPLPopErrorHandler();
if ( res == 0 )
{
std::cout << "No CRS updates were necessary." << std::endl;
}
else if ( res > 0 )
{
std::cout << res << " CRSs updated." << std::endl;
}
else if ( res == std::numeric_limits<int>::min() )
{
std::cout << "CRSs synchronization not possible." << std::endl;
}
else if ( res < 0 )
{
std::cout << -res << " CRSs could not be updated." << std::endl;
}
exit( 0 );
}
示例3: CPL_transform
// [[Rcpp::export]]
Rcpp::List CPL_transform(Rcpp::List sfc, Rcpp::CharacterVector proj4) {
// import proj4string:
OGRSpatialReference *dest = new OGRSpatialReference;
handle_error(dest->importFromProj4((const char *) (proj4[0])));
// transform geometries:
std::vector<OGRGeometry *> g = ogr_from_sfc(sfc, NULL);
if (g.size() == 0) {
dest->Release(); // #nocov
Rcpp::stop("CPL_transform: zero length geometry list"); // #nocov
}
OGRCoordinateTransformation *ct =
OGRCreateCoordinateTransformation(g[0]->getSpatialReference(), dest);
if (ct == NULL) {
dest->Release(); // #nocov
Rcpp::stop("OGRCreateCoordinateTransformation() returned NULL: PROJ.4 available?"); // #nocov
}
for (size_t i = 0; i < g.size(); i++) {
CPLPushErrorHandler(CPLQuietErrorHandler);
OGRErr err = 0;
if (! g[i]->IsEmpty())
err = g[i]->transform(ct);
CPLPopErrorHandler();
if (err == 1 || err == 6) {
OGRwkbGeometryType geomType = g[i]->getGeometryType();
OGRGeometryFactory f;
f.destroyGeometry(g[i]);
g[i] = f.createGeometry(geomType);
} else
handle_error(err);
}
Rcpp::List ret = sfc_from_ogr(g, true); // destroys g;
ct->DestroyCT(ct);
dest->Release();
return ret;
}
示例4: CPLPushErrorHandler
CPLErr SAGADataset::GetGeoTransform( double *padfGeoTransform )
{
if( padfGeoTransform == NULL )
return CE_Failure;
SAGARasterBand *poGRB = dynamic_cast<SAGARasterBand *>(GetRasterBand( 1 ));
if( poGRB == NULL )
{
padfGeoTransform[0] = 0;
padfGeoTransform[1] = 1;
padfGeoTransform[2] = 0;
padfGeoTransform[3] = 0;
padfGeoTransform[4] = 0;
padfGeoTransform[5] = 1;
return CE_Failure;
}
/* check if we have a PAM GeoTransform stored */
CPLPushErrorHandler( CPLQuietErrorHandler );
CPLErr eErr = GDALPamDataset::GetGeoTransform( padfGeoTransform );
CPLPopErrorHandler();
if( eErr == CE_None )
return CE_None;
padfGeoTransform[1] = poGRB->m_Cellsize;
padfGeoTransform[5] = poGRB->m_Cellsize * -1.0;
padfGeoTransform[0] = poGRB->m_Xmin - poGRB->m_Cellsize / 2;
padfGeoTransform[3] = poGRB->m_Ymin + (nRasterYSize - 1) * poGRB->m_Cellsize + poGRB->m_Cellsize / 2;
/* tilt/rotation is not supported by SAGA grids */
padfGeoTransform[4] = 0.0;
padfGeoTransform[2] = 0.0;
return CE_None;
}
示例5: CPLGetExtension
int OGRShapeDataSource::OpenFile( const char *pszNewName, int bUpdate,
int bTestOpen )
{
SHPHandle hSHP;
DBFHandle hDBF;
const char *pszExtension = CPLGetExtension( pszNewName );
(void) bTestOpen;
if( !EQUAL(pszExtension,"shp") && !EQUAL(pszExtension,"shx")
&& !EQUAL(pszExtension,"dbf") )
return FALSE;
/* -------------------------------------------------------------------- */
/* SHPOpen() should include better (CPL based) error reporting, */
/* and we should be trying to distinquish at this point whether */
/* failure is a result of trying to open a non-shapefile, or */
/* whether it was a shapefile and we want to report the error */
/* up. */
/* */
/* Care is taken to suppress the error and only reissue it if */
/* we think it is appropriate. */
/* -------------------------------------------------------------------- */
CPLPushErrorHandler( CPLQuietErrorHandler );
if( bUpdate )
hSHP = DS_SHPOpen( pszNewName, "r+" );
else
hSHP = DS_SHPOpen( pszNewName, "r" );
CPLPopErrorHandler();
if( hSHP == NULL
&& (!EQUAL(CPLGetExtension(pszNewName),"dbf")
|| strstr(CPLGetLastErrorMsg(),".shp") == NULL) )
{
CPLString osMsg = CPLGetLastErrorMsg();
CPLError( CE_Failure, CPLE_OpenFailed, "%s", osMsg.c_str() );
return FALSE;
}
CPLErrorReset();
/* -------------------------------------------------------------------- */
/* Open the .dbf file, if it exists. To open a dbf file, the */
/* filename has to either refer to a successfully opened shp */
/* file or has to refer to the actual .dbf file. */
/* -------------------------------------------------------------------- */
if( hSHP != NULL || EQUAL(CPLGetExtension(pszNewName),"dbf") )
{
if( bUpdate )
{
hDBF = DS_DBFOpen( pszNewName, "r+" );
if( hSHP != NULL && hDBF == NULL )
{
for(int i=0;i<2;i++)
{
VSIStatBufL sStat;
const char* pszDBFName = CPLResetExtension(pszNewName,
(i == 0 ) ? "dbf" : "DBF");
VSILFILE* fp = NULL;
if( VSIStatExL( pszDBFName, &sStat, VSI_STAT_EXISTS_FLAG) == 0 )
{
fp = VSIFOpenL(pszDBFName, "r+");
if (fp == NULL)
{
CPLError( CE_Failure, CPLE_OpenFailed,
"%s exists, but cannot be opened in update mode",
pszDBFName );
SHPClose(hSHP);
return FALSE;
}
VSIFCloseL(fp);
break;
}
}
}
}
else
hDBF = DS_DBFOpen( pszNewName, "r" );
}
else
hDBF = NULL;
if( hDBF == NULL && hSHP == NULL )
return FALSE;
/* -------------------------------------------------------------------- */
/* Create the layer object. */
/* -------------------------------------------------------------------- */
OGRShapeLayer *poLayer;
poLayer = new OGRShapeLayer( this, pszNewName, hSHP, hDBF, NULL, FALSE, bUpdate,
wkbNone );
poLayer->SetModificationDate(
CSLFetchNameValue( papszOpenOptions, "DBF_DATE_LAST_UPDATE" ) );
/* -------------------------------------------------------------------- */
/* Add layer to data source layer list. */
/* -------------------------------------------------------------------- */
//.........这里部分代码省略.........
示例6: main
//.........这里部分代码省略.........
}
/* -------------------------------------------------------------------- */
/* Report RPCs */
/* -------------------------------------------------------------------- */
papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, "RPC" ) : NULL;
if( bShowMetadata && CSLCount(papszMetadata) > 0 )
{
printf( "RPC Metadata:\n" );
for( i = 0; papszMetadata[i] != NULL; i++ )
{
printf( " %s\n", papszMetadata[i] );
}
}
/* -------------------------------------------------------------------- */
/* Setup projected to lat/long transform if appropriate. */
/* -------------------------------------------------------------------- */
if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None )
pszProjection = GDALGetProjectionRef(hDataset);
if( pszProjection != NULL && strlen(pszProjection) > 0 )
{
OGRSpatialReferenceH hProj, hLatLong = NULL;
hProj = OSRNewSpatialReference( pszProjection );
if( hProj != NULL )
hLatLong = OSRCloneGeogCS( hProj );
if( hLatLong != NULL )
{
CPLPushErrorHandler( CPLQuietErrorHandler );
hTransform = OCTNewCoordinateTransformation( hProj, hLatLong );
CPLPopErrorHandler();
OSRDestroySpatialReference( hLatLong );
}
if( hProj != NULL )
OSRDestroySpatialReference( hProj );
}
/* -------------------------------------------------------------------- */
/* Report corners. */
/* -------------------------------------------------------------------- */
printf( "Corner Coordinates:\n" );
GDALInfoReportCorner( hDataset, hTransform, "Upper Left",
0.0, 0.0 );
GDALInfoReportCorner( hDataset, hTransform, "Lower Left",
0.0, GDALGetRasterYSize(hDataset));
GDALInfoReportCorner( hDataset, hTransform, "Upper Right",
GDALGetRasterXSize(hDataset), 0.0 );
GDALInfoReportCorner( hDataset, hTransform, "Lower Right",
GDALGetRasterXSize(hDataset),
GDALGetRasterYSize(hDataset) );
GDALInfoReportCorner( hDataset, hTransform, "Center",
GDALGetRasterXSize(hDataset)/2.0,
GDALGetRasterYSize(hDataset)/2.0 );
if( hTransform != NULL )
{
OCTDestroyCoordinateTransformation( hTransform );
hTransform = NULL;
}
/* ==================================================================== */
示例7: CPLError
//.........这里部分代码省略.........
else
osTmpFileName.Printf("/vsimem/ogrgpsbabeldatasource_%p", this);
int bRet = FALSE;
if (IsSpecialFile(pszFilename))
{
/* Special file : don't try to open it */
char** argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
bTracks, pszGPSBabelDriverName, pszFilename);
VSILFILE* tmpfp = VSIFOpenL(osTmpFileName.c_str(), "wb");
bRet = (CPLSpawn(argv, NULL, tmpfp, TRUE) == 0);
VSIFCloseL(tmpfp);
tmpfp = NULL;
CSLDestroy(argv);
argv = NULL;
}
else
{
VSILFILE* fp = VSIFOpenL(pszFilename, "rb");
if (fp == NULL)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot open file %s", pszFilename);
return FALSE;
}
char** argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
bTracks, pszGPSBabelDriverName, "-");
VSILFILE* tmpfp = VSIFOpenL(osTmpFileName.c_str(), "wb");
CPLPushErrorHandler(CPLQuietErrorHandler);
bRet = (CPLSpawn(argv, fp, tmpfp, TRUE) == 0);
CPLPopErrorHandler();
CSLDestroy(argv);
argv = NULL;
CPLErr nLastErrorType = CPLGetLastErrorType();
int nLastErrorNo = CPLGetLastErrorNo();
CPLString osLastErrorMsg = CPLGetLastErrorMsg();
VSIFCloseL(tmpfp);
tmpfp = NULL;
VSIFCloseL(fp);
fp = NULL;
if (!bRet)
{
if (strstr(osLastErrorMsg.c_str(), "This format cannot be used in piped commands") == NULL)
{
CPLError(nLastErrorType, nLastErrorNo, "%s", osLastErrorMsg.c_str());
}
else
{
VSIStatBuf sStatBuf;
if (VSIStat(pszFilename, &sStatBuf) != 0)
{
CPLError(CE_Failure, CPLE_NotSupported,
"Driver %s only supports real (non virtual) files", pszGPSBabelDriverName);
return FALSE;
}
/* Try without piping in */
argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
示例8: gv_symbol_manager_get_symbol
GvSymbolObj *
gv_symbol_manager_get_symbol(GvSymbolManager *manager, const char *symbol_name)
{
gchar *pszOpenEVHome = NULL;
gchar *pszSymbolsDir = NULL;
gchar *pszAbsolutePath = NULL;
gchar *pszPathSeparator = NULL;
GDALDatasetH hDataset;
GvSymbolObj *poSymbol;
CPLXMLNode *xml_shape = NULL;
GByte *rgba_buffer;
/* -------------------------------------------------------------------- */
/* Lookup the symbol in the hash table, and return it if found. */
/* -------------------------------------------------------------------- */
poSymbol = g_hash_table_lookup( manager->symbol_cache, symbol_name );
if( poSymbol != NULL )
return poSymbol;
/* -------------------------------------------------------------------- */
/* We didn't already have it, so try to find a file to load it */
/* from. */
/* -------------------------------------------------------------------- */
#ifndef WIN32
pszPathSeparator = "/";
#else
pszPathSeparator = "\\";
#endif /* WIN32 */
/* validate inputs */
g_return_val_if_fail( manager != NULL, 0 );
g_return_val_if_fail( symbol_name != NULL, 0 );
/* get an absolute path */
if ( !g_path_is_absolute( symbol_name ) )
{
/* check configuration option first */
pszSymbolsDir = g_strdup( gv_manager_get_preference( gv_get_manager(),
"symbols_dir" ) );
/* if not configured check $OPENEV_HOME */
if ( !pszSymbolsDir )
{
pszOpenEVHome = g_getenv( "OPENEV_HOME" );
if( pszOpenEVHome == NULL )
pszOpenEVHome = g_getenv( "OPENEVHOME" );
if ( pszOpenEVHome )
pszSymbolsDir = g_strjoin( pszPathSeparator, pszOpenEVHome,
"symbols", NULL );
}
/* get current directory as last resort */
if ( !pszSymbolsDir )
pszSymbolsDir = g_get_current_dir();
pszAbsolutePath = g_strjoin( pszPathSeparator, pszSymbolsDir,
symbol_name, NULL );
g_free( pszSymbolsDir );
}
else
pszAbsolutePath = g_strdup( symbol_name );
/* -------------------------------------------------------------------- */
/* pszAbsolutePath contains a newly allocated string that is */
/* suitable for using as a key in the hash table. If a texture */
/* is found in the hash table then this string needs to be */
/* freed. If one isn't found then the string is used in the */
/* hash table and should be freed when the associated hash */
/* table entry is released */
/* -------------------------------------------------------------------- */
CPLDebug( "OpenEV",
"gv_symbol_manager_get_symbol(%s) ... need to load.",
pszAbsolutePath );
/*
* validate path by opening with GDAL and looking for an error
* Disable CPL error handler to supress error reporting
*/
CPLErrorReset();
CPLPushErrorHandler( CPLQuietErrorHandler );
hDataset = GDALOpen( pszAbsolutePath, GA_ReadOnly );
CPLPopErrorHandler();
if ( hDataset )
{
rgba_buffer = gdal_to_rgba( hDataset );
if ( rgba_buffer )
{
gv_symbol_manager_inject_raster_symbol(
manager, symbol_name,
GDALGetRasterXSize( hDataset ),
GDALGetRasterYSize( hDataset ),
rgba_buffer );
CPLFree( rgba_buffer );
}
GDALClose( hDataset );
}
//.........这里部分代码省略.........
示例9: CPLError
//.........这里部分代码省略.........
sPicture.progress_hook = WEBPDatasetProgressHook;
#endif
if (!WebPPictureAlloc(&sPicture))
{
CPLError(CE_Failure, CPLE_AppDefined, "WebPPictureAlloc() failed");
VSIFree(pabyBuffer);
VSIFCloseL( fpImage );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Acquire source imagery. */
/* -------------------------------------------------------------------- */
CPLErr eErr = CE_None;
eErr = poSrcDS->RasterIO( GF_Read, 0, 0, nXSize, nYSize,
pabyBuffer, nXSize, nYSize, GDT_Byte,
nBands, NULL,
nBands, nBands * nXSize, 1, NULL );
/* -------------------------------------------------------------------- */
/* Import and write to file */
/* -------------------------------------------------------------------- */
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
if (eErr == CE_None && nBands == 4)
{
if (!WebPPictureImportRGBA(&sPicture, pabyBuffer, nBands * nXSize))
{
CPLError(CE_Failure, CPLE_AppDefined, "WebPPictureImportRGBA() failed");
eErr = CE_Failure;
}
}
else
#endif
if (eErr == CE_None &&
!WebPPictureImportRGB(&sPicture, pabyBuffer, nBands * nXSize))
{
CPLError(CE_Failure, CPLE_AppDefined, "WebPPictureImportRGB() failed");
eErr = CE_Failure;
}
if (eErr == CE_None && !WebPEncode(&sConfig, &sPicture))
{
const char* pszErrorMsg = NULL;
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
switch(sPicture.error_code)
{
case VP8_ENC_ERROR_OUT_OF_MEMORY: pszErrorMsg = "Out of memory"; break;
case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY: pszErrorMsg = "Out of memory while flushing bits"; break;
case VP8_ENC_ERROR_NULL_PARAMETER: pszErrorMsg = "A pointer parameter is NULL"; break;
case VP8_ENC_ERROR_INVALID_CONFIGURATION: pszErrorMsg = "Configuration is invalid"; break;
case VP8_ENC_ERROR_BAD_DIMENSION: pszErrorMsg = "Picture has invalid width/height"; break;
case VP8_ENC_ERROR_PARTITION0_OVERFLOW: pszErrorMsg = "Partition is bigger than 512k. Try using less SEGMENTS, or increase PARTITION_LIMIT value"; break;
case VP8_ENC_ERROR_PARTITION_OVERFLOW: pszErrorMsg = "Partition is bigger than 16M"; break;
case VP8_ENC_ERROR_BAD_WRITE: pszErrorMsg = "Error while flusing bytes"; break;
case VP8_ENC_ERROR_FILE_TOO_BIG: pszErrorMsg = "File is bigger than 4G"; break;
case VP8_ENC_ERROR_USER_ABORT: pszErrorMsg = "User interrupted"; break;
default: break;
}
#endif
if (pszErrorMsg)
CPLError(CE_Failure, CPLE_AppDefined, "WebPEncode() failed : %s", pszErrorMsg);
else
CPLError(CE_Failure, CPLE_AppDefined, "WebPEncode() failed");
eErr = CE_Failure;
}
/* -------------------------------------------------------------------- */
/* Cleanup and close. */
/* -------------------------------------------------------------------- */
CPLFree( pabyBuffer );
WebPPictureFree(&sPicture);
VSIFCloseL( fpImage );
if( eErr != CE_None )
{
VSIUnlink( pszFilename );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Re-open dataset, and copy any auxiliary pam information. */
/* -------------------------------------------------------------------- */
GDALOpenInfo oOpenInfo(pszFilename, GA_ReadOnly);
/* If outputing to stdout, we can't reopen it, so we'll return */
/* a fake dataset to make the caller happy */
CPLPushErrorHandler(CPLQuietErrorHandler);
WEBPDataset *poDS = (WEBPDataset*) WEBPDataset::Open( &oOpenInfo );
CPLPopErrorHandler();
if( poDS )
{
poDS->CloneInfo( poSrcDS, GCIF_PAM_DEFAULT );
return poDS;
}
return NULL;
}
示例10: CPLPopErrorHandler
Debug::~Debug()
{
CPLPopErrorHandler();
}
示例11: CPLGetExtension
int OGRShapeDataSource::OpenFile( const char *pszNewName, int bUpdate,
int bTestOpen )
{
SHPHandle hSHP;
DBFHandle hDBF;
const char *pszExtension = CPLGetExtension( pszNewName );
(void) bTestOpen;
if( !EQUAL(pszExtension,"shp") && !EQUAL(pszExtension,"shx")
&& !EQUAL(pszExtension,"dbf") )
return FALSE;
/* -------------------------------------------------------------------- */
/* SHPOpen() should include better (CPL based) error reporting, */
/* and we should be trying to distinquish at this point whether */
/* failure is a result of trying to open a non-shapefile, or */
/* whether it was a shapefile and we want to report the error */
/* up. */
/* */
/* Care is taken to suppress the error and only reissue it if */
/* we think it is appropriate. */
/* -------------------------------------------------------------------- */
CPLPushErrorHandler( CPLQuietErrorHandler );
if( bUpdate )
hSHP = SHPOpen( pszNewName, "r+" );
else
hSHP = SHPOpen( pszNewName, "r" );
CPLPopErrorHandler();
if( hSHP == NULL
&& (!EQUAL(CPLGetExtension(pszNewName),"dbf")
|| strstr(CPLGetLastErrorMsg(),".shp") == NULL) )
{
CPLString osMsg = CPLGetLastErrorMsg();
CPLError( CE_Failure, CPLE_OpenFailed, "%s", osMsg.c_str() );
return FALSE;
}
CPLErrorReset();
/* -------------------------------------------------------------------- */
/* Open the .dbf file, if it exists. To open a dbf file, the */
/* filename has to either refer to a successfully opened shp */
/* file or has to refer to the actual .dbf file. */
/* -------------------------------------------------------------------- */
if( hSHP != NULL || EQUAL(CPLGetExtension(pszNewName),"dbf") )
{
if( bUpdate )
hDBF = DBFOpen( pszNewName, "r+" );
else
hDBF = DBFOpen( pszNewName, "r" );
}
else
hDBF = NULL;
if( hDBF == NULL && hSHP == NULL )
return FALSE;
/* -------------------------------------------------------------------- */
/* Is there an associated .prj file we can read? */
/* -------------------------------------------------------------------- */
OGRSpatialReference *poSRS = NULL;
const char *pszPrjFile = CPLResetExtension( pszNewName, "prj" );
FILE *fp = NULL;
fp = VSIFOpenL( pszPrjFile, "r" );
#ifndef WIN32
if( NULL == fp )
{
pszPrjFile = CPLResetExtension( pszNewName, "PRJ" );
fp = VSIFOpenL( pszPrjFile, "r" );
}
#endif
if( fp != NULL )
{
char **papszLines;
VSIFCloseL( fp );
papszLines = CSLLoad( pszPrjFile );
poSRS = new OGRSpatialReference();
if( poSRS->importFromESRI( papszLines ) != OGRERR_NONE )
{
delete poSRS;
poSRS = NULL;
}
CSLDestroy( papszLines );
}
/* -------------------------------------------------------------------- */
/* Create the layer object. */
/* -------------------------------------------------------------------- */
OGRShapeLayer *poLayer;
//.........这里部分代码省略.........
示例12: CPLResetExtension
int OGRIdrisiLayer::Detect_AVL_ADC(const char* pszFilename)
{
// --------------------------------------------------------------------
// Look for .adc file
// --------------------------------------------------------------------
const char* pszADCFilename = CPLResetExtension(pszFilename, "adc");
VSILFILE* fpADC = VSIFOpenL(pszADCFilename, "rb");
if (fpADC == NULL)
{
pszADCFilename = CPLResetExtension(pszFilename, "ADC");
fpADC = VSIFOpenL(pszADCFilename, "rb");
}
char** papszADC = NULL;
if (fpADC != NULL)
{
VSIFCloseL(fpADC);
fpADC = NULL;
CPLPushErrorHandler(CPLQuietErrorHandler);
papszADC = CSLLoad2(pszADCFilename, 1024, 256, NULL);
CPLPopErrorHandler();
CPLErrorReset();
}
if (papszADC == NULL)
return FALSE;
CSLSetNameValueSeparator( papszADC, ":" );
const char *pszVersion = CSLFetchNameValue( papszADC, "file format " );
if( pszVersion == NULL || !EQUAL( pszVersion, "IDRISI Values A.1" ) )
{
CSLDestroy( papszADC );
return FALSE;
}
const char *pszFileType = CSLFetchNameValue( papszADC, "file type " );
if( pszFileType == NULL || !EQUAL( pszFileType, "ascii" ) )
{
CPLDebug("IDRISI", ".adc file found, but file type != ascii");
CSLDestroy( papszADC );
return FALSE;
}
const char* pszRecords = CSLFetchNameValue( papszADC, "records " );
if( pszRecords == NULL || atoi(pszRecords) != (int)nTotalFeatures )
{
CPLDebug("IDRISI", ".adc file found, but 'records' not found or not "
"consistent with feature number declared in .vdc");
CSLDestroy( papszADC );
return FALSE;
}
const char* pszFields = CSLFetchNameValue( papszADC, "fields " );
if( pszFields == NULL || atoi(pszFields) <= 1 )
{
CPLDebug("IDRISI", ".adc file found, but 'fields' not found or invalid");
CSLDestroy( papszADC );
return FALSE;
}
// --------------------------------------------------------------------
// Look for .avl file
// --------------------------------------------------------------------
const char* pszAVLFilename = CPLResetExtension(pszFilename, "avl");
fpAVL = VSIFOpenL(pszAVLFilename, "rb");
if (fpAVL == NULL)
{
pszAVLFilename = CPLResetExtension(pszFilename, "AVL");
fpAVL = VSIFOpenL(pszAVLFilename, "rb");
}
if (fpAVL == NULL)
{
CSLDestroy( papszADC );
return FALSE;
}
// --------------------------------------------------------------------
// Build layer definition
// --------------------------------------------------------------------
int iCurField;
char szKey[32];
iCurField = 0;
sprintf(szKey, "field %d ", iCurField);
char** papszIter = papszADC;
const char* pszLine;
int bFieldFound = FALSE;
CPLString osFieldName;
while((pszLine = *papszIter) != NULL)
{
//CPLDebug("IDRISI", "%s", pszLine);
if (strncmp(pszLine, szKey, strlen(szKey)) == 0)
{
const char* pszColon = strchr(pszLine, ':');
if (pszColon)
{
//.........这里部分代码省略.........
示例13: CPLPushErrorHandler
int OGRAVCBinDataSource::Open( const char * pszNewName, int bTestOpen )
{
/* -------------------------------------------------------------------- */
/* Open the source file. Supress error reporting if we are in */
/* TestOpen mode. */
/* -------------------------------------------------------------------- */
if( bTestOpen )
CPLPushErrorHandler( CPLQuietErrorHandler );
psAVC = AVCE00ReadOpen( pszNewName );
if( bTestOpen )
{
CPLPopErrorHandler();
CPLErrorReset();
}
if( psAVC == NULL )
return FALSE;
pszName = CPLStrdup( pszNewName );
pszCoverageName = CPLStrdup( psAVC->pszCoverName );
/* -------------------------------------------------------------------- */
/* Create layers for the "interesting" sections of the coverage. */
/* -------------------------------------------------------------------- */
int iSection;
papoLayers = (OGRLayer **)
CPLCalloc( sizeof(OGRLayer *), psAVC->numSections );
nLayers = 0;
for( iSection = 0; iSection < psAVC->numSections; iSection++ )
{
AVCE00Section *psSec = psAVC->pasSections + iSection;
switch( psSec->eType )
{
case AVCFileARC:
case AVCFilePAL:
case AVCFileCNT:
case AVCFileLAB:
case AVCFileRPL:
case AVCFileTXT:
case AVCFileTX6:
papoLayers[nLayers++] = new OGRAVCBinLayer( this, psSec );
break;
case AVCFilePRJ:
{
char **papszPRJ;
AVCBinFile *hFile;
hFile = AVCBinReadOpen(psAVC->pszCoverPath,
psSec->pszFilename,
psAVC->eCoverType,
psSec->eType,
psAVC->psDBCSInfo);
if( hFile && poSRS == NULL )
{
papszPRJ = AVCBinReadNextPrj( hFile );
poSRS = new OGRSpatialReference();
if( poSRS->importFromESRI( papszPRJ ) != OGRERR_NONE )
{
CPLError( CE_Warning, CPLE_AppDefined,
"Failed to parse PRJ section, ignoring." );
delete poSRS;
poSRS = NULL;
}
AVCBinReadClose( hFile );
}
}
break;
default:
;
}
}
return nLayers > 0;
}
示例14: main
int main(int argc, char** argv)
{
/* Check strict compilation and runtime library version as we use C++ API */
if (! GDAL_CHECK_VERSION(argv[0]))
exit(1);
EarlySetConfigOptions(argc, argv);
/* -------------------------------------------------------------------- */
/* Generic arg processing. */
/* -------------------------------------------------------------------- */
GDALAllRegister();
argc = GDALGeneralCmdLineProcessor( argc, &argv, 0 );
if( argc < 1 )
exit( -argc );
for( int i = 0; i < argc; i++ )
{
if( EQUAL(argv[i], "--utility_version") )
{
printf("%s was compiled against GDAL %s and is running against GDAL %s\n",
argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME"));
CSLDestroy( argv );
return 0;
}
else if( EQUAL(argv[i],"--help") )
{
Usage();
}
}
GDALRasterizeOptionsForBinary* psOptionsForBinary = GDALRasterizeOptionsForBinaryNew();
GDALRasterizeOptions *psOptions = GDALRasterizeOptionsNew(argv + 1, psOptionsForBinary);
CSLDestroy( argv );
if( psOptions == NULL )
{
Usage();
}
if( !(psOptionsForBinary->bQuiet) )
{
GDALRasterizeOptionsSetProgress(psOptions, GDALTermProgress, NULL);
}
if( psOptionsForBinary->pszSource == NULL )
Usage("No input file specified.");
if( psOptionsForBinary->pszDest == NULL )
Usage("No output file specified.");
/* -------------------------------------------------------------------- */
/* Open input file. */
/* -------------------------------------------------------------------- */
GDALDatasetH hInDS = GDALOpenEx( psOptionsForBinary->pszSource, GDAL_OF_VECTOR | GDAL_OF_VERBOSE_ERROR,
NULL, NULL, NULL );
if( hInDS == NULL )
exit( 1 );
/* -------------------------------------------------------------------- */
/* Open output file if it exists. */
/* -------------------------------------------------------------------- */
GDALDatasetH hDstDS = NULL;
if( !(psOptionsForBinary->bCreateOutput) )
{
CPLPushErrorHandler( CPLQuietErrorHandler );
hDstDS = GDALOpenEx( psOptionsForBinary->pszDest, GDAL_OF_RASTER | GDAL_OF_VERBOSE_ERROR | GDAL_OF_UPDATE,
NULL, NULL, NULL );
CPLPopErrorHandler();
}
if (hDstDS == NULL && !psOptionsForBinary->bQuiet && !psOptionsForBinary->bFormatExplicitlySet)
CheckExtensionConsistency(psOptionsForBinary->pszDest, psOptionsForBinary->pszFormat);
int bUsageError = FALSE;
GDALDatasetH hRetDS = GDALRasterize(psOptionsForBinary->pszDest,
hDstDS,
hInDS,
psOptions, &bUsageError);
if(bUsageError == TRUE)
Usage();
int nRetCode = (hRetDS) ? 0 : 1;
GDALClose(hInDS);
GDALClose(hRetDS);
GDALRasterizeOptionsFree(psOptions);
GDALRasterizeOptionsForBinaryFree(psOptionsForBinary);
GDALDestroyDriverManager();
return nRetCode;
}
示例15: CPLError
//.........这里部分代码省略.........
/* -------------------------------------------------------------------- */
GByte *pabyBuffer;
pabyBuffer = (GByte *) VSIMalloc( 3 * nXSize * nYSize );
if (pabyBuffer == NULL)
{
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create the dataset. */
/* -------------------------------------------------------------------- */
VSILFILE *fpImage;
fpImage = VSIFOpenL( pszFilename, "wb" );
if( fpImage == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Unable to create WEBP file %s.\n",
pszFilename );
VSIFree(pabyBuffer);
return NULL;
}
/* -------------------------------------------------------------------- */
/* WEBP library settings */
/* -------------------------------------------------------------------- */
sPicture.colorspace = 0;
sPicture.width = nXSize;
sPicture.height = nYSize;
sPicture.writer = WEBPDatasetWriter;
sPicture.custom_ptr = fpImage;
if (!WebPPictureAlloc(&sPicture))
{
CPLError(CE_Failure, CPLE_AppDefined, "WebPPictureAlloc() failed");
VSIFree(pabyBuffer);
VSIFCloseL( fpImage );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Acquire source imagery. */
/* -------------------------------------------------------------------- */
CPLErr eErr = CE_None;
eErr = poSrcDS->RasterIO( GF_Read, 0, 0, nXSize, nYSize,
pabyBuffer, nXSize, nYSize, GDT_Byte,
3, NULL,
3, 3 * nXSize, 1 );
/* -------------------------------------------------------------------- */
/* Import and write to file */
/* -------------------------------------------------------------------- */
if (eErr == CE_None &&
!WebPPictureImportRGB(&sPicture, pabyBuffer, 3 * nXSize))
{
CPLError(CE_Failure, CPLE_AppDefined, "WebPPictureImportRGB() failed");
eErr = CE_Failure;
}
if (eErr == CE_None && !WebPEncode(&sConfig, &sPicture))
{
CPLError(CE_Failure, CPLE_AppDefined, "WebPEncode() failed");
eErr = CE_Failure;
}
/* -------------------------------------------------------------------- */
/* Cleanup and close. */
/* -------------------------------------------------------------------- */
CPLFree( pabyBuffer );
WebPPictureFree(&sPicture);
VSIFCloseL( fpImage );
if( eErr != CE_None )
{
VSIUnlink( pszFilename );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Re-open dataset, and copy any auxilary pam information. */
/* -------------------------------------------------------------------- */
GDALOpenInfo oOpenInfo(pszFilename, GA_ReadOnly);
/* If outputing to stdout, we can't reopen it, so we'll return */
/* a fake dataset to make the caller happy */
CPLPushErrorHandler(CPLQuietErrorHandler);
WEBPDataset *poDS = (WEBPDataset*) WEBPDataset::Open( &oOpenInfo );
CPLPopErrorHandler();
if( poDS )
{
poDS->CloneInfo( poSrcDS, GCIF_PAM_DEFAULT );
return poDS;
}
return NULL;
}