gis: GISLibrary

gis_connectionR Documentation

GISLibrary

Description

Functions for interacting with GISLibrary, the primary Met Council ESRI geospatial database.

Usage

gis_connection(
  dbname = "GISLibrary",
  uid = keyring::key_get("councilR.uid"),
  pwd = keyring::key_get("councilR.pwd")
)

import_from_gis(
  query,
  dbname = "GISLibrary",
  uid = keyring::key_get("councilR.uid"),
  pwd = keyring::key_get("councilR.pwd"),
  geometry = TRUE,
  .quiet = FALSE
)

Arguments

dbname

character, database name. Default is "GISLibrary".

uid

character, your network ID. Default is keyring::key_get("councilR.uid").

pwd

character, your network password. Default is keyring::key_get("councilR.pwd").

query

character, string with the database connection and feature class

geometry

logical, whether to pull the geometry column, if it exists. Default value is TRUE.

.quiet

logical, whether to print time elapsed message.

Details

  • gis_connection() creates an S4 Microsoft SQL Server object for GISLibrary. This function will not automatically close the connection, so take care to use DBI::dbDisconnect() once you are done.

  • import_from_gis() imports a given table from GISLibrary and converts it into a sf::sf() object. The connection will be automatically closed after the table is imported. If the table does not have any spatial data, the table will be returned as a data.frame.

Further examples can be found in vignette("Databases", package = "councilR").

Value

gis_connection() - A S4 Microsoft SQL Server object

import_from_gis() - A sf::sf() object or a data frame

See Also

Other database functions: FRED_connection(), FRED_oracle_connection(), emissions_connection()

Other database functions: FRED_connection(), FRED_oracle_connection(), emissions_connection()

Examples

## Not run: 
library(councilR)
library(DBI)
library(sf)

# set credentials if you haven't already
keyring::key_set_with_value("councilR.uid", "mc\\myuuid")
keyring::key_set_with_value("councilR.pwd", "password")

# create connection
gis <- gis_connection()

# pull table using SQL and convert to sf
DBI::dbGetQuery(gis, "select *, Shape.STAsText() as wkt from GISLibrary.dbo.COUNTIES where CO_NAME = 'ANOKA'") %>%
  st_as_sf(wkt = "wkt", crs = 26915)

# disconnect
DBI::dbDisconnect(gis)

# import a specific table, with no additional SQL logic
import_from_gis(query = "GISLibrary.dbo.COUNTIES", dbname = "GISLibrary")

## End(Not run)


Metropolitan-Council/councilR documentation built on Jan. 28, 2025, 8:33 p.m.