1

I have a CSV with a column of filtered ids, and because of the filter, the ids are out of order (they start at 23 and not 1) and from it I create another layer with the same number of features, but at the same time put the ids column in it, the ids start at 1, is there a possibility for me to match the ids of both layers? They have the same number of features

iface.addVectorLayer(url,'03p','delimitedtext')
camada = iface.activeLayer()
parameter = {
    'INPUT': camada,
    'TARGET_CRS': 'EPSG:31983',
    'OUTPUT': 'memory:Reprojected3'
}
layer = processing.run('native:reprojectlayer', parameter)['OUTPUT']
QgsProject.instance().addMapLayer(layer)
rp = layer.dataProvider()

filterstring = "\"Data/Hora GPS\" > '20/12/2019 12:33:00' AND \"Data/Hora GPS\" < '21/12/2019 16:51:00'" 
layer.setSubsetString(filterstring)


layer.startEditing()
fieldid = QgsField('id', QVariant.Double)
layer.addExpressionField("@id", fieldid)
layer.commitChanges()

layer = QgsProject.instance().mapLayersByName("Reprojected3")[0] 

vl = QgsVectorLayer("linestring?crs=EPSG:31983","03","memory")
pr = vl.dataProvider()
pr.addAttributes([QgsField("Distancia(m)", QVariant.Double),
                 QgsField("Tempo(s)", QVariant.Double),
                 QgsField("Velocidade(cm/s)", QVariant.Double),
                 QgsField("Longitude", QVariant.Double)])

fieldid2 = QgsField('id', QVariant.Double)
vl.addExpressionField("@id",fieldid2)
1
  • Can you please share your data with us?
    – Taras
    Commented Nov 3, 2023 at 9:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.