8

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.

2
  • 1
    How is this not a sort? Have you tried sorting by area before writing?
    – Sean
    Commented Aug 23, 2011 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
    Commented Aug 23, 2011 at 22:40

2 Answers 2

8

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.

1
  • thanks for pointing out the sort command as now it actually creates a new file and is not just a visual sort.
    – GeorgeC
    Commented Aug 23, 2011 at 23:41
0

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?

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.