I have around 1320 point/centroid features in a shapefile for my research plots. Each point/centroid has X and Y coordinate associated with them which were calculated using Field Calculator > Geometry > $X $Y in QGIS. At present the reference IDs are in no particular order. But eventually I would like to create a new attribute column by the order shown in the below image. this image.

At first I tried to sort my points by X and Y (selecting 10 consecutive points at a time) but due to fact that all points in a single row don't lie on the same northing or easting line, the plot order was not proper.

So I would like to know if there is a neat way to sort these points spatially (X and Y) and then assign a sequence ID in the order as shown in the image.

  • 1
    Please embed images in your question; this way there's no chance it will be a dead link, and more people will see it. What you really want to do is use division (or subtraction then division) on the X and Y dimensions to manufacture rows and columns, then order by row, column, and X within the cell. In order to make this answerable, you should pick one of the three available tools, since this is, in effect three different questions that can get three different right answers.
    – Vince
    Commented Aug 2, 2015 at 2:28

1 Answer 1


It may be not the "neat way" what you have asked for, but i would go for this if i have a lots of points (but you have only 1400(c) points).

  1. Separate each block ( in your image there are three blocks) using arcmap fishnet tool or others.
  2. Now run following operation on every block (for your image the rightmost block where 90 points are in place)
  3. Run sort tool, use "Shape" field with "Ascending" and select "UR" at first and "Descending" for second with same other setting.This will create two featureclasses one is "Left to Right" and "Top to Bottom" another "Right to Left" and "Bottom to Top" in terms of feature alignment.

  4. Now assign an attribute for each row- you may use following field calculator code (this adds 1,2,3 etc for each column e.g all points in a row with attribute value of one.).

    flg = 0
    def x(f):## Where f is objectid of any sequential field
        global flg
        if math.fmod(int(f),38)==1.0: ## for my case 38 is the point in each row
            return flg
            return flg
  5. Then delete "Odd" flagged rows from "Ascending" featureclass and "Even" from "Descending" featureclass (you have got two feature classes with opposite direction but there is no change in the attribute)

  6. Now run "Merge" tool for these two featureclasses which return back the original featureclass but with that "ZIGZAG" direction.

  7. Apply these methods for other blocks.

N.B. All these can be automatized with better understanding

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.