Setting layer identifiable, seachable and removable with Python in QGIS 3? Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How to write Python code with QList classLoad postgis vectorlayer with AuthConfigIdpyQGIS - set grid annotation direction 'Vertical Descending'How to set and configure a value relation edittype in QGIS 2.14?How to use the method makeDifference in the console?Understanding QGIS API documentationWriting a python processing script with Qgis 3.0How to change layer symbology in QGIS 3 with QgsFeatureRendererV2?Toggle labels on/off for a layer with PyQGIS 2?Python Scripting in QGIS to add features and select them?
Do wooden building fires get hotter than 600°C?
Amount of permutations on an NxNxN Rubik's Cube
Is it fair for a professor to grade us on the possession of past papers?
Google .dev domain strangely redirects to https
An adverb for when you're not exaggerating
How could we fake a moon landing now?
Can a Beast Master ranger change beast companions?
Project Euler #1 in C++
Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?
Why do early math courses focus on the cross sections of a cone and not on other 3D objects?
What order were files/directories output in dir?
How do living politicians protect their readily obtainable signatures from misuse?
Why we try to capture variability?
How do I tell what width chain my used chainring needs?
Why is it faster to reheat something than it is to cook it?
Misunderstanding of Sylow theory
Putting class ranking in CV, but against dept guidelines
What does it mean that physics no longer uses mechanical models to describe phenomena?
Sum letters are not two different
Does the Mueller report show a conspiracy between Russia and the Trump Campaign?
Draw 4 of the same figure in the same tikzpicture
Is it possible for SQL statements to execute concurrently within a single session in SQL Server?
Is it possible to force a specific program to remain in memory after closing it?
Movie where a circus ringmaster turns people into animals
Setting layer identifiable, seachable and removable with Python in QGIS 3?
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?How to write Python code with QList classLoad postgis vectorlayer with AuthConfigIdpyQGIS - set grid annotation direction 'Vertical Descending'How to set and configure a value relation edittype in QGIS 2.14?How to use the method makeDifference in the console?Understanding QGIS API documentationWriting a python processing script with Qgis 3.0How to change layer symbology in QGIS 3 with QgsFeatureRendererV2?Toggle labels on/off for a layer with PyQGIS 2?Python Scripting in QGIS to add features and select them?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
With PyQGIS, I want to set project layer properties (Project Menu > Properties > DataSource) such as Identifiable, Searchable and Required (for Read Only, the method is QgsVectorLayer.setReadOnly() (link)).
In the API doc, for the method QgsProject.nonIdentifiableLayers(), it says:
Deprecated since version since: QGIS 3.4 use
QgsMapLayer.setFlags()instead
But there is no clear documentation (for me) or example for how to use this new method QgsMapLayer.setFlags().
I would like to understand how to use this method.
qgis pyqgis qgis-3 pyqgis-3
add a comment |
With PyQGIS, I want to set project layer properties (Project Menu > Properties > DataSource) such as Identifiable, Searchable and Required (for Read Only, the method is QgsVectorLayer.setReadOnly() (link)).
In the API doc, for the method QgsProject.nonIdentifiableLayers(), it says:
Deprecated since version since: QGIS 3.4 use
QgsMapLayer.setFlags()instead
But there is no clear documentation (for me) or example for how to use this new method QgsMapLayer.setFlags().
I would like to understand how to use this method.
qgis pyqgis qgis-3 pyqgis-3
add a comment |
With PyQGIS, I want to set project layer properties (Project Menu > Properties > DataSource) such as Identifiable, Searchable and Required (for Read Only, the method is QgsVectorLayer.setReadOnly() (link)).
In the API doc, for the method QgsProject.nonIdentifiableLayers(), it says:
Deprecated since version since: QGIS 3.4 use
QgsMapLayer.setFlags()instead
But there is no clear documentation (for me) or example for how to use this new method QgsMapLayer.setFlags().
I would like to understand how to use this method.
qgis pyqgis qgis-3 pyqgis-3
With PyQGIS, I want to set project layer properties (Project Menu > Properties > DataSource) such as Identifiable, Searchable and Required (for Read Only, the method is QgsVectorLayer.setReadOnly() (link)).
In the API doc, for the method QgsProject.nonIdentifiableLayers(), it says:
Deprecated since version since: QGIS 3.4 use
QgsMapLayer.setFlags()instead
But there is no clear documentation (for me) or example for how to use this new method QgsMapLayer.setFlags().
I would like to understand how to use this method.
qgis pyqgis qgis-3 pyqgis-3
qgis pyqgis qgis-3 pyqgis-3
edited Apr 12 at 6:34
Taras
2,3703730
2,3703730
asked Apr 11 at 14:27
J. MonticoloJ. Monticolo
1,958320
1,958320
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I tried to understand the behavior of the setFlags method by see on a vector layer the results of :
vl = iface.activeLayer()
flags = 1
vl.setFlags(QgsMapLayer.LayerFlag(flags))
# result : the layer is identifiable and required
I looked at the Python API doc for QgsMapLayer, in these attributes and :
- Identifiable = 1 (= 2 power 0)
- Removable = 2 (= 2 power 1)
- Searchable = 4 (= 2 power 2)
If we draw a binary table :
Num2 power 22 power 12 power 0
0
0
0
0
1
0
0
1
2
0
1
0
3
0
1
1
4
1
0
0
5
1
0
1
6
1
1
0
7
1
1
1
and a table of project layer settings (DataSource tab) with the result of vl.setFlags(QgsMapLayer.LayerFlag(Num)), 1 as True and 0 as False :
NumSearchable Required Identifiable
0
0
1
0
1
0
1
1
2
0
0
0
3
0
0
1
4
1
1
0
5
1
1
1
6
1
0
0
7
1
0
1
- Identifiable behavior equals 2 power 0
- Searchage behavior equals 2 power 2
- but Removable behavior is the inverse of 2 power 1.
... and wait ! Required is the inverse of Removable.
For set these settings for a layer in a project, the code is :
vl = activeLayer()
identifiable = QgsMapLayer.Identifiable
searchable = QgsMapLayer.Searchable
removable = QgsMapLayer.Removable
# for a non-required and identifiable layer
vl.setFlags(QgsMapLayer.LayerFlag(identifiable + removable))
# for a searchable only layer
vl.setFlags(QgsMapLayer.LayerFlag(searchable + removable))
# for a searchable and required layer
vl.setFlags(QgsMapLayer.LayerFlag(searchable))
Or a function :
def layer_settings(vectorLayer, isIdentifiable=True,
isSearchable=True, isRequired=False):
flags = 0
if isIdentifiable:
flags += QgsMapLayer.Identifiable
if isSearchable:
flags += QgsMapLayer.Searchable
if not isRequired:
flags += QgsMapLayer.Removable
vectorLayer.setFlags(QgsMapLayer.LayerFlag(flags))
vl = iface.activeLayer()
# for an identifiable and required layer
layer_settings(vl, True, False, True)
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318506%2fsetting-layer-identifiable-seachable-and-removable-with-python-in-qgis-3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I tried to understand the behavior of the setFlags method by see on a vector layer the results of :
vl = iface.activeLayer()
flags = 1
vl.setFlags(QgsMapLayer.LayerFlag(flags))
# result : the layer is identifiable and required
I looked at the Python API doc for QgsMapLayer, in these attributes and :
- Identifiable = 1 (= 2 power 0)
- Removable = 2 (= 2 power 1)
- Searchable = 4 (= 2 power 2)
If we draw a binary table :
Num2 power 22 power 12 power 0
0
0
0
0
1
0
0
1
2
0
1
0
3
0
1
1
4
1
0
0
5
1
0
1
6
1
1
0
7
1
1
1
and a table of project layer settings (DataSource tab) with the result of vl.setFlags(QgsMapLayer.LayerFlag(Num)), 1 as True and 0 as False :
NumSearchable Required Identifiable
0
0
1
0
1
0
1
1
2
0
0
0
3
0
0
1
4
1
1
0
5
1
1
1
6
1
0
0
7
1
0
1
- Identifiable behavior equals 2 power 0
- Searchage behavior equals 2 power 2
- but Removable behavior is the inverse of 2 power 1.
... and wait ! Required is the inverse of Removable.
For set these settings for a layer in a project, the code is :
vl = activeLayer()
identifiable = QgsMapLayer.Identifiable
searchable = QgsMapLayer.Searchable
removable = QgsMapLayer.Removable
# for a non-required and identifiable layer
vl.setFlags(QgsMapLayer.LayerFlag(identifiable + removable))
# for a searchable only layer
vl.setFlags(QgsMapLayer.LayerFlag(searchable + removable))
# for a searchable and required layer
vl.setFlags(QgsMapLayer.LayerFlag(searchable))
Or a function :
def layer_settings(vectorLayer, isIdentifiable=True,
isSearchable=True, isRequired=False):
flags = 0
if isIdentifiable:
flags += QgsMapLayer.Identifiable
if isSearchable:
flags += QgsMapLayer.Searchable
if not isRequired:
flags += QgsMapLayer.Removable
vectorLayer.setFlags(QgsMapLayer.LayerFlag(flags))
vl = iface.activeLayer()
# for an identifiable and required layer
layer_settings(vl, True, False, True)
add a comment |
I tried to understand the behavior of the setFlags method by see on a vector layer the results of :
vl = iface.activeLayer()
flags = 1
vl.setFlags(QgsMapLayer.LayerFlag(flags))
# result : the layer is identifiable and required
I looked at the Python API doc for QgsMapLayer, in these attributes and :
- Identifiable = 1 (= 2 power 0)
- Removable = 2 (= 2 power 1)
- Searchable = 4 (= 2 power 2)
If we draw a binary table :
Num2 power 22 power 12 power 0
0
0
0
0
1
0
0
1
2
0
1
0
3
0
1
1
4
1
0
0
5
1
0
1
6
1
1
0
7
1
1
1
and a table of project layer settings (DataSource tab) with the result of vl.setFlags(QgsMapLayer.LayerFlag(Num)), 1 as True and 0 as False :
NumSearchable Required Identifiable
0
0
1
0
1
0
1
1
2
0
0
0
3
0
0
1
4
1
1
0
5
1
1
1
6
1
0
0
7
1
0
1
- Identifiable behavior equals 2 power 0
- Searchage behavior equals 2 power 2
- but Removable behavior is the inverse of 2 power 1.
... and wait ! Required is the inverse of Removable.
For set these settings for a layer in a project, the code is :
vl = activeLayer()
identifiable = QgsMapLayer.Identifiable
searchable = QgsMapLayer.Searchable
removable = QgsMapLayer.Removable
# for a non-required and identifiable layer
vl.setFlags(QgsMapLayer.LayerFlag(identifiable + removable))
# for a searchable only layer
vl.setFlags(QgsMapLayer.LayerFlag(searchable + removable))
# for a searchable and required layer
vl.setFlags(QgsMapLayer.LayerFlag(searchable))
Or a function :
def layer_settings(vectorLayer, isIdentifiable=True,
isSearchable=True, isRequired=False):
flags = 0
if isIdentifiable:
flags += QgsMapLayer.Identifiable
if isSearchable:
flags += QgsMapLayer.Searchable
if not isRequired:
flags += QgsMapLayer.Removable
vectorLayer.setFlags(QgsMapLayer.LayerFlag(flags))
vl = iface.activeLayer()
# for an identifiable and required layer
layer_settings(vl, True, False, True)
add a comment |
I tried to understand the behavior of the setFlags method by see on a vector layer the results of :
vl = iface.activeLayer()
flags = 1
vl.setFlags(QgsMapLayer.LayerFlag(flags))
# result : the layer is identifiable and required
I looked at the Python API doc for QgsMapLayer, in these attributes and :
- Identifiable = 1 (= 2 power 0)
- Removable = 2 (= 2 power 1)
- Searchable = 4 (= 2 power 2)
If we draw a binary table :
Num2 power 22 power 12 power 0
0
0
0
0
1
0
0
1
2
0
1
0
3
0
1
1
4
1
0
0
5
1
0
1
6
1
1
0
7
1
1
1
and a table of project layer settings (DataSource tab) with the result of vl.setFlags(QgsMapLayer.LayerFlag(Num)), 1 as True and 0 as False :
NumSearchable Required Identifiable
0
0
1
0
1
0
1
1
2
0
0
0
3
0
0
1
4
1
1
0
5
1
1
1
6
1
0
0
7
1
0
1
- Identifiable behavior equals 2 power 0
- Searchage behavior equals 2 power 2
- but Removable behavior is the inverse of 2 power 1.
... and wait ! Required is the inverse of Removable.
For set these settings for a layer in a project, the code is :
vl = activeLayer()
identifiable = QgsMapLayer.Identifiable
searchable = QgsMapLayer.Searchable
removable = QgsMapLayer.Removable
# for a non-required and identifiable layer
vl.setFlags(QgsMapLayer.LayerFlag(identifiable + removable))
# for a searchable only layer
vl.setFlags(QgsMapLayer.LayerFlag(searchable + removable))
# for a searchable and required layer
vl.setFlags(QgsMapLayer.LayerFlag(searchable))
Or a function :
def layer_settings(vectorLayer, isIdentifiable=True,
isSearchable=True, isRequired=False):
flags = 0
if isIdentifiable:
flags += QgsMapLayer.Identifiable
if isSearchable:
flags += QgsMapLayer.Searchable
if not isRequired:
flags += QgsMapLayer.Removable
vectorLayer.setFlags(QgsMapLayer.LayerFlag(flags))
vl = iface.activeLayer()
# for an identifiable and required layer
layer_settings(vl, True, False, True)
I tried to understand the behavior of the setFlags method by see on a vector layer the results of :
vl = iface.activeLayer()
flags = 1
vl.setFlags(QgsMapLayer.LayerFlag(flags))
# result : the layer is identifiable and required
I looked at the Python API doc for QgsMapLayer, in these attributes and :
- Identifiable = 1 (= 2 power 0)
- Removable = 2 (= 2 power 1)
- Searchable = 4 (= 2 power 2)
If we draw a binary table :
Num2 power 22 power 12 power 0
0
0
0
0
1
0
0
1
2
0
1
0
3
0
1
1
4
1
0
0
5
1
0
1
6
1
1
0
7
1
1
1
and a table of project layer settings (DataSource tab) with the result of vl.setFlags(QgsMapLayer.LayerFlag(Num)), 1 as True and 0 as False :
NumSearchable Required Identifiable
0
0
1
0
1
0
1
1
2
0
0
0
3
0
0
1
4
1
1
0
5
1
1
1
6
1
0
0
7
1
0
1
- Identifiable behavior equals 2 power 0
- Searchage behavior equals 2 power 2
- but Removable behavior is the inverse of 2 power 1.
... and wait ! Required is the inverse of Removable.
For set these settings for a layer in a project, the code is :
vl = activeLayer()
identifiable = QgsMapLayer.Identifiable
searchable = QgsMapLayer.Searchable
removable = QgsMapLayer.Removable
# for a non-required and identifiable layer
vl.setFlags(QgsMapLayer.LayerFlag(identifiable + removable))
# for a searchable only layer
vl.setFlags(QgsMapLayer.LayerFlag(searchable + removable))
# for a searchable and required layer
vl.setFlags(QgsMapLayer.LayerFlag(searchable))
Or a function :
def layer_settings(vectorLayer, isIdentifiable=True,
isSearchable=True, isRequired=False):
flags = 0
if isIdentifiable:
flags += QgsMapLayer.Identifiable
if isSearchable:
flags += QgsMapLayer.Searchable
if not isRequired:
flags += QgsMapLayer.Removable
vectorLayer.setFlags(QgsMapLayer.LayerFlag(flags))
vl = iface.activeLayer()
# for an identifiable and required layer
layer_settings(vl, True, False, True)
edited Apr 11 at 14:38
answered Apr 11 at 14:27
J. MonticoloJ. Monticolo
1,958320
1,958320
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318506%2fsetting-layer-identifiable-seachable-and-removable-with-python-in-qgis-3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown