本文整理汇总了C++中OGRGeometry::WkbSize方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRGeometry::WkbSize方法的具体用法?C++ OGRGeometry::WkbSize怎么用?C++ OGRGeometry::WkbSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRGeometry
的用法示例。
在下文中一共展示了OGRGeometry::WkbSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OGR2SQLITE_ST_AsBinary
static
void OGR2SQLITE_ST_AsBinary(sqlite3_context* pContext,
int argc, sqlite3_value** argv)
{
OGRGeometry* poGeom = OGR2SQLITE_GetGeom(pContext, argc, argv, NULL);
if( poGeom != NULL )
{
int nBLOBLen = poGeom->WkbSize();
GByte* pabyGeomBLOB = (GByte*) VSIMalloc(nBLOBLen);
if( pabyGeomBLOB != NULL )
{
if( poGeom->exportToWkb(wkbNDR, pabyGeomBLOB) == OGRERR_NONE )
sqlite3_result_blob( pContext, pabyGeomBLOB, nBLOBLen, CPLFree);
else
{
VSIFree(pabyGeomBLOB);
sqlite3_result_null (pContext);
}
}
else
sqlite3_result_null (pContext);
delete poGeom;
}
else
sqlite3_result_null (pContext);
}
示例2: importBodyFromWkb
OGRErr OGRCurveCollection::importBodyFromWkb( OGRGeometry* poGeom,
unsigned char * pabyData,
int nSize,
int nDataOffset,
int bAcceptCompoundCurve,
OGRErr (*pfnAddCurveDirectlyFromWkb)(OGRGeometry* poGeom, OGRCurve* poCurve),
OGRwkbVariant eWkbVariant )
{
/* -------------------------------------------------------------------- */
/* Get the Geoms. */
/* -------------------------------------------------------------------- */
int nIter = nCurveCount;
nCurveCount = 0;
for( int iGeom = 0; iGeom < nIter; iGeom++ )
{
OGRErr eErr;
OGRGeometry* poSubGeom = NULL;
/* Parses sub-geometry */
unsigned char* pabySubData = pabyData + nDataOffset;
if( nSize < 9 && nSize != -1 )
return OGRERR_NOT_ENOUGH_DATA;
OGRwkbGeometryType eSubGeomType;
OGRBoolean bIs3D;
if ( OGRReadWKBGeometryType( pabySubData, eWkbVariant, &eSubGeomType, &bIs3D ) != OGRERR_NONE )
return OGRERR_FAILURE;
if( (eSubGeomType != wkbCompoundCurve && OGR_GT_IsCurve(eSubGeomType)) ||
(bAcceptCompoundCurve && eSubGeomType == wkbCompoundCurve) )
{
eErr = OGRGeometryFactory::
createFromWkb( pabySubData, NULL,
&poSubGeom, nSize, eWkbVariant );
}
else
{
CPLDebug("OGR", "Cannot add geometry of type (%d) to geometry of type (%d)",
eSubGeomType, poGeom->getGeometryType());
return OGRERR_UNSUPPORTED_GEOMETRY_TYPE;
}
if( eErr == OGRERR_NONE )
eErr = pfnAddCurveDirectlyFromWkb(poGeom, (OGRCurve*)poSubGeom);
if( eErr != OGRERR_NONE )
{
delete poSubGeom;
return eErr;
}
int nSubGeomWkbSize = poSubGeom->WkbSize();
if( nSize != -1 )
nSize -= nSubGeomWkbSize;
nDataOffset += nSubGeomWkbSize;
}
return OGRERR_NONE;
}
示例3: CreateFeature
//.........这里部分代码省略.........
sqlite3_stmt *hInsertStmt;
#ifdef DEBUG
CPLDebug( "OGR_SQLITE", "prepare(%s)", osCommand.c_str() );
#endif
rc = sqlite3_prepare( hDB, osCommand, -1, &hInsertStmt, NULL );
if( rc != SQLITE_OK )
{
CPLError( CE_Failure, CPLE_AppDefined,
"In CreateFeature(): sqlite3_prepare(%s):\n %s",
osCommand.c_str(), sqlite3_errmsg(hDB) );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Bind the geometry */
/* -------------------------------------------------------------------- */
int nBindField = 1;
if( osGeomColumn.size() != 0 &&
poGeom != NULL &&
eGeomFormat != OSGF_FGF )
{
if ( eGeomFormat == OSGF_WKT )
{
char *pszWKT = NULL;
poGeom->exportToWkt( &pszWKT );
rc = sqlite3_bind_text( hInsertStmt, nBindField++, pszWKT, -1, CPLFree );
}
else if( eGeomFormat == OSGF_WKB )
{
int nWKBLen = poGeom->WkbSize();
GByte *pabyWKB = (GByte *) CPLMalloc(nWKBLen + 1);
poGeom->exportToWkb( wkbNDR, pabyWKB );
rc = sqlite3_bind_blob( hInsertStmt, nBindField++, pabyWKB, nWKBLen, CPLFree );
}
else if ( eGeomFormat == OSGF_SpatiaLite )
{
int nBLOBLen;
GByte *pabySLBLOB;
ExportSpatiaLiteGeometry( poGeom, nSRSId, wkbNDR, bHasM,
bSpatialite2D, &pabySLBLOB, &nBLOBLen );
rc = sqlite3_bind_blob( hInsertStmt, nBindField++, pabySLBLOB,
nBLOBLen, CPLFree );
}
else
{
CPLAssert(0);
}
if( rc != SQLITE_OK )
{
CPLError( CE_Failure, CPLE_AppDefined,
"sqlite3_bind_blob/text() failed:\n %s",
sqlite3_errmsg(hDB) );
sqlite3_finalize( hInsertStmt );
return OGRERR_FAILURE;
}
}
/* -------------------------------------------------------------------- */
示例4: insertLayer
bool QgsShapeFile::insertLayer(QString dbname, QString schema, QString geom_col, QString srid, PGconn * conn, QProgressDialog * pro, bool &fin){
connect(pro, SIGNAL(cancelled()), this, SLOT(cancelImport()));
import_cancelled = false;
bool result = true;
QString query = "CREATE TABLE "+schema+"."+table_name+"(gid int4 PRIMARY KEY, ";
for(int n=0; n<column_names.size() && result; n++){
if(!column_names[n][0].isLetter())
result = false;
char * esc_str = new char[column_names[n].length()*2+1];
PQescapeString(esc_str, (const char *)column_names[n].lower(), column_names[n].length());
query += esc_str;
query += " ";
query += column_types[n];
if(n<column_names.size()-1)
query += ", ";
delete[] esc_str;
}
query += " )";
PGresult *res = PQexec(conn, (const char *)query);
qWarning(query);
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
// flag error and send query and error message to stdout on debug
result = false;
qWarning(PQresultErrorMessage(res));
}
else {
PQclear(res);
}
query = "SELECT AddGeometryColumn(\'" + dbname + "\', \'" + table_name + "\', \'"+geom_col+"\', " + srid +
", \'" + geom_type + "\', 2)";
if(result) res = PQexec(conn, (const char *)query);
if(PQresultStatus(res)!=PGRES_TUPLES_OK){
result = false;
}
else{
qWarning(query);
qWarning(PQresultErrorMessage(res));
PQclear(res);
}
//adding the data into the table
for(int m=0;m<features && result; m++){
if(import_cancelled){
fin = true;
break;
}
OGRFeature *feat = ogrLayer->GetNextFeature();
if(feat){
OGRGeometry *geom = feat->GetGeometryRef();
if(geom){
query = "INSERT INTO "+schema+"."+table_name+QString(" VALUES( %1, ").arg(m);
int num = geom->WkbSize();
char * geo_temp = new char[num*3];
geom->exportToWkt(&geo_temp);
QString geometry(geo_temp);
QString quotes;
for(int n=0; n<column_types.size(); n++){
if(column_types[n] == "int" || column_types[n] == "float")
quotes = " ";
else
quotes = "\'";
query += quotes;
// escape the string value
QString val = feat->GetFieldAsString(n);
char * esc_str = new char[val.length()*2+1];
PQescapeString(esc_str, (const char *)val.lower(), val.length());
// add escaped value to the query
query += esc_str;
query += QString(quotes + ", ");
delete[] esc_str;
}
query += QString("GeometryFromText(\'")+geometry+QString("\', ")+srid+QString("))");
if(result)
res = PQexec(conn, (const char *)query);
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
// flag error and send query and error message to stdout on debug
result = false;
qWarning(PQresultErrorMessage(res));
}
else {
PQclear(res);
}
pro->setProgress(pro->progress()+1);
qApp->processEvents();
delete[] geo_temp;
}
delete feat;
}
}
//.........这里部分代码省略.........