Resolve Nodes from Data Commons
dc_get_resolve(
nodes,
expression,
api_key = Sys.getenv("DATACOMMONS_API_KEY"),
base_url = Sys.getenv("DATACOMMONS_BASE_URL", unset =
"https://api.datacommons.org/v2/"),
return_type = "json"
)A character vector of terms to resolve.
A string defining the property expression (e.g., "<-description->dcid").
Your Data Commons API key. If not provided, uses the
environment variable DATACOMMONS_API_KEY.
The base URL of the Data Commons API. Defaults to the public
endpoint. For custom deployments, must end with /core/api/v2/.
Return format: either "list" (parsed R object) or
"json" (JSON string).
A list or JSON string, depending on return_type.
# Find the DCID of a place by another known ID
dc_get_resolve(
nodes = "Q30",
expression = "<-wikidataId->dcid"
)
#> [1] "{\"entities\":[{\"node\":\"Q30\",\"candidates\":[{\"dcid\":\"country/USA\"}]}]}"
# Find the DCID of a place by coordinates
dc_get_resolve(
nodes = "37.42#-122.08",
expression = "<-geoCoordinate->dcid"
)
#> iterating ■■■ 5% | ETA: 21s
#> [1] "{\"entities\":[{\"node\":\"37.42#-122.08\",\"candidates\":[{\"dcid\":\"geoId/0649670\",\"dominantType\":\"City\"},{\"dcid\":\"geoId/06085\",\"dominantType\":\"County\"},{\"dcid\":\"geoId/06\",\"dominantType\":\"State\"},{\"dcid\":\"country/USA\",\"dominantType\":\"Country\"},{\"dcid\":\"geoId/06085504601\",\"dominantType\":\"CensusTract\"},{\"dcid\":\"geoId/060855046011\",\"dominantType\":\"CensusBlockGroup\"},{\"dcid\":\"geoId/0608592830\",\"dominantType\":\"CensusCountyDivision\"},{\"dcid\":\"geoId/0618\",\"dominantType\":\"CongressionalDistrict\"},{\"dcid\":\"geoId/sch0626280\",\"dominantType\":\"SchoolDistrict\"},{\"dcid\":\"ipcc_50/37.25_-122.25_USA\",\"dominantType\":\"IPCCPlace_50\"},{\"dcid\":\"zip/94043\",\"dominantType\":\"CensusZipCodeTabulationArea\"}]}]}"
# Find the DCID of a place by name
dc_get_resolve(
nodes = "Georgia",
expression = "<-description->dcid"
)
#> [1] "{\"entities\":[{\"node\":\"Georgia\",\"candidates\":[{\"dcid\":\"geoId/13\"},{\"dcid\":\"country/GEO\"},{\"dcid\":\"geoId/5027700\"}]}]}"
# Find the DCID of a place by name, with a type filter
dc_get_resolve(
nodes = "Georgia",
expression = "<-description{typeOf:State}->dcid"
)
#> [1] "{\"entities\":[{\"node\":\"Georgia\",\"candidates\":[{\"dcid\":\"geoId/13\"}]}]}"
# Find the DCID of multiple places by name, with a type filter
dc_get_resolve(
nodes = "Mountain View, CA", "New York City",
expression = "<-description{typeOf:City}->dcid"
)
#> [1] "{\"entities\":[{\"node\":\"Mountain View, CA\",\"candidates\":[{\"dcid\":\"geoId/0649670\"},{\"dcid\":\"geoId/0649651\"}]}]}"