[QGIS-Developer] projected CRS

Nyall Dawson nyall.dawson at gmail.com
Wed Oct 13 17:49:19 PDT 2021


On Wed, 13 Oct 2021 at 20:10, Stefan Giese (WhereGroup)
<stefan.giese at wheregroup.com> wrote:
>
> in python I would do it like this one:
>
> l = iface.activeLayer()
> if l.crs().authid() != "":
>     print(l.crs().authid ())
> else:
>     print("No projection")

This isn't quite right -- e.g. a geographic CRS like WGS 84 will still
have an authid ("EPSG:4326"). As Etienne pointed out .isGeographic()
is the correct way to test that.

I think here you might be trying to check instead if the layer has a
valid CRS set (as opposed to "no CRS set"), which should be tested
instead by:

if not l.crs().isValid():
     print("No CRS set")

(Also noting that a perfectly valid CRS may not have an authid if it
came from a custom wkt definition and isn't matched to any official
registry entry)... phew!

Nyall


>
> Am 13.10.2021 um 11:50 schrieb pierluigi de rosa:
>
> Dear all,
>
> mayble a very simple question.
> Is it possible to check quickly if a layer has a projected CRS or not?
> in QgsCoordinateReferenceSystem I have not found a method able to do that check.
> Thanks for your attention
> Pierluigi
>
> --
> Ing. Pierluigi De Rosa (PhD in Earth Science)
> Contract Professor of Geographic Information System at University of Perugia
> cel: 3497558268 / fax: 075 7823038
> skype: pierluigi.derosa
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
> --
> Mit freundlichen Grüßen
> Stefan Giese
> Projektleiter/Consultant
>
> ---------------------------------------------
> Schon gewusst?
> In unserem Blog geben wir Tipps & Tricks zu
> Open-Source-GIS-Software und berichten aus unserem Experten-Alltag:
> https://wheregroup.com/blog/
> ---------------------------------------------
>
> WhereGroup GmbH
> Schwimmbadstr. 2
> 79100 Freiburg
> Germany
>
> Fon: +49 (0)761 / 519 102 - 61
> Fax: +49 (0)761 / 519 102 - 11
>
> stefan.giese at wheregroup.com
> www.wheregroup.com
> Geschäftsführer:
> Olaf Knopp, Peter Stamm
> Amtsgericht Bonn, HRB 9885
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the QGIS-Developer mailing list