Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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).

share|improve this question

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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