mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 13:13:36 +00:00
134 lines
15 KiB
Markdown
134 lines
15 KiB
Markdown
|
---
|
||
|
toc_priority: 21
|
||
|
toc_title: Cell Stations
|
||
|
---
|
||
|
|
||
|
# Cell Stations
|
||
|
|
||
|
This dataset is from [OpenCellid](https://www.opencellid.org/) - The world's largest Open Database of Cell Towers.
|
||
|
|
||
|
As of 2021 it contains more than 40 million records about cell towers (GSM, LTE, UMTS, etc.) around the world with their geographical coordinates and metadata (country code, network, etc).
|
||
|
|
||
|
OpenCelliD Project is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License, and we redistribute a snapshot of this dataset under the terms of the same license. The up to date version of the dataset is available to download after sign in.
|
||
|
|
||
|
|
||
|
## Get the Dataset
|
||
|
|
||
|
Download the snapshot of the dataset from Feb 2021: [https://datasets.clickhouse.tech/cell_towers.csv.xz] (729 MB).
|
||
|
|
||
|
Optionally validate the integrity:
|
||
|
```
|
||
|
md5sum cell_towers.csv.xz
|
||
|
8cf986f4a0d9f12c6f384a0e9192c908 cell_towers.csv.xz
|
||
|
```
|
||
|
|
||
|
Decompress it with the following command:
|
||
|
```
|
||
|
xz -d cell_towers.csv.xz
|
||
|
```
|
||
|
|
||
|
Create a table:
|
||
|
|
||
|
```
|
||
|
CREATE TABLE cell_towers
|
||
|
(
|
||
|
radio Enum8('' = 0, 'CDMA' = 1, 'GSM' = 2, 'LTE' = 3, 'NR' = 4, 'UMTS' = 5),
|
||
|
mcc UInt16,
|
||
|
net UInt16,
|
||
|
area UInt16,
|
||
|
cell UInt64,
|
||
|
unit Int16,
|
||
|
lon Float64,
|
||
|
lat Float64,
|
||
|
range UInt32,
|
||
|
samples UInt32,
|
||
|
changeable UInt8,
|
||
|
created DateTime,
|
||
|
updated DateTime,
|
||
|
averageSignal UInt8
|
||
|
)
|
||
|
ENGINE = MergeTree ORDER BY (radio, mcc, net, created);
|
||
|
```
|
||
|
|
||
|
Insert the dataset:
|
||
|
```
|
||
|
clickhouse-client --query "INSERT INTO cell_towers FORMAT CSVWithNames" < cell_towers.csv
|
||
|
```
|
||
|
|
||
|
|
||
|
## Run some queries
|
||
|
|
||
|
Number of cell towers by type:
|
||
|
```
|
||
|
SELECT radio, count() AS c FROM cell_towers GROUP BY radio ORDER BY c DESC
|
||
|
|
||
|
┌─radio─┬────────c─┐
|
||
|
│ UMTS │ 20686487 │
|
||
|
│ LTE │ 12101148 │
|
||
|
│ GSM │ 9931312 │
|
||
|
│ CDMA │ 556344 │
|
||
|
│ NR │ 867 │
|
||
|
└───────┴──────────┘
|
||
|
|
||
|
5 rows in set. Elapsed: 0.011 sec. Processed 43.28 million rows, 43.28 MB (3.83 billion rows/s., 3.83 GB/s.)
|
||
|
```
|
||
|
|
||
|
Cell towers by mobile country code (MCC):
|
||
|
```
|
||
|
SELECT mcc, count() FROM cell_towers GROUP BY mcc ORDER BY count() DESC LIMIT 10
|
||
|
|
||
|
┌─mcc─┬─count()─┐
|
||
|
│ 310 │ 5024650 │
|
||
|
│ 262 │ 2622423 │
|
||
|
│ 250 │ 1953176 │
|
||
|
│ 208 │ 1891187 │
|
||
|
│ 724 │ 1836150 │
|
||
|
│ 404 │ 1729151 │
|
||
|
│ 234 │ 1618924 │
|
||
|
│ 510 │ 1353998 │
|
||
|
│ 440 │ 1343355 │
|
||
|
│ 311 │ 1332798 │
|
||
|
└─────┴─────────┘
|
||
|
|
||
|
10 rows in set. Elapsed: 0.019 sec. Processed 43.28 million rows, 86.55 MB (2.33 billion rows/s., 4.65 GB/s.)
|
||
|
```
|
||
|
|
||
|
See the dictionary here: [https://en.wikipedia.org/wiki/Mobile_country_code](https://en.wikipedia.org/wiki/Mobile_country_code).
|
||
|
|
||
|
So, the top countries are USA, Germany and Russia.
|
||
|
|
||
|
You may want to create an [External Dictionary](../../sql-reference/dictionaries/external-dictionaries/external-dicts/) in ClickHouse to decode these values.
|
||
|
|
||
|
|
||
|
### Example of using `pointInPolygon` function
|
||
|
|
||
|
Create a table where we will store polygons:
|
||
|
|
||
|
```
|
||
|
CREATE TEMPORARY TABLE moscow (polygon Array(Tuple(Float64, Float64)));
|
||
|
```
|
||
|
|
||
|
This is a rough shape of Moscow (without "new Moscow"):
|
||
|
|
||
|
```
|
||
|
INSERT INTO moscow VALUES ([(37.84172564285271, 55.78000432402266), (37.8381207618713, 55.775874525970494), (37.83979446823122, 55.775626746008065), (37.84243326983639, 55.77446586811748), (37.84262672750849, 55.771974101091104), (37.84153238623039, 55.77114545193181), (37.841124690460184, 55.76722010265554), (37.84239076983644, 55.76654891107098), (37.842283558197025, 55.76258709833121), (37.8421759312134, 55.758073999993734), (37.84198330422974, 55.75381499999371), (37.8416827275085, 55.749277102484484), (37.84157576190186, 55.74794544108413), (37.83897929098507, 55.74525257875241), (37.83739676451868, 55.74404373042019), (37.838732481460525, 55.74298009816793), (37.841183997352545, 55.743060321833575), (37.84097476190185, 55.73938799999373), (37.84048155819702, 55.73570799999372), (37.840095812164286, 55.73228210777237), (37.83983814285274, 55.73080491981639), (37.83846476321406, 55.729799917464675), (37.83835745269769, 55.72919751082619), (37.838636380279524, 55.72859509486539), (37.8395161005249, 55.727705075632784), (37.83897964285276, 55.722727886185154), (37.83862557539366, 55.72034817326636), (37.83559735744853, 55.71944437307499), (37.835370708803126, 55.71831419154461), (37.83738169402022, 55.71765218986692), (37.83823396494291, 55.71691750159089), (37.838056931213345, 55.71547311301385), (37.836812846557606, 55.71221445615604), (37.83522525396725, 55.709331054395555), (37.83269301586908, 55.70953687463627), (37.829667367706236, 55.70903403789297), (37.83311126588435, 55.70552351822608), (37.83058993121339, 55.70041317726053), (37.82983872750851, 55.69883771404813), (37.82934501586913, 55.69718947487017), (37.828926414016685, 55.69504441658371), (37.82876530422971, 55.69287499999378), (37.82894754100031, 55.690759754047335), (37.827697554878185, 55.68951421135665), (37.82447346292115, 55.68965045405069), (37.83136543914793, 55.68322046195302), (37.833554015869154, 55.67814012759211), (37.83544184655761, 55.67295011628339), (37.837480388885474, 55.6672498719639), (37.838960677246064, 55.66316274139358), (37.83926093121332, 55.66046999999383), (37.839025050262435, 55.65869897264431), (37.83670784390257, 55.65794084879904), (37.835656529083245, 55.65694309303843), (37.83704060449217, 55.65689306460552), (37.83696819873806, 55.65550363526252), (37.83760389616388, 55.65487847246661), (37.83687972750851, 55.65356745541324), (37.83515216004943, 55.65155951234079), (37.83312418518067, 55.64979413590619), (37.82801726983639, 55.64640836412121), (37.820614174591, 55.64164525405531), (37.818908190475426, 55.6421883258084), (37.81717543386075, 55.64112490388471), (37.81690987037274, 55.63916106913107), (37.815099354492155, 55.637925371757085), (37.808769150787356, 55.633798276884455), (37.80100123544311, 55.62873670012244), (37.79598013491824, 55.62554336109055), (37.78634567724606, 55.62033499605651), (37.78334147619623, 55.618768681480326), (37.77746201055901, 55.619855533402706), (37.77527329626457, 55.61909966711279), (37.77801986242668, 55.618770300976294), (37.778212973541216, 55.617257701952106), (37.77784818518065, 55.61574504433011), (37.77016867724609, 55.61148576294007), (37.760191219573976, 55.60599579539028), (37.75338926983641, 55.60227892751446), (37.746329965606634, 55.59920577639331), (37.73939925396728, 55.59631430313617), (37.73273665739439, 55.5935318803559), (37.7299954450912, 55.59350760316188), (37.7268679946899, 55.59469840523759), (37.72626726983634, 55.59229549697373), (37.7262673598022, 55.59081598950582), (37.71897193121335, 55.5877595845419), (37.70871550793456, 55.58393177431724), (37.700497489410374, 55.580917323756644), (37.69204305026244, 55.57778089778455), (37.68544477378839, 55.57815154690915), (37.68391050793454, 55.57472945079756), (37.678803592590306, 55.57328235936491), (37.6743402539673, 55.57255251445782), (37.66813862698363, 55.57216388774464), (37.617927457672096, 55.57505691895805), (37.60443099999999, 55.5757737568051), (37.599683515869145, 55.57749105910326), (37.59754177842709, 55.57796291823627), (37.59625834786988, 55.57906686095235), (37.59501783265684, 55.57746616444403
|
||
|
```
|
||
|
|
||
|
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.)
|
||
|
```
|
||
|
|
||
|
The data is also available for interactive queries in the [Playground](https://gh-api.clickhouse.tech/play?user=play), [example](https://gh-api.clickhouse.tech/play?user=play#U0VMRUNUIG1jYywgY291bnQoKSBGUk9NIGNlbGxfdG93ZXJzIEdST1VQIEJZIG1jYyBPUkRFUiBCWSBjb3VudCgpIERFU0M=).
|
||
|
|
||
|
Although you cannot create temporary tables there.
|
||
|
|
||
|
[Original article](https://clickhouse.tech/docs/en/getting_started/example_datasets/cell-towers/) <!--hide-->
|