This function takes st_crs
-class object and a
PostgreSQL database connection (with PostGIS extension), and
returns the matching SRID(s) for that CRS. If a match is not
found, a new entry can be created in the PostgreSQL
spatial_ref_sys
table using the parameters specified by the
CRS. New entries will be created with auth_name =
'rpostgis_custom'
, with the default value being the next open value
between 880001-889999 (a different SRID value can be entered if desired.)
pgSRID(conn, crs, create.srid = FALSE, new.srid = NULL)
A connection object to a PostgreSQL database.
crs object, created through a call to
st_crs
.
Logical. If no matching SRID is found, should a new
SRID be created? User must have write access on
spatial_ref_sys
table.
Integer. Optional SRID to give to a newly created
SRID. If left NULL (default), the next open value of
srid
in spatial_ref_sys
between 880001 and
889999 will be used.
SRID code (integer).
if (FALSE) {
drv <- dbDriver("PostgreSQL")
conn <- dbConnect(drv, dbname = "dbname", host = "host", port = "5432",
user = "user", password = "password")
(crs <- sf::st_crs("+proj=longlat"))
pgSRID(conn, crs)
(crs2 <- sf::st_crs(paste("+proj=stere", "+lat_0=52.15616055555555 +lon_0=5.38763888888889",
"+k=0.999908 +x_0=155000 +y_0=463000", "+ellps=bessel",
"+towgs84=565.237,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812",
"+units=m")))
pgSRID(conn, crs2, create.srid = TRUE)
}