当前位置: 首页>>代码示例>>C++>>正文


C++ OGRFieldDefn类代码示例

本文整理汇总了C++中OGRFieldDefn的典型用法代码示例。如果您正苦于以下问题:C++ OGRFieldDefn类的具体用法?C++ OGRFieldDefn怎么用?C++ OGRFieldDefn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OGRFieldDefn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Get_Layer

//---------------------------------------------------------
CSG_Shapes * COGR_DataSource::Read_Shapes(int iLayer)
{
	OGRLayer	*pLayer	= Get_Layer(iLayer);

	//-----------------------------------------------------
	if( pLayer && Get_Type(iLayer) != SHAPE_TYPE_Undefined )
	{
		int				iField;
		OGRFeature		*pFeature;
		OGRFeatureDefn	*pDef		= pLayer->GetLayerDefn();
		CSG_Shapes		*pShapes	= SG_Create_Shapes(Get_Type(iLayer), CSG_String(pDef->GetName()));

		for(iField=0; iField<pDef->GetFieldCount(); iField++)
		{
			OGRFieldDefn	*pDefField	= pDef->GetFieldDefn(iField);

			pShapes->Add_Field(pDefField->GetNameRef(), COGR_Driver::Get_Type(pDefField->GetType()));
		}

		pLayer->ResetReading();

		//-------------------------------------------------
		while( (pFeature = pLayer->GetNextFeature()) != NULL && SG_UI_Process_Get_Okay(false) )
		{
			OGRGeometry	*pGeometry	= pFeature->GetGeometryRef();

			if( pGeometry != NULL )
			{
				CSG_Shape	*pShape	= pShapes->Add_Shape();

				for(iField=0; iField<pDef->GetFieldCount(); iField++)
				{
					OGRFieldDefn	*pDefField	= pDef->GetFieldDefn(iField);

					switch( pDefField->GetType() )
					{
					default:			pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField)));	break;
					case OFTString:		pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField)));	break;
					case OFTInteger:	pShape->Set_Value(iField, pFeature->GetFieldAsInteger(iField));	break;
					case OFTReal:		pShape->Set_Value(iField, pFeature->GetFieldAsDouble (iField));	break;
					}
				}

				//-----------------------------------------
				if( _Read_Geometry(pShape, pGeometry) == false )
				{
					pShapes->Del_Shape(pShape);
				}
			}

			OGRFeature::DestroyFeature(pFeature);
		}

		return( pShapes );
	}

	//-----------------------------------------------------
	return( NULL );
}
开发者ID:am2222,项目名称:SAGA-GIS,代码行数:60,代码来源:ogr_driver.cpp

示例2: EQUAL

OGRErr OGRILI2Layer::ICreateFeature( OGRFeature *poFeature ) {
    char szTempBuffer[80];
    const char* tid;
    int iField = 0;
    if( poFeatureDefn->GetFieldCount() &&
        EQUAL(poFeatureDefn->GetFieldDefn(iField)->GetNameRef(), "TID") )
    {
        tid = poFeature->GetFieldAsString(0);
        ++iField;
    }
    else
    {
        snprintf( szTempBuffer, sizeof(szTempBuffer), CPL_FRMT_GIB,
                  poFeature->GetFID() );
        tid = szTempBuffer;
    }

    VSILFILE* fp = poDS->GetOutputFP();
    if (fp == NULL)
        return OGRERR_FAILURE;

    VSIFPrintfL(fp, "<%s TID=\"%s\">\n", poFeatureDefn->GetName(), tid);

    // Write out Geometries
    for( int iGeomField = 0;
         iGeomField < poFeatureDefn->GetGeomFieldCount();
         iGeomField++ )
    {
        OGRGeomFieldDefn *poFieldDefn
            = poFeatureDefn->GetGeomFieldDefn(iGeomField);
        OGRGeometry* poGeom = poFeature->GetGeomFieldRef(iGeomField);
        if( poGeom != NULL )
        {
            CPLString iliGeomType = GetIliGeomType(poFieldDefn->GetNameRef());
            OGR2ILIGeometryAppend( poGeom, fp, poFieldDefn->GetNameRef(),
                                   iliGeomType );
        }
    }

    // Write all "set" fields.
    for( ; iField < poFeatureDefn->GetFieldCount(); iField++ )
    {

        OGRFieldDefn *poField = poFeatureDefn->GetFieldDefn( iField );

        if( poFeature->IsFieldSet( iField ) )
        {
            const char *pszRaw = poFeature->GetFieldAsString( iField );
            VSIFPrintfL(fp, "<%s>%s</%s>\n", poField->GetNameRef(), pszRaw, poField->GetNameRef());
        }
    }

    VSIFPrintfL(fp, "</%s>\n", poFeatureDefn->GetName());

    return OGRERR_NONE;
}
开发者ID:Wedjaa,项目名称:node-gdal,代码行数:56,代码来源:ogrili2layer.cpp

示例3: wgMB2WX

wxString wxGISTable::GetColLabelValue(int col)
{
    wxString label;
    OGRFieldDefn* pOGRFieldDefn = m_pOGRFeatureDefn->GetFieldDefn(col);
    label = wgMB2WX(pOGRFieldDefn->GetNameRef());
    if(!m_sFIDKeyName.IsEmpty())
    {
        if(label == m_sFIDKeyName);
        label += _(" [*]");
    }
    return label;
}
开发者ID:jacklibj,项目名称:r5,代码行数:12,代码来源:tableview.cpp

示例4: main

int main() {
    // Read in raster data for night time lights
    int band_number = 1; // only one band, starts with one
    Raster* raster = import_raster("raster.tif", band_number);

    // Read in shapefile data containing municipality administrative regions
    int layer_number = 0; // only one layer, starts with zero
    OGRLayer* shapelayer = import_shapefile("MEX_adm2.shp", layer_number);

    shapelayer->SetAttributeFilter("ID_1 = 1834");       // Filter for Yucatan
    const int idx_of_number_field = 5;             // Column number of municipality number
    const int idx_of_name_field = 6;               // Column number of municipality name

    OGRFeature* poFeature;
    int feature_ctr = 0;
    while( (poFeature = shapelayer->GetNextFeature()) != NULL ) {
        cerr << "Feature: " << feature_ctr++ << "\t";
        int feature_num = poFeature->GetFieldAsInteger(idx_of_number_field);
        string feature_name = poFeature->GetFieldAsString(idx_of_name_field);

        OGRFeatureDefn *poFDefn = shapelayer->GetLayerDefn();
        for( int iField = 0; iField < poFDefn->GetFieldCount(); iField++ ) {
            OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );
            if( poFieldDefn->GetType() == OFTString )  cerr << poFeature->GetFieldAsString(iField) << ",";
        }

        OGRGeometry* poGeometry = poFeature->GetGeometryRef();
        if( poGeometry != NULL) {
            // For contiguous regions
            if ( wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon ) {
                cerr << " polygon" << endl;
                report_raster_data_within_polygon(raster, (OGRPolygon *) poGeometry, feature_num, feature_name);
            // For disjoint regions
            } else if ( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon ) {
                cerr << " multipolygon" << endl;
                OGRMultiPolygon *multipolygon = (OGRMultiPolygon *) poGeometry;
                for (int i = 0; i<multipolygon->getNumGeometries(); i++) {
                    report_raster_data_within_polygon(raster, (OGRPolygon*) multipolygon->getGeometryRef(i), feature_num, feature_name);
                }
            // Is this really the right shapefile?
            } else {
                cerr << "No polygon or multipolygon geometry for this feature: " << poGeometry->getGeometryName() << endl;
            }
        } else {
            cerr << "No geometry for this feature" << endl;
        }
    }
    OGRFeature::DestroyFeature( poFeature );
}
开发者ID:PulliamLab-UFL,项目名称:dengue,代码行数:49,代码来源:clip_raster_by_region.cpp

示例5: OGRGMEAttributesToGeoJSON

