From teljeurc@tcd.ie Fri Jan 28 01:11:29 2000 Received: from mxu4.u.washington.edu (mxu4.u.washington.edu [140.142.33.8]) by lists.u.washington.edu (8.9.3+UW99.09/8.9.3+UW99.09) with ESMTP id BAA11262 for ; Fri, 28 Jan 2000 01:11:28 -0800 Received: from truxa1.tcd.ie (truxa1.tcd.ie [134.226.1.158]) by mxu4.u.washington.edu (8.9.3+UW99.09/8.9.3+UW99.09) with ESMTP id BAA17506 for ; Fri, 28 Jan 2000 01:11:27 -0800 Received: from [134.226.184.21] (smd021.smd.tcd.ie [134.226.184.21]) by truxa1.tcd.ie (8.9.3/8.9.3) with ESMTP id JAA18066 for ; Fri, 28 Jan 2000 09:11:25 GMT X-Sender: teljeurc@mail.tcd.ie Message-Id: In-Reply-To: <3890B188.57099BE@sph.emory.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="============_-1263071553==_============" Date: Fri, 28 Jan 2000 09:15:42 +0000 To: waphgis@u.washington.edu From: Conor Teljeur Subject: Re: Adjacencies in ArcView --============_-1263071553==_============ Content-Type: text/plain; charset="us-ascii" >Has anyone come across a way to get adjacency matrices >(or simply a list of the adjacent counties for each >county in a state) in ArcView? I can see how to get >this by finding them for each county one at a time, but >am wondering if anyone has (or knows of) an Avenue Script >(or other way) to automate it and create the set of >adjacencies for a whole state without doing one county >at a time. Hi I take it that you are using this for some sort of Bayesian analysis. We do this regularly and use the attached script [neighbour.ave] which calculates contiguous neighbours for all polygons in a theme. You should first put an index field into the attributes file that identifies polygons from 1 to x. The output will be a comma delimited textfile with x rows in order 1 to x each containing the neighbours for that polygon. We normally open the text file in Excel for ease of calculating the offset [cumulative number of neighbours]. I hope this is what you were looking for, Conor --============_-1263071553==_============ Content-Type: text/plain; name="neighbour.ave"; charset="us-ascii" Content-Disposition: attachment; filename="neighbour.ave" '*** Export the neighbor matrix to a .txt file theProject = av.GetProject theView = av.GetActiveDoc theTheme = theView.GetactiveThemes.Get(0) theFTab = theTheme.GetFTab 'Get the name for neighbor file to export theFN = FileDialog.Put("neighbor.txt".AsFileName, "*.txt", "Name An Adjacency File To Write") 'Get the list of fields in FTab numeric_fields = {} 'Numeric fields in the VTab field_aliases = {} 'List of field aliases all_fields = theFTab.GetFields 'Build list of numeric fields from all fields. 'Also list of field aliases to display to user. for each f in all_fields if (f.IsTypeNumber) then numeric_fields.Add(f) field_aliases.Add(f.GetAlias) end end fname = MsgBox.ListAsString(field_aliases, "Select the variable for identification:", "Export Neighbor Matrix to a TEXT File") if (fname <> nil) then 'Match the alias to the actual field object theField = numeric_fields.Get(field_aliases.FindByValue(fname)) else exit end ' Set modified flag, clear any previous selection av.GetProject.SetModified(true) theFTab.GetSelection.ClearAll theFTab.UpdateSelection ' find the total number of records theCount = theFTab.GetNumRecords ' define an output file for storing adjacency relationship outFile = LineFile.Make(theFN, #FILE_PERM_WRITE) ' Find out adjacent polygons for each individual polygon theBitMap = theFTab.GetSelection for each rec in theFTab theIndex = theFTab.ReturnValueNumber(theField, rec) theRecord = rec.Clone theFTab.GetSelection.Set(theRecord) theFTab.UpdateSelection theFTab.SelectByFTab(theFTab, #FTAB_RELTYPE_ISWITHINDISTANCEOF, 0, #VTAB_SELTYPE_NEW) selBitMap = theFTab.GetSelection theString = theIndex.AsString for each rec in selBitMap recVal = theFTab.ReturnValue(theField, rec) if (recval <> theIndex) then theString = theString++recVal.AsString end end ' Write results to file and clear the selection outFile.WriteElt(theString) theFTab.GetSelection.ClearAll end outFile.Close --============_-1263071553==_============-- .