where layer B basically has the same geometry in exactly the same positions
The problem is that it is not true.
LineString geometries are defined by their vertices. But since this vector data model (the Simple Features, or Simple Feature Access model) is not topological, layer B has vertices where layer A don't. Layer B geometries are not a subset of layer A ones.
Spatial operations (like Union, Intersection, Difference) in non-topological data models tend to fail. It also happens with polygons (peaks and gaps that are created from a difference are famous).
The only way to perform fail-safe spatial operations in this data model, is by creating a pseudo-topology. It means create vertices at layer A where there are vertices at layer B.
If vertices of layer B are a subset of vertices of layer A, the difference will work.
- Create a new layer A, with geometry by expression:
line_merge(
collect_geometries(
array(
line_substring($geometry, 0, 10),
line_substring($geometry, 10, length($geometry) - 10),
line_substring($geometry, length($geometry) - 10, length($geometry)))))
You can check new layer A vertices in edit mode with the vertex tool. New vertices at 10 meters from start and end must be created.
Note: Look at the expression, there was no need to extract the mid line substring first, to next get the first and end portions through a difference. You can extract the first and end substrings just with:
collect_geometries(
array(
line_substring($geometry, 0, 10),
line_substring($geometry, length($geometry) - 10, length($geometry))))
Best Answer
It seems like you want the difference in x and y coordinates?
The following will return that using the top left corner point as a reference, like your diagram shows.
You will need to load the raster to your QGIS session as RASTER_A and RASTER_B or modify the script here to reference their names as you have them stored. Run in the python console:
In the case shown below it is showing the shift between RASTER_A in colour and RASTER_B in grey, both in units as well as % of the respective pixel size. i.e. here RASTER_B is shifted east by ~2 units or ~112% and shifted north by ~1.3 units or ~74%.