json_object* OGRGMEAttributesToGeoJSON( OGRFeature* poFeature )
{
    if ( NULL == poFeature )
        return NULL;
    json_object* pjoProperties = json_object_new_object();
    CPLAssert( NULL != pjoProperties );

    OGRFeatureDefn* poDefn = poFeature->GetDefnRef();
    for( int nField = 0; nField < poDefn->GetFieldCount(); ++nField ) {
        json_object* pjoProperty = NULL;
        OGRFieldDefn* poFieldDefn = poDefn->GetFieldDefn( nField );
        if ( NULL == poFieldDefn )
            continue;
        OGRFieldType eType = poFieldDefn->GetType();

        if( !poFeature->IsFieldSet(nField) )
            pjoProperty = NULL;

        // In GME integers are encoded as strings.
        else if( OFTInteger == eType )
            pjoProperty = json_object_new_string( poFeature->GetFieldAsString( nField ) );

        else if( OFTReal == eType )
            pjoProperty = json_object_new_gme_double( poFeature->GetFieldAsDouble(nField) );

        // Supported types are integer, double and string. So treating everything else as strings
        else
            pjoProperty = json_object_new_string( poFeature->GetFieldAsString(nField) );

        json_object_object_add( pjoProperties, poFieldDefn->GetNameRef(), pjoProperty );
    }
    int nGxId = poFeature->GetFieldIndex("gx_id");
    if (nGxId < 0) {
        json_object* pjoProperty = NULL;
        GIntBig nFID = poFeature->GetFID();

        char acGxId[128];
        snprintf(acGxId, 128, "GDAL-" CPL_FRMT_GIB, nFID);
        CPLDebug("GME", "gx_id is not set, so adding \"gx_id\": \"%s\" field.",
                 acGxId);

        pjoProperty = json_object_new_string( acGxId );
        json_object_object_add( pjoProperties, "gx_id", pjoProperty);
    }

    return pjoProperties;
}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:47,代码来源:ogrgmejson.cpp

示例6: wxString

wxString wxGISGridTable::GetColLabelValue(int col)
{
    wxString label;
    OGRFeatureDefn* pOGRFeatureDefn = m_pGISDataset->GetDefinition();
    if(!pOGRFeatureDefn)
        return wxEmptyString;

	OGRFieldDefn* pOGRFieldDefn = pOGRFeatureDefn->GetFieldDefn(col);
	if(pOGRFieldDefn)
		label = wxString(pOGRFieldDefn->GetNameRef(), wxConvUTF8);

    if(label.IsSameAs(m_pGISDataset->GetFIDColumn(), false))
    {
        label.Append(_(" [*]"));
	}
    return label;
}
开发者ID:Mileslee,项目名称:wxgis,代码行数:17,代码来源:tableview.cpp

示例7: OGRFeatureDefn

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;
}
开发者ID:htoooth,项目名称:CNSDTFL,代码行数:17,代码来源:fmts.cvct2gdal.cpp

示例8: Convert2OGR

bool TeOGRDriver::createAttributeTable(TeTable &table)
{
	if(ogrLayer_ == 0)
		return false;

	TeAttributeList::iterator it;
	TeAttributeList list = table.attributeList();
	for(it = list.begin(); it != list.end(); ++it)
	{
		OGRFieldDefn oField = Convert2OGR(*it);
		
		if((*it).rep_.type_ == TeSTRING)
			oField.SetWidth((*it).rep_.numChar_);
		
		if(ogrLayer_->CreateField(&oField) != OGRERR_NONE)
			return false;
	}
	return true;
}
开发者ID:Universefei,项目名称:Terralib-analysis,代码行数:19,代码来源:TeOGRDriver.cpp

示例9: while

