9

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.

Taras
  • 32,823
  • 4
  • 66
  • 137
Michael
  • 434
  • 3
  • 9
  • 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? – Michael Stimson Oct 01 '18 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 Oct 01 '18 at 11:21
  • 1
    Does https://gis.stackexchange.com/questions/20942/how-to-copy-a-geometry-from-one-feature-to-another-without-attributes help? Or https://gis.stackexchange.com/questions/178870/copy-geometry-from-one-layer-onto-attributes-of-another ? – Michael Stimson Oct 01 '18 at 11:26
  • 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 Oct 01 '18 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 Oct 01 '18 at 17:11

4 Answers4

10

There is the Geometry Paster Plugin

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

Taras
  • 32,823
  • 4
  • 66
  • 137
Maxim Dubinin
  • 2,159
  • 17
  • 26
  • 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 Dec 20 '18 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 Dec 14 '20 at 17:30
  • I modified my answer to add EN video link (what was I thinking! :shocked:) – Maxim Dubinin Dec 15 '20 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)
Maxim Dubinin
  • 2,159
  • 17
  • 26
  • 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 Dec 08 '18 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
Yogesh Chavan
  • 2,705
  • 2
  • 9
  • 24
  • 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 Feb 12 '22 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. – Ovidiu Jeler Feb 14 '22 at 05: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. – Andy Harfoot May 04 '23 at 09: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.

nr_aus
  • 3,535
  • 6
  • 26