Message posté par : Sylvain M.
----------------------------------------
Pour le fun, j'ai cherché sur ma pause ce midi.
Voici un code Python qui marche, à adapter avec les noms des champs et la somme de surface
recherchée :
-----------------
Code :
from qgis.utils import iface
from PyQt5.QtCore import QVariant
_CHAMP_NOM = 'NOM'
_CHAMP_SURFACE = 'SURFACE'
_VALEUR_CHERCHEE = 22
layer = iface.activeLayer()
# Create a dictionary of all features
feature_dict = {f.id(): f for f in layer.getFeatures()}
# Build a spatial index
index = QgsSpatialIndex()
for f in feature_dict.values():
index.insertFeature(f)
# Loop through all features and find features that touch each feature
for f in feature_dict.values():
geom = f.geometry()
intersecting_ids = index.intersects(geom.boundingBox())
for intersecting_id in intersecting_ids:
# Look up the feature from the dictionary
intersecting_f = feature_dict[intersecting_id]
if (f != intersecting_f and
not intersecting_f.geometry().disjoint(geom)):
if (float(intersecting_f[_CHAMP_SURFACE]) + float(f[_CHAMP_SURFACE])) ==
_VALEUR_CHERCHEE:
print(intersecting_f[_CHAMP_NOM] + ' et ' + f[_CHAMP_NOM] +
' ont la somme de surface recherchée')
-----------------
----------------------------------------
Le message est situé
https://georezo.net/forum/viewtopic.php?pid=359947#p359947
Pour y répondre : qgis_fr(a)ml.georezo.net ou reply de votre messagerie
Pour vous désabonner connectez-vous sur le forum puis Profil / Abonnement
--
Association GeoRezo - le portail géomatique
https://georezo.net