In pyQGIS i tried this code (contains also debug prints):
def joinLayers(inputlayer, layer, index_field, name = "JOINED", dataProvider = "ESRI Shapefile"):
a = []
b = []
outpath = getPath(inputlayer.source(), name)
inputfields = inputlayer.pendingFields()
nameoflayer = layer.name()
toappend = layer.pendingFields()
for fild in toappend:
a.append(fild.name() + "j")
fname = fild.name()
newfield = QgsField(unicode(fname+ "j"), fild.type(), fild.typeName(), fild.length(), fild.precision(), fild.comment())
b.append(newfield.name())
inputfields.append(newfield, QgsFields.OriginJoin)
print a
print b
output = QgsVectorFileWriter(outpath, dataProvider, inputfields, inputlayer.crs(), layer.wkbType(), inputlayer.dataProvider().encoding())
del output
Main problem is renaming fields in for loop over QgsFields.
a
- [u'UWIj', u'Wellj', u'UBHIj', u'Boreholej', u'Statej', u'Jurisdictij', u'Offshorej', u'Basinj', u'Sub-basinj', u'Latitudej', u'Longitudej', u'Legislatioj', u'Titlej', u'Operatorj', u'Classj', u'Structurej', u'Seismic loj', u'Drilled byj', u'Rigsj', u'Spud/Kickj', u'TD Datej', u'Rig releasj', u'Start deptj', u"Driller'sj", u'Oil showj', u'Gas showj', u'Condensatej', u'Oil fieldj', u'Discoveryj', u'Statusj', u'Well headj', u'Basic relej', u'WCRj']
b
- [u'UWIj', u'Wellj', u'UBHIj', u'Boreholej', u'Statej', u'Jurisdictij', u'Offshorej', u'Basinj', u'Sub-basinj', u'Latitudej', u'Longitudej', u'Legislatioj', u'Titlej', u'Operatorj', u'Classj', u'Structurej', u'Seismic loj', u'Drilled byj', u'Rigsj', u'Spud/Kickj', u'TD Datej', u'Rig releasj', u'Start deptj', u"Driller'sj", u'Oil showj', u'Gas showj', u'Condensatej', u'Oil fieldj', u'Discoveryj', u'Statusj', u'Well headj', u'Basic relej', u'WCRj']
After write this fields into QgsVectorFileWriter, some fields doesn´t have "j" suffix.
For example attribute Condensate, see attribute table in qgis: