Qt+QGIS二次开发:向shp矢量图层中添加新的字段
添加一个新的字段到shp文件中,并且从 Excel 里导入数据到该字段。原shp文件里的字段ID应该与Excel里的字段ID一一对应才能正确的导入。下图分别是shp的字段和Excel的字段 将class字段添加到shp中去: (1)从Excel中读取数据(为了读取方便,存为.csv或者txt文件) QStringList readFromCSV(QString mfilename) { QStringList readlist; if (mfilename != "" ) { QFileInfo csvFI(mfilename); QString ext = csvFI.suffix(); if ( ext == " csv " || ext == " txt " ) { QFile *importFile = new QFile(mfilename); if ( !importFile->open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::information(NULL, " error " , " Cannot open import file ! " , QMessageBox::Yes | QMessageBox::No); return readlist; } readlist.clear();