Databases Reference
In-Depth Information
Figure 8-6. Road segments
Our app analyzes each road segment as a data tuple, calculating a center point for each.
We use a geohash value to construct a bounding box around that center point, then join
the data to collect metrics for all the trees nearby, as Figure 8-7 shows.
Figure 8-7. Trees near road segments
The join occurs in the get-shade function where both the roads and trees tuples ref‐
erence the ?geohash field:
( defn tree-distance [ tree_lat tree_lng road_lat road_lng ]
"calculates distance from a tree to the midpoint of a road segment"
( let [ y ( - tree_lat road_lat )
x ( - tree_lng road_lng )]
( Math/sqrt ( + ( Math/pow y 2.0 ) ( Math/pow x 2.0 )))))
( defn get-shade [ trees roads ]
"subquery to join the tree and road estimates, to maximize for shade"
( <- [ ?road_name ?geohash ?road_lat ?road_lng ?road_alt
 
Search WWH ::




Custom Search