Appendix 1. Avenue code to check planar topology in a polygon shapefile theView = av.GetActiveDoc theActiveTheme = theView.GetActiveThemes.Get(0) if ( theActiveTheme.Is ( FTHEME ).NOT ) then return NIL end theFTab = theActiveTheme.GetFTab theShapeFld = theFTab.FindField ( "Shape" ) if ( theShapeFld = NIL ) then MsgBox.Warning ( "Error in getting shape field for theFtab","") end '******************* ' CLEAN the POLYGONS '******************* ' get the filename for the new polygon shapefile def = "z" + theActiveTheme.GetName theFN = FileDialog.Put(def.asFilename, "*.shp", "Cleaned Shapefile") if ( theFN = NIL ) then return FALSE end ' clean the shapes and put into a new theme Shape.SetCleanPreference ( #SHAPE_CLEAN_HIGHEST_QUALITY ) theNewFTab = theFTab.ExportClean ( theFN, FALSE) if (( theNewFTab.HasError)) then msgBox.Warning ( "Error making ftab!","") return NIL end theNewFTab.SetEditable ( TRUE ) theNewFTab.BeginTransaction theNShapeFld = theNewFTab.FindField ( "Shape" ) ' (re-)calculate the AREA and PERIMETER theAFld = theNewFTab.FindField ( "Area" ) if ( theAFld = NIL ) then theNewFTab.AddFields ( { Field.Make ( "Area", #FIELD_FLOAT, 16, 5 ) } ) theAFld = theNewFTab.FindField ( "Area" ) end thePFld = theNewFTab.FindField ( "Perimeter" ) if ( thePFld = NIL ) then theNewFTab.AddFields ( { Field.Make ( "Perimeter", #FIELD_FLOAT, 16, 5 ) } ) thePFld = theNewFTab.FindField ( "Perimeter" ) end for each rec in theNewFTab theNewFTab.SetValue ( theAFld, rec, ( theNewFTab.ReturnValue ( theNShapeFld, rec ).ReturnArea ) ) theNewFTab.SetValue ( thePFld, rec, ( theNewFTab.ReturnValue ( theNShapeFld, rec ).ReturnLength ) ) end '******************* ' CHECK TOPOLOGY '******************* theFld = Field.Make ("Type", #FIELD_CHAR, 8, 0) theNewFTab.AddFields ( { theFld } ) ' get a list of the polygons thePolygons = List.Make theOrigBM = theNewFTab.GetSelection if ( theOrigBM.Count = 0 ) then theOrigBM.Not end for each rec in theNewFTab thePolygons.Add ( theFTab.ReturnValue ( theShapeFld, rec ) ) theNewFTab.SetValue ( theFld, rec, "Original" ) end '******************* ' FIND GAPS '******************* theMER = theActiveTheme.ReturnExtent.Scale ( 2 ) theMERArea = theActiveTheme.ReturnExtent.ReturnArea theShape2 = thePolygons.Get(0) for each theP in thePolygons theShape2 = theP.ReturnUnion ( theShape2 ) end theGaps1 = theMER.ReturnDifference ( theShape2 ) ' remove the largest polygon theGaps = theGaps1.Explode for each i in 0..(theGaps.Count - 1) if ( theGaps.Get(i).ReturnArea > theMERArea ) then theGaps.Remove ( i ) break end end '******************* ' FIND OVERLAPS '******************* theOverlapShapes = List.Make for each i in 0..(thePolygons.Count - 2) for each j in (i+1)..(thePolygons.Count - 1) theOL = thePolygons.Get(i).ReturnIntersection ( thePolygons.Get(j) ) if ( theOL.ReturnArea > 0.0 ) then theOverlapShapes.Add ( theOL ) end end end theOverlaps = List.Make for each theOL in theOverlapShapes theOL2 = theOL.Explode for each theOL3 in theOL2 theOverlaps.Add ( theOL3 ) end end ' ************ ' now add the gaps and overlaps to the new shapefile ' **************** theNumOverlaps = theOverlaps.Count theNumGaps = theGaps.Count if ( ( theNumOverlaps > 0 ) OR ( theNumGaps > 0 ) )then for each theP in theOverlaps rec = theNewFTab.AddRecord theNewFTab.SetValue ( theNShapeFld, rec, theP ) theNewFTab.SetValue ( theFld, rec, "Overlap" ) theNewFTab.SetValue ( theAFld, rec, ( theNewFTab.ReturnValue ( theNShapeFld, rec ).ReturnArea ) ) theNewFTab.SetValue ( thePFld, rec, ( theNewFTab.ReturnValue ( theNShapeFld, rec ).ReturnLength ) ) end for each theG in theGaps rec = theNewFTab.AddRecord theNewFTab.SetValue ( theNShapeFld, rec, theG ) theNewFTab.SetValue ( theFld, rec, "Gap" ) theNewFTab.SetValue ( theAFld, rec, ( theNewFTab.ReturnValue ( theNShapeFld, rec ).ReturnArea ) ) theNewFTab.SetValue ( thePFld, rec, ( theNewFTab.ReturnValue ( theNShapeFld, rec ).ReturnLength ) ) end end msgBox.info ("Found "+theNumOverlaps.asString + " overlaps and "+theNumGaps.asString + " gaps!","") ' finish up the new theme theNewFTab.EndTransaction theNewFTab.SetEditable ( FALSE ) theFTheme = FTheme.Make ( theNewFTab ) theView.AddTheme ( theFTheme )