# Generating trade areas based on drive/walk-time isolines

<div align="left"><figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FhB2W9xXbzzo0kEuXMe3S%2Fintermediate%20banner.png?alt=media&#x26;token=4acd2cc7-c7e8-46c0-9669-6f6b73c030dd" alt="Intermediate difficulty banner" width="175"><figcaption></figcaption></figure></div>

## Requirements

To run this example you'll need:

* An active CARTO organization
* The latest version of the [Analytics Toolbox Advanced](https://academy.carto.com/advanced-spatial-analytics/spatial-analytics-for-snowflake/step-by-step-tutorials/broken-reference) installed in your Snowflake database

## Example

In this example, we will create isolines around some Starbucks locations in order to estimate their trade areas based on drive-time areas around them.

You can use any point table to replicate this analysis, or if you want to replicate this example exactly, you can subscribe to the [CARTO Academy](https://app.snowflake.com/marketplace/listing/GZT0Z4CM1E9J2/carto-carto-academy-data-for-tutorials?search=carto%20academy) data via the Snowflake Data Marketplace. The table we will be using is called **SAFEGRAPH\_COREPLACES\_STARBUCKS\_NY**.&#x20;

This process will generate a new table with the columns of the input table (except the column with the point geometry) plus a new column with the isoline polygon (geom column).

{% hint style="warning" %}
**WARNING**

This function consumes isolines quota. Each call consumes as many units of quota as the number of rows your input table or query has. Before running, we recommend checking the size of the data to be geocoded and your available quota using the [LDS\_QUOTA\_INFO()](https://academy.carto.com/advanced-spatial-analytics/spatial-analytics-for-snowflake/step-by-step-tutorials/broken-reference) function.
{% endhint %}

### Creating isolines from the Snowflake console <a href="#create-isolines-from-the-snowflake-console" id="create-isolines-from-the-snowflake-console"></a>

As a module within CARTO’s Analytics Toolbox, the location data services ([lds](https://academy.carto.com/advanced-spatial-analytics/spatial-analytics-for-snowflake/step-by-step-tutorials/broken-reference)) capabilities are available as SQL procedures that can be executed directly from your Snowflake console or client of choice after connecting your Snowflake project with your CARTO account. To check whether your Snowflake account or Service Account has access to the LDS module, please execute this query:

```sql
SELECT CARTO.CARTO.VERSION_ADVANCED()
```

The lds module is generally available in the Analytics Toolbox since the “July 26, 2022” version. Please check the [Getting Access](https://academy.carto.com/advanced-spatial-analytics/spatial-analytics-for-snowflake/step-by-step-tutorials/broken-reference) section if you run into any errors when running the query above.

For this example we will use a table with the Starbucks addresses geocoded `MYDB.MYSCHEMA.SAFEGRAPH_COREPLACES_STARBUCKS_NY` . The table contains information about Starbucks stores and a column called “geom” with the geographic coordinates (latitude and longitude) of each location. Around these locations we will create isolines based on 5 minutes walking.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FoM4BeAOVE5Jv6OzAq63Y%2FSnowflake%20Starbucks%20data%20preview.png?alt=media&#x26;token=3a42cd15-3e45-4cc0-b865-cbb7f4fa1b0a" alt=""><figcaption></figcaption></figure>

In order to create the isolines, we will execute the [CREATE\_ISOLINES()](https://academy.carto.com/advanced-spatial-analytics/spatial-analytics-for-snowflake/step-by-step-tutorials/broken-reference) procedure, which has the following structure:

```
CALL CARTO.CARTO.CREATE_ISOLINES(
    'my-schema.my-table',
    'my-schema.my-output-table',
    'my_geom_column',
    mode, range, range type
);
```

You can find more information on this in our [documentation](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/lds#create_isolines). To create 5-minute isolines for our Starbucks locations, we can adapt this in the following way:&#x20;

```sql
SELECT 
    CARTO.CARTO.ISOLINE(geom, 'walk', 300, 'time') AS geom_isoline, *
FROM MYDB.MYSCHEMA.SAFEGRAPH_COREPLACES_STARBUCKS_NY

CALL CARTO.CARTO.CREATE_ISOLINES(
    'MYDB.MYSCHEMA.SAFEGRAPH_COREPLACES_STARBUCKS_NY',
    'MYDB.MYSCHEMA.OUTPUT',
    'geom',
    'walk', 300, 'time'
);
```

In the query, we call the ISOLINE() function specifying:

* `geom_isoline` as column name for the origin geometry column
* "mode” parameter = “walk”
* “range\_value” parameter = 300 seconds (5 min).
* Last but not least, we need to use FROM call to specify the input table for the geocoding.

This output query has the same schema as the input one, but adding the “GEOM\_ISOLINE” column with the geometry of the polygon of the isoline that we have calculated.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FoM4BeAOVE5Jv6OzAq63Y%2FSnowflake%20Starbucks%20data%20preview.png?alt=media&#x26;token=3a42cd15-3e45-4cc0-b865-cbb7f4fa1b0a" alt=""><figcaption></figcaption></figure>

And your results should look something like this!

{% embed url="<https://clausa.app.carto.com/map/96c50282-9262-4560-960f-33695a29210f>" %}

You can also run this type of analysis the no-code way in [CARTO Workflows](https://academy.carto.com/creating-workflows/introduction-to-carto-workflows)! Check out the tutorial below to get started.

{% embed url="<https://academy.carto.com/building-interactive-maps/data-analysis/analyzing-multiple-drive-time-catchment-areas-dynamically>" %}

<img src="https://content.gitbook.com/content/FEElAdsRIl9DzfMhbRlB/blobs/GWtJUWkKFcCzxcPMkgpe/eu-flag-website.png" alt="EU flag" data-size="line"> This project has received funding from the [European Union’s Horizon 2020](https://ec.europa.eu/programmes/horizon2020/en) research and innovation programme under grant agreement No 960401.
