# A New Approach to Identifying Crash Hotspot Intersections (CHIs) Using Spatial Weights Matrices
## 2 Methodology
### Methods  
#### 2.3.1 The INDSWMI Generation Algorithm  
A spatial weights matrix (SWM), the conceptualization of spatial relationships between features [46], is the key input parameter for hotspot analysis. The SWMs can be mainly divided into contiguity-based spatial weights matrices (CSWMs) and distance-band spatial weights matrices (DSWMs). The CSWM, which expresses the existence of a neighbor relation as a binary value, 1 or 0, is widely used in region-based hotspot analysis [47]. The DSWM, which expresses the spatial relationships as distance weights [48], is intrinsically most appropriate for point-based hotspot analysis. We adopted the DSWM to express the spatial relationships between intersections since intersections are a typical point feature.  
The inverse network distance-band spatial weights matrix of intersections (INDSWMI) based on the DSWM is an N\(\times\)N matrix. Generally, \(W_{ij}\) is defined using inverse Euclidean distance measurement. However, intersections are constrained by the road network, which has complex topological and geometric relationships [49]. The inverse network distance along the road is more appropriate for the measurement of \(W_{ij}\) of the INDSWMI, which is defined as  
\[W_{ij}=\left\{\begin{array}{ll}1/nd_{ij},&nd_{ij}\leq distance\;band\\ 0,&nd_{ij}>distance\;band\end{array}\right. \tag{1}\]  
where the distance band is a cutoff distance that can be specified in accordance with the minimum number of neighbors of each intersection (the minimum number of neighbors is 1 in this research according to the suggestion of [PERSON] and [PERSON] [29]); \(nd_{ij}\) is the network distance between intersections\(i\) and \(j\). If \(nd_{ij}\) is less than or equal to the distance band, then \(W_{ij}=1/nd_{ij}\) (reverse network distance); otherwise, \(W_{ij}=0\). \(nd_{ij}\) is expressed as  
\[nd_{ij}=\sum\limits_{k=1}^{n}length(r_{k},r_{k}\in sp(I_{i},I_{j})) \tag{2}\]  
where \(sp(I_{i},I_{j})\) is the shortest path set of intersections \(i\) and \(j\), calculated by [PERSON]'s algorithm [50], and contains a series of road segments \((r_{k})\); \(nd_{ij}\) is the total length of road segments within \(sp(I_{i},I_{j})\).  
Note that row standardization of \(W_{ij}\) is suggested to create proportional weights in cases where intersections have an unequal number of neighbor intersections [29]. The row-standardized form of \(W_{ij}\) for hotspot analysis is expressed as  
\[W_{ij}=\left\{\begin{array}{ll}\frac{1/nd_{ij}}{\sum\limits_{j=1}^{n}1/nd_{ ij}},&nd_{ij}\leq distance\quad band\\ \\ 0&,\quad nd_{ij}>distance\quad band\end{array}\right. \tag{3}\]  
Based on Equations (1) and (2), we used the qt framework [51], an open source cross-platform, to develop the INDSWMI generation algorithm with PostGreSQL/PostGIS. Figure 2 shows the definitions of the main data types: intersection, network distance of intersections (NDI), network distance matrix of intersections (NDMI), spatial weight of intersections (SWI), and INDSWMI.  
Using the main data types, we developed a five-step algorithm with pseudocode shown in Figure 3 to generate the INDSWMI. The five steps are to (1) connect to the PostGreSQL/PostGIS database; (2) cache the intersection table in the PostGreSQL/PostGIS database to memory; (3) build the NDMI using the pgr_dijkstra fuction provided by the pgrouting extension for the PostGreSQL/PostGIS database; (4) generate the INDSWMI based on the NDMI restricted by the distance band; and (5) save the INDSWMI to the swm file format.  
Figure 2: Definition of main data types of the INDSWMI generation algorithm.