<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Any way to import a self defined neighborhood matrix? in Spatial Statistics Questions</title>
    <link>https://community.esri.com/t5/spatial-statistics-questions/any-way-to-import-a-self-defined-neighborhood/m-p/355318#M1160</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, I created a self-defined neighborhood matrix in SAS. So now the matrix has each row attached to a UID and each column with a special variable name. I wonder if there is a way to read in this matrix and further do spatial auto-correlation analysis. Which function or toolbox should I use?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to use some other open source software to import it but failed as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help is appreciated. Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xiaomin Ruan&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Geospatial and Population Studies, University of New Mexico&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 25 Aug 2011 17:38:45 GMT</pubDate>
    <dc:creator>XiaominRuan</dc:creator>
    <dc:date>2011-08-25T17:38:45Z</dc:date>
    <item>
      <title>Any way to import a self defined neighborhood matrix?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/any-way-to-import-a-self-defined-neighborhood/m-p/355318#M1160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, I created a self-defined neighborhood matrix in SAS. So now the matrix has each row attached to a UID and each column with a special variable name. I wonder if there is a way to read in this matrix and further do spatial auto-correlation analysis. Which function or toolbox should I use?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to use some other open source software to import it but failed as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help is appreciated. Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xiaomin Ruan&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Geospatial and Population Studies, University of New Mexico&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Aug 2011 17:38:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/any-way-to-import-a-self-defined-neighborhood/m-p/355318#M1160</guid>
      <dc:creator>XiaominRuan</dc:creator>
      <dc:date>2011-08-25T17:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to import a self defined neighborhood matrix?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/any-way-to-import-a-self-defined-neighborhood/m-p/355319#M1161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry to keep bothering with this, but I don't know where else to go with these questions. Perhaps I should make my question more specific. I read about how ArcGIS construct an optimized weight matrix like the example below (saw this from archived forum link).&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=1528&amp;amp;t=257453&amp;amp;ESRISessionID=lmlYQEgTGcEloQtIpmMhyO5uYBy1MWwbH8SB69T1EID5sP3TfM0YLWJ0hdRzjJv4-Q=="&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=1528&amp;amp;t=257453&amp;amp;ESRISessionID=lmlYQEgTGcEloQtIpmMhyO5uYBy1MWwbH8SB69T1EID5sP3TfM0YLWJ0hdRzjJv4-Q==&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;StationID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2 1/10&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 3 1/7&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 1 1/10&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 3 1/20&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 1 1/6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 2 1/15&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 3 0 &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But what I created is a nXn matrix standardized by row, in tab deliminated text format, with the unique ID at the first column, like the example below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;IDName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1&amp;nbsp; 0&amp;nbsp; 0.5&amp;nbsp; 0.5&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2&amp;nbsp; 0.5&amp;nbsp; 0&amp;nbsp; 0.5&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3&amp;nbsp; 0.5&amp;nbsp; 0.5&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0.2&amp;nbsp; 0&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;7&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0&amp;nbsp; 0.2&amp;nbsp; 0.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;8&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0&amp;nbsp; 0.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;9&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0.2&amp;nbsp; 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My Python script is also attached for further diagnostics. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help appreciated!&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xiaomin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Sep 2011 19:02:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/any-way-to-import-a-self-defined-neighborhood/m-p/355319#M1161</guid>
      <dc:creator>XiaominRuan</dc:creator>
      <dc:date>2011-09-02T19:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to import a self defined neighborhood matrix?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/any-way-to-import-a-self-defined-neighborhood/m-p/355320#M1162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is some code that places your NbyN matrix into a GWT sparse format....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import locale as LOCALE

fo = open("weights.txt", "r")
fw = open("weights.gwt", "w")
header = fo.readline()
fw.write("%s" % header)
data = fo.readlines()
for row in data:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rowVals = row.split()
&amp;nbsp;&amp;nbsp;&amp;nbsp; rowID = rowVals[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; weights = rowVals[1:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; for colID, weight in enumerate(weights):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w = LOCALE.atof(weight)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if w != 0.0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fw.write("%s %i %s\n" % (rowID, colID+1, weight))

fo.close()
fw.close()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I put your format into "weights.txt" and get out "weights.gwt".&amp;nbsp; This will allow you to use it directly in most of our tools.&amp;nbsp; However, if you want to construct a SWM format... it is perhaps best to change the header line to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fw.write("%s %s %s\n" % (header.strip(), "NID", "WEIGHT"))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then open the output file in excel and save in DBF format.&amp;nbsp; Lastly, call the "Generate Spatial Weights Matrix" tool in ArcGIS and use the "Convert from Table" conceptualization in order to give you the binary SWM format.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are many ways to skin this cat and I really like that you are attempting to use PySAL for it.&amp;nbsp; Unfortunately, I have been to busy with release to get to working with conversions in the latest and greatest PySAL.&amp;nbsp; Perhaps Ill wrap some code into my WeightsUtilities to convert full NumPy arrays to SWM formats?....&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:38:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/any-way-to-import-a-self-defined-neighborhood/m-p/355320#M1162</guid>
      <dc:creator>MarkJanikas</dc:creator>
      <dc:date>2021-12-11T16:38:50Z</dc:date>
    </item>
  </channel>
</rss>

