6

I try to calculate the azimuth between a row of polygonsheets to print the number of the last and the next sheet inside the sheet in direction of the last and the next sheet. This should help to orient inside a big Project- Atlas with many sheets. The script (not complete):

for feature in layer.getFeatures(): 
    count = layer.featureCount() 
    geom = feature.geometry()
    polycent = geom.centroid().asPoint()

while i < count
    azimuth = polycent[i].azimuth(polycent[i+1])

The error code is 'float' object has no attribute 'azimuth' - but my polycent[i] is no 'float' object - isn't it? How can I ask for the azimuth between the actual and the next centroid?

2
  • It will not work, because azimuth is an attribut of a line - not a point. I have to try another way. Sorry.
    – tomzappa
    Commented Aug 1, 2018 at 14:05
  • No. azimuth is a point method. QgsPoint.azimuth(QgsPoint) Commented Aug 1, 2018 at 14:12

1 Answer 1

6

In your code, polycent is always set the last polygon's centroid. So you must add centroids to a list.

Change your code into that:

polycents = [] # empty list
for feature in layer.getFeatures():
    geom = feature.geometry()

    # add centroid to the list
    polycents.append(geom.centroid().asPoint())

azimuths = [] 
count = layer.featureCount()
i = 0
while i < count
    azimuth = polycents[i].azimuth(polycents[i+1])
    azimuths.append(azimuth)
    i += 1

# and you can access any azimuth value by index now
print(azimuths[0])
1
  • Dear Kadir, it looks so easy ;-) and it's working. i thank you very much.
    – tomzappa
    Commented Aug 1, 2018 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.