Created
January 26, 2026 23:03
-
-
Save CEZERT/2db5c2e3aaf302581d9bed97d7e38dcc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from qgis.core import QgsGeometry, QgsPoint, QgsProject | |
| layer = QgsProject.instance().mapLayersByName('test')[0] | |
| layer.startEditing() | |
| for f in layer.getFeatures(): | |
| geom = f.geometry() | |
| # sécurité : seulement LineString | |
| if geom.isMultipart(): | |
| continue | |
| pts = geom.constGet().points() | |
| dist = 0.0 | |
| new_pts = [] | |
| for i, p in enumerate(pts): | |
| if i > 0: | |
| dist += pts[i-1].distance(p) | |
| new_pts.append(QgsPoint(p.x(), p.y(), p.z(), dist)) | |
| f.setGeometry(QgsGeometry.fromPolyline(new_pts)) | |
| layer.updateFeature(f) | |
| layer.commitChanges() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment