本文整理汇总了C++中CPLRealloc函数 的典型用法代码示例。如果您正苦于以下问题:C++ CPLRealloc函数的具体用法?C++ CPLRealloc怎么用?C++ CPLRealloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CPLRealloc函数 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: CPLQuadTreeNodeAddFeatureAlg1
static void CPLQuadTreeNodeAddFeatureAlg1( CPLQuadTree* hQuadTree,
QuadTreeNode *psNode,
void* hFeature,
const CPLRectObj* pRect)
{
int i;
if (psNode->nNumSubNodes == 0)
{
/* If we have reached the max bucket capacity, try to insert */
/* in a subnode if possible */
if (psNode->nFeatures >= hQuadTree->nBucketCapacity)
{
CPLRectObj half1, half2, quad1, quad2, quad3, quad4;
CPLQuadTreeSplitBounds(hQuadTree->dfSplitRatio, &psNode->rect, &half1, &half2);
CPLQuadTreeSplitBounds(hQuadTree->dfSplitRatio, &half1, &quad1, &quad2);
CPLQuadTreeSplitBounds(hQuadTree->dfSplitRatio, &half2, &quad3, &quad4);
if (memcmp(&psNode->rect, &quad1, sizeof(CPLRectObj)) != 0 &&
memcmp(&psNode->rect, &quad2, sizeof(CPLRectObj)) != 0 &&
memcmp(&psNode->rect, &quad3, sizeof(CPLRectObj)) != 0 &&
memcmp(&psNode->rect, &quad4, sizeof(CPLRectObj)) != 0 &&
(CPL_RectContained(pRect, &quad1) ||
CPL_RectContained(pRect, &quad2) ||
CPL_RectContained(pRect, &quad3) ||
CPL_RectContained(pRect, &quad4)))
{
psNode->nNumSubNodes = 4;
psNode->apSubNode[0] = CPLQuadTreeNodeCreate(&quad1);
psNode->apSubNode[1] = CPLQuadTreeNodeCreate(&quad2);
psNode->apSubNode[2] = CPLQuadTreeNodeCreate(&quad3);
psNode->apSubNode[3] = CPLQuadTreeNodeCreate(&quad4);
int oldNumFeatures = psNode->nFeatures;
void** oldFeatures = psNode->pahFeatures;
CPLRectObj* pasOldBounds = psNode->pasBounds;
psNode->nFeatures = 0;
psNode->pahFeatures = NULL;
psNode->pasBounds = NULL;
/* redispatch existing pahFeatures in apSubNodes */
int i;
for(i=0;i<oldNumFeatures;i++)
{
if( hQuadTree->pfnGetBounds == NULL )
CPLQuadTreeNodeAddFeatureAlg1(hQuadTree, psNode, oldFeatures[i], &pasOldBounds[i]);
else
{
CPLRectObj bounds;
hQuadTree->pfnGetBounds(oldFeatures[i], &bounds);
CPLQuadTreeNodeAddFeatureAlg1(hQuadTree, psNode, oldFeatures[i], &bounds);
}
}
CPLFree(oldFeatures);
CPLFree(pasOldBounds);
/* recurse back on this psNode now that it has apSubNodes */
CPLQuadTreeNodeAddFeatureAlg1(hQuadTree, psNode, hFeature, pRect);
return;
}
}
}
else
{
/* -------------------------------------------------------------------- */
/* If there are apSubNodes, then consider whether this object */
/* will fit in them. */
/* -------------------------------------------------------------------- */
for(i=0; i<psNode->nNumSubNodes; i++ )
{
if( CPL_RectContained(pRect, &psNode->apSubNode[i]->rect))
{
CPLQuadTreeNodeAddFeatureAlg1( hQuadTree, psNode->apSubNode[i], hFeature, pRect);
return;
}
}
}
/* -------------------------------------------------------------------- */
/* If none of that worked, just add it to this psNodes list. */
/* -------------------------------------------------------------------- */
psNode->nFeatures++;
if( psNode->nFeatures == 1 )
{
CPLAssert( psNode->pahFeatures == NULL );
psNode->pahFeatures = (void**) CPLMalloc( hQuadTree->nBucketCapacity * sizeof(void*) );
if( hQuadTree->pfnGetBounds == NULL )
psNode->pasBounds = (CPLRectObj*) CPLMalloc( hQuadTree->nBucketCapacity * sizeof(CPLRectObj) );
}
else if( psNode->nFeatures > hQuadTree->nBucketCapacity )
{
psNode->pahFeatures = (void**) CPLRealloc( psNode->pahFeatures, sizeof(void*) * psNode->nFeatures );
if( hQuadTree->pfnGetBounds == NULL )
psNode->pasBounds = (CPLRectObj*) CPLRealloc( psNode->pasBounds, sizeof(CPLRectObj) * psNode->nFeatures );
}
psNode->pahFeatures[psNode->nFeatures-1] = hFeature;
if( hQuadTree->pfnGetBounds == NULL )
psNode->pasBounds[psNode->nFeatures-1] = *pRect;
//.........这里部分代码省略.........
开发者ID:0004c, 项目名称:node-gdal, 代码行数:101, 代码来源:cpl_quad_tree.cpp
示例2: CPLDebug
OGRLayer *OGRSelafinDataSource::ICreateLayer( const char *pszLayerName, OGRSpatialReference *poSpatialRefP, OGRwkbGeometryType eGType, char ** papszOptions ) {
CPLDebug("Selafin","CreateLayer(%s,%s)",pszLayerName,(eGType==wkbPoint)?"wkbPoint":"wkbPolygon");
// Verify we are in update mode.
if ( !bUpdate )
{
CPLError( CE_Failure, CPLE_NoWriteAccess,
"Data source %s opened read-only. "
"New layer %s cannot be created.",
pszName, pszLayerName );
return NULL;
}
// Check that new layer is a point or polygon layer
if( eGType != wkbPoint )
{
CPLError( CE_Failure, CPLE_NoWriteAccess, "Selafin format can only handle %s layers whereas input is %s\n.", OGRGeometryTypeToName(wkbPoint),OGRGeometryTypeToName(eGType));
return NULL;
}
// Parse options
const char *pszTemp=CSLFetchNameValue(papszOptions,"DATE");
const double dfDate = pszTemp != NULL ? CPLAtof(pszTemp) : 0.0;
// Set the SRS of the datasource if this is the first layer
if (nLayers==0 && poSpatialRefP!=NULL) {
poSpatialRef=poSpatialRefP;
poSpatialRef->Reference();
const char* szEpsg=poSpatialRef->GetAttrValue("GEOGCS|AUTHORITY",1);
int nEpsg=0;
if (szEpsg!=NULL) nEpsg=(int)strtol(szEpsg,NULL,10);
if (nEpsg==0) {
CPLError(CE_Warning,CPLE_AppDefined,"Could not find EPSG code for SRS. The SRS won't be saved in the datasource.");
} else {
poHeader->nEpsg=nEpsg;
}
}
// Create the new layer in the Selafin file by adding a "time step" at the end
// Beware, as the new layer shares the same header, it automatically contains the same number of features and fields as the existing ones. This may not be intuitive for the user.
if (VSIFSeekL(poHeader->fp,0,SEEK_END)!=0) return NULL;
if (Selafin::write_integer(poHeader->fp,4)==0 ||
Selafin::write_float(poHeader->fp,dfDate)==0 ||
Selafin::write_integer(poHeader->fp,4)==0) {
CPLError( CE_Failure, CPLE_FileIO, "Could not write to Selafin file %s.\n",pszName);
return NULL;
}
double *pdfValues=NULL;
if (poHeader->nPoints>0)
{
pdfValues=(double*)VSI_MALLOC2_VERBOSE(sizeof(double),poHeader->nPoints);
if( pdfValues == NULL )
return NULL;
}
for (int i=0;i<poHeader->nVar;++i) {
if (Selafin::write_floatarray(poHeader->fp,pdfValues,poHeader->nPoints)==0) {
CPLError( CE_Failure, CPLE_FileIO, "Could not write to Selafin file %s.\n",pszName);
CPLFree(pdfValues);
return NULL;
}
}
CPLFree(pdfValues);
VSIFFlushL(poHeader->fp);
poHeader->nSteps++;
// Create two layers as usual, one for points and one for elements
nLayers+=2;
papoLayers = (OGRSelafinLayer **) CPLRealloc(papoLayers, sizeof(void*) * nLayers);
CPLString szName=pszLayerName;
CPLString szNewLayerName=szName+"_p";
papoLayers[nLayers-2] =
new OGRSelafinLayer( szNewLayerName, bUpdate, poSpatialRef, poHeader,
poHeader->nSteps-1, POINTS );
szNewLayerName=szName+"_e";
papoLayers[nLayers-1] =
new OGRSelafinLayer( szNewLayerName, bUpdate, poSpatialRef, poHeader,
poHeader->nSteps-1, ELEMENTS );
return papoLayers[nLayers-2];
}
开发者ID:ryandavid, 项目名称:rotobox, 代码行数:73, 代码来源:ogrselafindatasource.cpp
示例3: while
int OGRMDBDataSource::OpenGDB(OGRMDBTable* poGDB_GeomColumns)
{
int iTableName = poGDB_GeomColumns->GetColumnIndex("TableName", TRUE);
int iFieldName = poGDB_GeomColumns->GetColumnIndex("FieldName", TRUE);
int iShapeType = poGDB_GeomColumns->GetColumnIndex("ShapeType", TRUE);
int iExtentLeft = poGDB_GeomColumns->GetColumnIndex("ExtentLeft", TRUE);
int iExtentRight = poGDB_GeomColumns->GetColumnIndex("ExtentRight", TRUE);
int iExtentBottom = poGDB_GeomColumns->GetColumnIndex("ExtentBottom", TRUE);
int iExtentTop = poGDB_GeomColumns->GetColumnIndex("ExtentTop", TRUE);
int iSRID = poGDB_GeomColumns->GetColumnIndex("SRID", TRUE);
int iHasZ = poGDB_GeomColumns->GetColumnIndex("HasZ", TRUE);
if (iTableName < 0 || iFieldName < 0 || iShapeType < 0 ||
iExtentLeft < 0 || iExtentRight < 0 || iExtentBottom < 0 ||
iExtentTop < 0 || iSRID < 0 || iHasZ < 0)
return FALSE;
while(poGDB_GeomColumns->GetNextRow())
{
OGRMDBLayer *poLayer;
char* pszTableName = poGDB_GeomColumns->GetColumnAsString(iTableName);
char* pszFieldName = poGDB_GeomColumns->GetColumnAsString(iFieldName);
if (pszTableName == NULL || pszFieldName == NULL)
{
CPLFree(pszTableName);
CPLFree(pszFieldName);
continue;
}
OGRMDBTable* poTable = poDB->GetTable(pszTableName);
if (poTable == NULL)
{
CPLFree(pszTableName);
CPLFree(pszFieldName);
continue;
}
poLayer = new OGRMDBLayer( this, poTable );
if( poLayer->Initialize( pszTableName,
pszFieldName,
poGDB_GeomColumns->GetColumnAsInt(iShapeType),
poGDB_GeomColumns->GetColumnAsDouble(iExtentLeft),
poGDB_GeomColumns->GetColumnAsDouble(iExtentRight),
poGDB_GeomColumns->GetColumnAsDouble(iExtentBottom),
poGDB_GeomColumns->GetColumnAsDouble(iExtentTop),
poGDB_GeomColumns->GetColumnAsInt(iSRID),
poGDB_GeomColumns->GetColumnAsInt(iHasZ) )
!= CE_None )
{
delete poLayer;
}
else
{
papoLayers = (OGRMDBLayer**)CPLRealloc(papoLayers, (nLayers+1) * sizeof(OGRMDBLayer*));
papoLayers[nLayers++] = poLayer;
}
CPLFree(pszTableName);
CPLFree(pszFieldName);
}
return TRUE;
}
开发者ID:0004c, 项目名称:node-gdal, 代码行数:65, 代码来源:ogrmdbdatasource.cpp
示例4: CPLStrdup
//.........这里部分代码省略.........
CSLFetchNameValue( papszOptions, "GEOMETRY_NAME" );
if( pszGeometryName == NULL )
pszGeometryName = "ORA_GEOMETRY";
const bool bGeomNullable =
CPLFetchBool(const_cast<const char**>(papszOptions), "GEOMETRY_NULLABLE", true);
/* -------------------------------------------------------------------- */
/* Create a basic table with the FID. Also include the */
/* geometry if this is not a PostGIS enabled table. */
/* -------------------------------------------------------------------- */
const char *pszExpectedFIDName =
CPLGetConfigOption( "OCI_FID", "OGR_FID" );
OGROCIStatement oStatement( poSession );
/* -------------------------------------------------------------------- */
/* If geometry type is wkbNone, do not create a geometry column. */
/* -------------------------------------------------------------------- */
if ( CSLFetchNameValue( papszOptions, "TRUNCATE" ) == NULL )
{
if (eType == wkbNone)
{
snprintf( szCommand, sizeof(szCommand),
"CREATE TABLE \"%s\" ( "
"%s INTEGER PRIMARY KEY)",
pszSafeLayerName, pszExpectedFIDName);
}
else
{
snprintf( szCommand, sizeof(szCommand),
"CREATE TABLE \"%s\" ( "
"%s INTEGER PRIMARY KEY, "
"%s %s%s )",
pszSafeLayerName, pszExpectedFIDName,
pszGeometryName, SDO_GEOMETRY,
(!bGeomNullable) ? " NOT NULL":"");
}
if (bNoLogging)
{
char szCommand2[1024];
strncpy( szCommand2, szCommand, sizeof(szCommand) );
snprintf( szCommand, sizeof(szCommand), "%s NOLOGGING "
"VARRAY %s.SDO_ELEM_INFO STORE AS SECUREFILE LOB (NOCACHE NOLOGGING) "
"VARRAY %s.SDO_ORDINATES STORE AS SECUREFILE LOB (NOCACHE NOLOGGING) ",
szCommand2, pszGeometryName, pszGeometryName);
}
if( oStatement.Execute( szCommand ) != CE_None )
{
CPLFree( pszSafeLayerName );
return NULL;
}
}
/* -------------------------------------------------------------------- */
/* Create the layer object. */
/* -------------------------------------------------------------------- */
const char *pszLoaderFile = CSLFetchNameValue(papszOptions,"LOADER_FILE");
OGROCIWritableLayer *poLayer;
if( pszLoaderFile == NULL )
poLayer = new OGROCITableLayer( this, pszSafeLayerName, eType,
EQUAL(szSRSId,"NULL") ? -1 : atoi(szSRSId),
TRUE, TRUE );
else
poLayer =
new OGROCILoaderLayer( this, pszSafeLayerName,
pszGeometryName,
EQUAL(szSRSId,"NULL") ? -1 : atoi(szSRSId),
pszLoaderFile );
/* -------------------------------------------------------------------- */
/* Set various options on the layer. */
/* -------------------------------------------------------------------- */
poLayer->SetLaunderFlag( CSLFetchBoolean(papszOptions, "LAUNDER", false) );
poLayer->SetPrecisionFlag( CSLFetchBoolean(papszOptions, "PRECISION", true));
if( CSLFetchNameValue(papszOptions,"DIM") != NULL )
poLayer->SetDimension( atoi(CSLFetchNameValue(papszOptions,"DIM")) );
poLayer->SetOptions( papszOptions );
if( eType != wkbNone && !bGeomNullable )
poLayer->GetLayerDefn()->GetGeomFieldDefn(0)->SetNullable(FALSE);
/* -------------------------------------------------------------------- */
/* Add layer to data source layer list. */
/* -------------------------------------------------------------------- */
papoLayers = (OGROCILayer **)
CPLRealloc( papoLayers, sizeof(OGROCILayer *) * (nLayers+1) );
papoLayers[nLayers++] = poLayer;
CPLFree( pszSafeLayerName );
return poLayer;
}
开发者ID:nextgis-borsch, 项目名称:lib_gdal, 代码行数:101, 代码来源:ogrocidatasource.cpp
示例5: CPLErrorV
void CPLErrorV(CPLErr eErrClass, int err_no, const char *fmt, va_list args )
{
CPLErrorContext *psCtx = CPLGetErrorContext();
if (psCtx->nFailureIntoWarning > 0 && eErrClass == CE_Failure)
eErrClass = CE_Warning;
/* -------------------------------------------------------------------- */
/* Expand the error message */
/* -------------------------------------------------------------------- */
#if defined(HAVE_VSNPRINTF)
{
int nPR;
va_list wrk_args;
#ifdef va_copy
va_copy( wrk_args, args );
#else
wrk_args = args;
#endif
/* -------------------------------------------------------------------- */
/* If CPL_ACCUM_ERROR_MSG=ON accumulate the error messages, */
/* rather than just replacing the last error message. */
/* -------------------------------------------------------------------- */
int nPreviousSize = 0;
if ( psCtx->psHandlerStack != NULL &&
EQUAL(CPLGetConfigOption( "CPL_ACCUM_ERROR_MSG", "" ), "ON"))
{
nPreviousSize = strlen(psCtx->szLastErrMsg);
if (nPreviousSize)
{
if (nPreviousSize + 1 + 1 >= psCtx->nLastErrMsgMax)
{
psCtx->nLastErrMsgMax *= 3;
psCtx = (CPLErrorContext *)
CPLRealloc(psCtx, sizeof(CPLErrorContext) - DEFAULT_LAST_ERR_MSG_SIZE + psCtx->nLastErrMsgMax + 1);
CPLSetTLS( CTLS_ERRORCONTEXT, psCtx, TRUE );
}
psCtx->szLastErrMsg[nPreviousSize] = '\n';
psCtx->szLastErrMsg[nPreviousSize+1] = '0';
nPreviousSize ++;
}
}
while( ((nPR = CPLvsnprintf( psCtx->szLastErrMsg+nPreviousSize,
psCtx->nLastErrMsgMax-nPreviousSize, fmt, wrk_args )) == -1
|| nPR >= psCtx->nLastErrMsgMax-nPreviousSize-1)
&& psCtx->nLastErrMsgMax < 1000000 )
{
#ifdef va_copy
va_end( wrk_args );
va_copy( wrk_args, args );
#else
wrk_args = args;
#endif
psCtx->nLastErrMsgMax *= 3;
psCtx = (CPLErrorContext *)
CPLRealloc(psCtx, sizeof(CPLErrorContext) - DEFAULT_LAST_ERR_MSG_SIZE + psCtx->nLastErrMsgMax + 1);
CPLSetTLS( CTLS_ERRORCONTEXT, psCtx, TRUE );
}
va_end( wrk_args );
}
#else
// !HAVE_VSNPRINTF
CPLvsnprintf( psCtx->szLastErrMsg, psCtx->nLastErrMsgMax, fmt, args);
#endif
/* -------------------------------------------------------------------- */
/* Obfuscate any password in error message */
/* -------------------------------------------------------------------- */
char* pszPassword = strstr(psCtx->szLastErrMsg, "password=");
if( pszPassword != NULL )
{
char* pszIter = pszPassword + strlen("password=");
while( *pszIter != ' ' && *pszIter != '\0' )
{
*pszIter = 'X';
pszIter ++;
}
}
/* -------------------------------------------------------------------- */
/* If the user provided an handling function, then */
/* call it, otherwise print the error to stderr and return. */
/* -------------------------------------------------------------------- */
psCtx->nLastErrNo = err_no;
psCtx->eLastErrType = eErrClass;
if( CPLGetConfigOption("CPL_LOG_ERRORS",NULL) != NULL )
CPLDebug( "CPLError", "%s", psCtx->szLastErrMsg );
/* -------------------------------------------------------------------- */
/* Invoke the current error handler. */
/* -------------------------------------------------------------------- */
if( psCtx->psHandlerStack != NULL )
{
psCtx->psHandlerStack->pfnHandler(eErrClass, err_no,
//.........这里部分代码省略.........
开发者ID:drownedout, 项目名称:datamap, 代码行数:101, 代码来源:cpl_error.cpp
示例6: MAIN_START
//.........这里部分代码省略.........
nOrder = atoi(argv[++i]);
aosTO.SetNameValue("MAX_GCP_ORDER", argv[i] );
}
else if( EQUAL(argv[i],"-tps") )
{
aosTO.SetNameValue("METHOD", "GCP_TPS" );
nOrder = -1;
}
else if( EQUAL(argv[i],"-rpc") )
{
aosTO.SetNameValue("METHOD", "RPC" );
}
else if( EQUAL(argv[i],"-geoloc") )
{
aosTO.SetNameValue("METHOD", "GEOLOC_ARRAY" );
}
else if( EQUAL(argv[i],"-i") )
{
bInverse = TRUE;
}
else if( EQUAL(argv[i],"-to") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
aosTO.AddString( argv[++i] );
}
else if( EQUAL(argv[i],"-gcp") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(4);
char* endptr = nullptr;
/* -gcp pixel line easting northing [elev] */
nGCPCount++;
pasGCPs = static_cast<GDAL_GCP *>(
CPLRealloc(pasGCPs, sizeof(GDAL_GCP) * nGCPCount));
GDALInitGCPs( 1, pasGCPs + nGCPCount - 1 );
pasGCPs[nGCPCount-1].dfGCPPixel = CPLAtof(argv[++i]);
pasGCPs[nGCPCount-1].dfGCPLine = CPLAtof(argv[++i]);
pasGCPs[nGCPCount-1].dfGCPX = CPLAtof(argv[++i]);
pasGCPs[nGCPCount-1].dfGCPY = CPLAtof(argv[++i]);
if( argv[i+1] != nullptr &&
(CPLStrtod(argv[i+1], &endptr) != 0.0 || argv[i+1][0] == '0') )
{
// Check that last argument is really a number and not a
// filename looking like a number (see ticket #863).
if (endptr && *endptr == 0)
pasGCPs[nGCPCount-1].dfGCPZ = CPLAtof(argv[++i]);
}
/* should set id and info? */
}
else if( EQUAL(argv[i],"-output_xy") )
{
bOutputXY = TRUE;
}
else if( EQUAL(argv[i],"-coord") && i + 2 < argc)
{
bCoordOnCommandLine = true;
dfX = CPLAtof(argv[++i]);
dfY = CPLAtof(argv[++i]);
if( i + 1 < argc && CPLGetValueType(argv[i+1]) != CPL_VALUE_STRING )
dfZ = CPLAtof(argv[++i]);
if( i + 1 < argc && CPLGetValueType(argv[i+1]) != CPL_VALUE_STRING )
dfT = CPLAtof(argv[++i]);
}
else if( argv[i][0] == '-' )
开发者ID:AsgerPetersen, 项目名称:gdal, 代码行数:67, 代码来源:gdaltransform.cpp
示例7: while
//.........这里部分代码省略.........
GByte *pszIconvSrcBuf = (GByte*) CPLCalloc((nSrcLen+1),nTargetCharWidth);
unsigned int iSrc;
for( iSrc = 0; iSrc <= nSrcLen; iSrc++ )
{
if( nTargetCharWidth == 1 )
pszIconvSrcBuf[iSrc] = (GByte) pwszSource[iSrc];
else if( nTargetCharWidth == 2 )
((short *)pszIconvSrcBuf)[iSrc] = (short) pwszSource[iSrc];
else if( nTargetCharWidth == 4 )
((GInt32 *)pszIconvSrcBuf)[iSrc] = pwszSource[iSrc];
}
/* -------------------------------------------------------------------- */
/* Create the iconv() translation object. */
/* -------------------------------------------------------------------- */
iconv_t sConv;
sConv = iconv_open( pszDstEncoding, pszSrcEncoding );
if ( sConv == (iconv_t)-1 )
{
CPLFree( pszIconvSrcBuf );
CPLError( CE_Warning, CPLE_AppDefined,
"Recode from %s to %s failed with the error: \"%s\".",
pszSrcEncoding, pszDstEncoding, strerror(errno) );
return CPLStrdup( "" );
}
/* -------------------------------------------------------------------- */
/* XXX: There is a portability issue: iconv() function could be */
/* declared differently on different platforms. The second */
/* argument could be declared as char** (as POSIX defines) or */
/* as a const char**. Handle it with the ICONV_CONST macro here. */
/* -------------------------------------------------------------------- */
ICONV_CONST char *pszSrcBuf = (ICONV_CONST char *) pszIconvSrcBuf;
/* iconv expects a number of bytes, not characters */
nSrcLen *= sizeof(wchar_t);
/* -------------------------------------------------------------------- */
/* Allocate destination buffer. */
/* -------------------------------------------------------------------- */
size_t nDstCurLen = MAX(CPL_RECODE_DSTBUF_SIZE, nSrcLen + 1);
size_t nDstLen = nDstCurLen;
char *pszDestination = (char *)CPLCalloc( nDstCurLen, sizeof(char) );
char *pszDstBuf = pszDestination;
while ( nSrcLen > 0 )
{
size_t nConverted =
iconv( sConv, &pszSrcBuf, &nSrcLen, &pszDstBuf, &nDstLen );
if ( nConverted == (size_t)-1 )
{
if ( errno == EILSEQ )
{
// Skip the invalid sequence in the input string.
nSrcLen--;
pszSrcBuf += sizeof(wchar_t);
static int bHasWarned = FALSE;
if (!bHasWarned)
{
bHasWarned = TRUE;
CPLError(CE_Warning, CPLE_AppDefined,
"One or several characters couldn't be converted correctly from %s to %s.\n"
"This warning will not be emitted anymore",
pszSrcEncoding, pszDstEncoding);
}
continue;
}
else if ( errno == E2BIG )
{
// We are running out of the output buffer.
// Dynamically increase the buffer size.
size_t nTmp = nDstCurLen;
nDstCurLen *= 2;
pszDestination =
(char *)CPLRealloc( pszDestination, nDstCurLen );
pszDstBuf = pszDestination + nTmp - nDstLen;
nDstLen += nDstCurLen - nTmp;
continue;
}
else
break;
}
}
pszDestination[nDstCurLen - nDstLen] = '\0';
iconv_close( sConv );
CPLFree( pszIconvSrcBuf );
return pszDestination;
}
开发者ID:AsherBond, 项目名称:MondocosmOS, 代码行数:101, 代码来源:cpl_recode_iconv.cpp
示例8: LaunderName
//.........这里部分代码省略.........
else if( wkbFlatten(eType) == wkbGeometryCollection )
{
if( IsNewIngres() )
pszGeometryType = "GEOMETRYCOLLECTION";
}
else if( wkbFlatten(eType) == wkbUnknown )
{
if( IsNewIngres() )
// this is also used as the generic geometry type.
pszGeometryType = "GEOMETRYCOLLECTION";
}
/* -------------------------------------------------------------------- */
/* Try to get the SRS Id of this spatial reference system, */
/* adding tot the srs table if needed. */
/* -------------------------------------------------------------------- */
int nSRSId = -1;
if( poSRS != NULL && IsNewIngres() == TRUE )
nSRSId = FetchSRSId( poSRS );
/* -------------------------------------------------------------------- */
/* Form table creation command. */
/* -------------------------------------------------------------------- */
CPLString osCommand;
if( pszGeometryType == NULL )
{
osCommand.Printf( "CREATE TABLE %s ( "
" %s INTEGER )",
pszLayerName, pszExpectedFIDName );
}
else
{
if(nSRSId != -1)
{
osCommand.Printf( "CREATE TABLE %s ("
" %s INTEGER NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS seq_%s IDENTITY (START WITH 1 INCREMENT BY 1),"
" %s %s SRID %d ) ",
pszLayerName,
pszExpectedFIDName,
pszLayerName,
pszGeomColumnName,
pszGeometryType,
nSRSId);
}
else
{
osCommand.Printf( "CREATE TABLE %s ("
" %s INTEGER NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS seq_%s IDENTITY (START WITH 1 INCREMENT BY 1),"
" %s %s )",
pszLayerName,
pszExpectedFIDName,
pszLayerName,
pszGeomColumnName,
pszGeometryType);
}
}
/* -------------------------------------------------------------------- */
/* Execute the create table command. */
/* -------------------------------------------------------------------- */
{
OGRIngresStatement oStmt( hConn );
if( !oStmt.ExecuteSQL( osCommand ) )
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create the layer object. */
/* -------------------------------------------------------------------- */
OGRIngresTableLayer *poLayer;
OGRErr eErr;
poLayer = new OGRIngresTableLayer( this, pszLayerName, TRUE, nSRSId );
eErr = poLayer->Initialize(pszLayerName);
if (eErr == OGRERR_FAILURE)
{
delete poLayer;
return NULL;
}
poLayer->SetLaunderFlag( CSLFetchBoolean(papszOptions,"LAUNDER",TRUE) );
poLayer->SetPrecisionFlag( CSLFetchBoolean(papszOptions,"PRECISION",TRUE));
/* -------------------------------------------------------------------- */
/* Add layer to data source layer list. */
/* -------------------------------------------------------------------- */
papoLayers = (OGRIngresLayer **)
CPLRealloc( papoLayers, sizeof(OGRIngresLayer *) * (nLayers+1) );
papoLayers[nLayers++] = poLayer;
CPLFree( pszLayerName );
return poLayer;
}
开发者ID:0004c, 项目名称:node-gdal, 代码行数:101, 代码来源:ogringresdatasource.cpp
示例9: CPLStrdup
int OGRSDTSDataSource::Open( const char * pszFilename, int bTestOpen )
{
pszName = CPLStrdup( pszFilename );
/* -------------------------------------------------------------------- */
/* Verify that the extension is DDF if we are testopening. */
/* -------------------------------------------------------------------- */
if( bTestOpen && !(strlen(pszFilename) > 4 &&
EQUAL(pszFilename+strlen(pszFilename)-4,".ddf")) )
return FALSE;
/* -------------------------------------------------------------------- */
/* Check a few bits of the header to see if it looks like an */
/* SDTS file (really, if it looks like an ISO8211 file). */
/* -------------------------------------------------------------------- */
if( bTestOpen )
{
FILE *fp;
char pachLeader[10];
fp = VSIFOpen( pszFilename, "rb" );
if( fp == NULL )
return FALSE;
if( VSIFRead( pachLeader, 1, 10, fp ) != 10
|| (pachLeader[5] != '1' && pachLeader[5] != '2'
&& pachLeader[5] != '3' )
|| pachLeader[6] != 'L'
|| (pachLeader[8] != '1' && pachLeader[8] != ' ') )
{
VSIFClose( fp );
return FALSE;
}
VSIFClose( fp );
}
/* -------------------------------------------------------------------- */
/* Create a transfer, and open it. */
/* -------------------------------------------------------------------- */
poTransfer = new SDTSTransfer();
if( !poTransfer->Open( pszFilename ) )
{
delete poTransfer;
poTransfer = NULL;
return FALSE;
}
/* -------------------------------------------------------------------- */
/* Initialize the projection. */
/* -------------------------------------------------------------------- */
SDTS_XREF *poXREF = poTransfer->GetXREF();
poSRS = new OGRSpatialReference();
if( EQUAL(poXREF->pszSystemName,"UTM") )
{
poSRS->SetUTM( poXREF->nZone, TRUE );
}
if( EQUAL(poXREF->pszDatum,"NAS") )
poSRS->SetGeogCS("NAD27", "North_American_Datum_1927",
"Clarke 1866", 6378206.4, 294.978698213901 );
else if( EQUAL(poXREF->pszDatum,"NAX") )
poSRS->SetGeogCS("NAD83", "North_American_Datum_1983",
"GRS 1980", 6378137, 298.257222101 );
else if( EQUAL(poXREF->pszDatum,"WGC") )
poSRS->SetGeogCS("WGS 72", "WGS_1972", "NWL 10D", 6378135, 298.26 );
else if( EQUAL(poXREF->pszDatum,"WGE") )
poSRS->SetGeogCS("WGS 84", "WGS_1984",
"WGS 84", 6378137, 298.257223563 );
else
poSRS->SetGeogCS("WGS 84", "WGS_1984",
"WGS 84", 6378137, 298.257223563 );
poSRS->Fixup();
/* -------------------------------------------------------------------- */
/* Initialize a layer for each source dataset layer. */
/* -------------------------------------------------------------------- */
for( int iLayer = 0; iLayer < poTransfer->GetLayerCount(); iLayer++ )
{
SDTSIndexedReader *poReader;
if( poTransfer->GetLayerType( iLayer ) == SLTRaster )
continue;
poReader = poTransfer->GetLayerIndexedReader( iLayer );
if( poReader == NULL )
continue;
papoLayers = (OGRSDTSLayer **)
CPLRealloc( papoLayers, sizeof(void*) * ++nLayers );
//.........这里部分代码省略.........
开发者ID:bbradbury, 项目名称:lib_gdal, 代码行数:101, 代码来源:ogrsdtsdatasource.cpp
示例10: CPLError
OGRLayer *
OGRTABDataSource::ICreateLayer( const char * pszLayerName,
OGRSpatialReference *poSRSIn,
OGRwkbGeometryType /* eGeomTypeIn */,
char ** papszOptions )
{
IMapInfoFile *poFile;
char *pszFullFilename;
const char *pszOpt = NULL;
if( !m_bUpdate )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Cannot create layer on read-only dataset.");
return NULL;
}
/* -------------------------------------------------------------------- */
/* If it's a single file mode file, then we may have already */
/* instantiated the low level layer. We would just need to */
/* reset the coordinate system and (potentially) bounds. */
/* -------------------------------------------------------------------- */
if( m_bSingleFile )
{
if( m_bSingleLayerAlreadyCreated )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Unable to create new layers in this single file dataset.");
return NULL;
}
m_bSingleLayerAlreadyCreated = TRUE;
poFile = (IMapInfoFile *) m_papoLayers[0];
}
else
{
if( m_bCreateMIF )
{
pszFullFilename = CPLStrdup( CPLFormFilename( m_pszDirectory,
pszLayerName, "mif" ) );
poFile = new MIFFile;
}
else
{
pszFullFilename = CPLStrdup( CPLFormFilename( m_pszDirectory,
pszLayerName, "tab" ) );
poFile = new TABFile;
}
if( poFile->Open( pszFullFilename, TABWrite, FALSE ) != 0 )
{
CPLFree( pszFullFilename );
delete poFile;
return FALSE;
}
m_nLayerCount++;
m_papoLayers = (IMapInfoFile **)
CPLRealloc(m_papoLayers,sizeof(void*)*m_nLayerCount);
m_papoLayers[m_nLayerCount-1] = poFile;
CPLFree( pszFullFilename );
}
poFile->SetDescription( poFile->GetName() );
/* -------------------------------------------------------------------- */
/* Assign the coordinate system (if provided) and set */
/* reasonable bounds. */
/* -------------------------------------------------------------------- */
if( poSRSIn != NULL )
{
poFile->SetSpatialRef( poSRSIn );
// SetSpatialRef() has cloned the passed geometry
poFile->GetLayerDefn()->GetGeomFieldDefn(0)->SetSpatialRef(poFile->GetSpatialRef());
}
// Pull out the bounds if supplied
if( (pszOpt=CSLFetchNameValue(papszOptions, "BOUNDS")) != NULL ) {
double dfBounds[4];
if( CPLsscanf(pszOpt, "%lf,%lf,%lf,%lf", &dfBounds[0],
&dfBounds[1],
&dfBounds[2],
&dfBounds[3]) != 4 )
{
CPLError( CE_Failure, CPLE_IllegalArg,
"Invalid BOUNDS parameter, expected min_x,min_y,max_x,max_y\n" );
}
else
{
poFile->SetBounds( dfBounds[0], dfBounds[1], dfBounds[2], dfBounds[3] );
}
}
if( !poFile->IsBoundsSet() && !m_bCreateMIF )
//.........这里部分代码省略.........
开发者ID:AbdelghaniDr, 项目名称:mirror, 代码行数:101, 代码来源:mitab_ogr_datasource.cpp
示例11: oStatement
OGRSpatialReference *OGRIngresDataSource::FetchSRS( int nId )
{
char szCommand[1024];
char **papszRow;
OGRIngresStatement oStatement(GetConn());
if( nId < 0 )
return NULL;
/*
* Only the new Ingres Geospatial library
*/
if(IsNewIngres() == FALSE)
return NULL;
/* -------------------------------------------------------------------- */
/* First, we look through our SRID cache, is it there? */
/* -------------------------------------------------------------------- */
int i;
for( i = 0; i < nKnownSRID; i++ )
{
if( panSRID[i] == nId )
return papoSRS[i];
}
OGRSpatialReference *poSRS = NULL;
sprintf( szCommand,
"SELECT srtext FROM spatial_ref_sys WHERE srid = %d",
nId );
oStatement.ExecuteSQL(szCommand);
char *pszWKT = NULL;
papszRow = NULL;
papszRow = oStatement.GetRow();
if( papszRow != NULL)
{
if(papszRow[0] != NULL )
{
//VARCHAR uses the first two bytes for length
pszWKT = &papszRow[0][2];
}
}
poSRS = new OGRSpatialReference();
if( pszWKT == NULL || poSRS->importFromWkt( &pszWKT ) != OGRERR_NONE )
{
delete poSRS;
poSRS = NULL;
}
/* -------------------------------------------------------------------- */
/* Add to the cache. */
/* -------------------------------------------------------------------- */
panSRID = (int *) CPLRealloc(panSRID,sizeof(int) * (nKnownSRID+1) );
papoSRS = (OGRSpatialReference **)
CPLRealloc(papoSRS, sizeof(void*) * (nKnownSRID + 1) );
panSRID[nKnownSRID] = nId;
papoSRS[nKnownSRID] = poSRS;
return poSRS;
}
开发者ID:0004c, 项目名称:node-gdal, 代码行数:67, 代码来源:ogringresdatasource.cpp
示例12: CPLAssert
int OGRTABDataSource::Open( GDALOpenInfo* poOpenInfo, int bTestOpen )
{
CPLAssert( m_pszName == NULL );
m_pszName = CPLStrdup( poOpenInfo->pszFilename );
m_bUpdate = (poOpenInfo->eAccess == GA_Update );
/* -------------------------------------------------------------------- */
/* If it is a file, try to open as a Mapinfo file. */
/* -------------------------------------------------------------------- */
if( !poOpenInfo->bIsDirectory )
{
IMapInfoFile *poFile;
poFile = IMapInfoFile::SmartOpen( m_pszName, m_bUpdate, bTestOpen );
if( poFile == NULL )
return FALSE;
poFile->SetDescription( poFile->GetName() );
m_nLayerCount = 1;
m_papoLayers = (IMapInfoFile **) CPLMalloc(sizeof(void*));
m_papoLayers[0] = poFile;
m_pszDirectory = CPLStrdup( CPLGetPath(m_pszName) );
m_bSingleFile = TRUE;
m_bSingleLayerAlreadyCreated = TRUE;
}
/* -------------------------------------------------------------------- */
/* Otherwise, we need to scan the whole directory for files */
/* ending in .tab or .mif. */
/* -------------------------------------------------------------------- */
else
{
char **papszFileList = CPLReadDir( m_pszName );
m_pszDirectory = CPLStrdup( m_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, m_bUpdate, bTestOpen );
CPLFree( pszSubFilename );
if( poFile == NULL )
{
CSLDestroy( papszFileList );
return FALSE;
}
poFile->SetDescription( poFile->GetName() );
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:AbdelghaniDr, 项目名称:mirror, 代码行数:86, 代码来源:mitab_ogr_datasource.cpp
示例13: CPLMalloc
CPLString &CPLString::vPrintf( const char *pszFormat, va_list args )
{
/* -------------------------------------------------------------------- */
/* This implementation for platforms without vsnprintf() will */
/* just plain fail if the formatted contents are too large. */
/* -------------------------------------------------------------------- */
#if !defined(HAVE_VSNPRINTF)
char *pszBuffer = (char *) CPLMalloc(30000);
if( vsprintf( pszBuffer, pszFormat, args) > 29998 )
{
CPLError( CE_Fatal, CPLE_AppDefined,
"CPLString::vPrintf() ... buffer overrun." );
}
*this = pszBuffer;
CPLFree( pszBuffer );
/* -------------------------------------------------------------------- */
/* This should grow a big enough buffer to hold any formatted */
/* result. */
/* -------------------------------------------------------------------- */
#else
char szModestBuffer[500];
int nPR;
va_list wrk_args;
#ifdef va_copy
va_copy( wrk_args, args );
#else
wrk_args = args;
#endif
nPR = vsnprintf( szModestBuffer, sizeof(szModestBuffer), pszFormat,
wrk_args );
if( nPR == -1 || nPR >= (int) sizeof(szModestBuffer)-1 )
{
int nWorkBufferSize = 2000;
char *pszWorkBuffer = (char *) CPLMalloc(nWorkBufferSize);
#ifdef va_copy
va_end( wrk_args );
va_copy( wrk_args, args );
#else
wrk_args = args;
#endif
while( (nPR=vsnprintf( pszWorkBuffer, nWorkBufferSize, pszFormat,wrk_args))
>= nWorkBufferSize-1
|| nPR == -1 )
{
nWorkBufferSize *= 4;
pszWorkBuffer = (char *) CPLRealloc(pszWorkBuffer,
nWorkBufferSize );
#ifdef va_copy
va_end( wrk_args );
va_copy( wrk_args, args );
#else
wrk_args = args;
#endif
}
*this = pszWorkBuffer;
CPLFree( pszWorkBuffer );
}
else
{
*this = szModestBuffer;
}
va_end( wrk_args );
#endif
return *this;
}
开发者ID:dlsyaim, 项目名称:osgEarthX, 代码行数:72, 代码来源:cplstring.cpp
示例14: CPLQuadTreeNodeAddFeatureAlg2
六六分期app的软件客服如何联系?不知道吗?加qq群【895510560】即可!标题:六六分期
阅读:19155| 2023-10-27
今天小编告诉大家如何处理win10系统火狐flash插件总是崩溃的问题,可能很多用户都不知
阅读:9981| 2022-11-06
今天小编告诉大家如何对win10系统删除桌面回收站图标进行设置,可能很多用户都不知道
阅读:8320| 2022-11-06
今天小编告诉大家如何对win10系统电脑设置节能降温的设置方法,想必大家都遇到过需要
阅读:8690| 2022-11-06
我们在使用xp系统的过程中,经常需要对xp系统无线网络安装向导设置进行设置,可能很多
阅读:8632| 2022-11-06
今天小编告诉大家如何处理win7系统玩cf老是与主机连接不稳定的问题,可能很多用户都不
阅读:9649| 2022-11-06
电脑对日常生活的重要性小编就不多说了,可是一旦碰到win7系统设置cf烟雾头的问题,很
阅读:8615| 2022-11-06
我们在日常使用电脑的时候,有的小伙伴们可能在打开应用的时候会遇见提示应用程序无法
阅读:7994| 2022-11-06
今天小编告诉大家如何对win7系统打开vcf文件进行设置,可能很多用户都不知道怎么对win
阅读:8647| 2022-11-06
今天小编告诉大家如何对win10系统s4开启USB调试模式进行设置,可能很多用户都不知道怎
阅读:7530| 2022-11-06
请发表评论