Deprecated: Return type of Lime\App::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/Lime/App.php on line 1357

Deprecated: Return type of Lime\App::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/Lime/App.php on line 1346

Deprecated: Return type of Lime\App::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/Lime/App.php on line 1342

Deprecated: Return type of Lime\App::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/Lime/App.php on line 1361

Deprecated: Creation of dynamic property MongoHybrid\MongoLite::$db is deprecated in /home/heraudcoyp/www/admin/lib/MongoHybrid/MongoLite.php on line 20

Deprecated: Return type of MongoLite\Cursor::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/MongoLite/Cursor.php on line 254

Deprecated: Return type of MongoLite\Cursor::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/MongoLite/Cursor.php on line 263

Deprecated: Return type of MongoLite\Cursor::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/MongoLite/Cursor.php on line 259

Deprecated: Return type of MongoLite\Cursor::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/MongoLite/Cursor.php on line 267

Deprecated: Return type of MongoLite\Cursor::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/MongoLite/Cursor.php on line 247
Triangulation de Delaunay entre des points dans QGIS – heraud.co
n°13
Triangulation de Delaunay entre des points dans QGIS
Python, Qgis
13 mai 2018

Au travers de l'interface Python, on peut construire une triangulation de Delaunay entre des points QGIS. Ou plutôt : on ne peut pas directement – du moins pas à ma connaissance – mais on peut faire appel à librairie externe qui sait le faire.

Triangulation de Delaunay entre des points
Triangulation de Delaunay entre des points

C'est légèrement bricolé, mais efficace. J'utilise les fonctions du projet delaunay de Peter Beard. On a besoin ici uniquement du fichier geometry.py qui contient les routines géométriques nécessaires. Pour faire appel à ces fonctions dans pyQGIS, il faut placer le fichier dans le dossier lib de l'installation Python de QGIS. Sous Windows et si vous avez installé QGIS via OSGeo, ce sera ici C:\OSGeo4W64\apps\Python27\Lib.

Ci-dessous le code d'une utilisation typique

# coding: utf8

from qgis.core import *
from qgis.gui import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *

import math
from geometry import *
# by Peter Beard, https://github.com/PeterBeard/delaunay
# to import Python external library to QGIS, put the .py (here geometry.py) file in C:\OSGeo4W64\apps\Python27\Lib

inputPts = [QgsPoint(7.7,48.6), QgsPoint(2.3,48.9), QgsPoint(4.3,50.8), QgsPoint(13.4,52.5), QgsPoint(12.6,55.7), QgsPoint(-0.1,51.5), QgsPoint(5.4,43.3)]
#Qgis Point objects (Strasbourg, Paris, Berlin, Copenhagen, London, Marseille)


# Translate Points (Qgis Point objects) into geometry.py points

delaunayPts = []
for pt in inputPts:
    geometryPoint = Point(pt.x(), pt.y())
    delaunayPts.append(geometryPoint)

delaunayTriangles = delaunay_triangulation(delaunayPts) #returns geometry.py Triangle objects


# Get lines from group of Delaunay triangles

delaunayLines = [] #Pairs (here tuples) of Qgis Point objects (start and end of line)

for triangle in delaunayTriangles:
    pointA = QgsPoint(triangle[0].x, triangle[0].y)
    pointB = QgsPoint(triangle[1].x, triangle[1].y)
    pointC = QgsPoint(triangle[2].x, triangle[2].y)

    if pointA in inputPts and pointB in inputPts:
    #excludes automatically created bounding points from geometry.py

        lineA = (pointA, pointB)
        delaunayLines.append(lineA)

    if pointA in inputPts and pointC in inputPts:
        lineB = (pointA, pointC)
        delaunayLines.append(lineB)

    if pointB in inputPts and pointC in inputPts:
        lineC = (pointB, pointC)
        delaunayLines.append(lineC)


# Delete duplicates

def removeTupleDuplicatesinArray(array):
    duplicateFreeArray = []

    for t in array:
        if (t[0],t[1]) not in duplicateFreeArray and (t[1],t[0]) not in duplicateFreeArray:
            duplicateFreeArray.append(t)
    return duplicateFreeArray

delaunayLines = removeTupleDuplicatesinArray(delaunayLines)


# Preview lines

for line in delaunayLines:
    rb = QgsRubberBand( qgis.utils.iface.mapCanvas(), True )
    rb.setColor (Qt.blue)
    rb.addPoint(QgsPoint(line[0].x(), line[0].y()))
    rb.addPoint(QgsPoint(line[1].x(), line[1].y()))

c. héraud-louisadat

architecte & développeur
67200 Strasbourg
heraud-arobase-laponies-point-fr

*1992, Strasbourg.

Diplômé d'état en 2016 de l'ENSA Paris-Malaquais et de la RWTH Aachen et habilité à maîtrise d'oeuvre en nom propre (HMONP) en 2019, j'ai travaillé pour diverses agences d'architecture à Paris et Berlin puis fait de la recherche en histoire de l'art sur l'architecture Heimatschutz. J'ai fondé l'agence Atkinson-Héraud Architectes en 2023 avec Isabelle Atkinson-Evans. Je développe également des applications pour le Web et la 3D.

Amis, famille et blogroll : Anaïs Héraud-Louisadat, Héraud–Baumann, Till Baumann, Antoine Le Dreff, Station Zéro, BALT.

alsace europe