-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: finding nearby points of interest (POIs) for location-based ser… #34
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
open Rtree | ||
open Printf | ||
(* Sample Point of Interest data structure *) | ||
type poi = { | ||
name : string; | ||
latitude : float; | ||
longitude : float; | ||
} | ||
|
||
|
||
module Rtree = struct | ||
|
||
(* Function to insert POIs into the R-tree *) | ||
let insert_pois rtree pois = | ||
List.iter (fun poi -> Rtree.insert rtree (poi.latitude, poi.longitude, poi)) pois | ||
|
||
(* Function to load geospatial data from a CSV file *) | ||
let load_geospatial_data_from_csv filename = | ||
let ic = open_in filename in | ||
let csv = Csv.of_channel ~has_header:true ic in | ||
let pois = ref [] in | ||
Csv.iter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make this more functional I think we should use fold_left instead of iter + mutable state :)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @patricoferris, will do that |
||
(fun row -> | ||
let name = row.(0) in | ||
let latitude = float_of_string row.(1) in | ||
let longitude = float_of_string row.(2) in | ||
pois := { name; latitude; longitude } :: !pois | ||
) | ||
csv; | ||
close_in ic; | ||
List.rev !pois | ||
|
||
(* Example usage with geospatial data from a CSV file *) | ||
let () = | ||
let rtree = Rtree.create () in | ||
|
||
(* Load geospatial data from external csv file *) | ||
let csv = | ||
List.map (fun name -> name, Csv.load name) | ||
[ "example/pois.csv"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not valid OCaml as we need an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok @patricoferris , I will have to check and correct that |
||
|
||
|
||
(* Perform real-world spatial queries *) | ||
let nearby_pois = find_nearby_pois rtree 42.3601 (-71.0589) 1.0 in | ||
List.iter (fun poi -> Printf.printf("Nearby: %s\n" poi.name)) nearby_pois |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name,latitude,longitude | ||
Restaurant A,42.3601,-71.0589 | ||
Cafe B,42.3605,-71.0587 | ||
Park C,42.3609,-71.0585 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about making this it's own module: