Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Mankavelda
Copy link

…vices.
This PR makes the following changes
*closes issue #33

Real world example: finding nearby points of interest (POIs) for location-based services.

description
This pull request introduces a code example that shows the application of the R-tree library to solve a real-world challenge: finding nearby points of interest (POIs) for location-based services. The example demonstrates how the R-tree data structure efficiently organizes and queries geospatial data, which is vital for applications such as navigation, mapping, and location-based recommendations.

Key Components

  1. Sample Data: The code example defines a custom data structure, poi, to represent points of interest. Each poi object includes attributes like name, latitude, and longitude, which are typical of geospatial data.

  2. Integration with R-tree Library: The code demonstrates the seamless integration of the OCaml R-tree library. The library's functionalities, including creating an R-tree, inserting data, and performing spatial queries, are used in the example.

  3. Data Insertion: The code inserts a list of sample POIs into the R-tree. This operation organizes the POIs spatially within the tree structure, which is essential for efficient spatial queries.

  4. Spatial Query: To illustrate the R-tree's capabilities, the code performs a spatial query to find nearby POIs within a specified radius of a given location. The R-tree's range query functionality is employed, optimizing the process of identifying relevant points of interest.

Copy link
Contributor

@patricoferris patricoferris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Mankavelda -- you will need to add a dune file to build main.ml. You should be able to use the tests as a basis to do that.

open Rtree
open Printf
(* Sample Point of Interest data structure *)
type poi = {
Copy link
Contributor

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:

module Poi = struct
  type t = {...}
end

let ic = open_in filename in
let csv = Csv.of_channel ~has_header:true ic in
let pois = ref [] in
Csv.iter
Copy link
Contributor

Choose a reason for hiding this comment

The 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 :))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @patricoferris, will do that

(* Load geospatial data from external csv file *)
let csv =
List.map (fun name -> name, Csv.load name)
[ "example/pois.csv"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not valid OCaml as we need an in afterwards.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok @patricoferris , I will have to check and correct that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants