I'm seeing a weird line segment offset in QGIS when comparing a single line segment specified with geographic coordinates (EPSG:4326) to the same line using UTM coordinates (EPSG:32734).
I start off with the EPSG:32734 coordinates for the line segment.
<QgsGeometry: LineString (353532.02861238544574007 6216811.98138812929391861, 283662.96248470252612606 6225440.52935113664716482)>
Then I use QGIS to transform these coordinates to EPSG:4326 for the GeoLine segment.
<QgsGeometry: LineString (19.41068025493579086 -34.17938946469345041, 18.65515095861225348 -34.08948039934628582)>
While zoomed out the two lines, UTMLine and GeoLine appear to be perfectly aligned.
But when zooming in you notice that although the end points are aligned there is now some divergence between the lines between the end-points.
The QGIS project CRS is set to EPSG:32734, see status bar in first image posted above.
My understanding is as per https://docs.qgis.org/3.28/en/docs/user_manual/working_with_projections/working_with_projections.html
Every project in QGIS also has an associated Coordinate Reference System. The project CRS determines how data is projected from its underlying raw coordinates to the flat map rendered within your QGIS map canvas.
QGIS supports “on the fly” CRS transformation for both raster and vector data. This means that regardless of the underlying CRS of particular map layers in your project, they will always be automatically transformed into the common CRS defined for your project. Behind the scenes, QGIS transparently reprojects all layers contained within your project into the project’s CRS, so that they will all be rendered in the correct position with respect to each other!
So in this case the GeoLine layer will be transformed to EPSG:32734 since it is the project CRS, and in doing the transform myself using pyqgis the UTM coordinates are within 8-9 decimal places of the coordinates of the line in UTMLine layer.
So how come when QGIS then renders the two single line segment lines, basically going from the same EPSG:32734 coordinates there is this divergence away from the end points?
I thought that possibly QGIS wasn't drawing a straight line for the GeoLine layer using the two end points, but was possibly deciding to render a geodesic line.
So I used the QgsDistance.geodesicLine()
method to generate a point.
geodesicPts = self.distanceCalculator.geodesicLine(startGeo, endGeo, markerDistanceAlongSegment)
markerPoint = geodesicPts[0][1]
But when the coordinates returned were used to plot a feature point it landed up on top of the line in the UTMLine layer and not on the line in the GeoLine layer.
So what logic is QGIS using to render the line in the GeoLine layer?