本文整理汇总了C++中OGRFieldDefn::SetType方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFieldDefn::SetType方法的具体用法?C++ OGRFieldDefn::SetType怎么用?C++ OGRFieldDefn::SetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFieldDefn
的用法示例。
在下文中一共展示了OGRFieldDefn::SetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: oOGRFieldDefn
OGRFeatureDefn * cvct2gdal::CVCT2GDALFeatureDefn ( VCTFeatureDefn * poVCTFeatDefn )
{
OGRFeatureDefn * poOGRFeatDefn = new OGRFeatureDefn();
for ( auto iVCTFieldDefn = poVCTFeatDefn->fielddefnlist.begin();
iVCTFieldDefn != poVCTFeatDefn->fielddefnlist.end(); ++iVCTFieldDefn )
{
OGRFieldDefn oOGRFieldDefn ( "", OFTInteger );
oOGRFieldDefn.SetName ( iVCTFieldDefn->name.c_str() );
oOGRFieldDefn.SetWidth ( iVCTFieldDefn->width );
oOGRFieldDefn.SetPrecision ( iVCTFieldDefn->precision );
oOGRFieldDefn.SetType ( CVCT2GDALFieldType ( iVCTFieldDefn->type ) );
poOGRFeatDefn->AddFieldDefn ( &oOGRFieldDefn );
}
return poOGRFeatDefn;
}
示例2:
OGRErr OGRLayerWithTransaction::AlterFieldDefn( int iField,
OGRFieldDefn* poNewFieldDefn,
int nFlags )
{
if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
OGRErr eErr = m_poDecoratedLayer->AlterFieldDefn(iField, poNewFieldDefn, nFlags);
if( m_poFeatureDefn && eErr == OGRERR_NONE )
{
OGRFieldDefn* poSrcFieldDefn = m_poDecoratedLayer->GetLayerDefn()->GetFieldDefn(iField);
OGRFieldDefn* poDstFieldDefn = m_poFeatureDefn->GetFieldDefn(iField);
poDstFieldDefn->SetName(poSrcFieldDefn->GetNameRef());
poDstFieldDefn->SetType(poSrcFieldDefn->GetType());
poDstFieldDefn->SetSubType(poSrcFieldDefn->GetSubType());
poDstFieldDefn->SetWidth(poSrcFieldDefn->GetWidth());
poDstFieldDefn->SetPrecision(poSrcFieldDefn->GetPrecision());
poDstFieldDefn->SetDefault(poSrcFieldDefn->GetDefault());
poDstFieldDefn->SetNullable(poSrcFieldDefn->IsNullable());
}
return eErr;
}
示例3: AlterFieldDefn
//.........这里部分代码省略.........
/* Update all the internal features. Hopefully there aren't any */
/* external features referring to our OGRFeatureDefn! */
/* -------------------------------------------------------------------- */
for( GIntBig i = 0; i < nMaxFeatureCount; i++ )
{
if( papoFeatures[i] == NULL )
continue;
OGRField* poFieldRaw = papoFeatures[i]->GetRawFieldRef(iField);
if( papoFeatures[i]->IsFieldSet(iField) )
{
poFieldRaw->Integer64 = poFieldRaw->Integer;
}
}
}
else if (poNewFieldDefn->GetType() == OFTReal &&
poFieldDefn->GetType() == OFTInteger)
{
/* -------------------------------------------------------------------- */
/* Update all the internal features. Hopefully there aren't any */
/* external features referring to our OGRFeatureDefn! */
/* -------------------------------------------------------------------- */
for( GIntBig i = 0; i < nMaxFeatureCount; i++ )
{
if( papoFeatures[i] == NULL )
continue;
OGRField* poFieldRaw = papoFeatures[i]->GetRawFieldRef(iField);
if( papoFeatures[i]->IsFieldSet(iField) )
{
poFieldRaw->Real = poFieldRaw->Integer;
}
}
}
else if (poNewFieldDefn->GetType() == OFTReal &&
poFieldDefn->GetType() == OFTInteger64)
{
/* -------------------------------------------------------------------- */
/* Update all the internal features. Hopefully there aren't any */
/* external features referring to our OGRFeatureDefn! */
/* -------------------------------------------------------------------- */
for( GIntBig i = 0; i < nMaxFeatureCount; i++ )
{
if( papoFeatures[i] == NULL )
continue;
OGRField* poFieldRaw = papoFeatures[i]->GetRawFieldRef(iField);
if( papoFeatures[i]->IsFieldSet(iField) )
{
poFieldRaw->Real = (double) poFieldRaw->Integer64;
}
}
}
else
{
if (poNewFieldDefn->GetType() != OFTString)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Can only convert from OFTInteger to OFTReal, or from anything to OFTString");
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Update all the internal features. Hopefully there aren't any */
/* external features referring to our OGRFeatureDefn! */
/* -------------------------------------------------------------------- */
for( GIntBig i = 0; i < nMaxFeatureCount; i++ )
{
if( papoFeatures[i] == NULL )
continue;
OGRField* poFieldRaw = papoFeatures[i]->GetRawFieldRef(iField);
if( papoFeatures[i]->IsFieldSet(iField) )
{
char* pszVal = CPLStrdup(papoFeatures[i]->GetFieldAsString(iField));
/* Little trick to unallocate the field */
OGRField sField;
sField.Set.nMarker1 = OGRUnsetMarker;
sField.Set.nMarker2 = OGRUnsetMarker;
papoFeatures[i]->SetField(iField, &sField);
poFieldRaw->String = pszVal;
}
}
}
poFieldDefn->SetType(poNewFieldDefn->GetType());
}
if (nFlags & ALTER_NAME_FLAG)
poFieldDefn->SetName(poNewFieldDefn->GetNameRef());
if (nFlags & ALTER_WIDTH_PRECISION_FLAG)
{
poFieldDefn->SetWidth(poNewFieldDefn->GetWidth());
poFieldDefn->SetPrecision(poNewFieldDefn->GetPrecision());
}
return OGRERR_NONE;
}
示例4: GenerateFeatureDefn
bool OGRGeoJSONReader::GenerateFeatureDefn( json_object* poObj )
{
OGRFeatureDefn* poDefn = poLayer_->GetLayerDefn();
CPLAssert( NULL != poDefn );
bool bSuccess = false;
/* -------------------------------------------------------------------- */
/* Read collection of properties. */
/* -------------------------------------------------------------------- */
json_object* poObjProps = NULL;
poObjProps = OGRGeoJSONFindMemberByName( poObj, "properties" );
if( NULL != poObjProps &&
json_object_get_type(poObjProps) == json_type_object )
{
if (bIsGeocouchSpatiallistFormat)
{
poObjProps = json_object_object_get(poObjProps, "properties");
if( NULL == poObjProps ||
json_object_get_type(poObjProps) != json_type_object )
{
return true;
}
}
json_object_iter it;
it.key = NULL;
it.val = NULL;
it.entry = NULL;
json_object_object_foreachC( poObjProps, it )
{
int nFldIndex = poDefn->GetFieldIndex( it.key );
if( -1 == nFldIndex )
{
/* Detect the special kind of GeoJSON output by a spatiallist of GeoCouch */
/* such as http://gd.iriscouch.com/cphosm/_design/geo/_rewrite/data?bbox=12.53%2C55.73%2C12.54%2C55.73 */
if (strcmp(it.key, "_id") == 0)
bFoundId = true;
else if (bFoundId && strcmp(it.key, "_rev") == 0)
bFoundRev = true;
else if (bFoundRev && strcmp(it.key, "type") == 0 &&
it.val != NULL && json_object_get_type(it.val) == json_type_string &&
strcmp(json_object_get_string(it.val), "Feature") == 0)
bFoundTypeFeature = true;
else if (bFoundTypeFeature && strcmp(it.key, "properties") == 0 &&
it.val != NULL && json_object_get_type(it.val) == json_type_object)
{
if (bFlattenGeocouchSpatiallistFormat < 0)
bFlattenGeocouchSpatiallistFormat = CSLTestBoolean(
CPLGetConfigOption("GEOJSON_FLATTEN_GEOCOUCH", "TRUE"));
if (bFlattenGeocouchSpatiallistFormat)
{
poDefn->DeleteFieldDefn(poDefn->GetFieldIndex("type"));
bIsGeocouchSpatiallistFormat = true;
return GenerateFeatureDefn(poObj);
}
}
OGRFieldDefn fldDefn( it.key,
GeoJSONPropertyToFieldType( it.val ) );
poDefn->AddFieldDefn( &fldDefn );
}
else
{
OGRFieldDefn* poFDefn = poDefn->GetFieldDefn(nFldIndex);
OGRFieldType eType = poFDefn->GetType();
if( eType == OFTInteger )
{
OGRFieldType eNewType = GeoJSONPropertyToFieldType( it.val );
if( eNewType == OFTReal )
poFDefn->SetType(eNewType);
}
}
}
bSuccess = true; // SUCCESS
}