Skip to contents

get_socrata_data is get_open_data with source_type set to "socrata" (the only currently supported option). get_open_data can return a selected dataset using Socrata Query Language (SoQL) parameters as a tibble or sf object. Details on SoQL queries are found in the Socrata API documentation https://dev.socrata.com/docs/queries/.

Usage

get_open_data(
  data = NULL,
  source_url = NULL,
  source_type = "socrata",
  select = NULL,
  where = NULL,
  query = NULL,
  location = NULL,
  dist = NULL,
  diag_ratio = NULL,
  unit = NULL,
  asp = NULL,
  name_col = NULL,
  name = NULL,
  coords = c("longitude", "latitude"),
  geometry = FALSE,
  token = NULL,
  from_crs = 4326,
  crs = NULL,
  clean_names = TRUE
)

get_socrata_data(
  data = NULL,
  source_url = NULL,
  select = NULL,
  where = NULL,
  query = NULL,
  location = NULL,
  dist = NULL,
  diag_ratio = NULL,
  unit = NULL,
  asp = NULL,
  name_col = NULL,
  name = NULL,
  coords = c("longitude", "latitude"),
  geometry = FALSE,
  token = NULL,
  from_crs = 4326,
  crs = NULL,
  clean_names = TRUE
)

Arguments

data

A data set identifier (known as a resource for Socrata). If data is set to "list" and a valid source_url is provided, the function returns a list of all available resources.

source_url

A data source url. For Socrata, this should the base url for the open data portal.

source_type

Data source type; defaults to "socrata" which is currently the only supported option.

select

SODA $select parameter. Set of columns to be returned, similar to a SELECT in SQL. https://dev.socrata.com/docs/queries/select.html

where

SODA $where parameter. Filters the rows to be returned, similar to WHERE. https://dev.socrata.com/docs/queries/where.html

query

SODA $query parameter. A full SoQL query string, all as one parameter. https://dev.socrata.com/docs/queries/query.html

location

sf or bbox obkect

dist

buffer distance in units. Optional.

diag_ratio

ratio of diagonal distance of area's bounding box used as buffer distance. e.g. if the diagonal distance is 3000 meters and the "diag_ratio = 0.1" a 300 meter will be used. Ignored when dist is provided.

unit

Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; defaults to "meter"

asp

Aspect ratio of width to height as a numeric value (e.g. 0.33) or character (e.g. "1:3"). If numeric, get_asp() returns the same value without modification.

name_col

name of column in Socrata data with location names (e.g. County)

name

location name to return

coords

Name(s) of column with coordinate data, Default: c("longitude", "latitude")

geometry

If TRUE and latitude/longitude columns available, return a sf() object. Default FALSE.

token

Access token or API Key; required to access data from Socrata.

from_crs

Coordinate reference system used to match the location CRS to the source data.

crs

Coordinate reference system to return.

clean_names

If TRUE, pass data frame to janitor::clean_names; defaults to TRUE.

Examples

## Get Q2 2020 vehicle crash data for Cecil County, Maryland
if (FALSE) {
  get_open_data(
    source_url = "https://opendata.maryland.gov",
    data = "65du-s3qu",
    where = "(year = '2020') AND (quarter = 'Q2')",
    name_col = "county_desc",
    name = "Cecil",
    token = Sys.getenv("MARYLAND_OPEN_DATA_API_KEY")
  )
}