2

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?

4

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

  • Thank you for your detailed answer! I tried to create a new colmn for the y-coordinate, but it's becoming empty? No values are displayed. What can be the problem then? – SoS Mar 12 '14 at 12:12
  • Better save the edits 3 to 4 4 times and check it....... – Arun Mar 12 '14 at 12:14
  • @Willy, do you know if it's possible to do this with polygons? I think your answer only works for points? – SoS Mar 13 '14 at 9:16
  • @Willy, thank you for editing your answer! One more question - after I have made the centroids and given them coordinates, how do I add this information to my polygon file? – SoS Mar 14 '14 at 8:08
  • 1
    OK, for that (in hindsight) in the original file of the polygons, I create an explicit index column. Using the FieldCalculator, I make a new text column called 'index' with the value of the row number $rownumber from the record section of the function list. That give 1, 2, 3, etc. When you carry out the create centroids step, that index (and all other attributes) will be inherited into the attribute table of the new shapefile. You could then create a 'Join` LAYER|PROPERTIES|JOINS based on the index. Reopen the attribute table and you will see new columns with the values from the centroid. – Willy Mar 16 '14 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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