Class: QgsProjectionSelectionDialog

A generic dialog to prompt the user for a Coordinate Reference System.

Typically you will use this when you want to prompt the user for a coordinate system identifier e.g. from a plugin you might do this to get an epsg code:

crs = QgsCoordinateReferenceSystem()
mySelector = QgsProjectionSelectionDialog( iface.mainWindow() )
mySelector.setCrs( crs )
if mySelector.exec():
  mCrs = mySelector.crs()

If you wish to embed the projection selector into an existing dialog the you probably want to look at QgsProjectionSelectionWidget instead.

QgsProjectionSelectionDialog

QgsProjectionSelectionDialog

Class Hierarchy

Inheritance diagram of qgis.gui.QgsProjectionSelectionDialog

Base classes

QDialog

QWidget

QObject

QPaintDevice

Methods

crs

Returns the CRS currently selected in the widget.

filters

Returns the filters set on the available CRS.

hasValidSelection

Returns True if the dialog has a valid CRS defined.

setCrs

Sets the initial crs to show within the dialog.

setFilters

Sets filters for the available CRS.

setMessage

Sets a message to show in the dialog.

setNotSetText

Sets the text to show for the not set option.

setOgcWmsCrsFilter

filters this dialog by the given CRSs

setRequireValidSelection

Sets the dialog to require a valid selection only, preventing users from accepting the dialog if no selection is present.

setShowNoProjection

Sets whether a "no/invalid" projection option should be shown.

showNoCrsForLayerMessage

When called, the dialog will show a default "layer has no CRS set" message above the projection selector.

showNoProjection

Returns whether the "no/invalid" projection option is shown.

class qgis.gui.QgsProjectionSelectionDialog[source]

Bases: QDialog

__init__(parent: QWidget | None = None, fl: Qt.WindowFlags | Qt.WindowType = QgsGuiUtils.ModalDialogFlags, filters: QgsCoordinateReferenceSystemProxyModel.Filters | QgsCoordinateReferenceSystemProxyModel.Filter = QgsCoordinateReferenceSystemProxyModel.FilterHorizontal | QgsCoordinateReferenceSystemProxyModel.FilterCompound)

Constructor for QgsProjectionSelectionDialog.

Since QGIS 3.36, the optional filter argument can be used to specify filters on the systems shown in the dialog. The default is to show all horizontal and compound CRS in order to match the behavior of older QGIS releases. The filter can be altered to also include vertical CRS if desired.

Parameters:
crs(self) QgsCoordinateReferenceSystem[source]

Returns the CRS currently selected in the widget.

See also

setCrs()

Return type:

QgsCoordinateReferenceSystem

filters(self) QgsCoordinateReferenceSystemProxyModel.Filters[source]

Returns the filters set on the available CRS.

See also

setFilters()

Added in version 3.36.

Return type:

QgsCoordinateReferenceSystemProxyModel.Filters

hasValidSelection(self) bool[source]

Returns True if the dialog has a valid CRS defined.

Added in version 3.24.

Return type:

bool

setCrs(self, crs: QgsCoordinateReferenceSystem)[source]

Sets the initial crs to show within the dialog.

See also

crs()

Parameters:

crs (QgsCoordinateReferenceSystem)

setFilters(self, filters: QgsCoordinateReferenceSystemProxyModel.Filters | QgsCoordinateReferenceSystemProxyModel.Filter)[source]

Sets filters for the available CRS.

See also

filters()

Added in version 3.36.

Parameters:

filters (Union[QgsCoordinateReferenceSystemProxyModel.Filters, QgsCoordinateReferenceSystemProxyModel.Filter])

setMessage(self, message: str | None)[source]

Sets a message to show in the dialog.

Parameters:

message (Optional[str])

setNotSetText(self, text: str | None, description: str | None = '')[source]

Sets the text to show for the not set option. Note that this option is not shown by default and must be set visible by calling setShowNoProjection().

Since QGIS 3.24, the description argument can be used to specify a detailed description which is shown when the option is selected.

Added in version 3.16.

Parameters:
  • text (Optional[str])

  • description (Optional[str] = '')

setOgcWmsCrsFilter(self, crsFilter: Iterable[str | None])[source]

filters this dialog by the given CRSs

Sets this dialog to filter the available projections to those listed by the given Coordinate Reference Systems.

Parameters:

crsFilter (Iterable[Optional[str]]) – a list of OGC Coordinate Reference Systems to filter the list of projections by. This is useful in (e.g.) WMS situations where you just want to offer what the WMS server can support.

Warning

This function’s behavior is undefined if it is called after the dialog is shown.

setRequireValidSelection(self)[source]

Sets the dialog to require a valid selection only, preventing users from accepting the dialog if no selection is present.

Added in version 3.18.

setShowNoProjection(self, show: bool)[source]

Sets whether a “no/invalid” projection option should be shown. If this option is selected, calling crs() will return an invalid QgsCoordinateReferenceSystem.

Parameters:

show (bool)

showNoCrsForLayerMessage(self)[source]

When called, the dialog will show a default “layer has no CRS set” message above the projection selector.

See also

setMessage()

Added in version 3.16.

showNoProjection(self) bool[source]

Returns whether the “no/invalid” projection option is shown. If this option is selected, calling crs() will return an invalid QgsCoordinateReferenceSystem.

Return type:

bool