# A New Approach to Identifying Crash Hotspot Intersections (CHIs) Using Spatial Weights Matrices
## 2 Methodology
### Methods
#### 2.3.2. The KDSWMCI Generation Algorithm  
To identify the crash hotspot intersections (CHIs), we should build the k-nearest distance-band spatial weights matrix between crash and intersection (KDSWMCI, k=1) based on CSWM by obtaining the adjacency crashes and the number of crashes at each intersection. Generally, an SWM is an N\(\times\)N matrix whose elements are spatial weights. In this research, we expanded the SWM to an M\(\times\)N matrix, as shown in Equation (4), which can accommodate different numbers of intersections and crashes. There is one row for each intersection and one column for each crash. \[ \begin{array}{ccccc}&1&2&j&n\\ 1&w_{11}&w_{12}&w_{1j}&w_{1n}\\ \textit{KDSWMIC}=&2&w_{21}&w_{22}&w_{2j}&w_{2n}\\ &i&w_{i1}&w_{i1}&w_{ij}&w_{in}\\ &m&w_{m1}&w_{m2}&w_{mj}&w_{mm}\end{array}  \tag{4}\]  
Here, \(m\) is the number of crashes; \(n\) is the number of intersections; \(i\) is the unique identifier of a crash; \(j\) is the unique identifier of an intersection; and \(W_{ij}\) is the weight that quantifies the spatial relationship between crashes and intersections. If crash \(i\) occurs on intersection \(j\), then \(W_{ij}=1\); otherwise, \(W_{ij}=0\). We can determine that a crash is on an intersection if the geometric relationships between the crash and intersection meet both of Conditions 1 and 2:  
1. Condition 1: The shortest distance between the crash and the intersection is less than or equal to the threshold distance. 2. Condition 2: The intersection-related crash relates to one, and only one, intersection. That means that the k-nearest neighbor is the same as the 1 st-nearest neighbor. Therefore, if crash \(i\) occurs on  
Figure 3: The INDSWMI generation algorithm. intersection \(j\), then the shortest distance between crash \(i\) and intersection \(j\) should be the minimum distance in all datasets. According to Conditions (1) and (2), the weight of the KDSWMCI is expressed as  
\[W_{ij}=\left\{ \begin{array}{ccc}1,&if&d_{ij}\leq\textit{threshold}&\textit{ distance}&\textit{and}&d_{ij}\leq\forall d_{ik}\\ &&0&,&\textit{else}\end{array} \right. \tag{5}\]  
where \(d_{ij}\) is the Euclidean distance between crash \(i\) and intersection \(j\); \(d_{ik}\) is the Euclidean distance between crash \(i\) and intersection \(k\). A threshold distance of 28.5 m was selected by considering ten-lane intersections and Global Positioning System (GPS) positioning accuracy according to the following premises:  
1. Crash GPS coordinates have a positioning error of approximately 10 m [52]. A crash is considered to occur on the intersection if its coordinates are within 10 m of the buffer of the intersection considering the positioning error. 2. As the Interstate Highway standards for the U.S. Interstate Highway System use a 12 foot (3.7 m) standard lane width, a crash occurring on the intersection can be determined if its coordinates are within (\(3.7\times n/2\)) m of the buffer of the intersection, where \(n\) is the number of lanes of the intersection. We realized the KDSWMCI generation algorithm based on the qt framework with the PostGreSQL/PostGIS database. Figure 4 shows the definitions of the main data types: crash, spatial weight between crash and intersection (SWCI), and KDSWMCI. Note that the structure of intersections used in the algorithm is defined in Figure 2.  
Based on the main data types, we developed a five-step algorithm with pseudocode shown in Figure 5 to generate the KDSWMCI: (1) connect to the PostGreSQL/PostGIS database; (2) cache the intersection and crash table in the PostGreSQL/PostGIS database to memory; (3) build the KDSWMCI using the st_within function and Euclidean distance measurement provided by the postgis extension for PostGreSQL to determine whether a crash is on an intersection according to Conditions 1 and 2; (4) save the crash-intersection spatial relationships to the KDSWMCI table in the PostGreSQL/PostGIS database; (5) compute the number of crashes for each intersection based on the KDSWMCI table.