2

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

  • 1
    As a workaround, you can copy-paste the geometries in edit mode. – Veronika Grishina May 6 at 11:45
  • What prevents you from bringing fields to the same data type and then merging? – Cyril Mikhalchenko May 6 at 12:36
  • I would need to check 15+ input layers for identical field names with different data types then convert data types. Not doable in graphical modeler. I would need to use pyqgis. – BERA May 6 at 12:38
  • would it be too complicated if you apply "Drop field(s)" before running merge? – Taras May 6 at 13:02
  • Since there is no option to drop all field, yes. I would need to specify all field names for each input layer. – BERA May 6 at 13:06
2

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

Let's assume we have two 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

| improve this answer | |
  • 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 at 16:11
  • yes, this can be done also...I thought that merge is a mandatory step in your workflow. – Taras May 6 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)
| improve this answer | |

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.