Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate layer #15348

Closed
qgib opened this issue Jun 28, 2012 · 10 comments
Closed

Duplicate layer #15348

qgib opened this issue Jun 28, 2012 · 10 comments

Comments

@qgib
Copy link
Contributor

qgib commented Jun 28, 2012

Author Name: Olivier redlead (@olivierdalang)
Original Redmine Issue: 5899

Assignee: Giuseppe Sucameli


Hi !

Often you want to display one Shapefile with several layers (example : for the shapefile LandUse.shp, show column "land_use_current" on one layer, and "land_use_projet" on another layer)

When you want to do so, you have to add the Shapefile several times, meaning you have to go in your file hierarchy to find it again each time you want a new layer from your data.

It would be really nice to have a little "duplicate layer" button !

Thanks !

@qgib
Copy link
Contributor Author

qgib commented Jul 16, 2012

Author Name: Giuseppe Sucameli (@brushtyler)


In the meantime, select the vector layer then open the QGis python console and run:

iface = qgis.utils.iface; vl = iface.activeLayer(); iface.addVectorLayer(vl.source(), vl.name() + "_clone", vl.providerType())

You can also create a little plugin using the previous snippet.

@qgib
Copy link
Contributor Author

qgib commented Jul 16, 2012

Author Name: Giuseppe Sucameli (@brushtyler)


Sorry, I've misunderstood the subject. The previous code adds to the map the +same+ sublayer.

It's difficult to do it using a one-line python script like the previous one, but if you know the sublayer name you can just replace @vl.source()@ with @vl.source().split("|")[0] + "|layername=my_sublayer_name"@ where @my_sublayer_name@ is the name of your sublayer.

@qgib
Copy link
Contributor Author

qgib commented Aug 14, 2012

Author Name: Bernd Vogelgesang (Bernd Vogelgesang)


I already found several past feature requests which weren't processed or where the relevance of the topic didn't get clear enough.
#11543
#13614
Working with complex datasets nearly always requires building views for different aspects of the underlying data.
Having to add the same dataset through the file wizard all the time is a tedious task when you need multiple of these views (e.g. queries, different labeling, colors etc)

Use case: I have 13 groups of monitoring plots, where i have to produce overview maps of. For this, i need as basis a point, line and area layer which i then query for the group-id and put those layers in a group within the TOC for quick on/off of the features.

Having the possibility to quickly duplicate the original set for performing queries and changing additional setting would be a real helper.
Shouldn't mention it, but in ArcGIS, this is a basic feature for a long time (right-click action on layer in TOC to duplicate it).

Coding python scripts themselves is beyond average users abilities i fear...

@qgib
Copy link
Contributor Author

qgib commented Aug 15, 2012

Author Name: Alister Hood (@AlisterH)


Olivier redlead wrote:

Often you want to display one Shapefile with several layers (example : for the shapefile LandUse.shp, show column "land_use_current" on one layer, and "land_use_projet" on another layer)

Am I missing something here? I thought a shapefile could only contain a single layer...
Do you mean you want to display different labels depending on the contents of different columns? This is possible with the new expression based labelling, but they will all be formatted the same. If you want to format them differently, then you need rule-based labelling, and there is already a ticket open for that.
Or do you mean you want to run several queries on the layer, based on different columns, and use different symbols for each one? This is possible with the rule-based renderer.

@qgib
Copy link
Contributor Author

qgib commented Aug 15, 2012

Author Name: Alister Hood (@AlisterH)


Bernd Vogelgesang wrote:

put those layers in a group within the TOC for quick on/off of the features.

Ah, OK. That's the use case.
Yes, I've found myself wanting to toggle the visibility of features per rule when using the rule based renderer. As long as that isn't possible then I'm sure plenty of people would appreciate a "duplicate layer" plugin.

@qgib
Copy link
Contributor Author

qgib commented Aug 15, 2012

Author Name: Alister Hood (@AlisterH)


Should this be merged with #11543?
N.B. copy and paste (#11543) would be slightly better than duplicate, as you could paste into a different QGIS project.

@qgib
Copy link
Contributor Author

qgib commented Aug 16, 2012

Author Name: Giovanni Manghi (@gioman)


Alister Hood wrote:

Should this be merged with #11543?
N.B. copy and paste (#11543) would be slightly better than duplicate, as you could paste into a different QGIS project.

I'm not sure that #11543 is about copy/paste layers between projects, seems really a duplicate of this ticket.

By the way the one line code given by Giuseppe works like a charm (it works also for rasters with a trivial change) and I really would like to see a "clone layer" button (or "clone layer" right click dialog entry) dialog to be added to the standard toolbar. I already asked this privately to Giuseppe, let's see what he says.


  • assigned_to_id was configured as Giuseppe Sucameli
  • fixed_version_id was configured as Version 2.0.0

@qgib
Copy link
Contributor Author

qgib commented Aug 16, 2012

Author Name: James Stott (@jamesstott)


The duplicate layer button/option on the right click menu would be a great addition.

A slight extension of this would be to enable you to add a layer for each value in a column of a dataset.

For example, say I have a table with land uses (say 10 different types), and I want to create a separate layer with each land use in it. At the moment you would have to add the layer 10 number of times, and then do right click > query 10 times. A simple way to add a layer for each category in the land use type column would save a lot of time in this case.

@qgib
Copy link
Contributor Author

qgib commented Nov 2, 2012

Author Name: Alexander Bruy (@alexbruy)


Implemented in c11df1a


  • status_id was changed from Open to Closed
  • resolution was changed from to fixed

@qgib
Copy link
Contributor Author

qgib commented Nov 2, 2012

Author Name: Giovanni Manghi (@gioman)


Alexander Bruy wrote:

Implemented in c11df1a

great addition Alexander! Thanks!

@qgib qgib added this to the Version 2.0.0 milestone May 24, 2019
@qgib qgib closed this as completed May 24, 2019
JamesShaeffer pushed a commit to JamesShaeffer/QGIS that referenced this issue Nov 20, 2019
follow up 9db908c

(cherry picked from commit 572a60b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant