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've written a script which produces a polygon shapefile of the extents of all the thousands of rasters in our library. I want to organise the FID so that the files with the largest extents are on the bottom so that an area of interest can be easily selected.

By organise FID - i mean that the layers should be drawn (in the shapefile) from the smallest extent to the largest extent as otherwise (like in layer ordering) the record of the dataset that has the highest FID will get selected over anything below it. This is not a simple (temporary within map/layer) sort but it has to be to permanently change the order in which the rows are written into the shapefile.

share|improve this question
How is this not a sort? Have you tried sorting by area before writing? – Sean Aug 23 '11 at 12:54
sort doesn't affect the order in which the rows in a shape file (or more accurately the dbf which the shp refers to) are drawn. I understand that they draw (and thus are selectable) in the fixed FID order. – GeorgeC Aug 23 '11 at 22:40
up vote 7 down vote accepted

You can reorder the shapefile by area, or any field, using OGR. Use the "order by" clause. This will create a new shapefile.

ArcGIS for Desktop (since 10.0), with an Advanced (formerly called ArcInfo) license, has a Sort command.

share|improve this answer
thanks for pointing out the sort command as now it actually creates a new file and is not just a visual sort. – GeorgeC Aug 23 '11 at 23:41

There are some inherent problems with what you are wanting.
1. the shape file is not a database. the shp is the list of objects the dbf is the list of attributes and the shx is the index of the two tables.
In other words which row goes with which row in each file.
IF you manually force re-ordering (or it sounds like you want re-numbering) then polygona will not be matched with polygona in the attributes.
So now this square represents another raster image.
2. The FID field is not managable by anything other than the software.
Just as a note: In your question you reference layers - layers are not "in" a shape file. A shapefile is "a" Layer.

My suggestion would be to re-organize how the footprints are written. Perhaps output by year? Maybe by drive or path?

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.