library(sparklyr)
library(apache.sedona)
sc <- spark_connect(master = "spark://HOST:PORT")
if (!inherits(sc, "test_connection")) {
range_query_min_x <- -87
range_query_max_x <- -50
range_query_min_y <- 34
range_query_max_y <- 54
geom_factory <- invoke_new(
sc,
"org.locationtech.jts.geom.GeometryFactory"
)
range_query_polygon <- invoke_new(
sc,
"org.locationtech.jts.geom.Envelope",
range_query_min_x,
range_query_max_x,
range_query_min_y,
range_query_max_y
) %>%
invoke(geom_factory, "toGeometry", .)
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"
)
range_query_result_sdf <- sedona_range_query(
rdd,
x = range_query_polygon,
query_type = "intersect",
index_type = "rtree",
result_type = "sdf"
)
}
Run the code above in your browser using DataLab