Given are:

  • a polygon shapefile/feature class (FC) containing municipal districts
  • a point shapefile/FC containing locations of, lets say, trees.

My goal is to append an unique value (1, 2, 3, ...) to the point shapefile/FC which is:

  1. sorted from north to south (or vice versa)
  2. and sorted/grouped by the municipal districts (the priority of sorting lies on the municipal districts)

I managed to solve 1. by generating y-coordinates for each point and than running this script which calculates and sorts unique values by means of the the y-coordinate column: enter image description here

However, I do not know how to solve 2. Finally my map should look like this (the numbers in red are the ones I'd like to calculate instead):

enter image description here

  • 2
    I would strongly suggest rethinking your design. A unique ID should not have any semantic meaning (like its ordering meaning something). Its sole purpose is to uniquely identify a record. If you want to relate the points to the polygons using IDs, create an explicit foreign key. This can be easily accomplish with a spatial join.
    – blah238
    Commented Apr 17, 2014 at 8:51
  • Thank you! The unique ID is not touched at all. Beside the shapfile's/FC's unique ID I'd like to have a further column with a numbering sorted in ascending order only for visualizing purposes. I also thought of a spatial join but this will lead to the same value for all points within the same polygon. And I'd like to have unique ones... Commented Apr 17, 2014 at 9:15
  • 1
    What about unique values with a spatial join to polygons but different number range? Like in your example, the upper polygon would have 100 as number. Join to your points and you'll get 101 and 102. Then points in the next polygon gets 201, 202 etc.
    – Martin
    Commented Apr 17, 2014 at 9:24
  • There are some ideas and SQL-based solutions in this question for a related but not identical problem: How to number polygons according to their spatial relationships?
    – blah238
    Commented Apr 17, 2014 at 9:27
  • @Martin Thanks for your straight forward solution. Running the script mentioned in the question again will lead to my aspired goal. If you like, just write an answer with this hint and I'll mark it as answered. Commented Apr 17, 2014 at 9:33

1 Answer 1


You can create unique values but based on which polygon the point resides in. Add a unique attribute which is at least 10 times larger than the amount of points to your polygons, and the join this value to your points.

Like in your example, the upper polygon would have 100. Join to your points and create unique values that is something like 101 and 102. Then points in the next polygon gets 201, 202 etc.

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.