---
title: geo.groupByArea() function
description: geo.groupByArea() groups rows by geographic area.
url: https://docs.influxdata.com/flux/v0/stdlib/experimental/geo/groupbyarea/
estimated_tokens: 936
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/experimental/geo/groupbyarea/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.63.0+

InfluxDB support

> [!Important]
> `geo.groupByArea()` is experimental and [subject to change at any time](/flux/v0/stdlib/experimental/#experimental-packages-are-subject-to-change).

`geo.groupByArea()` groups rows by geographic area.

Area sizes are determined by the specified `level`.
Each geographic area is assigned a unique identifier (the S2 cell ID token)
which is stored in the `newColumn`.
Results are grouped by `newColumn`.

##### Function type signature

```js
(
    <-tables: stream[{A with s2_cell_id: string, lon: float, lat: float}],
    level: int,
    newColumn: string,
    ?s2cellIDLevel: int,
) => stream[B] where B: Record
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### newColumn

(Required)
Name of the new column for the unique identifier for each geographic area.

### level

(Required)[S2 Cell level](https://s2geometry.io/resources/s2cell_statistics.html)used to determine the size of each geographic area.

### s2cellIDLevel

[S2 Cell level](https://s2geometry.io/resources/s2cell_statistics.html)used in the `s2_cell_id` tag. Default is `-1` (detects S2 cell level from the `s2_cell_id` tag).

### tables

Input data. Default is piped-forward data (`<-`).

## Examples

### Group geotemporal data by geographic area

```js
import "experimental/geo"

data
    |> geo.groupByArea(newColumn: "foo", level: 4)
```

[](#view-example-input-and-output)

View example input and output

#### Input data

|       \_time       |\*id |  lat   |   lon   |\*s2\_cell\_id|
|--------------------|-----|--------|---------|--------------|
|2021-01-03T02:00:00Z|a213b|39.08433|\-75.9978|     89bc     |

|       \_time       |\*id |  lat   |   lon   |\*s2\_cell\_id|
|--------------------|-----|--------|---------|--------------|
|2021-01-01T00:00:00Z|a213b|41.01433|\-70.7515|     89e4     |

|       \_time       |\*id |  lat  |   lon   |\*s2\_cell\_id|
|--------------------|-----|-------|---------|--------------|
|2021-01-02T01:00:00Z|a213b|40.9228|\-73.3527|     89ec     |

#### Output data

|\*foo|       \_time       | id  |  lat   |   lon   |s2\_cell\_id|
|-----|--------------------|-----|--------|---------|------------|
| 89b |2021-01-03T02:00:00Z|a213b|39.08433|\-75.9978|    89bc    |

|\*foo|       \_time       | id  |  lat   |   lon   |s2\_cell\_id|
|-----|--------------------|-----|--------|---------|------------|
| 89f |2021-01-01T00:00:00Z|a213b|41.01433|\-70.7515|    89e4    |
| 89f |2021-01-02T01:00:00Z|a213b|40.9228 |\-73.3527|    89ec    |

#### Related

* [Work with geo-temporal data](/influxdb/v2/query-data/flux/geo/)

[transformations](/flux/v0/tags/transformations/)[geotemporal](/flux/v0/tags/geotemporal/)
| _time | *id | lat | lon | *s2_cell_id |
| --- | --- | --- | --- | --- |
| _time | *id | lat | lon | *s2_cell_id |
| 2021-01-03T02:00:00Z | a213b | 39.08433 | -75.9978 | 89bc |

| _time | *id | lat | lon | *s2_cell_id |
| --- | --- | --- | --- | --- |
| _time | *id | lat | lon | *s2_cell_id |
| 2021-01-01T00:00:00Z | a213b | 41.01433 | -70.7515 | 89e4 |

| _time | *id | lat | lon | *s2_cell_id |
| --- | --- | --- | --- | --- |
| _time | *id | lat | lon | *s2_cell_id |
| 2021-01-02T01:00:00Z | a213b | 40.9228 | -73.3527 | 89ec |

| *foo | _time | id | lat | lon | s2_cell_id |
| --- | --- | --- | --- | --- | --- |
| *foo | _time | id | lat | lon | s2_cell_id |
| 89b | 2021-01-03T02:00:00Z | a213b | 39.08433 | -75.9978 | 89bc |

| *foo | _time | id | lat | lon | s2_cell_id |
| --- | --- | --- | --- | --- | --- |
| *foo | _time | id | lat | lon | s2_cell_id |
| 89f | 2021-01-01T00:00:00Z | a213b | 41.01433 | -70.7515 | 89e4 |
| 89f | 2021-01-02T01:00:00Z | a213b | 40.9228 | -73.3527 | 89ec |
