Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to Sheets places_in.md file #367

Merged
merged 9 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 0 additions & 285 deletions Gemfile.lock

This file was deleted.

73 changes: 45 additions & 28 deletions api/sheets/places_in.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,75 @@
---
layout: default
title: Places within a Place
title: Retrieving Places Contained Within Another Place
nav_order: 2
parent: Google Sheets
grand_parent: API
---

# Retrieve places contained within another place
# Retrieving Places Contained Within Another Place

Given a list of parent [`Place`](https://datacommons.org/browser/Place) [DCIDs](/glossary.html),
(e.g. any [`State`](https://datacommons.org/browser/State), [`Country`](https://datacommons.org/browser/Country), etc.), return a list of child places
contained within the specified DCIDs. Only returns children whose place type matches
the request's `placeType` parameter.
The `=DCPLACESIN(dcids, placeType)` formula returns lists of child places from a list of parent [Place](https://datacommons.org/browser/Place) [DCIDs](https://docs.datacommons.org/glossary.html), such as [State](https://datacommons.org/browser/State), [Country](https://datacommons.org/browser/Country), and so on. It only returns children with a place type that matches the `placeType` parameter.

## General information about this endpoint
> **Note**
>
> Be sure to follow the instructions for [Installing and Enabling the Sheets Add-On](/api/sheets/) before using this formula.

**Formula**: `=DCPLACESIN(dcids, placeType)`
## Formula {#formula}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check the formatting of these shortcuts (or what's in the brackets). here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Formula {#formula}
## Formula


**Required arguments**:
```
=DCPLACESIN(dcids, placeType)
```

* `dcids`: A list of (parent) `Place` nodes, identified by their DCIDs.
## Required Arguments {#required-arguments}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Required Arguments {#required-arguments}
## Required Arguments


* `placeType`: The type of the contained (child) `Place` nodes to filter by. For example, `City` and `County` are contained within `State`. For a
full list of available types, see [the Data Commons graph browser entry for `Place`](https://datacommons.org/browser/Place).
* `dcids`: A list of (parent) `Place` nodes, identified by their DCIDs.
* `placeType`: The type of the contained (child) `Place` nodes to filter by. For example,`City` and `County`are contained within `State`. For a full list of available types, see [the Data Commons graph browser entry for Place](https://datacommons.org/browser/Place).

beets marked this conversation as resolved.
Show resolved Hide resolved
## Returns

## Assembling the information you will need to use this formula
Lists of child places from a list of parent [Place](https://datacommons.org/browser/Place) [DCIDs](https://docs.datacommons.org/glossary.html), such as [State](https://datacommons.org/browser/State), [Country](https://datacommons.org/browser/Country), and so on. Returns a list of child places of the specified place dcids, of the specified place type.

This endpoint requires the argument `dcids`. [DCIDs](/glossary.html) are unique node identifiers defined by Data Commons. Your query will need to specify the DCIDs for the parent places of interest.

This endpoint also requires the argument `placeType`, specifying the type of the child places you desire in the response.
> **Note**:
> It’s best to minimize the number of function calls to `=DCPLACESIN(dcids, placeType)` by using a single call to get the names for a column of nodes. This is because a spreadsheet will make one call to a Google server [*per custom function call*](https://developers.google.com/apps-script/guides/sheets/functions#optimization). If your sheet contains many thousands of separate calls to `=DCPLACESIN(dcids, placeType)` you can expect it to be slow and return with errors.

## Examples

Before trying this method out, make sure to follow the setup directions in [the main section for Sheets docs](/api/sheets/index.html).
This section contains examples of using the `=DCPLACESIN(dcids, placeType)` formula to return lists of child places from a list of parent [Place](https://datacommons.org/browser/Place) [DCIDs](/glossary.html), such as [State](https://datacommons.org/browser/State), [Country](https://datacommons.org/browser/Country), and so.

### Example 1: Retrieve a List of Counties in Delaware
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add descriptions for these examples like the GETNAME page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bo said he would prefer creating videos for each example, although I do like the example descriptions in the GETNAME page. Please let me know what you decide.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still have text descriptions, even if there are videos or images.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add them


To retrieve a list of counties in Delaware, perform the following steps:

1. Place your cursor in the cell where you want to add the DCID for Delaware. In this case, cell A1.
2. Enter the Delaware DCID of “geoId/10”.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 55, we use bold instead of quotes to show what the user should enter. I personally prefer the bold, but we should probably standardize across examples (and the other pages.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. it's been hard to standardize across the PR's, and i can do a sweep after the first versions are in. i'll update these to bold for now though

3. In cell B1, enter `DCGETNAME(A1)` to retrieve Delaware's name from the DCID in cell A1.
4. Move to the cell C3 and enter the formula `=DCPLACESIN(A1, "County")` to retrieve the county names and press **Enter**. The DCIDs for the three Delaware counties populate column C.
5. Retrieve the Delaware county names by entering the formula `=DCGETNAME(C1:C3)` into cell D1.

![Retrieving a List of Counties in Delaware](/assets/images/sheets/sheets_places_in_counties_in_delaware.png)

### Example 2: Retrieve Congressional Districts in Alaska and Hawaii

### Example 1: Retrieve a list of the counties in Delaware.
To retrieve the congressional districts in Alaska and Hawaii, perform the following steps:

![](/assets/images/sheets/sheets_places_in_counties_in_delaware.png)
1. In cell A1, enter **geoId/02** for the DCID of Alaska and in Cell A2, enter **geoId/15** for the DCID of Hawaii.
2. Enter `=DCGETNAME(A1:A2)` in cell B1 to retrieve the names of Alaska and Hawaii into column B.
3. Retrieve the DCIDs for the congressional districts by enter `=DCPLACESIN(A1:A2, "CongressionalDistrict")` into cell C1.
4. Finally, retrieve the names of the congressional districts by entering `=DCGETNAMES(C1:C3)` into cell D1.

### Example 2: Retrieve a list of congressional districts in Alaska and Hawaii.
![Retrieving Congressional Districts in Alaska and Hawaii](/assets/images/sheets/sheets_places_in_congressional_districts_ak_hi.png)

![](/assets/images/sheets/sheets_places_in_congressional_districts_ak_hi.png)
## Error Returns

## Error Responses
The `=DCPLACESIN(dcids, placeType)` formula returns names associated with given DCIDs to a cell or a column range of cells. See the Examples section above for examples of positive returns. If a DCID does not exist, the `=DCPLACESIN(dcids, placeType)` formula returns a value of #REF!. For example, the `=DCPLACESIN(A1, "CongressionalDistrict")` formula should return the congressional districts for the DCID in cell A1. However, because the “geoId/123123123” DCID does not exist, an error of #REF! is returned to cell B1 in the following sheet:

If you pass a bad DCID value, you will see a reference error appear:
![alt_text](/assets/images/sheets/sheets_places_in_wrong_dcid.png)

![](/assets/images/sheets/sheets_places_in_bad_dcid.png)
If you provide an empty cell for a DCID, the `=DCPLACESIN(dcids, placeType)` formula returns a value of #ERROR!, as shown show in the following image:

Likewise, if you pass a nonexistent place type, you will also see a reference error appear:
![alt_text](/assets/images/sheets/sheets_places_in_no_input.png)

![](/assets/images/sheets/sheets_places_in_bad_place_type.png)
Finally, if you provide an invalid property to the `=DCPLACESIN(dcids, placeType)` formula, an error of #REF! is also returned, as follows:

If you pass an empty DCID, an error will appear:
![alt_text](/assets/images/sheets/sheets_places_in_bad_property.png)

![](/assets/images/sheets/sheets_places_in_empty_cell.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please cut the "fill place dcid's" sidebar from this image - it's confusing to see Alaska in there, but the cell geoId/0200 highlighted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/sheets/sheets_places_in_counties_in_delaware.png
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please cut the "fill place dcid's" sidebar from this image - it's confusing to see Delaware in there, but the cell for Kent County highlighted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.