QDebug operator<<(QDebug dbg, OGRLayer* layer)
{
    layer->ResetReading();
    OGRFeatureDefn* def = layer->GetLayerDefn();
    FeaturePtr feat;
    while ((feat = FeaturePtr(layer->GetNextFeature())) != nullptr)
    {
        for (int i = 0; i < def->GetFieldCount(); ++i)
        {
            OGRFieldDefn* fdef = def->GetFieldDefn(i);
            switch (fdef->GetType())
            {
            case OFTInteger:
                dbg << fdef->GetNameRef() << feat->GetFieldAsInteger(i);
                break;
            case OFTReal:
                dbg << fdef->GetNameRef() << feat->GetFieldAsDouble(i);
                break;
            case OFTString:
                dbg << fdef->GetNameRef() << feat->GetFieldAsString(i);
                break;
            default:
                dbg << "Unknown type:" << fdef->GetType();
            }
        }
        dbg << "-----";
    }

    return dbg;
}
开发者ID:lesserwhirls,项目名称:Wave,代码行数:30,代码来源:ogrtools.cpp

示例10: wxString

wxString wxGISFeatureDataset::GetAsString(int row, int col)
{
	if(m_poLayer->GetFeatureCount() <= row) 
		return wxString(); 
	else 
	{
		OGRFeature* pFeature = GetAt(row);
		OGRFieldDefn* pDef = pFeature->GetFieldDefnRef(col);
		switch(pDef->GetType())
		{
		case OFTDate:
			{
				int year, mon, day, hour, min, sec, flag;
				pFeature->GetFieldAsDateTime(col, &year, &mon, &day, &hour, &min, &sec, &flag);
				wxDateTime dt(day, wxDateTime::Month(mon - 1), year, hour, min, sec);
				return dt.Format(_("%d-%m-%Y"));//wxString::Format(_("%.2u-%.2u-%.4u"), day, mon, year );
			}
		case OFTTime:
			{
				int year, mon, day, hour, min, sec, flag;
				pFeature->GetFieldAsDateTime(col, &year, &mon, &day, &hour, &min, &sec, &flag);
				wxDateTime dt(day, wxDateTime::Month(mon - 1), year, hour, min, sec);
				return dt.Format(_("%H:%M:%S"));//wxString::Format(_("%.2u:%.2u:%.2u"), hour, min, sec);
			}
		case OFTDateTime:
			{
				int year, mon, day, hour, min, sec, flag;
				pFeature->GetFieldAsDateTime(col, &year, &mon, &day, &hour, &min, &sec, &flag);
				wxDateTime dt(day, wxDateTime::Month(mon - 1), year, hour, min, sec);
				return dt.Format(_("%d-%m-%Y %H:%M:%S"));//wxString::Format(_("%.2u-%.2u-%.4u %.2u:%.2u:%.2u"), day, mon, year, hour, min, sec);
			}
		case OFTReal:				
			return wxString::Format(_("%.6f"), pFeature->GetFieldAsDouble(col));
		default:
			return wgMB2WX(pFeature->GetFieldAsString(col));
		}
		//return wgMB2WX(GetAt(row)->GetFieldAsString(col));
	}
}
开发者ID:jacklibj,项目名称:r5,代码行数:39,代码来源:featuredataset.cpp

示例11: WriteFeatureAttributes

void OGRBNALayer::WriteFeatureAttributes(VSILFILE* fp, OGRFeature *poFeature )
{
    int i;
    OGRFieldDefn *poFieldDefn;
    int nbOutID = poDS->GetNbOutId();
    if (nbOutID < 0)
        nbOutID = poFeatureDefn->GetFieldCount();
    for(i=0;i<nbOutID;i++)
    { 
        if (i < poFeatureDefn->GetFieldCount())
        {
            poFieldDefn = poFeatureDefn->GetFieldDefn( i );
            if( poFeature->IsFieldSet( i ) )
            {
                if (poFieldDefn->GetType() == OFTReal)
                {
                    char szBuffer[64];
                    OGRFormatDouble(szBuffer, sizeof(szBuffer),
                                    poFeature->GetFieldAsDouble(i), '.');
                    VSIFPrintfL( fp, "\"%s\",", szBuffer);
                }
                else
                {
                    const char *pszRaw = poFeature->GetFieldAsString( i );
                    VSIFPrintfL( fp, "\"%s\",", pszRaw);
                }
            }
            else
            {
                VSIFPrintfL( fp, "\"\",");
            }
        }
        else
        {
            VSIFPrintfL( fp, "\"\",");
        }
    }
}
开发者ID:Mofangbao,项目名称:node-gdal,代码行数:38,代码来源:ogrbnalayer.cpp

