[QGIS-Developer] Offset lines via qgis python

Ujaval Gandhi ujaval at spatialthoughts.com
Wed Jun 9 01:52:07 PDT 2021


This particular implementation is C++ (see the .cpp extension on the file).
But the C++ and Python API is almost identical, so you can use the C++ code
as a reference for your PyQGIS code.
[image: Logo] <https://spatialthoughts.com/>
Ujaval Gandhi
Spatial Thoughts
mobile: +91-8095684687
email: ujaval at spatialthoughts.com
[image: LinkedIn icon] <https://www.linkedin.com/in/spatialthoughts/>  [image:
Twitter icon] <https://twitter.com/spatialthoughts>



On Wed, Jun 9, 2021 at 2:11 PM Prem Kumar <prem.netgis at gmail.com> wrote:

> Hi Ujaval,
>
> Thank you very much for pointing that out. That serves my purpose.
>
> In fact, I had initially searched for a python implementation of the
> Offsetlines processing tool but did not get it. Just a quick question, how
> do we trace whether the processing tool implementation is in python or c++?
>
> -Prem
>
> On Wed, Jun 9, 2021 at 1:53 PM Ujaval Gandhi <ujaval at spatialthoughts.com>
> wrote:
>
>> You can look at the implementation
>> <https://github.com/qgis/QGIS/blob/2d1aa68f0d044f2aced7ebeca8d2fa6b754ac970/src/analysis/processing/qgsalgorithmoffsetlines.cpp>
>> of offsetline algorithm and you'll notice that it
>> uses geometry.offsetCurve(). You can do the same in your code.
>> [image: Logo] <https://spatialthoughts.com/>
>> Ujaval Gandhi
>> Spatial Thoughts
>> mobile: +91-8095684687
>> email: ujaval at spatialthoughts.com
>> [image: LinkedIn icon] <https://www.linkedin.com/in/spatialthoughts/>  [image:
>> Twitter icon] <https://twitter.com/spatialthoughts>
>>
>>
>>
>> On Wed, Jun 9, 2021 at 1:31 PM Prem Kumar <prem.netgis at gmail.com> wrote:
>>
>>> Hi Team,
>>>
>>> Just wondering if there is a python api which gets an offset line or
>>> parallel line (to both left and right sides) to a given line geometry in
>>> Qgis Python. I know there exists a processing tool called Offsetlines
>>> <https://docs.qgis.org/3.16/en/docs/user_manual/processing_algs/qgis/vectorgeometry.html#offset-lines> but
>>> need this similar functionality at geometry object level so that I can
>>> create offset lines only when needed based on my logic.
>>>
>>> The only way now is that I can perform the Offset lines on the entire
>>> layer and then access the offset geometry if needed.
>>>
>>> On other hand, shapely has parallel_offset
>>> <https://shapely.readthedocs.io/en/stable/manual.html#object.parallel_offset> but
>>> this needs conversion from shapely geometry to qgisgeometry.
>>>
>>> Just looking for thoughts on this to optimize heavy geometry operations.
>>> Appreciate your help.
>>>
>>> -Prem
>>> _______________________________________________
>>> QGIS-Developer mailing list
>>> QGIS-Developer at lists.osgeo.org
>>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210609/4c926a39/attachment.html>


More information about the QGIS-Developer mailing list