Class: QgsProject¶
- class qgis.core.QgsProject¶
Bases:
PyQt5.QtCore.QObject
,QgsExpressionContextGenerator
,QgsExpressionContextScopeGenerator
,QgsProjectTranslator
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
QgsProject
is available both as a singleton (QgsProject.instance()
) and for use as standalone objects. The QGIS project singleton always gives access to the canonical project reference open within the main QGIS application.Note
QgsProject
has two general kinds of state to make persistent. (I.e., to read and write.) First, QGIS proprietary information. Second plugin information.QgsProject(parent: QObject = None, capabilities: Union[Qgis.ProjectCapabilities, Qgis.ProjectCapability] = Qgis.ProjectCapability.ProjectStyles) Create a new QgsProject.
Most of the time you want to use
QgsProject.instance()
instead as many components of QGIS work with the singleton.Since QGIS 3.26.1 the
capabilities
argument specifies optional capabilities which can be selectively enabled for the project. These affect theQgsProject
object for its entire lifetime.Enums
Bases:
enum.IntEnum
alias of
ProjectFileFormat
alias of
ProjectReadFlag
Methods
Returns full absolute path to the project file if the project is stored in a file system - derived from
fileName()
.Returns full absolute path to the project folder if the project is stored in a file system - derived from
fileName()
.Accepts the specified style entity
visitor
, causing it to visit all style entities associated with the project.Add a layer to the map of loaded layers.
Add a list of layers to the map of loaded layers.
Returns pointer to the project's annotation manager.
Convenience function to query default area measurement units for project.
Returns a map of all attached files with identifier and real paths.
Returns an identifier for an attachment file path An attachment identifier is a string which does not depend on the project archive storage location.
Transactional editing means that on supported datasources (postgres databases) the edit state of all tables that originate from the same database are synchronized and executed in a server side transaction.
Returns the current auxiliary storage.
A list of layers with which intersections should be avoided.
Returns the current avoid intersections mode.
Returns the default background color used by default map canvases.
Returns the base name of the project file without the path and without extension - derived from
fileName()
.Returns the project's bookmark manager, which manages bookmarks within the project.
Returns the project's capabilities, which dictate optional functionality which can be selectively enabled for a
QgsProject
object.Clears the project, removing all settings and resetting it back to an empty, default state.
Attempts to commit to the underlying data provider any buffered changes made since the last to call to
startEditing()
.Returns the number of registered layers.
Attaches a file to the project
Create layer group instance defined in an arbitrary project file.
- rtype:
QgsExpressionContext
- rtype:
QgsExpressionContextScope
Returns the project's native coordinate reference system.
A map of custom project variables.
Returns the data defined properties used for overrides in user defined server parameters
Returns the default CRS for new layers based on the settings and the current project CRS
Returns the project's display settings, which settings and properties relating to how a
QgsProject
should display values such as map coordinates and bearings.Convenience function to query default distance measurement units for project.
Dump out current project properties to stderr
Returns the edit buffer group
Returns the project's elevation properties, which contains the project's elevation related settings.
Returns a proj string representing the project's ellipsoid setting, e.g., "WGS84".
Returns a list of child keys with values which exist within the the specified
scope
andkey
.Returns error message from previous read/write
Should default values be evaluated on provider side when requested and not when committed.
Returns QFileInfo object for the project's associated file.
Returns the project's file name.
Returns the type of paths used when storing file paths in a QGS/QGZ project file.
Returns the project's flags, which dictate the behavior of the project.
Triggers the collection strings of .qgs to be included in ts file and calls
writeTsFile()
Returns the project's home path.
Returns the
QgsProject
singleton instanceReturns
True
if the project has been modified since the lastwrite()
Returns
True
if the project comes from a zip archive,False
otherwise.Returns project's global labeling engine settings
Returns last modified time of the project file as returned by the file system (or other project storage).
Returns the date and time when the project was last saved.
Returns the QGIS version which the project was last saved using.
Returns the source project file path if the layer with matching
id
is embedded from other project file.Returns a pointer to the project's internal layer store.
Returns pointer to the helper class that synchronizes map layer registry with layer tree
Returns pointer to the root (invisible) node of the project's layer tree
Returns the project's layout manager, which manages print layouts, atlases and reports within the project.
Returns the main annotation layer associated with the project.
Retrieve a pointer to a registered layer by layer ID.
Returns a map of all registered layers by layer ID.
Retrieve a list of matching registered layers by layer name.
Retrieves a list of matching registered layers by layer
shortName
.Returns the list of custom project map scales.
Returns pointer to the project's map theme collection.
Returns a reference to the project's metadata store.
Gets the list of layers which currently should not be taken into account on map identification
Returns the original path associated with the project.
Returns path resolver object with considering whether the project uses absolute or relative paths and using current project's path.
Returns any manual project home path setting, or an empty string if not set.
Returns pointer to project storage implementation that handles read/write of the project file.
Reads given project file from the given file.
Reads a boolean from the specified
scope
andkey
.Reads a double from the specified
scope
andkey
.Reads a string from the specified
scope
andkey
.Reads the layer described in the associated DOM node.
Reads a string list from the specified
scope
andkey
.Reads an integer from the specified
scope
andkey
.Transforms a
filename
read from the project file to an absolute path.Registers the containers that require translation into the translationContext.
Registers the objects that require translation into the
translationContext
.- rtype:
QgsRelationManager
Reload all registered layer's provider data caches, synchronising the layer with any changes in the datasource.
Removes all registered layers.
Removes the attached file
Remove the given
key
from the specifiedscope
.Remove a layer from the registry by layer ID.
Remove a set of layers from the registry by layer ID.
Returns a set of map layers that are required in the project and therefore they should not get removed from the project.
Resolves an attachment identifier to a attachment file path
Stops a current editing operation on vectorLayer and discards any uncommitted edits.
Returns the user name that did the last save.
Returns the full user name that did the last save.
Returns the color used to highlight selected features
Sets the default area measurement units for the project.
Transactional editing means that on supported datasources (postgres databases) the edit state of all tables that originate from the same database are synchronized and executed in a server side transaction.
Sets the list of layers with which intersections should be avoided.
Sets the avoid intersections mode.
Sets the default background
color
used by default map canvases.Change handler for missing layers.
Sets the project's native coordinate reference system.
A map of custom project variables.
Sets the data defined properties used for overrides in user defined server parameters to
properties
Flag the project as dirty (modified).
Sets the default distance measurement units for the project.
Sets the project's ellipsoid from a proj string representation, e.g., "WGS84".
Defines if default values should be evaluated on provider side when requested and not when committed.
Sets the file name associated with the project.
Sets the
type
of paths used when storing file paths in a QGS/QGZ project file.Sets whether a project
flag
isenabled
.Sets the project's
flags
, which dictate the behavior of the project.Set the current project singleton instance to
project
Sets project's global labeling engine settings
Sets the list of custom project map
scales
.Sets the project's
metadata
store.Set a list of layers which should not be taken into account on map identification
Sets the original
path
associated with the project.Sets the project's home
path
.Sets the
colors
for the project's color scheme (seeQgsProjectColorScheme
).Configures a set of map layers that are required in the project and therefore they should not get removed from the project.
Sets the
color
used to highlight selected features.The snapping configuration for this project.
Sets the project's title.
Convenience function to set topological editing
Set transaction mode
Sets the project's coordinate transform
context
, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.Sets the trust option allowing to indicate if the extent has to be read from the XML document when data source has no metadata or if the data provider has to determine it.
Sets whether project
mapScales()
areenabled
.The snapping configuration for this project.
Makes the layer editable.
Returns the project's style settings, which contains settings and properties relating to how a
QgsProject
should handle styling.Returns a list of child keys which contain other keys that exist within the the specified
scope
andkey
.Takes a layer from the registry.
Returns the project's time settings, which contains the project's temporal range and other time based settings.
Returns the project's title.
Convenience function to query topological editing status
Returns the matching transaction group from a provider key and connection string.
Returns the transaction mode
Returns a copy of the project's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.
Translates the project with QTranslator and qm file
Returns
True
if the trust option is activated,False
otherwise.Returns
True
if projectmapScales()
are enabled.Returns the number of registered valid layers.
Returns the project's view settings, which contains settings and properties relating to how a
QgsProject
should be viewed and behave inside a map canvas (e.g.Returns the project's views manager, which manages map views (including 3d maps) in the project.
Writes the project to a file.
Write an integer
value
to the project file.Write a boolean
value
to the project file.Write a double
value
to the project file.Prepare a filename to save it to the project file.
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
Attributes
- AllProperties = 1¶
- class AvoidIntersectionsMode(value)¶
Bases:
enum.IntEnum
Flags which control how intersections of pre-existing feature are handled when digitizing new features.
Note
Prior to QGIS 3.26 this was available as
QgsProject
.AvoidIntersectionsModeNew in version 3.26.
AllowIntersections
: Overlap with any feature allowed when digitizing new featuresAvoidIntersectionsCurrentLayer
: Overlap with features from the active layer when digitizing new features not allowedAvoidIntersectionsLayers
: Overlap with features from a specified list of layers when digitizing new features not allowed
- class DataDefinedServerProperty¶
Bases:
int
- FileFormat¶
alias of
ProjectFileFormat
- NoProperty = 0¶
- ReadFlag¶
alias of
ProjectReadFlag
- ReadFlags¶
alias of
ProjectReadFlags
- WMSOnlineResource = 2¶
- absoluteFilePath(self) str ¶
Returns full absolute path to the project file if the project is stored in a file system - derived from
fileName()
. Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages).New in version 3.2.
- Return type:
str
- absolutePath(self) str ¶
Returns full absolute path to the project folder if the project is stored in a file system - derived from
fileName()
. Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages).New in version 3.2.
- Return type:
str
- accept(self, visitor: QgsStyleEntityVisitorInterface) bool ¶
Accepts the specified style entity
visitor
, causing it to visit all style entities associated with the project.Returns
True
if the visitor should continue visiting other objects, orFalse
if visiting should be canceled.New in version 3.10.
- Parameters:
visitor (QgsStyleEntityVisitorInterface) –
- Return type:
bool
- addMapLayer(self, mapLayer: QgsMapLayer, addToLegend: bool = True) QgsMapLayer ¶
Add a layer to the map of loaded layers.
The
layersAdded()
andlayerWasAdded()
signals will always be emitted. ThelegendLayersAdded()
signal is emitted only if addToLegend isTrue
. If you are adding multiple layers at once, you should useaddMapLayers()
instead.- Parameters:
mapLayer (QgsMapLayer) – A layer to add to the registry
addToLegend (bool = True) – If
True
(by default), the layer will be added to the legend and to the main canvas. If you have a private layer you can set this parameter toFalse
to hide it.
- Return type:
- Returns:
None
if unable to add layer, otherwise pointer to newly added layer
See also
Note
As a side-effect
QgsProject
is made dirty.Note
Use addMapLayers if adding more than one layer at a time
Note
takeOwnership is not available in the Python bindings - the registry will always take ownership
See also
- addMapLayers(self, mapLayers: Iterable[QgsMapLayer], addToLegend: bool = True) List[QgsMapLayer] ¶
Add a list of layers to the map of loaded layers.
The
layersAdded()
andlayerWasAdded()
signals will always be emitted. ThelegendLayersAdded()
signal is emitted only if addToLegend isTrue
.- Parameters:
mapLayers (Iterable[QgsMapLayer]) – A list of layer which should be added to the registry
addToLegend (bool = True) – If
True
(by default), the layers will be added to the legend and to the main canvas. If you have a private layer you can set this parameter toFalse
to hide it.
- Return type:
List[QgsMapLayer]
- Returns:
a list of the map layers that were added successfully. If a layer or already exists in the registry, it will not be part of the returned QList.
Note
As a side-effect
QgsProject
is made dirty.Note
takeOwnership is not available in the Python bindings - the registry will always take ownership
See also
New in version 1.8.
- annotationManager(self) QgsAnnotationManager ¶
Returns pointer to the project’s annotation manager.
New in version 3.0.
- Return type:
- areaUnits(self) QgsUnitTypes.AreaUnit ¶
Convenience function to query default area measurement units for project.
See also
New in version 2.14.
- Return type:
- areaUnitsChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- attachedFiles(self) List[str] ¶
Returns a map of all attached files with identifier and real paths.
See also
New in version 3.22.
- Return type:
List[str]
- attachmentIdentifier(self, attachedFile: str) str ¶
Returns an identifier for an attachment file path An attachment identifier is a string which does not depend on the project archive storage location.
- Parameters:
attachedFile (str) – An attachment file path
- Return type:
str
- Returns:
An identifier for the attached file
New in version 3.22.
- autoTransaction(self) bool ¶
Transactional editing means that on supported datasources (postgres databases) the edit state of all tables that originate from the same database are synchronized and executed in a server side transaction.
New in version 2.16.
Deprecated since version QGIS: 3.26 use transactionMode instead
- Return type:
bool
- auxiliaryStorage(self) QgsAuxiliaryStorage ¶
Returns the current auxiliary storage.
New in version 3.0.
- Return type:
- avoidIntersectionsLayers(self) List[QgsVectorLayer] ¶
A list of layers with which intersections should be avoided.
New in version 3.0.
- Return type:
List[QgsVectorLayer]
- avoidIntersectionsLayersChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- avoidIntersectionsMode(self) Qgis.AvoidIntersectionsMode ¶
Returns the current avoid intersections mode.
New in version 3.14.
- Return type:
- avoidIntersectionsModeChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- backgroundColor(self) QColor ¶
Returns the default background color used by default map canvases.
See also
New in version 3.10.
- Return type:
QColor
- backgroundColorChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- baseName(self) str ¶
Returns the base name of the project file without the path and without extension - derived from
fileName()
.New in version 3.2.
- Return type:
str
- blockDirtying¶
alias of
ProjectDirtyBlocker
- bookmarkManager(self) QgsBookmarkManager ¶
Returns the project’s bookmark manager, which manages bookmarks within the project.
New in version 3.10.
- Return type:
- capabilities(self) Qgis.ProjectCapabilities ¶
Returns the project’s capabilities, which dictate optional functionality which can be selectively enabled for a
QgsProject
object.New in version 3.26.1.
- Return type:
- childEvent(self, QChildEvent)¶
- clear(self)¶
Clears the project, removing all settings and resetting it back to an empty, default state.
See also
New in version 2.4.
- cleared¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- commitChanges(self, stopEditing: bool = True, vectorLayer: QgsVectorLayer = None) Tuple[bool, List[str]] ¶
Attempts to commit to the underlying data provider any buffered changes made since the last to call to
startEditing()
.Returns the result of the attempt. If a commit fails (i.e.
False
is returned), the in-memory changes are left untouched and are not discarded. This allows editing to continue if the commit failed on e.g. a disallowed value in a Postgres database - the user can re-edit and try again.The commits occur in distinct stages, (add attributes, add features, change attribute values, change geometries, delete features, delete attributes) so if a stage fails, it can be difficult to roll back cleanly. Therefore any error message returned by commitErrors also includes which stage failed so that the user has some chance of repairing the damage cleanly.
- Parameters:
stopEditing (bool = True) – if set to
False
, the layer will stay in editing mode. Otherwise the layer editing mode will be disabled if the commit is successful.vectorLayer (
QgsVectorLayer
= None) – for which the changes will be committed. For buffered transactions this parameter is not mandatory, as the changes from all layers will be committed.
- Return type:
Tuple[bool, List[str]]
- Returns:
True
if the commit was successful.commitErrors: will be set to a list of descriptive errors if the commit fails.
See also
See also
New in version 3.26.
- connectNotify(self, QMetaMethod)¶
- count(self) int ¶
Returns the number of registered layers.
- Return type:
int
- createAttachedFile(self, nameTemplate: str) str ¶
Attaches a file to the project
- Parameters:
nameTemplate (str) – Any filename template, used as a basename for attachment file, i.e. “myfile.ext”
- Return type:
str
- Returns:
The path to the file where the contents can be written to.
Note
If the attachment file is used as a source for a project layer, the attachment will be removed automatically when the layer is deleted.
New in version 3.22.
- createEmbeddedGroup(self, groupName: str, projectFilePath: str, invisibleLayers: Iterable[str], flags: Qgis.ProjectReadFlags | Qgis.ProjectReadFlag = Qgis.ProjectReadFlags()) QgsLayerTreeGroup ¶
Create layer group instance defined in an arbitrary project file.
The optional
flags
argument can be used to control layer reading behavior.New in version 2.4.
- Parameters:
groupName (str) –
projectFilePath (str) –
invisibleLayers (Iterable[str]) –
flags (Union[Qgis.ProjectReadFlags) –
- Return type:
- createExpressionContext(self) QgsExpressionContext ¶
- Return type:
- createExpressionContextScope(self) QgsExpressionContextScope ¶
- Return type:
- crs(self) QgsCoordinateReferenceSystem ¶
Returns the project’s native coordinate reference system.
See also
See also
New in version 3.0.
- Return type:
- crsChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- customEvent(self, QEvent)¶
- customVariables(self) Dict[str, Any] ¶
A map of custom project variables. To get all available variables including generated ones use
QgsExpressionContextUtils.projectScope()
instead.- Return type:
Dict[str, Any]
- customVariablesChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- dataDefinedServerProperties(self) QgsPropertyCollection ¶
Returns the data defined properties used for overrides in user defined server parameters
New in version 3.14.
- Return type:
- defaultCrsForNewLayers(self) QgsCoordinateReferenceSystem ¶
Returns the default CRS for new layers based on the settings and the current project CRS
- Return type:
- dirtySet¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- disconnectNotify(self, QMetaMethod)¶
- displaySettings(self) QgsProjectDisplaySettings ¶
Returns the project’s display settings, which settings and properties relating to how a
QgsProject
should display values such as map coordinates and bearings.New in version 3.12.
- Return type:
- distanceUnits(self) QgsUnitTypes.DistanceUnit ¶
Convenience function to query default distance measurement units for project.
See also
See also
New in version 2.14.
- Return type:
- distanceUnitsChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- dumpProperties(self)¶
Dump out current project properties to stderr
- editBufferGroup(self) QgsVectorLayerEditBufferGroup ¶
Returns the edit buffer group
New in version 3.26.
- Return type:
- elevationProperties(self) QgsProjectElevationProperties ¶
Returns the project’s elevation properties, which contains the project’s elevation related settings.
New in version 3.26.
- Return type:
- ellipsoid(self) str ¶
Returns a proj string representing the project’s ellipsoid setting, e.g., “WGS84”.
See also
See also
New in version 3.0.
- Return type:
str
- ellipsoidChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- entryList(self, scope: str, key: str) List[str] ¶
Returns a list of child keys with values which exist within the the specified
scope
andkey
.This method does not return keys that contain other keys. See
subkeyList()
to retrieve keys which contain other keys.Note
equivalent to
QgsSettings
entryList()
- Parameters:
scope (str) –
key (str) –
- Return type:
List[str]
- error(self) str ¶
Returns error message from previous read/write
- Return type:
str
- evaluateDefaultValues(self) bool ¶
Should default values be evaluated on provider side when requested and not when committed.
Deprecated since version Test: whether the
flags()
method returns the Qgis.ProjectFlag.EvaluateDefaultValuesOnProviderSide flag instead.- Return type:
bool
- fileInfo(self) QFileInfo ¶
Returns QFileInfo object for the project’s associated file.
Note
The use of this method is discouraged since QGIS 3.2 as it only works with project files stored in the file system. It is recommended to use
absoluteFilePath()
,baseName()
,lastModifiedTime()
as replacements that are aware of the fact that projects may be saved in other project storages.See also
Deprecated since version QGIS: 3.2 use
absoluteFilePath()
,baseName()
orlastModifiedTime()
instead- Return type:
QFileInfo
- fileName(self) str ¶
Returns the project’s file name. This is the file or the storage URI which contains the project’s XML representation.
See also
See also
- Return type:
str
- fileNameChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- filePathStorage(self) Qgis.FilePathType ¶
Returns the type of paths used when storing file paths in a QGS/QGZ project file.
See also
New in version 3.22.
- Return type:
- flags(self) Qgis.ProjectFlags ¶
Returns the project’s flags, which dictate the behavior of the project.
See also
See also
New in version 3.26.
- Return type:
- generateTsFile(self, locale: str)¶
Triggers the collection strings of .qgs to be included in ts file and calls
writeTsFile()
New in version 3.4.
- Parameters:
locale (str) –
- homePath(self) str ¶
Returns the project’s home path. This will either be a manually set home path (see
presetHomePath()
) or the path containing the project file itself.This method always returns the absolute path to the project’s home. See
presetHomePath()
to retrieve any manual project home path override (e.g. relative home paths).See also
See also
See also
- Return type:
str
- homePathChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- instance() QgsProject ¶
Returns the
QgsProject
singleton instance- Return type:
- isDirty(self) bool ¶
Returns
True
if the project has been modified since the lastwrite()
- Return type:
bool
- isDirtyChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- isSignalConnected(self, QMetaMethod) bool ¶
- isZipped(self) bool ¶
Returns
True
if the project comes from a zip archive,False
otherwise.- Return type:
bool
- labelingEngineSettings(self) QgsLabelingEngineSettings ¶
Returns project’s global labeling engine settings
New in version 3.0.
- Return type:
- labelingEngineSettingsChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- lastModified(self) QDateTime ¶
Returns last modified time of the project file as returned by the file system (or other project storage).
New in version 3.2.
- Return type:
QDateTime
- lastSaveDateTime(self) QDateTime ¶
Returns the date and time when the project was last saved.
New in version 3.14.
- Return type:
QDateTime
- lastSaveVersion(self) QgsProjectVersion ¶
Returns the QGIS version which the project was last saved using.
New in version 3.14.
- Return type:
- layerIsEmbedded(self, id: str) str ¶
Returns the source project file path if the layer with matching
id
is embedded from other project file.Returns an empty string if the matching layer is not embedded.
- Parameters:
id (str) –
- Return type:
str
- layerLoaded¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- layerRemoved¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- layerStore(self) QgsMapLayerStore ¶
Returns a pointer to the project’s internal layer store. /since QGIS 3.0
- Return type:
- layerTreeRegistryBridge(self) QgsLayerTreeRegistryBridge ¶
Returns pointer to the helper class that synchronizes map layer registry with layer tree
New in version 2.4.
- Return type:
- layerTreeRoot(self) QgsLayerTree ¶
Returns pointer to the root (invisible) node of the project’s layer tree
New in version 2.4.
- Return type:
- layerWasAdded¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- layerWillBeRemoved¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- layersAdded¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- layersRemoved¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- layersWillBeRemoved¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- layoutManager(self) QgsLayoutManager ¶
Returns the project’s layout manager, which manages print layouts, atlases and reports within the project.
New in version 3.0.
- Return type:
- legendLayersAdded¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- loadingLayer¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- loadingLayerMessageReceived¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- mainAnnotationLayer(self) QgsAnnotationLayer ¶
Returns the main annotation layer associated with the project.
This layer is always present in projects, and will always be rendered above any other map layers during map render jobs.
It forms the default location to place new annotation items which should appear above all map layers.
New in version 3.16.
- Return type:
- mapLayer(self, layerId: str) QgsMapLayer ¶
Retrieve a pointer to a registered layer by layer ID.
- Parameters:
layerId (str) – ID of layer to retrieve
- Return type:
- Returns:
matching layer, or
None
if no matching layer found
See also
See also
- mapLayers(self, validOnly: bool = False) object ¶
Returns a map of all registered layers by layer ID.
- Parameters:
validOnly (bool = False) – if set only valid layers will be returned
See also
See also
See also
layers()
- Return type:
object
- mapLayersByName(self, layerName: str) List[QgsMapLayer] ¶
Retrieve a list of matching registered layers by layer name.
- Parameters:
layerName (str) – name of layers to match
- Return type:
List[QgsMapLayer]
- Returns:
list of matching layers
See also
See also
- mapLayersByShortName(self, shortName: str) List[QgsMapLayer] ¶
Retrieves a list of matching registered layers by layer
shortName
. If layer’s short name is empty a match with layer’s name is attempted.- Return type:
List[QgsMapLayer]
- Returns:
list of matching layers
See also
See also
New in version 3.10.
- Parameters:
shortName (str) –
- mapScales(self) List[float] ¶
Returns the list of custom project map scales.
The scales list consists of a list of scale denominator values, e.g. 1000 for a 1:1000 scale.
See also
See also
Deprecated since version Use:
viewSettings()
instead- Return type:
List[float]
- mapScalesChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- mapThemeCollection(self) QgsMapThemeCollection ¶
Returns pointer to the project’s map theme collection.
Note
renamed in QGIS 3.0, formerly
QgsVisibilityPresetCollection
New in version 2.12.
- Return type:
- mapThemeCollectionChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- metadata(self) QgsProjectMetadata ¶
Returns a reference to the project’s metadata store.
See also
See also
New in version 3.2.
- Return type:
- metadataChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- missingDatumTransforms¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- nonIdentifiableLayers(self) List[str] ¶
Gets the list of layers which currently should not be taken into account on map identification
Deprecated since version QGIS: 3.4 use
QgsMapLayer.setFlags()
instead- Return type:
List[str]
- nonIdentifiableLayersChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- oldProjectVersionWarning¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- originalPath(self) str ¶
Returns the original path associated with the project.
This is intended for use with non-qgs/qgz project files (see
QgsCustomProjectOpenHandler
) in order to allow custom project open handlers to specify the original file name of the project. For custom project formats, it is NOT appropriate to callsetFileName()
with the original project path, as this causes the original (non QGIS) project file to be overwritten when the project is next saved.See also
New in version 3.14.
- Return type:
str
- pathResolver(self) QgsPathResolver ¶
Returns path resolver object with considering whether the project uses absolute or relative paths and using current project’s path.
New in version 3.0.
- Return type:
- presetHomePath(self) str ¶
Returns any manual project home path setting, or an empty string if not set.
This path may be a relative path. See
homePath()
to retrieve a path which is always an absolute path.See also
See also
See also
New in version 3.2.
- Return type:
str
- projectColorsChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- projectSaved¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- projectStorage(self) QgsProjectStorage ¶
Returns pointer to project storage implementation that handles read/write of the project file. If the project file is stored in the local file system, returns
None
. The project storage object is inferred fromfileName()
of the project.New in version 3.2.
- Return type:
- read(self, filename: str, flags: Qgis.ProjectReadFlags | Qgis.ProjectReadFlag = Qgis.ProjectReadFlags()) bool ¶
Reads given project file from the given file.
- Parameters:
filename (str) – name of project file to read
flags (Union[Qgis.ProjectReadFlags) – optional flags which control the read behavior of projects
- Returns:
True
if project file has been read successfully
read(self, flags: Union[Qgis.ProjectReadFlags, Qgis.ProjectReadFlag] = Qgis.ProjectReadFlags()) -> bool Reads the project from its currently associated file (see
fileName()
).The
flags
argument can be used to specify optional flags which control the read behavior of projects.- Return type:
bool
- Returns:
True
if project file has been read successfully
- readBoolEntry(self, scope: str, key: str, def_: bool = False) Tuple[bool, bool] ¶
Reads a boolean from the specified
scope
andkey
.- Parameters:
scope (str) – entry scope (group) name
key (str) – entry key name. Keys are ‘/’-delimited entries, implying a hierarchy of keys and corresponding values.
def (bool = False) – default value to return if the specified
key
does not exist within thescope
.def –
- Return type:
Tuple[bool, bool]
- Returns:
entry value as boolean from
scope
given itskey
ok: set to
True
if key exists and has been successfully retrieved as a boolean
- readDoubleEntry(self, scope: str, key: str, def_: float = 0) Tuple[float, bool] ¶
Reads a double from the specified
scope
andkey
.- Parameters:
scope (str) – entry scope (group) name
key (str) – entry key name. Keys are ‘/’-delimited entries, implying a hierarchy of keys and corresponding values.
def (float = 0) – default value to return if the specified
key
does not exist within thescope
.def –
- Return type:
Tuple[float, bool]
- Returns:
entry value as double from
scope
given itskey
ok: set to
True
if key exists and has been successfully retrieved as a double
- readEntry(self, scope: str, key: str, def_: str = '') Tuple[str, bool] ¶
Reads a string from the specified
scope
andkey
.- Parameters:
scope (str) – entry scope (group) name
key (str) – entry key name. Keys are ‘/’-delimited entries, implying a hierarchy of keys and corresponding values.
def (str = '') – default value to return if the specified
key
does not exist within thescope
.def –
- Return type:
Tuple[str, bool]
- Returns:
entry value as string from
scope
given itskey
ok: set to
True
if key exists and has been successfully retrieved as a string value
- readLayer(self, layerNode: QDomNode) bool ¶
Reads the layer described in the associated DOM node.
Note
This method is mainly for use by
QgsProjectBadLayerHandler
subclasses that may fix definition of bad layers with the user’s help in GUI. Calling this method with corrected DOM node adds the layer back to the project.- Parameters:
layerNode (QDomNode) – represents a
QgsProject
DOM node that encodes a specific layer.- Return type:
bool
- readListEntry(self, scope: str, key: str, def_: Iterable[str] = []) Tuple[List[str], bool] ¶
Reads a string list from the specified
scope
andkey
.- Parameters:
scope (str) – entry scope (group) name
key (str) – entry key name. Keys are ‘/’-delimited entries, implying a hierarchy of keys and corresponding values.
def (Iterable[str] = []) – default value to return if the specified
key
does not exist within thescope
.def –
- Return type:
Tuple[List[str], bool]
- Returns:
entry value as a string list
ok: set to
True
if key exists and has been successfully retrieved as a string list
- readMapLayer¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- readNumEntry(self, scope: str, key: str, def_: int = 0) Tuple[int, bool] ¶
Reads an integer from the specified
scope
andkey
.- Parameters:
scope (str) – entry scope (group) name
key (str) – entry key name. Keys are ‘/’-delimited entries, implying a hierarchy of keys and corresponding values.
def (int = 0) – default value to return if the specified
key
does not exist within thescope
.def –
- Return type:
Tuple[int, bool]
- Returns:
entry value as integer from
scope
given itskey
ok: set to
True
if key exists and has been successfully retrieved as an integer
- readPath(self, filename: str) str ¶
Transforms a
filename
read from the project file to an absolute path.- Parameters:
filename (str) –
- Return type:
str
- readProject¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- readProjectWithContext¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- readVersionMismatchOccurred¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- receivers(self, PYQT_SIGNAL) int ¶
- registerTranslatableContainers(self, translationContext: QgsTranslationContext, parent: QgsAttributeEditorContainer, layerId: str)¶
Registers the containers that require translation into the translationContext. This is a recursive function to get all the child containers.
- Parameters:
translationContext (QgsTranslationContext) – where the objects will be registered
parent (QgsAttributeEditorContainer) – parent-container containing list of children
layerId (str) – to store under the correct context
New in version 3.4.
- registerTranslatableObjects(self, translationContext: QgsTranslationContext)¶
Registers the objects that require translation into the
translationContext
. So there can be created a ts file with these values.New in version 3.4.
- Parameters:
translationContext (QgsTranslationContext) –
- relationManager(self) QgsRelationManager ¶
- Return type:
- reloadAllLayers(self)¶
Reload all registered layer’s provider data caches, synchronising the layer with any changes in the datasource.
See also
- removeAll¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- removeAllMapLayers(self)¶
Removes all registered layers. If the registry has ownership of any layers these layers will also be deleted.
Note
As a side-effect the
QgsProject
instance is marked dirty.Note
Calling this method will cause the
removeAll()
signal to be emitted.See also
See also
- removeAttachedFile(self, path: str) bool ¶
Removes the attached file
- Parameters:
path (str) – Path to the attached file
- Return type:
bool
- Returns:
Whether removal succeeded.
See also
New in version 3.22.
- removeEntry(self, scope: str, key: str) bool ¶
Remove the given
key
from the specifiedscope
.- Parameters:
scope (str) –
key (str) –
- Return type:
bool
- removeMapLayer(self, layerId: str)¶
Remove a layer from the registry by layer ID.
The specified layer will be removed from the registry. If the registry has ownership of the layer then it will also be deleted.
- Parameters:
layerId (str) – ID of the layer to remove
Note
As a side-effect the
QgsProject
instance is marked dirty.See also
See also
removeMapLayer(self, layer:
QgsMapLayer
) Remove a layer from the registry.The specified layer will be removed from the registry. If the registry has ownership of the layer then it will also be deleted.
- Parameters:
layer – The layer to remove.
None
values are ignored.
Note
As a side-effect the
QgsProject
instance is marked dirty.See also
See also
- removeMapLayers(self, layerIds: Iterable[str])¶
Remove a set of layers from the registry by layer ID.
The specified layers will be removed from the registry. If the registry has ownership of any layers these layers will also be deleted.
- Parameters:
layerIds (Iterable[str]) – list of IDs of the layers to remove
Note
As a side-effect the
QgsProject
instance is marked dirty.See also
See also
New in version 1.8.
removeMapLayers(self, layers: Iterable[QgsMapLayer]) Remove a set of layers from the registry.
The specified layers will be removed from the registry. If the registry has ownership of any layers these layers will also be deleted.
- Parameters:
layers – A list of layers to remove.
None
values are ignored.
Note
As a side-effect the
QgsProject
instance is marked dirty.See also
See also
- requiredLayers(self) Set[QgsMapLayer] ¶
Returns a set of map layers that are required in the project and therefore they should not get removed from the project. The set of layers may be configured by users in project properties. and it is mainly a hint for the user interface to protect users from removing layers that important in the project. The
removeMapLayer()
,removeMapLayers()
calls do not block removal of layers listed here.Deprecated since version QGIS: 3.4 use
QgsMapLayer.flags()
insteadNew in version 3.2.
- Return type:
Set[QgsMapLayer]
- resolveAttachmentIdentifier(self, identifier: str) str ¶
Resolves an attachment identifier to a attachment file path
- Parameters:
identifier (str) – An attachment identifier
- Return type:
str
- Returns:
The attachment file path, or an empty string if the identifier is invalid
New in version 3.22.
- rollBack(self, stopEditing: bool = True, vectorLayer: QgsVectorLayer = None) Tuple[bool, List[str]] ¶
Stops a current editing operation on vectorLayer and discards any uncommitted edits.
- Parameters:
stopEditing (bool = True) – if set to
False
, the layer will stay in editing mode. Otherwise the layer editing mode will be disabled if the rollback is successful.vectorLayer (
QgsVectorLayer
= None) – for which the changes will be rolled back. For buffered transactions this parameter is not mandatory, as the changes from all layers will be rolled back.
- Return type:
Tuple[bool, List[str]]
- Returns:
True
if the rollback was successful.rollbackErrors: will be set to a list of descriptive errors if the rollback fails.
See also
See also
New in version 3.26.
- saveUser(self) str ¶
Returns the user name that did the last save.
See also
New in version 3.12.
- Return type:
str
- saveUserFullName(self) str ¶
Returns the full user name that did the last save.
See also
New in version 3.12.
- Return type:
str
- selectionColor(self) QColor ¶
Returns the color used to highlight selected features
See also
New in version 3.10.
- Return type:
QColor
- selectionColorChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setAreaUnits(self, unit: QgsUnitTypes.AreaUnit)¶
Sets the default area measurement units for the project.
See also
See also
New in version 3.0.
- Parameters:
unit (QgsUnitTypes.AreaUnit) –
- setAutoTransaction(self, autoTransaction: bool)¶
Transactional editing means that on supported datasources (postgres databases) the edit state of all tables that originate from the same database are synchronized and executed in a server side transaction.
Warning
Make sure that this is only called when all layers are not in edit mode.
New in version 2.16.
Deprecated since version QGIS: 3.26 use setTransactionMode instead
- Parameters:
autoTransaction (bool) –
- setAvoidIntersectionsLayers(self, layers: Iterable[QgsVectorLayer])¶
Sets the list of layers with which intersections should be avoided. Only used if the avoid intersection mode is set to advanced.
New in version 3.0.
- Parameters:
layers (Iterable[QgsVectorLayer]) –
- setAvoidIntersectionsMode(self, mode: Qgis.AvoidIntersectionsMode)¶
Sets the avoid intersections mode.
New in version 3.14.
- Parameters:
mode (Qgis.AvoidIntersectionsMode) –
- setBackgroundColor(self, color: QColor | Qt.GlobalColor | QGradient)¶
Sets the default background
color
used by default map canvases.See also
New in version 3.10.
- Parameters:
color (Union[QColor) –
- setBadLayerHandler(self, handler: QgsProjectBadLayerHandler)¶
Change handler for missing layers. Deletes old handler and takes ownership of the new one.
- Parameters:
handler (QgsProjectBadLayerHandler) –
- setCrs(self, crs: QgsCoordinateReferenceSystem, adjustEllipsoid: bool = False)¶
Sets the project’s native coordinate reference system. If
adjustEllipsoid
is set toTrue
, the ellpsoid of this project will be set to the ellipsoid imposed by the CRS.See also
See also
New in version 3.0.
- Parameters:
crs (QgsCoordinateReferenceSystem) –
adjustEllipsoid (bool = False) –
- setCustomVariables(self, customVariables: Dict[str, Any])¶
A map of custom project variables. Be careful not to set generated variables.
- Parameters:
customVariables (Dict[str) –
- setDataDefinedServerProperties(self, properties: QgsPropertyCollection)¶
Sets the data defined properties used for overrides in user defined server parameters to
properties
New in version 3.14.
- Parameters:
properties (QgsPropertyCollection) –
- setDirty(self, b: bool = True)¶
Flag the project as dirty (modified). If this flag is set, the user will be asked to save changes to the project before closing the current project.
Note
promoted to public slot in 2.16
New in version 2.4.
- Parameters:
b (bool = True) –
- setDistanceUnits(self, unit: QgsUnitTypes.DistanceUnit)¶
Sets the default distance measurement units for the project.
See also
See also
New in version 3.0.
- Parameters:
unit (QgsUnitTypes.DistanceUnit) –
- setEllipsoid(self, ellipsoid: str)¶
Sets the project’s ellipsoid from a proj string representation, e.g., “WGS84”.
See also
See also
New in version 3.0.
- Parameters:
ellipsoid (str) –
- setEvaluateDefaultValues(self, evaluateDefaultValues: bool)¶
Defines if default values should be evaluated on provider side when requested and not when committed.
Deprecated since version use: setFlag( Qgis.ProjectFlag.EvaluateDefaultValuesOnProviderSide ) instead.
- Parameters:
evaluateDefaultValues (bool) –
- setFileName(self, name: str)¶
Sets the file name associated with the project. This is the file or the storage URI which contains the project’s XML representation.
- Parameters:
name (str) – project file name
See also
- setFilePathStorage(self, type: Qgis.FilePathType)¶
Sets the
type
of paths used when storing file paths in a QGS/QGZ project file.See also
New in version 3.22.
- Parameters:
type (Qgis.FilePathType) –
- setFlag(self, flag: Qgis.ProjectFlag, enabled: bool = True)¶
Sets whether a project
flag
isenabled
.See also
See also
New in version 3.26.
- Parameters:
flag (Qgis.ProjectFlag) –
enabled (bool = True) –
- setFlags(self, flags: Qgis.ProjectFlags | Qgis.ProjectFlag)¶
Sets the project’s
flags
, which dictate the behavior of the project.See also
See also
New in version 3.26.
- Parameters:
flags (Union[Qgis.ProjectFlags) –
- setInstance(project: QgsProject)¶
Set the current project singleton instance to
project
Note
this method is provided mainly for the server, which caches the projects and (potentially) needs to switch the current instance on every request.
Warning
calling this method can have serious, unintended consequences, including instability, data loss and undefined behavior. Use with EXTREME caution!
See also
New in version 3.10.11.
- Parameters:
project (QgsProject) –
- setLabelingEngineSettings(self, settings: QgsLabelingEngineSettings)¶
Sets project’s global labeling engine settings
New in version 3.0.
- Parameters:
settings (QgsLabelingEngineSettings) –
- setMapScales(self, scales: Iterable[float])¶
Sets the list of custom project map
scales
.The
scales
list consists of a list of scale denominator values, e.g. 1000 for a 1:1000 scale.See also
See also
Deprecated since version Use:
viewSettings()
instead- Parameters:
scales (Iterable[float]) –
- setMetadata(self, metadata: QgsProjectMetadata)¶
Sets the project’s
metadata
store.See also
See also
New in version 3.2.
- Parameters:
metadata (QgsProjectMetadata) –
- setNonIdentifiableLayers(self, layers: Iterable[QgsMapLayer])¶
Set a list of layers which should not be taken into account on map identification
Deprecated since version QGIS: 3.4 use
QgsMapLayer.setFlags()
insteadsetNonIdentifiableLayers(self, layerIds: Iterable[str]) Set a list of layers which should not be taken into account on map identification
Deprecated since version QGIS: 3.4 use
QgsMapLayer.setFlags()
instead- Parameters:
layers (Iterable[QgsMapLayer]) –
- setOriginalPath(self, path: str)¶
Sets the original
path
associated with the project.This is intended for use with non-qgs/qgz project files (see
QgsCustomProjectOpenHandler
) in order to allow custom project open handlers to specify the original file name of the project. For custom project formats, it is NOT appropriate to callsetFileName()
with the original project path, as this causes the original (non QGIS) project file to be overwritten when the project is next saved.See also
New in version 3.14.
- Parameters:
path (str) –
- setPresetHomePath(self, path: str)¶
Sets the project’s home
path
. If an empty path is specified than the home path will be automatically determined from the project’s file path.See also
See also
See also
New in version 3.2.
- Parameters:
path (str) –
- setProjectColors(self, colors: Iterable[Tuple[QColor | Qt.GlobalColor | QGradient, str]])¶
Sets the
colors
for the project’s color scheme (seeQgsProjectColorScheme
).See also
New in version 3.6.
- Parameters:
colors (Iterable[Tuple[Union[QColor) –
- setRequiredLayers(self, layers: Iterable[QgsMapLayer])¶
Configures a set of map layers that are required in the project and therefore they should not get removed from the project. The set of layers may be configured by users in project properties. and it is mainly a hint for the user interface to protect users from removing layers that important in the project. The
removeMapLayer()
,removeMapLayers()
calls do not block removal of layers listed here.Deprecated since version QGIS: 3.4 use
QgsMapLayer.setFlags()
insteadNew in version 3.2.
- Parameters:
layers (Iterable[QgsMapLayer]) –
- setSelectionColor(self, color: QColor | Qt.GlobalColor | QGradient)¶
Sets the
color
used to highlight selected features.See also
New in version 3.10.
- Parameters:
color (Union[QColor) –
- setSnappingConfig(self, snappingConfig: QgsSnappingConfig)¶
The snapping configuration for this project.
New in version 3.0.
- Parameters:
snappingConfig (QgsSnappingConfig) –
- setTitle(self, title: str)¶
Sets the project’s title.
- Parameters:
title (str) – new title
Note
Since QGIS 3.2 this is just a shortcut to setting the title in the project’s
metadata()
.See also
New in version 2.4.
- setTopologicalEditing(self, enabled: bool)¶
Convenience function to set topological editing
- Parameters:
enabled (bool) –
- setTransactionMode(self, transactionMode: Qgis.TransactionMode) bool ¶
Set transaction mode
- Return type:
bool
- Returns:
True
if the transaction mode could be changed
Note
Transaction mode can be changed only when all layers are not in edit mode.
See also
Qgis.TransactionMode
New in version 3.26.
- Parameters:
transactionMode (Qgis.TransactionMode) –
- setTransformContext(self, context: QgsCoordinateTransformContext)¶
Sets the project’s coordinate transform
context
, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.See also
See also
New in version 3.0.
- Parameters:
context (QgsCoordinateTransformContext) –
- setTrustLayerMetadata(self, trust: bool)¶
Sets the trust option allowing to indicate if the extent has to be read from the XML document when data source has no metadata or if the data provider has to determine it. Moreover, when this option is activated, primary key unicity is not checked for views and materialized views with Postgres provider.
- Parameters:
trust (bool) –
True
to trust the project,False
otherwise
Deprecated since version Use: setFlag( Qgis.ProjectFlag.TrustStoredLayerStatistics ) instead.
- setUseProjectScales(self, enabled: bool)¶
Sets whether project
mapScales()
areenabled
.See also
See also
Deprecated since version Use:
viewSettings()
instead- Parameters:
enabled (bool) –
- snappingConfig(self) QgsSnappingConfig ¶
The snapping configuration for this project.
New in version 3.0.
- Return type:
- snappingConfigChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- startEditing(self, vectorLayer: QgsVectorLayer = None) bool ¶
Makes the layer editable.
This starts an edit session on vectorLayer. Changes made in this edit session will not be made persistent until
commitChanges()
is called, and can be reverted by callingrollBack()
.- Return type:
bool
- Returns:
True
if the layer was successfully made editable, orFalse
if the operation failed (e.g. due to an underlying read-only data source, or lack of edit support by the backend data provider).
See also
See also
New in version 3.26.
- Parameters:
vectorLayer (
QgsVectorLayer
= None) –
- styleSettings(self) QgsProjectStyleSettings ¶
Returns the project’s style settings, which contains settings and properties relating to how a
QgsProject
should handle styling. (e.g. styling of a newly added vector layer)New in version 3.26.
- Return type:
- subkeyList(self, scope: str, key: str) List[str] ¶
Returns a list of child keys which contain other keys that exist within the the specified
scope
andkey
.This method only returns keys with keys, it will not return keys that contain only values. See
entryList()
to retrieve keys with values.Note
equivalent to
QgsSettings
subkeyList()
- Parameters:
scope (str) –
key (str) –
- Return type:
List[str]
- takeMapLayer(self, layer: QgsMapLayer) QgsMapLayer ¶
Takes a layer from the registry. If the layer was owned by the project, the layer will be returned without deleting it. The caller takes ownership of the layer and is responsible for deleting it.
See also
New in version 3.0.
- Parameters:
layer (QgsMapLayer) –
- Return type:
- timeSettings(self) QgsProjectTimeSettings ¶
Returns the project’s time settings, which contains the project’s temporal range and other time based settings.
New in version 3.14.
- Return type:
- timerEvent(self, QTimerEvent)¶
- title(self) str ¶
Returns the project’s title.
See also
Note
Since QGIS 3.2 this is just a shortcut to retrieving the title from the project’s
metadata()
.- Return type:
str
- topologicalEditing(self) bool ¶
Convenience function to query topological editing status
- Return type:
bool
- topologicalEditingChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- transactionGroup(self, providerKey: str, connString: str) QgsTransactionGroup ¶
Returns the matching transaction group from a provider key and connection string.
Returns
None
if a matching transaction group is not available.New in version 3.2.
- Parameters:
providerKey (str) –
connString (str) –
- Return type:
- transactionGroupsChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- transactionMode(self) Qgis.TransactionMode ¶
Returns the transaction mode
See also
Qgis.TransactionMode
New in version 3.26.
- Return type:
- transformContext(self) QgsCoordinateTransformContext ¶
Returns a copy of the project’s coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.
See also
See also
New in version 3.0.
- Return type:
- transformContextChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- translate(self, context: str, sourceText: str, disambiguation: str = None, n: int = -1) str ¶
Translates the project with QTranslator and qm file
- Return type:
str
- Returns:
the result string (in case there is no QTranslator loaded the sourceText)
- Parameters:
context (str) – describing layer etc.
sourceText (str) – is the identifier of this text
disambiguation (str = None) – it’s the disambiguation
n (int = -1) – if -1 uses the appropriate form
New in version 3.4.
- trustLayerMetadata(self) bool ¶
Returns
True
if the trust option is activated,False
otherwise. This option allows indicateing if the extent has to be read from the XML document when data source has no metadata or if the data provider has to determine it. Moreover, when this option is activated, primary key unicity is not checked for views and materialized views with Postgres provider.Deprecated since version Test: whether the
flags()
method returns the Qgis.ProjectFlag.TrustStoredLayerStatistics flag instead.- Return type:
bool
- useProjectScales(self) bool ¶
Returns
True
if projectmapScales()
are enabled.See also
See also
Deprecated since version Use:
viewSettings()
instead- Return type:
bool
- validCount(self) int ¶
Returns the number of registered valid layers.
- Return type:
int
- viewSettings(self) QgsProjectViewSettings ¶
Returns the project’s view settings, which contains settings and properties relating to how a
QgsProject
should be viewed and behave inside a map canvas (e.g. map scales and default view extent)New in version 3.10.1.
- Return type:
- viewsManager(self) QgsMapViewsManager ¶
Returns the project’s views manager, which manages map views (including 3d maps) in the project.
New in version 3.24.
- Return type:
- write(self, filename: str) bool ¶
Writes the project to a file.
- Parameters:
filename (str) – destination file
- Returns:
True
if project was written successfully
Note
calling this implicitly sets the project’s filename (see
setFileName()
)Note
isDirty()
will be set toFalse
if project is successfully writtenNew in version 3.0.
write(self) -> bool Writes the project to its current associated file (see
fileName()
).- Return type:
bool
- Returns:
True
if project was written successfully
Note
isDirty()
will be set toFalse
if project is successfully written
- writeEntry(self, scope: str, key: str, value: int) bool ¶
Write an integer
value
to the project file.Keys are ‘/’-delimited entries, implying a hierarchy of keys and corresponding values
Note
The key string must be valid xml tag names in order to be saved to the file.
See also
writeEntry(self, scope: str, key: str, value: str) -> bool Write a string
value
to the project file.Keys are ‘/’-delimited entries, implying a hierarchy of keys and corresponding values
Note
The key string must be valid xml tag names in order to be saved to the file.
See also
writeEntry(self, scope: str, key: str, value: Iterable[str]) -> bool Write a string list
value
to the project file.Keys are ‘/’-delimited entries, implying a hierarchy of keys and corresponding values
Note
The key string must be valid xml tag names in order to be saved to the file.
See also
- Parameters:
scope (str) –
key (str) –
value (int) –
- Return type:
bool
- writeEntryBool(self, scope: str, key: str, value: bool) bool ¶
Write a boolean
value
to the project file.Keys are ‘/’-delimited entries, implying a hierarchy of keys and corresponding values
Note
The key string must be valid xml tag names in order to be saved to the file.
Note
available in Python bindings as writeEntryBool
See also
- Parameters:
scope (str) –
key (str) –
value (bool) –
- Return type:
bool
- writeEntryDouble(self, scope: str, key: str, value: float) bool ¶
Write a double
value
to the project file.Keys are ‘/’-delimited entries, implying a hierarchy of keys and corresponding values
Note
The key string must be valid xml tag names in order to be saved to the file.
Note
available in Python bindings as writeEntryDouble
See also
- Parameters:
scope (str) –
key (str) –
value (float) –
- Return type:
bool
- writeMapLayer¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- writePath(self, filename: str) str ¶
Prepare a filename to save it to the project file. Creates an absolute or relative path according to the project settings. Paths written to the project file should be prepared with this method.
- Parameters:
filename (str) –
- Return type:
str
- writeProject¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL