| Algorithm 2 Spatial Query Request Sent |
| G ←the minimum rectangle covers the query window |
| R ←the minimum rectangle that totally covers the sink node and query window G |
| id ← the identification of the data packet |
| X ← 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) |
| 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 |
| 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 |
| end |
| else begin |
| Step2. X sends the packet to its CH |
| end |
| else begin |
| Step1. X directly discards the packet; |
| end |
| } |