[GIS] Adding coordinates to polygon layer to sort polygons from north to south in QGIS

attribute-tablecoordinatespolygonqgis-2sorting

I have a polygon file, where each polygon represents one property.
I want to be able to sort the polygons from north to south or vice versa. I need them to be sorted in this way when I export them to a different program. In the other program I want the properties to appear in a north to south order when I visit them one by one.

My first problem is, the polygons don't have information about there coordinates in the attribute table.

How can I add this?

I have tried using the field calculator, but I don't seem to get it right.

And, next step, if I sort them in QGIS, can I somehow "save" that order so that they appear in the same order in the other program?

I have tried the method in the answer below, but I don't get it to work on my data. Then after almost giving up, I read in the help of the field calculator that $y gives the y coordinate of a point.

But I have a polygon layer?

What do I do?

Best Answer

This is pretty straightforward, but a question first. Is the data in UTM format, decimal degrees or some-other? Doesn't matter, but if you understand that then the sorting will be obvious.

You will create a new column in the attribute table. It will be autofilled with data for the y coordinate. It can then be sorted. The final step would be to use a plugin MMQGIS to keep that sort order for the other software.

  1. Firstly load the layer. Then open the attribute table. Turn on editing. That will make the Attribute table Field Calculator available.

    Attribute table Field Calculator

  2. Then you will create a new field (column). If your coodinate system is decimal degrees you must use Decimal number (real) with a precision of 5 or so. Regardless of the coordinate system when I do this I use real and width of 10 and precision of 10, cause it works with everything.

  3. Then in the expression box at the bottom you want $y to be in there. You type it straight in or select it from the tree of functions on the left, go to Geometry and it is there.

  4. OK that dialog and you should have a new column with the data. Then click on the column header to sort it. However that won't be permanent, even when you save it. But save the changes though and close the attribute table.

  5. Load the plugin MMQGIS and use the menu item MMQGIS|MODIFY|SORT.

ciao

EDIT

My apologies.

OK, for polygons, use the tool in the vector menu first

VECTOR|GEOMETRY TOOLS|POLYGON CENTROIDS

which will create a new layer. Then do as above.

See also How to determine the centroid of polygons?

polygon centroids