Consider the following CRS as examples:
QgsCoordinateReferenceSystem.fromEpsgId(4326)
QgsCoordinateReferenceSystem.fromEpsgId(25832)
QgsCoordinateReferenceSystem.fromEpsgId(3857)
How can I determine programmatically which axes they have and which axis is latitude/longitude resp. northing/easting resp. x/y if I have a QgsPoint
geometry in such system with a .x()
and .y()
coordinate? I.e. if I have a QgsPoint(10, 55)
in a EPSG:4326 layer, how can I know programmatically if its .x()
value 10
is a latitude or a longitude?
The WKT returned by toWkt()
does sometimes return information about the axes but not for EPSG:4326 plus I am not sure if the order in the returned WKT text is in any way corresponding to the x (first?) and y (second?) coordinates of the geometry:
>>> QgsCoordinateReferenceSystem.fromEpsgId(4326).toWkt()
'GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]'
>>> QgsCoordinateReferenceSystem.fromEpsgId(25832).toWkt()
'PROJCS["ETRS89 / UTM zone 32N",
GEOGCS["ETRS89",
DATUM["European_Terrestrial_Reference_System_1989",
SPHEROID["GRS 1980",6378137,298.257222101,
AUTHORITY["EPSG","7019"]],
AUTHORITY["EPSG","6258"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4258"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",9],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Easting",EAST],
AXIS["Northing",NORTH],
AUTHORITY["EPSG","25832"]]'
>>> QgsCoordinateReferenceSystem.fromEpsgId(3857).toWkt()
'PROJCS["WGS 84 / Pseudo-Mercator",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]],
PROJECTION["Mercator_1SP"],
PARAMETER["central_meridian",0],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",0],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Easting",EAST],
AXIS["Northing",NORTH],
EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs"],
AUTHORITY["EPSG","3857"]]'
hasAxisInverted
will returnTrue
. So if the order is not x/y, then it is inverted.