示例12: UNREFERENCED_PARAM

OGRErr OGRGeoJSONWriteLayer::CreateField(OGRFieldDefn* poField, int bApproxOK)
{
    UNREFERENCED_PARAM(bApproxOK);

    for( int i = 0; i < poFeatureDefn_->GetFieldCount(); ++i )
    {
        OGRFieldDefn* poDefn = poFeatureDefn_->GetFieldDefn(i);
        CPLAssert( NULL != poDefn );

        if( EQUAL( poDefn->GetNameRef(), poField->GetNameRef() ) )
        {
            CPLDebug( "GeoJSON", "Field '%s' already present in schema",
                      poField->GetNameRef() );
            
            // TODO - mloskot: Is this return code correct?
            return OGRERR_NONE;
        }
    }

    poFeatureDefn_->AddFieldDefn( poField );

    return OGRERR_NONE;
}
开发者ID:MattLatt,项目名称:GDAL_2.0.x_VC,代码行数:23,代码来源:ogrgeojsonwritelayer.cpp

示例13: feat

feature_ptr ogr_index_featureset<filterT>::next()
{
    if (itr_ != ids_.end())
    {
        int pos = *itr_++;
        layer_.SetNextByIndex (pos);

        ogr_feature_ptr feat (layer_.GetNextFeature());
        if ((*feat) != NULL)
        {
            // ogr feature ids start at 0, so add one to stay
            // consistent with other mapnik datasources that start at 1
            int feature_id = ((*feat)->GetFID() + 1);
            feature_ptr feature(feature_factory::create(feature_id));
            
            OGRGeometry* geom=(*feat)->GetGeometryRef();
            if (geom && !geom->IsEmpty())
            {
                ogr_converter::convert_geometry (geom, feature, multiple_geometries_);
            }
    #ifdef MAPNIK_DEBUG
            else
            {
                std::clog << "### Warning: feature with null geometry: " << (*feat)->GetFID() << "\n";
            }
    #endif
            
            int fld_count = layerdef_->GetFieldCount();
            for (int i = 0; i < fld_count; i++)
            {
                OGRFieldDefn* fld = layerdef_->GetFieldDefn (i);
                OGRFieldType type_oid = fld->GetType ();
                std::string fld_name = fld->GetNameRef ();
            
                switch (type_oid)
                {
                    case OFTInteger:
                    {
                       boost::put(*feature,fld_name,(*feat)->GetFieldAsInteger (i));
                       break;
                    }
                    
                    case OFTReal:
                    {
                       boost::put(*feature,fld_name,(*feat)->GetFieldAsDouble (i));
                       break;
                    }
                           
                    case OFTString:
                    case OFTWideString:     // deprecated !
                    {
                       UnicodeString ustr = tr_->transcode((*feat)->GetFieldAsString (i));
                       boost::put(*feature,fld_name,ustr);
                       break;
                    }
                    
                    case OFTIntegerList:
                    case OFTRealList:
                    case OFTStringList:
                    case OFTWideStringList: // deprecated !
                    {
                    #ifdef MAPNIK_DEBUG
                       std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
                    #endif
                       break;
                    }
                    
                    case OFTBinary:
                    {
                    #ifdef MAPNIK_DEBUG
                       std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
                    #endif
                       //boost::put(*feature,name,feat->GetFieldAsBinary (i, size));
                       break;
                    }
                       
                    case OFTDate:
                    case OFTTime:
                    case OFTDateTime:       // unhandled !
                    {
                    #ifdef MAPNIK_DEBUG
                       std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
                    #endif
                       break;
                    }
                    
                    default: // unknown
                    {
                    #ifdef MAPNIK_DEBUG
                       std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl;
                    #endif
                       break;
                    }
                }
            }
            return feature;
        }
    }
    
    return feature_ptr();
//.........这里部分代码省略.........
开发者ID:ParveenArora,项目名称:mapnik,代码行数:101,代码来源:ogr_index_featureset.cpp

示例14: WriteFeatureAttributes

void GTMTrackLayer::WriteFeatureAttributes( OGRFeature *poFeature )
{
    char* psztrackname = nullptr;
    int type = 1;
    unsigned int color = 0;
    for (int i = 0; i < poFeatureDefn->GetFieldCount(); ++i)
    {
        OGRFieldDefn *poFieldDefn = poFeatureDefn->GetFieldDefn( i );
        if( poFeature->IsFieldSetAndNotNull( i ) )
        {
            const char* l_pszName = poFieldDefn->GetNameRef();
            /* track name */
            if (STARTS_WITH(l_pszName, "name"))
            {
                CPLFree(psztrackname);
                psztrackname = CPLStrdup( poFeature->GetFieldAsString( i ) );
            }
            /* track type */
            else if (STARTS_WITH(l_pszName, "type"))
            {
                type = poFeature->GetFieldAsInteger( i );
                // Check if it is a valid type
                if (type < 1 || type > 30)
                    type = 1;
            }
            /* track color */
            else if (STARTS_WITH(l_pszName, "color"))
            {
                color = (unsigned int) poFeature->GetFieldAsInteger( i );
                if (color > 0xFFFFFF)
                    color = 0xFFFFFFF;
            }
        }
    }

    if (psztrackname == nullptr)
        psztrackname = CPLStrdup( "" );

    const size_t trackNameLength = strlen(psztrackname);

    const size_t bufferSize = 14 + trackNameLength;
    void* pBuffer = CPLMalloc(bufferSize);
    void* pBufferAux = pBuffer;
    /* Write track string name size to buffer */
    appendUShort(pBufferAux, (unsigned short) trackNameLength);
    pBufferAux = (char*)pBufferAux + 2;

    /* Write track name */
    memcpy((char*)pBufferAux, psztrackname, trackNameLength);
    pBufferAux = (char*)pBufferAux + trackNameLength;

    /* Write track type */
    appendUChar(pBufferAux, (unsigned char) type);
    pBufferAux = (char*)pBufferAux + 1;

    /* Write track color */
    appendInt(pBufferAux, color);
    pBufferAux = (char*)pBufferAux + 4;

    /* Write track scale */
    appendFloat(pBufferAux, 0);
    pBufferAux = (char*)pBufferAux + 4;

    /* Write track label */
    appendUChar(pBufferAux, 0);
    pBufferAux = (char*)pBufferAux + 1;

    /* Write track layer */
    appendUShort(pBufferAux, 0);

    VSIFWriteL(pBuffer, bufferSize, 1, poDS->getTmpTracksFP());
    poDS->incNumTracks();

    CPLFree(psztrackname);
    CPLFree(pBuffer);
}
开发者ID:koordinates,项目名称:gdal,代码行数:76,代码来源:gtmtracklayer.cpp

示例15: CPLError

OGRErr OGRMemLayer::AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags )
{
    if (!bUpdatable)
        return OGRERR_FAILURE;

    if (iField < 0 || iField >= poFeatureDefn->GetFieldCount())
    {
        CPLError( CE_Failure, CPLE_NotSupported,
                  "Invalid field index");
        return OGRERR_FAILURE;
    }

    OGRFieldDefn* poFieldDefn = poFeatureDefn->GetFieldDefn(iField);

    if ((nFlags & ALTER_TYPE_FLAG) &&
        poFieldDefn->GetType() != poNewFieldDefn->GetType())
    {
        if ((poNewFieldDefn->GetType() == OFTDate ||
             poNewFieldDefn->GetType() == OFTTime ||
             poNewFieldDefn->GetType() == OFTDateTime) &&
            (poFieldDefn->GetType() == OFTDate ||
             poFieldDefn->GetType() == OFTTime ||
             poFieldDefn->GetType() == OFTDateTime))
        {
            /* do nothing on features */
        }
        else if (poNewFieldDefn->GetType() == OFTInteger64 &&
                 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->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;
//.........这里部分代码省略.........
开发者ID:rashadkm,项目名称:lib_gdal,代码行数:101,代码来源:ogrmemlayer.cpp


注:本文中的OGRFieldDefn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。