5

I'm trying to merge two vector layer as part of a graphic model but get an error:

OBJECTID field in layer layer1 has different data type than in other layers (Integer64 instead of Real) Execution failed after 0.06 seconds

And both layers have a field called OBJECTID with different data types. I don't care about the attributes I just need the geometries. Isn't there a way of telling merge to ignore the attributes?

I would rather not have to drop/rename all fields prior to merge (I have a lot of layers, not only these two with many fields to drop). Maybe there is a QGIS equivalent of ArcGIS MakeFeatureLayer to disable fields prior to merging.

example

0

3 Answers 3

3

Another solution that may be used particularly in the Processing Modeler.

Let's assume there are two polygon layers 'layer_1' and 'layer_2' with its corresponding attribute tables accordingly, see image below.

input

With the following model, it is possible to merge two vector layers with no attributes only their geometries.

model

The output with its Attribute table will look as following

output


Note:

  1. On the last image, attributes were added by default

  2. For both SQL queries use these settings

    sql

2
  • Nice, didnt know Execute SQL works on "non-SQL"-inputs. select geometry from input1 union select geometry from input2 union ... did the trick
    – BERA
    May 6, 2020 at 16:11
  • yes, this can be done also...I thought that merge is a mandatory step in your workflow.
    – Taras
    May 6, 2020 at 16:28
1

I can suggest some PyQGIS but not sure if it corresponds to your requirements

layer_1 = QgsProject.instance().mapLayersByName('unit_1')[0]
layer_1_new = processing.run('qgis:deletecolumn',
    {'INPUT': layer_1,
    'COLUMN': ['id', 'length'], #here you will need to specify all the columns that have to be erased for the first layer
    'OUTPUT': "memory:"}
)["OUTPUT"]

layer_2 = QgsProject.instance().mapLayersByName('unit_2')[0]
layer_2_new = processing.run('qgis:deletecolumn',
    {'INPUT': layer_2,
    'COLUMN': ['id'], #here you will need to specify all the columns that have to be erased for the second layer
    'OUTPUT': "memory:"}
)["OUTPUT"]

layer_merged = processing.run('qgis:mergevectorlayers',
    {'CRS': 'EPSG:***', #use a proper EPSG
    'LAYERS': [layer_2_new, layer_1_new],
    'OUTPUT': 'memory:'}
)['OUTPUT']

QgsProject.instance().addMapLayer(layer_merged)
0
0

I could try with the Promote to the multipart option as shown in the video below:

https://www.youtube.com/watch?v=Vdqx4C0C3Mc&t=58s&ab_channel=MariuszKrukar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.