TransWikia.com

How to construct a line tangent to a curve from a point using PyQGIS

Geographic Information Systems Asked by maxwellhertz on July 18, 2021

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

Looks like it doesn't exist. But you can implement it. Combinig QgsGeometry and QgsGeometryUtils methods may help.

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

Answered by Kadir Şahbaz on July 18, 2021

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.

Answered by maxwellhertz on July 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP