library(sparklyr)
library(apache.sedona)
sc <- spark_connect(master = "spark://HOST:PORT")
if (!inherits(sc, "test_connection")) {
knn_query_pt_x <- -84.01
knn_query_pt_y <- 34.01
knn_query_pt_tbl <- sdf_sql(
sc,
sprintf(
"SELECT ST_GeomFromText(\"POINT(%f %f)\") AS `pt`",
knn_query_pt_x,
knn_query_pt_y
)
) %>%
collect()
knn_query_pt <- knn_query_pt_tbl$pt[[1]]
input_location <- "/dev/null" # replace it with the path to your input file
rdd <- sedona_read_geojson_to_typed_rdd(
sc,
location = input_location,
type = "polygon"
)
knn_result_sdf <- sedona_knn_query(
rdd,
x = knn_query_pt, k = 3, index_type = "rtree", result_type = "sdf"
)
}
Run the code above in your browser using DataLab