ArcGIS Enterprise SDK has something like this:

public void QueryTangent (
    esriSegmentExtension extension,
    double DistanceAlongCurve,
    bool asRatio,
    double Length,
    ILine tangent

Given a distance along the curve specified either as a ratio of the length or as a specific fixed distance, QueryTangent returns the Line tangent to the Point.

I wonder if anything like this exists in QGIS Python API? If not, is it possible to implement this function from scratch?

2 Answers 2


It looks like it doesn't exist. But you can implement it. Combining QgsGeometry and QgsGeometryUtils methods may help.

To begin with, I would examine interpolatePointOnLine, interpolatePointOnLineByValue, linePerpendicularAngle, perpendicularSegment, pointOnLineWithDistance methods.

  • Any hints? @Kadir Şahbaz Apr 3, 2021 at 6:31
  • Pedantic Stackexchange rules say your question was answered ;) Better add in a "how to" clarification or ask a new question for that. Apr 3, 2021 at 9:23
  • thanks @bugmenot123 Apr 3, 2021 at 9:46
  • @maxwellhertz I've added some method names to begin with. Apr 3, 2021 at 11:22
  • thank you I will check these out @Kadir Şahbaz Apr 3, 2021 at 14:00

As @Kadir Şahbaz mentioned it, there is no direct ways to calculate a tangent line to a curve using PyQGIS API. However, there is a workaround to my problem:

  1. Let's say we already have a point p lying on a curve c;
  2. Use QgsGeometryUtils.pointOnLineWithDistance to get anther point q that is very close to p on c;
  3. Connect p with q, then we have a line approximately tangent to p.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.