Set the right crs on sf object to plot coordinate points
Asked Answered
F

2

19

I'm trying to define the right CRS for my sf object. I want to plot points atop the following layer (country: the Netherlands):

Simple feature collection with 380 features and 3 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: 13565.4 ymin: 306846.2 xmax: 278026.1 ymax: 619232.6
epsg (SRID):    NA
proj4string:    +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs

output:

enter image description here

This layer has the correct projection.

But the POINT layer doesn't have the correct CRS project presumably because it has no proj4string?

Simple feature collection with 566 features and 5 fields
geometry type:  POINT
dimension:      XY
bbox:           xmin: 3.5837 ymin: 50.86487 xmax: 7.120998 ymax: 53.44835
epsg (SRID):    NA
proj4string:    NA

enter image description here

How do I set the same projection as the previous map so I can plot the coordinates points on it?

Fever answered 8/5, 2018 at 11:18 Comment(0)
P
27

In addition, there is the function st_set_crs(), which can be used in a pipe. For example,

points %>% st_set_crs(st_crs(polygons))

Prolusion answered 8/5, 2018 at 18:38 Comment(3)
I couldn't find a function st_set_crs in package sf. Is this outdated now?Hookah
It seems it's part of the geotidy package.Mini
sf::st_set_crs() exists.Hosmer
S
12

You can use st_crs.

As it says in the examples:

st_crs(x) <- value 

In your case it would probably be

st_crs(points) <- st_crs(polygons)

Note: the points should be registered in the same coordinate system, of course. If not, you would have to find out the correct coordinate system for them and then use st_transform to put them into the same coordinate system as the polygons.

Slowpoke answered 8/5, 2018 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.