Geo Data using the Cell Tower Dataset

3. Check how many cell towers are in Moscow:

```
SELECT count() FROM cell_towers
WHERE pointInPolygon((lon, lat), (SELECT * FROM moscow))
```

```
┌─count()─┐
│  310463 │
└─────────┘

1 rows in set. Elapsed: 0.067 sec. Processed 43.28 million rows, 692.42 MB (645.83 million rows/s., 10.33 GB/s.)
```

## Review of the schema[​](#review-of-the-schema "Direct link to Review of the schema")

Before building visualizations in Superset have a look at the columns that you will use. This dataset primarily provides the location (Longitude and Latitude) and radio types at mobile cellular towers worldwide. The column descriptions can be found in the [community forum](https://community.opencellid.org/t/documenting-the-columns-in-the-downloadable-cells-database-csv/186). The columns used in the visualizations that will be built are described below

Here is a description of the columns taken from the OpenCelliD forum:

|  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Column Description|  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | | radio Technology generation: CDMA, GSM, UMTS, 5G NR|  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | | mcc Mobile Country Code: `204` is The Netherlands| lon Longitude: With Latitude, approximate tower location|  |  | | --- | --- | | lat Latitude: With Longitude, approximate tower location | | | | | | | | | |

mcc

To find your MCC check [Mobile network codes](https://en.wikipedia.org/wiki/Mobile_country_code), and use the three digits in the **Mobile country code** column.

The schema for this table was designed for compact storage on disk and query speed.

- The `radio` data is stored as an `Enum8` (`UInt8`) rather than a string.
- `mcc` or Mobile country code, is stored as a `UInt16` as we know the range is 1 - 999.
- `lon` and `lat` are `Float64`.

None of the other fields are used in the queries or visualizations in this guide, but they're described in the forum linked above if you're interested.

## Build visualizations with Apache Superset[​](#build-visualizations-with-apache-superset "Direct link to Build visualizations with Apache Superset")

Superset is easy to run from Docker. If you already have Superset running, all you need to do is add ClickHouse Connect with `pip install clickhouse-connect`. If you need to install Superset open the **Launch Apache Superset in Docker** directly below.

Launch Apache Superset in Docker

Superset provides [installing Superset locally using Docker Compose](https://superset.apache.org/docs/installation/installing-superset-using-docker-compose/) instructions. After checking out the Apache Superset repo from GitHub you can run the latest development code, or a specific tag. We recommend release 2.0.0 as it is the latest release not marked as `pre-release`.

There are a few tasks to be done before running `docker compose`:

1. Add the official ClickHouse Connect driver
2. Obtain a Mapbox API key and add that as an environment variable (optional)
3. Specify the version of Superset to run

Tip

The commands below are to be run from the top level of the GitHub repo, `superset`.

## Official ClickHouse connect driver[​](#official-clickhouse-connect-driver "Direct link to Official ClickHouse connect driver")

To make the ClickHouse Connect driver available in the Superset deployment add it to the local requirements file:

```
echo "clickhouse-connect" >> ./docker/requirements-local.txt
```

## Mapbox[​](#mapbox "Direct link to Mapbox")

This is optional, you can plot location data in Superset without a Mapbox API key, but you will see a message telling you that you should add a key and the background image of the map will be missing (you will only see the data points and not the map background). Mapbox provides a free tier if you would like to use it.

Some of the sample visualizations that the guides have you create use location, for example longitude and latitude, data. Superset includes support for Mapbox maps. To use the Mapbox visualizations you need a Mapbox API key. Sign up for the [Mapbox free tier](https://account.mapbox.com/auth/signup/), and generate an API key.

Make the API key available to Superset:

```
echo "MAPBOX_API_KEY=pk.SAMPLE-Use-your-key-instead" >> docker/.env-non-dev
```

## Deploy Superset version 2.0.0[​](#deploy-superset-version-200 "Direct link to Deploy Superset version 2.0.0")

To deploy release 2.0.0 run:

```
git checkout 2.0.0
TAG=2.0.0 docker-compose -f docker-compose-non-dev.yml pull
TAG=2.0.0 docker-compose -f docker-compose-non-dev.yml up
```

To build a Superset dashboard using the OpenCelliD dataset you should:

- Add your ClickHouse service as a Superset **database**
- Add the table **cell\_towers** as a Superset **dataset**
- Create some **charts**
- Add the charts to a **dashboard**

### Add your ClickHouse service as a Superset database[​](#add-your-clickhouse-service-as-a-superset-database "Direct link to Add your ClickHouse service as a Superset database")

To connect to ClickHouse with HTTP(S) you need this information:

|  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Parameter(s) Description|  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | | `HOST` and `PORT` Typically, the port is 8443 when using TLS or 8123 when not using TLS.|  |  |  |  | | --- | --- | --- | --- | | `DATABASE NAME` Out of the box, there is a database named `default`, use the name of the database that you want to connect to.| `USERNAME` and `PASSWORD` Out of the box, the username is `default`. Use the username appropriate for your use case. | | | | | | | |

The details for your ClickHouse Cloud service are available in the ClickHouse Cloud console.
Select a service and click **Connect**:

Choose **HTTPS**. Connection details are displayed in an example `curl` command.

If you're using self-managed ClickHouse, the connection details are set by your ClickHouse administrator.

In Superset a database can be added by choosing the database type, and then providing the connection details. Open Superset and look for the **+**, it has a menu with **Data** and then **Connect database** options.

Choose **ClickHouse Connect** from the list:

Note

If **ClickHouse Connect** isn't one of your options, then you will need to install it. The command is `pip install clickhouse-connect`, and more info is [available here](https://pypi.org/project/clickhouse-connect/).

#### Add your connection details[​](#add-your-connection-details "Direct link to Add your connection details")

Tip

Make sure that you set **SSL** on when connecting to ClickHouse Cloud or other ClickHouse systems that enforce the use of SSL.

### Add the table **cell\_towers** as a Superset **dataset**[​](#add-the-table-cell_towers-as-a-superset-dataset "Direct link to add-the-table-cell_towers-as-a-superset-dataset")

In Superset a **dataset** maps to a table within a database. Click on add a dataset and choose your ClickHouse service, the database containing your table (`default`), and choose the `cell_towers` table:

### Create some **charts**[​](#create-some-charts "Direct link to create-some-charts")

When you choose to add a chart in Superset you have to specify the dataset (`cell_towers`) and the chart type. Since the OpenCelliD dataset provides longitude and latitude coordinates for cell towers we will create a **Map** chart. The **deck.gL Scatterplot** type is suited to this dataset as it works well with dense data points on a map.

#### Specify the query used for the map[​](#specify-the-query-used-for-the-map "Direct link to Specify the query used for the map")

A deck.gl Scatterplot requires a longitude and latitude, and one or more filters can also be applied to the query. In this example two filters are applied, one for cell towers with UMTS radios, and one for the Mobile country code assigned to The Netherlands.

The fields `lon` and `lat` contain the longitude and latitude:

Add a filter with `mcc` = `204` (or substitute any other `mcc` value):