I am new to geodetic data in R, so apologies if this is way off. I have got a dataset, with a column
geometry, which contains SFC points, and a second column
<list> <POINT [°]> <int [4,415]> (144.9179 -45.59569) <int [3,388]> (5.740768 49.15625) <int [6,214]> (2.18701 52.80779) <int [7,948]> (3.108628 50.58135) <int [2,298]> (-96.77081 37.37828)
I would like to input an x and y value, in order to find the row number, which I can then use to pull out the same value from the
IntersectingPoints column. The code I have written is:
x = 144.9179 y = -45.59569 point_ref=st_point(c(x,y)) which(pt$geometry == point_ref)
I was expecting this to output the first row, however, this does not work, I think as the geometry is classed as a list.
How I can output the row number?
The error when trying to run my code was:
Error in which(pt$geometry == point_ref) : 'list' object cannot be coerced to type 'double' In addition: Warning messages: 1: In which(pt$geometry == point_ref) : Incompatible methods ("Ops.sfc", "Ops.sfg") for "==" 2: In pt$geometry == point_ref : longer object length is not a multiple of shorter object length
When I run
st_sfc(point_ref) == st_geometry(pt), this does not find any results.
Output for 'st_sfc(point_ref):
Geometry set for 1 feature Geometry type: POINT Dimension: XY Bounding box: xmin: 144.9179 ymin: -45.59569xmax: 144.9179 ymax: -45.59569 CRS: NA POINT (144.9179 -45.59569)
Output for 'st_geometry(pt)' is:
Geometry set for 139709 features Geometry type: POINT Dimension: XY Bounding box: xmin: -172.9813 ymin: -56.81466 xmax: 171.9221 ymax: 71.08403 Geodetic CRS: WGS 84 First 5 geometries: POINT (144.9179 -45.59569)
I can see that the points are the same, so I would have thought that when these were run together, a match would have been found!