pgSRID {rpostgis} | R Documentation |
Find (or create) PostGIS SRID based on CRS object.
Description
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.)
Usage
pgSRID(conn, crs, create.srid = FALSE, new.srid = NULL)
Arguments
conn |
A connection object to a PostgreSQL database. |
crs |
crs object, created through a call to
|
create.srid |
Logical. If no matching SRID is found, should a new
SRID be created? User must have write access on
|
new.srid |
Integer. Optional SRID to give to a newly created
SRID. If left NULL (default), the next open value of
|
Value
SRID code (integer).
Author(s)
David Bucklin david.bucklin@gmail.com and Adrián Cidre González adrian.cidre@gmail.com
Examples
## Not run:
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)
## End(Not run)