Find (or create) PostGIS SRID based on CRS object.

Share:

Description

This function takes 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

1
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 CRS.

create.srid

Logical. If no matching SRID is found, should a new SRID be created? User must have write access on spatial_ref_sys table.

new.srid

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.

Value

SRID code (integer).

Author(s)

David Bucklin dbucklin@ufl.edu

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
drv <- dbDriver("PostgreSQL")
conn <- dbConnect(drv, dbname = "dbname", host = "host", port = "5432",
    user = "user", password = "password")
(crs <- CRS("+proj=longlat"))
pgSRID(conn, crs)
(crs2 <- 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)