本文整理汇总了C++中OGRFeature::SetFieldNull方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeature::SetFieldNull方法的具体用法?C++ OGRFeature::SetFieldNull怎么用?C++ OGRFeature::SetFieldNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFeature
的用法示例。
在下文中一共展示了OGRFeature::SetFieldNull方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
OGRFeature *OGRDB2Layer::GetNextRawFeature()
{
if( GetStatement() == nullptr )
return nullptr;
/* -------------------------------------------------------------------- */
/* If we are marked to restart then do so, and fetch a record. */
/* -------------------------------------------------------------------- */
if( !m_poStmt->Fetch() ) // fail is normal for final fetch
{
// CPLDebug("OGR_DB2Layer::GetNextRawFeature","Fetch failed");
delete m_poStmt;
m_poStmt = nullptr;
return nullptr;
}
// CPLDebug("OGR_DB2Layer::GetNextRawFeature","Create feature");
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
int iField;
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
if( pszFIDColumn != nullptr && m_poStmt->GetColId(pszFIDColumn) > -1 )
poFeature->SetFID(
atoi(m_poStmt->GetColData(m_poStmt->GetColId(pszFIDColumn))) );
else
poFeature->SetFID( iNextShapeId );
iNextShapeId++;
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Set the fields. */
/* -------------------------------------------------------------------- */
for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
if ( poFeatureDefn->GetFieldDefn(iField)->IsIgnored() )
continue;
int iSrcField = panFieldOrdinals[iField];
const char *pszValue = m_poStmt->GetColData( iSrcField );
if( pszValue == nullptr )
poFeature->SetFieldNull( iField );
else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
poFeature->SetField( iField,
m_poStmt->GetColDataLength(iSrcField),
(GByte *) pszValue );
else
poFeature->SetField( iField, pszValue );
}
/* -------------------------------------------------------------------- */
/* Try to extract a geometry. */
/* -------------------------------------------------------------------- */
if( pszGeomColumn != nullptr && !poFeatureDefn->IsGeometryIgnored())
{
iField = m_poStmt->GetColId( pszGeomColumn );
const char *pszGeomText = m_poStmt->GetColData( iField );
OGRGeometry *poGeom = nullptr;
OGRErr eErr = OGRERR_NONE;
if( pszGeomText != nullptr )
{
eErr = OGRGeometryFactory::createFromWkt(pszGeomText,
nullptr, &poGeom);
}
if ( eErr != OGRERR_NONE )
{
const char *pszMessage;
switch ( eErr )
{
case OGRERR_NOT_ENOUGH_DATA:
pszMessage = "Not enough data to deserialize";
break;
case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
pszMessage = "Unsupported geometry type";
break;
case OGRERR_CORRUPT_DATA:
pszMessage = "Corrupt data";
break;
default:
pszMessage = "Unrecognized error";
}
CPLError(CE_Failure, CPLE_AppDefined,
"GetNextRawFeature(): %s", pszMessage);
}
if( poGeom != nullptr )
{
if ( GetSpatialRef() )
poGeom->assignSpatialReference( poSRS );
poFeature->SetGeometryDirectly( poGeom );
}
}
//.........这里部分代码省略.........
示例2: if
OGRFeature *OGRMSSQLSpatialLayer::GetNextRawFeature()
{
if( GetStatement() == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* If we are marked to restart then do so, and fetch a record. */
/* -------------------------------------------------------------------- */
if( !poStmt->Fetch() )
{
delete poStmt;
poStmt = NULL;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
const char* pszFID;
if( pszFIDColumn != NULL && poStmt->GetColId(pszFIDColumn) > -1 &&
(pszFID = poStmt->GetColData(poStmt->GetColId(pszFIDColumn))) != NULL )
poFeature->SetFID( CPLAtoGIntBig(pszFID) );
else
poFeature->SetFID( iNextShapeId );
iNextShapeId++;
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Set the fields. */
/* -------------------------------------------------------------------- */
for( int iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
if ( poFeatureDefn->GetFieldDefn(iField)->IsIgnored() )
continue;
int iSrcField = panFieldOrdinals[iField];
const char *pszValue = poStmt->GetColData( iSrcField );
if( pszValue == NULL )
poFeature->SetFieldNull( iField );
else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
poFeature->SetField( iField,
poStmt->GetColDataLength(iSrcField),
(GByte *) pszValue );
else
poFeature->SetField( iField, pszValue );
}
/* -------------------------------------------------------------------- */
/* Try to extract a geometry. */
/* -------------------------------------------------------------------- */
if( pszGeomColumn != NULL && !poFeatureDefn->IsGeometryIgnored())
{
int iField = poStmt->GetColId( pszGeomColumn );
const char *pszGeomText = poStmt->GetColData( iField );
OGRGeometry *poGeom = NULL;
OGRErr eErr = OGRERR_NONE;
if( pszGeomText != NULL )
{
int nLength = poStmt->GetColDataLength( iField );
if ( nGeomColumnType == MSSQLCOLTYPE_GEOMETRY ||
nGeomColumnType == MSSQLCOLTYPE_GEOGRAPHY ||
nGeomColumnType == MSSQLCOLTYPE_BINARY)
{
switch ( poDS->GetGeometryFormat() )
{
case MSSQLGEOMETRY_NATIVE:
{
OGRMSSQLGeometryParser oParser( nGeomColumnType );
eErr = oParser.ParseSqlGeometry(
(unsigned char *) pszGeomText, nLength, &poGeom );
nSRSId = oParser.GetSRSId();
}
break;
case MSSQLGEOMETRY_WKB:
case MSSQLGEOMETRY_WKBZM:
eErr = OGRGeometryFactory::createFromWkb((unsigned char *) pszGeomText,
NULL, &poGeom, nLength);
break;
case MSSQLGEOMETRY_WKT:
eErr = OGRGeometryFactory::createFromWkt((char **) &pszGeomText,
NULL, &poGeom);
break;
}
}
else if (nGeomColumnType == MSSQLCOLTYPE_TEXT)
{
eErr = OGRGeometryFactory::createFromWkt((char **) &pszGeomText,
NULL, &poGeom);
}
}
if ( eErr != OGRERR_NONE )
{
//.........这里部分代码省略.........
示例3: OGRFeature
OGRFeature *OGRMySQLLayer::RecordToFeature( char **papszRow,
unsigned long *panLengths )
{
mysql_field_seek( hResultSet, 0 );
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
poFeature->SetFID( iNextShapeId );
m_nFeaturesRead++;
/* ==================================================================== */
/* Transfer all result fields we can. */
/* ==================================================================== */
for( int iField = 0;
iField < (int) mysql_num_fields(hResultSet);
iField++ )
{
MYSQL_FIELD *psMSField = mysql_fetch_field(hResultSet);
/* -------------------------------------------------------------------- */
/* Handle FID. */
/* -------------------------------------------------------------------- */
if( bHasFid && EQUAL(psMSField->name,pszFIDColumn) )
{
if( papszRow[iField] == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
"NULL primary key in RecordToFeature()" );
return NULL;
}
poFeature->SetFID( CPLAtoGIntBig(papszRow[iField]) );
}
if( papszRow[iField] == NULL )
{
const int iOGRField = poFeatureDefn->GetFieldIndex(psMSField->name);
if( iOGRField >= 0 )
poFeature->SetFieldNull( iOGRField );
continue;
}
/* -------------------------------------------------------------------- */
/* Handle MySQL geometry */
/* -------------------------------------------------------------------- */
if( pszGeomColumn && EQUAL(psMSField->name,pszGeomColumn))
{
OGRGeometry *poGeometry = NULL;
// Geometry columns will have the first 4 bytes contain the SRID.
OGRGeometryFactory::createFromWkb(
((GByte *)papszRow[iField]) + 4,
NULL,
&poGeometry,
static_cast<int>(panLengths[iField] - 4) );
if( poGeometry != NULL )
{
poGeometry->assignSpatialReference( GetSpatialRef() );
poFeature->SetGeometryDirectly( poGeometry );
}
continue;
}
/* -------------------------------------------------------------------- */
/* Transfer regular data fields. */
/* -------------------------------------------------------------------- */
const int iOGRField = poFeatureDefn->GetFieldIndex(psMSField->name);
if( iOGRField < 0 )
continue;
OGRFieldDefn *psFieldDefn = poFeatureDefn->GetFieldDefn( iOGRField );
if( psFieldDefn->GetType() == OFTBinary )
{
poFeature->SetField( iOGRField, static_cast<int>(panLengths[iField]),
(GByte *) papszRow[iField] );
}
else
{
poFeature->SetField( iOGRField, papszRow[iField] );
}
}
return poFeature;
}
示例4: if
OGRFeature *OGRWalkLayer::GetNextRawFeature()
{
if( GetStatement() == nullptr )
return nullptr;
/* -------------------------------------------------------------------- */
/* If we are marked to restart then do so, and fetch a record. */
/* -------------------------------------------------------------------- */
if( !poStmt->Fetch() )
{
delete poStmt;
poStmt = nullptr;
return nullptr;
}
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
if( pszFIDColumn != nullptr && poStmt->GetColId(pszFIDColumn) > -1 )
poFeature->SetFID(
atoi(poStmt->GetColData(poStmt->GetColId(pszFIDColumn))) );
else
poFeature->SetFID( iNextShapeId );
iNextShapeId++;
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Set the fields. */
/* -------------------------------------------------------------------- */
for( int iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
int iSrcField = panFieldOrdinals[iField]-1;
const char *pszValue = poStmt->GetColData( iSrcField );
if( pszValue == nullptr )
poFeature->SetFieldNull( iField );
else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
poFeature->SetField( iField,
poStmt->GetColDataLength(iSrcField),
(GByte *) pszValue );
else
poFeature->SetField( iField, pszValue );
}
/* -------------------------------------------------------------------- */
/* Try to extract a geometry. */
/* -------------------------------------------------------------------- */
if( pszGeomColumn != nullptr )
{
int iField = poStmt->GetColId( pszGeomColumn );
const char *pszGeomBin = poStmt->GetColData( iField );
int nGeomLength = poStmt->GetColDataLength( iField );
OGRGeometry *poGeom = nullptr;
OGRErr eErr = OGRERR_NONE;
if( pszGeomBin != nullptr && bGeomColumnWKB )
{
WKBGeometry *WalkGeom = (WKBGeometry *)CPLMalloc(sizeof(WKBGeometry));
if( Binary2WkbGeom((unsigned char *)pszGeomBin, WalkGeom, nGeomLength)
!= OGRERR_NONE )
{
CPLFree(WalkGeom);
return nullptr;
}
eErr = TranslateWalkGeom(&poGeom, WalkGeom);
DeleteWKBGeometry(*WalkGeom);
CPLFree(WalkGeom);
}
if ( eErr != OGRERR_NONE )
{
const char *pszMessage = nullptr;
switch ( eErr )
{
case OGRERR_NOT_ENOUGH_DATA:
pszMessage = "Not enough data to deserialize";
break;
case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
pszMessage = "Unsupported geometry type";
break;
case OGRERR_CORRUPT_DATA:
pszMessage = "Corrupt data";
break;
default:
pszMessage = "Unrecognized error";
}
CPLError(CE_Failure, CPLE_AppDefined,
"GetNextRawFeature(): %s", pszMessage);
}
if( poGeom != nullptr && eErr == OGRERR_NONE )
{
poGeom->assignSpatialReference( poSRS );
poFeature->SetGeometryDirectly( poGeom );
//.........这里部分代码省略.........