Show me the Code, Distance Matrix
: In this lesson, we will illustrate the importance open source code.
The Distance Matrix
algorithm documentation says nothing about how it calculates distances!
Watch a video of the issue.
Reading code to understand an algorithm
- Go to the QGIS GitHub repository github.com/qgis and search for “distancematrix” within the repository
- distance matrix algorithm source code
- line 179: Transforms the target features into the source CRS (coordinate reference system)
- line 182: CRS set to source CRS
- line 183: Ellipsoid set to context ellipsoid
- distance area class source code
- line 413: converts to meters
- the only information passed to
qgisdistancearea
is the context ellipsoid and transformation, and the source crs
- The API (applicaton progrmaming interface) guide can also be a quick and helpful reference to QGIS variables qgis.org/api
- there is a
context.ellipsoid()
and a context.distanceUnit()
, but the distance matrix algorithm never uses distanceUnit
.
Conclusions
Distance Matrix
appears to calculate distance in meters
, no matter what.
- Target features are automatically reprojected to match the CRS of input features
- If the input layer uses a projected coordinate system, that system is used or planar distance calculation.
- If the input layer uses a geographic coordinate system, the project ellipsoid is used for ellipsoidal distance calculation.
Main Page