10

In QGIS 3 does anyone know how to copy the geometry of one feature and paste it into another selected feature to just override the geometry?

Within PostGIS I did this with an update, but I'm looking for a visual way in QGIS. Simply copy and paste.

The only solution I found, is to insert the copy of a feature as a new entry, edit the missing attributes and delete the old one.

5
  • Are you looking to script this or are you after an existing tool/workflow? Is this for only one feature selected interactively or for all features in a layer? Commented Oct 1, 2018 at 11:09
  • I'm looking for a most easy workflow just to change the geometry of one selected feature. To do this with the edit toolbar 'copy' and then 'paste' with a selected feature adds just a new entry and doesn't overrides it.
    – Michael
    Commented Oct 1, 2018 at 11:21
  • 1
  • No, not really. The question of the first one seems to go into my direction, but the answer explains the insert of a copy as a new feature. The second one is to merge two layers together where to take the attributes from one layer and the geometry of another.
    – Michael
    Commented Oct 1, 2018 at 11:54
  • 2
    It sounds like you've already found the easiest way to do this. To simplify any further, you would have to code an entirely new tool.
    – csk
    Commented Oct 1, 2018 at 17:11

4 Answers 4

11

There is the Geometry Paster Plugin

Turns out we had a task for this too, so here we go:

3
  • 1
    Hallo Maxim, great work! Tested today the plugin. Does exactly what I was looking for. I like the integration in the edit-menu. Fits perfect there. Many many thanks.
    – Michael
    Commented Dec 20, 2018 at 21:25
  • Hi Maxim, sorry, but I don't understand Russian language. Is there an English translation for the Geometry Paster plugin?
    – Stu Smith
    Commented Dec 14, 2020 at 17:30
  • I modified my answer to add EN video link (what was I thinking! :shocked:) Commented Dec 15, 2020 at 18:19
5

not so visual, but it works

  1. Select feature, copy it
  2. Paste in a text doc, remove all except WKT geom
  3. Add stuff around your WKT: geom_from_wkt('YOUR WKT GEOM HERE')
  4. Select feature to replace geometry
  5. Use resulting line in Field calculator to replace geometry with a new one (text from 3)
1
  • Hi Maxim, thanks for this suggestion. I‘ll give it a try. Maybe next year with a little more spare time I wanna have a closer look at the plugin development. I‘m shure it should be possible with that.
    – Michael
    Commented Dec 8, 2018 at 13:45
4

You can select the source feature and copy ("Edit > Copy Features" or "CTRL + C"), then, in edit mode with the destination feature selected, use the "Delete Part" tool and click on the geometry you want to replace. After that, with the feature still selected (you can have the attribute table open to be sure because your feature will no longer have a geometry), use the "Add Part" tool and paste the copied geometry.

You can use the method to replace some or all parts of multipart geometry or the geometry of single part geometries.

  • Copy source geometry
  • Select destination feature
  • Delete Part
  • Add Part
3
  • 1
    I've been trying to replicate this but it always creates a new feature when pasting the copied geometry. I'm on QGIS 3.22, and have been trying to experiment with this very workflow for a few weeks. Am I missing something obvious?
    – Eron Lloyd
    Commented Feb 12, 2022 at 21:09
  • The features you want replaced must be selected and you have to use "Delete part" tool to delete existing geometries of the selected features. Next, use "Add part" tool and paste copied geometries to the selected features. Commented Feb 14, 2022 at 5:32
  • I am also unable to paste the replacement geometry into the record with the geometry removed. However if the replacement geometry is pasted as a new record, then the 'Merge Selected Features' tool can be used to combine this with the record with no geometry, choosing to keep all the attribute values from the latter. Commented May 4, 2023 at 9:41
1

Just to document an alternative solution, which I had to come up with because I found that the Geometry Paster plugin had some limitations with geometries that had large numbers of vertices.

There are also some different situations which required a bit more flexibility, or less map interaction, which the solution below allowed me to have.

I use the Field Calculator on a single record selection. Select the 'Update Existing Field' and under there, there is '' available as an option.

Then - it depends on where the source of the geometry is coming from, but lets say, the source is from another layer which has a record that contains the geometry I want in the destination layer.

The following expression will work.

geometry(get_feature_by_id(layer,feature_id))

Where 'layer' is simply the name of the layer as derived from the Map Layers listing. eg: 'permit_5ce54d18_5c0b_4297_930f_2212956c9e78' feature_id is just the fid, or other record ID.

Your Answer

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

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