# Energy-Efficient Spatial Query-Centric Geographic Routing Protocol in Wireless Sensor Networks
## 3 QTGrid Routing Protocol
### CH and PCH Election
#### 3.2.2 PCH Election
``` G \(\leftarrow\)the minimum rectangle covers the query window R \(\leftarrow\)the minimum rectangle that totally covers the sink node and query window G id \(\leftarrow\)the identification of the data packet X \(\leftarrow\)the sensor node that receives the packets ReceiveQueryRequestPackage (G, R, id){  Begin if(X is within the zone R)  then begin  if(X is a CH)  then begin //Judge that whether X has ever received the //current request packet before  if(package ID\(=\)id)  
Figure 6: Data aggregation. then begin Step1. X directly discards the packet; end else begin Step2. X sends the packet to its next routing hop CH; end else begin Step3. X sends the packet to its CH end else if (X is within the query window G) then begin if (X is a CH) then begin //Judge that whether X has ever received the //current request packet before if (package ID==id) then begin Step1. X directly discards the packet; end else begin Step4. X sends the packet to its CMs; end else begin Step2. X sends the packet to its CH end else begin Step1. [PERSON] directly discards the packet; end ```
**Algorithm 3 Sensor Data Feedback
``` X \(\leftarrow\) a sensor node in the query window queryWindow \(\leftarrow\) the query window L \(\leftarrow\) the hierarchical level of X's PCH in the query window input by the user Depth \(\leftarrow\) the depth of the quadtree structure GetDataOfRegion(queryWindow, L, Depth){ Begin if (X is a CH) if (0<Level<Depth-1) then begin Step1. Collects and aggregates the required sensing data from CMs; Step2. Aggregates the required sensing data by the algorithm in Section 3.4; Step3. Uses PCH selection algorithm to calculate the level = L PCH; Step4. Calculates the routing to the level = L PCH; Step5. Sends the data to higher level PCH by formula (4)&(5) until level = L PCH receives the data packet; end end ```
**Algorithm 4** Sensor Data Feedback
```

## 4 Simulations and Analyses

### Simulation Setup

Simulation was performed using Network Simulator MATLAB 7. The energy model is required to calculate energy consumption. In this study, the energy consumption of the node consisted of communication and calculation. Here, the communication energy model from the literature [49], which is commonly used, is introduced. The power consumption to transmit a \(k\)-bit message over distance \(d\) is given as follows:

\[E_{Tx}(k,d)=\left\{ \begin{array}{l}E_{elce}k+k\varepsilon_{fg}d^{2},d<d_{0}\\ E_{elce}k+k\varepsilon_{mp}d^{4},d\geq d_{0}\end{array} \right. \tag{6}\]

and the power consumption to receive the message is

\[E_{Rx}=E_{Rx}(k,d)=kE_{elce}, \tag{7}\]

where \(E_{elce}\) denotes electronic energy, which depends on factors, such as the digital coding, modulation, filtering, and spreading of the signal. \(\varepsilon_{fg}d^{2}\) or \(\varepsilon_{mp}d^{4}\) depends on the distance to the receiver and the acceptable bit-error rate. \(d_{0}\) is the threshold for switching to a different model, whose value can be set as adopted from the literature [50]. The calculation of nodes mainly included routing path and data aggregation, and the calculation energy consumption model is given as follows:

\[E_{C}=E_{r}+E_{da}, \tag{8}\]

where \(E_{r}\) is the computation cost of routing per time and \(E_{da}\) is the computation cost of data aggregation. Figure 7: Sensor data transmission zone. QTGrid was designed for large-scale WSNs. According to the comparison results of various relevant GRs in Table 1, we only selected GRs suitable for large-scale networks for comparison. In view of the superior performance of GeoGrid [26], QTBDC [43], and GCCR [20] in energy saving, load balance, and spatial query efficiency, they were used for comparison with QTGrid in terms of average network energy consumption, number of network surviving nodes, and spatial query energy consumption. We set the network layer number of QTBDC and QTGrid to three, and the corresponding number of grids for setting GeoGrid and GCCR was 64.