' Fast neighbors.ave ' This script is used for checking for neighbors, containment ' and overlaps. ' It was written by Timothy S. Thomas. ' Editing began on 11/27/00, and was last edited on 11/27/00. ' It is based on "Find neighbors little program". ' ********************************************************** ' Set up basic variables ' ********************************************************** ' This tells Arc/View that numerical output will be integer only. ' If we wanted decimal places, we would use something like ' "d.dd" Script.The.SetNumberFormat("d.dd") theProject = av.GetProject theView = av.GetActiveDoc theThemeList = theView.GetActiveThemes theTheme = theThemeList.Get(0) theFTab = theTheme.GetFTab numRecs = theFTab.GetNumRecords ' "Shape" is a special word in FTabs shapeField = theFTab.FindField("Shape") ' Permits changes to be made to the FTab theFTab.SetEditable(True) ' ********************************************************** ' This allows the user to pick a field as the basic unit for ' evaluation. ' ********************************************************** ' Gets new field list, reflecting deletions of fields fieldList = theFTab.GetFields.Clone fieldList.Insert("") idField = MsgBox.ChoiceAsString(fieldList,"Select ID field", "Choose ID field") ' ********************************************************** ' Make a comma-delimited file to hold neighbor codes ' ********************************************************** ' Shows message in message bar av.ShowMsg("Creating neighbor file") ' Creates file FTabFN = theFTab.GetSrcName.GetFileName baseString = FTabFN.GetBaseName extString = FTabFN.GetExtension newString = FTabFN.AsString.Substitute(baseString,"") new2String = baseString.Substitute(extString,"csv") neighborFN = FileDialog.Put( (newString + "neighbor " + new2String).AsFileName, "*.csv","Data file name") neighborFile = LineFile.Make(neighborFN,#FILE_PERM_WRITE) msg1 = "Divide by this to convert map units to area units" areaconv = MsgBox.Input(msg1,"Converstion factor","10000").AsNumber for each recnum in 0..(numRecs-1) thePoly = theFTab.ReturnValue(shapeField,recnum) theFTab.SelectByPolygon(thePoly,#VTAB_SELTYPE_NEW) for each s in theFTab.GetSelection otherPoly = theFTab.ReturnValue(shapeField,s) ' The reason for doing the following multiple area computation ' is that sometimes intersecting one way incorrectly returns ' 0 for area. area = thePoly.ReturnIntersection(otherPoly).ReturnArea if (area.IsNull) then area = otherPoly.ReturnIntersection(thePoly).ReturnArea end if (area.IsNull.Not) then area = area / areaconv area1 = thePoly.ReturnArea / areaconv area2 = otherPoly.ReturnArea / areaconv ' The CONTAINS command does not seem to select containment ' when the interior polygon shares a border with the ' exterior polygon. Therefore, those that share a boundary ' but are otherwise contained may appear in the overlapped ' category, though I have tried to adjust for this below. if (thePoly.Contains(otherPoly)) then extraString = ", Contains, " elseif (otherPoly.Contains(thePoly)) then extraString = ", Contained by, " else if ((area > (0.95*area1)) Or (area > (0.95*area2))) then if (area1 > area2) then extrastring = ", Contains probable (w/ bdry share), " else extrastring = ", Contained by probable (w/ bdry share), " end else extraString = ", Overlap, " end end extrastring = extrastring + area.AsString + " , " + area1.AsString + " , " + area2.AsString else extraString = "" end ' Writing a line of output to the file id2 = theFTab.ReturnValueString(idfield,s) id = theFTab.ReturnValueString(idfield,recnum) if (id<>id2) then theString = id + ", " + id2 + extraString neighborFile.WriteElt(theString) end end av.SetStatus(100*(recnum+1)/numrecs) end ' Clears selected features in the theme and theme table theTheme.ClearSelection ' Clears message in message bar av.ClearMsg ' Turns off editing in the FTab theFTab.SetEditable(false) ' Removes garbage objects av.PurgeObjects