The following scripts are an example of sorting polygons using qsort "SortPoly.ave" sets up the sort list and writes the resulting records "CompPoly.Ave" is the comparison routine for qsort '*********************************************************************** ' SortPoly.ave ' Sorts polygons in the active theme to a new shapefile theTitle = "Sort Polygons" theView = av.GetActiveDoc theTheme = theView.GetActiveThemes.Get(0) inFTab = theTheme.GetFTab ' Specify the output shapefile... fnDefault = FileName.GetCWD.MakeTmp("shape","shp") fnOutput = FileDialog.Put( fnDefault,"*.shp","Output Shape File" ) if (fnOutput = nil) then exit end ' Use selected shapes if there are any, otherwise iterate ' through the entire FTab... ' if (inFTab.GetSelection.Count > 0) then colToProcess = inFTab.GetSelection nRecs = colToProcess.Count else colToProcess = inFTab nRecs = colToProcess.GetNumRecords end '**** set global variable for the comparison routine _theFTab = inFTab '**** generate list of records rlist = List.Make for each r in colToProcess rlist.Add(r.Clone) end '**** sort it slist = av.Run("qsort",{rlist,"CompPoly"}) _theFTab = nil '**** now write out the new records fnOutput.SetExtension("shp") outFTab = FTab.MakeNew( fnOutput, POLYGON ) inFields = inFTab.GetFields newFields = List.Make for each f in inFields if (f.GetName <> "shape") then newFields.Add(f.Clone) end end outFTab.AddFields(newfields) nCount = 0 nRecAdded = 0 mpCount = 0 inSF = inFTab.FindField("shape") outSF = outFTab.FindField("shape") for each r in slist nRecNew = outFTab.AddRecord for each inF in inFTab.GetFields fName = inF.GetName outF = outFTab.FindField(fName) val = inFTab.ReturnValue(inF,r) outFTab.SetValue(outF,nRecNew,val) end nRecAdded = nRecAdded + 1 nCount = nCount + 1 av.SetStatus((nCount / nRecs) * 100) end av.ClearStatus av.ClearMsg if (MsgBox.YesNo("Add shapefile as theme to a view?", theTitle, true).Not) then exit end thmNew = FTheme.Make(outFTab) theView.AddTheme( thmNew ) '*********************************************************************** '*********************************************************************** ' CompPoly ' Polygon comparison routine for qsort ' Note that polygons to be drawn in the back are "lesser" than ' polygons to be drawn in the front. a = SELF.Get(0) b = SELF.Get(1) sf = _theFTab.FindField("shape") p1 = _theFTab.ReturnValue(sf,a) p2 = _theFTab.ReturnValue(sf,b) if (p1.ReturnArea > p2.ReturnArea) then return -1 end if (p2.ReturnArea > p1.ReturnArea) then return 1 end return 0 '***********************************************************************