Hi community, I have an object SpatVector and I want to filter the coordinates less than lon -75.84.
I am trying the following code and I don't get good result, because I get a numeric(0) object.
library(terra)
filtered_raster <- rast(filtered_raster)
> filtered_raster
#class : SpatVector
#geometry : polygons
#dimensions : 2101808, 1 (geometries, attributes)
#extent : -74.69778, -73.7997, 3.92994, 5.439994 (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=longlat +datum=WGS84 +no_defs
#names : layer
#type : <int>
#values : 1506
# 1510
# 1515
long_min <- -75.84
coords <- geom(filtered_raster)
#coords
# geom part x y hole
# [1,] 1 1 -76.36755 4.160056 0
# [2,] 1 1 -76.36755 4.159885 0
# [3,] 1 1 -76.36738 4.159885 0
# [4,] 1 1 -76.36738 4.160056 0
geometry_ids <- unique(coords[coords[, "x"] <= long_min, "geom"])
#coords[, "x"]
# [1] -76.36755 -76.36755 -76.36738 -76.36738 -76.36755 -75.96825 -75.96825 -75.96807
# [9] -75.96807 -75.96825 -76.36738 -76.36738 -76.36721 -76.36721 -76.36738 -76.02656
# [17] -76.02656 -76.02639 -76.02639 -76.02656 -75.95984 -75.95984 -75.95967 -75.95967
filtered_left <- filtered_raster2[geometry_ids, ]
In this image Im want get only the green polygon.
Any ideas?