I have a polygon layer and each polygon has the MEAN elevation as an attribute. I want to write a python script to loop through each polygon and compare its elevation with its neighboring polygons. If a surrounded polygon has lower elevation, it should store the result in a table as (From-To).
The answer on your question is in my view independent of what scripting language or programm you use.
For your question it is of importance that you define the relation between a polygon and bordering polygons. I would recommend searching for a function that is able to select surrounding polygons. If you cant find such function I would create small buffers and then intersect these buffers with surrounding polygons. The intersections can be used to select the surrounding polygons. Then you can extract all the height values of the surrounding polygons. After extraction you can do your calculation/selection.
In a script it would basically go like:
- create dataframe
- for loop: for each polygon in my dataset
- Selection: select polygons bordering a polygon
- Extraction: extract elevation of each bordering polygon
- calculation: calculation with all elevation values
- fill dataframe: add a new row in your dataframe starting with the central polygon followed by the results of your calculation
It is not exactly clear to me what you want to calculate in the end. So that you will have to figure out or ask more explicit. For exact scripting questions you will have to come with a piece of code I can see and reflect on. It is unlikely that somebody here is going to make the entire script for you.