forked from databrickslabs/mosaic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_Explore.py
86 lines (57 loc) · 1.72 KB
/
2_Explore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Databricks notebook source
# MAGIC %md
# MAGIC # Expore the created datasets
# COMMAND ----------
# MAGIC %md
# MAGIC ## Setup Mosaic
# COMMAND ----------
# MAGIC %pip install databricks-mosaic
# COMMAND ----------
import pyspark.sql.functions as f
import mosaic as mos
mos.enable_mosaic(spark, dbutils)
# COMMAND ----------
buildings = spark.read.table("open_street_maps.buildings")
hospital_buildings = spark.read.table("open_street_maps.hospital_buildings")
residential_buildings = spark.read.table("open_street_maps.residential_buildings")
train_station_buildings = spark.read.table("open_street_maps.train_station_buildings")
# COMMAND ----------
# MAGIC %md
# MAGIC ## Residential buildings heatmap
# COMMAND ----------
residential_buildings_counts = (residential_buildings
.groupBy("centroid_index_res_6")
.count()
)
# COMMAND ----------
# MAGIC %python
# MAGIC %%mosaic_kepler
# MAGIC residential_buildings_counts "centroid_index_res_6" "h3" 100000
# COMMAND ----------
# MAGIC %md
# MAGIC ## Train stations heatmap
# COMMAND ----------
train_station_buildings_counts = (train_station_buildings
.groupBy("centroid_index_res_6")
.count()
)
# COMMAND ----------
# MAGIC %python
# MAGIC %%mosaic_kepler
# MAGIC train_station_buildings_counts "centroid_index_res_6" "h3" 100000
# COMMAND ----------
# MAGIC %md
# MAGIC ## Most building-dense area
# COMMAND ----------
dense_residential_buildings = (residential_buildings
.groupBy("centroid_index_res_6")
.count()
.sort(f.col("count").desc())
.limit(1)
.join(residential_buildings, "centroid_index_res_6")
)
# COMMAND ----------
# MAGIC %python
# MAGIC %%mosaic_kepler
# MAGIC dense_residential_buildings "polygon" "geometry" 100000
# COMMAND ----------