This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new bc822490 [SEDONA-317] Use KeplerGL for visualization (#885)
bc822490 is described below
commit bc82249075b47f3b20c8b57671e1ccd9db8a8ddd
Author: Nilesh Gajwani <[email protected]>
AuthorDate: Tue Jul 4 08:13:49 2023 -0700
[SEDONA-317] Use KeplerGL for visualization (#885)
---
...eSedonaSQL_SpatialJoin_AirportsPerCountry.ipynb | 87 +++++++++++---------
binder/utilities.py | 96 ++++++++++++++++++++++
2 files changed, 143 insertions(+), 40 deletions(-)
diff --git a/binder/ApacheSedonaSQL_SpatialJoin_AirportsPerCountry.ipynb
b/binder/ApacheSedonaSQL_SpatialJoin_AirportsPerCountry.ipynb
index 43981263..7b630bd2 100644
--- a/binder/ApacheSedonaSQL_SpatialJoin_AirportsPerCountry.ipynb
+++ b/binder/ApacheSedonaSQL_SpatialJoin_AirportsPerCountry.ipynb
@@ -24,7 +24,7 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -34,7 +34,10 @@
"from pyspark.sql import SparkSession\n",
"from pyspark.sql.functions import col, expr, when\n",
"\n",
- "from sedona.spark import *"
+ "\n",
+ "\n",
+ "from sedona.spark import *\n",
+ "from utilities import getConfig"
]
},
{
@@ -46,7 +49,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 3,
"metadata": {},
"outputs": [
{
@@ -64,11 +67,11 @@
"The jars for the packages stored in: /Users/nileshgajwani/.ivy2/jars\n",
"org.apache.sedona#sedona-spark-shaded-3.0_2.12 added as a dependency\n",
"org.datasyslab#geotools-wrapper added as a dependency\n",
- ":: resolving dependencies ::
org.apache.spark#spark-submit-parent-c8d6364e-e535-48bc-9161-729cb68c80b1;1.0\n",
+ ":: resolving dependencies ::
org.apache.spark#spark-submit-parent-ccdb40df-96c2-42bf-bb17-f6b17333162d;1.0\n",
"\tconfs: [default]\n",
"\tfound org.apache.sedona#sedona-spark-shaded-3.0_2.12;1.4.1 in
central\n",
"\tfound org.datasyslab#geotools-wrapper;1.4.0-28.2 in central\n",
- ":: resolution report :: resolve 87ms :: artifacts dl 2ms\n",
+ ":: resolution report :: resolve 98ms :: artifacts dl 2ms\n",
"\t:: modules in use:\n",
"\torg.apache.sedona#sedona-spark-shaded-3.0_2.12;1.4.1 from central in
[default]\n",
"\torg.datasyslab#geotools-wrapper;1.4.0-28.2 from central in
[default]\n",
@@ -78,10 +81,10 @@
"\t---------------------------------------------------------------------\n",
"\t| default | 2 | 0 | 0 | 0 || 2 | 0
|\n",
"\t---------------------------------------------------------------------\n",
- ":: retrieving ::
org.apache.spark#spark-submit-parent-c8d6364e-e535-48bc-9161-729cb68c80b1\n",
+ ":: retrieving ::
org.apache.spark#spark-submit-parent-ccdb40df-96c2-42bf-bb17-f6b17333162d\n",
"\tconfs: [default]\n",
- "\t0 artifacts copied, 2 already retrieved (0kB/5ms)\n",
- "23/07/03 21:19:15 WARN NativeCodeLoader: Unable to load native-hadoop
library for your platform... using builtin-java classes where applicable\n",
+ "\t0 artifacts copied, 2 already retrieved (0kB/2ms)\n",
+ "23/07/03 23:08:06 WARN NativeCodeLoader: Unable to load native-hadoop
library for your platform... using builtin-java classes where applicable\n",
"Setting default log level to \"WARN\".\n",
"To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use
setLogLevel(newLevel).\n"
]
@@ -109,7 +112,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 4,
"metadata": {},
"outputs": [
{
@@ -219,7 +222,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
- "23/07/03 21:19:18 WARN package: Truncated the string representation of
a plan since it was too large. This behavior can be adjusted by setting
'spark.sql.debug.maxToStringFields'.\n"
+ "23/07/03 23:08:10 WARN package: Truncated the string representation of
a plan since it was too large. This behavior can be adjusted by setting
'spark.sql.debug.maxToStringFields'.\n"
]
}
],
@@ -240,7 +243,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -279,7 +282,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -295,7 +298,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 7,
"metadata": {},
"outputs": [
{
@@ -342,14 +345,14 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "23/07/03 21:19:20 WARN JoinQuery: UseIndex is true, but no index
exists. Will build index on the fly.\n"
+ "23/07/03 23:08:12 WARN JoinQuery: UseIndex is true, but no index
exists. Will build index on the fly.\n"
]
},
{
@@ -427,7 +430,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 9,
"metadata": {
"scrolled": true
},
@@ -491,24 +494,38 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "try:\n",
+ " from keplergl import KeplerGl\n",
+ "except ImportError:\n",
+ " !pip install keplergl\n",
+ " from keplergl import KeplerGl"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
"metadata": {},
"outputs": [
{
- "data": {
- "text/plain": [
- "<Axes: >"
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "User Guide: https://docs.kepler.gl/docs/keplergl-jupyter\n"
+ ]
},
{
"data": {
- "image/png":
"iVBORw0KGgoAAAANSUhEUgAAAkYAAADeCAYAAADYd89rAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAACCHUlEQVR4nO29eZxcZZ3v/3nOUvvS+5Z0ZyErgRASIETBQY2E6KgoziCjDjqMjg7oCOpcGa8s3pmBkRnXCzLOHWHmKqLO76qDC4ooCBJQIwHCEpKQlaQ7Sae7q7uraznnfH9/fJ9TW1dXV3VXdVd3P+/Xq17dVXWW59SpOs/nfFdBRASFQqFQKBQKBbTZHoBCoVAoFApFvaCEkUKhUCgUCoVECSOFQqFQKBQKiRJGCoVCoVAoFBIljBQKhUKhUCgkShgpFAqFQqFQSJQwUigUCoVCoZAoYaRQKBQKhUIhMWZ7ANPF
[...]
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "9df63933b69f4b18b5c66243b257dd34",
+ "version_major": 2,
+ "version_minor": 0
+ },
"text/plain": [
- "<Figure size 640x480 with 2 Axes>"
+ "KeplerGl(config={'version': 'v1', 'config': {'visState': {'filters':
[], 'layers': [{'id': 'ikzru0t', 'type': …"
]
},
"metadata": {},
@@ -517,21 +534,11 @@
],
"source": [
"df = groupedresult.toPandas()\n",
- "gdf = gpd.GeoDataFrame(df, geometry=\"country_geom\")\n",
+ "gdf = gpd.GeoDataFrame(df,
geometry=\"country_geom\").rename(columns={'country_geom':'geometry'})\n",
"\n",
- "import matplotlib.pyplot as plt\n",
- "from mpl_toolkits.axes_grid1 import make_axes_locatable\n",
- "fig, ax = plt.subplots(1, 1)\n",
- "divider = make_axes_locatable(ax)\n",
- "cax = divider.append_axes(\"right\", size=\"5%\", pad=0.1)\n",
+ "map_1 = KeplerGl(data={\"AirportCount\": gdf}, config=getConfig())\n",
"\n",
- "gdf.plot(\n",
- " column=\"AirportCount\",\n",
- " legend=True,\n",
- " cmap='OrRd',\n",
- " cax=cax,\n",
- " ax=ax\n",
- ")"
+ "map_1"
]
}
],
diff --git a/binder/utilities.py b/binder/utilities.py
new file mode 100644
index 00000000..7bcb0433
--- /dev/null
+++ b/binder/utilities.py
@@ -0,0 +1,96 @@
+def getConfig():
+ config = {'version': 'v1',
+ 'config': {'visState': {'filters': [],
+ 'layers': [{'id': 'ikzru0t',
+ 'type': 'geojson',
+ 'config': {'dataId':
'AirportCount',
+ 'label':
'AirportCount',
+ 'color': [218,
112, 191],
+ 'highlightColor':
[252, 242, 26, 255],
+ 'columns':
{'geojson': 'geometry'},
+ 'isVisible': True,
+ 'visConfig':
{'opacity': 0.8,
+
'strokeOpacity': 0.8,
+
'thickness': 0.5,
+
'strokeColor': [18, 92, 119],
+
'colorRange': {'name': 'Uber Viz Sequential 6',
+
'type': 'sequential',
+
'category': 'Uber',
+
'colors': ['#E6FAFA',
+
'#C1E5E6',
+
'#9DD0D4',
+
'#75BBC1',
+
'#4BA7AF',
+
'#00939C',
+
'#108188',
+
'#0E7077']},
+
'strokeColorRange': {'name': 'Global Warming',
+
'type': 'sequential',
+
'category': 'Uber',
+
'colors': ['#5A1846',
+
'#900C3F',
+
'#C70039',
+
'#E3611C',
+
'#F1920E',
+
'#FFC300']},
+
'radius': 10,
+
'sizeRange': [0, 10],
+
'radiusRange': [0, 50],
+
'heightRange': [0, 500],
+
'elevationScale': 5,
+
'enableElevationZoomFactor': True,
+
'stroked': False,
+
'filled': True,
+
'enable3d': False,
+
'wireframe': False},
+ 'hidden': False,
+ 'textLabel':
[{'field': None,
+
'color': [255, 255, 255],
+
'size': 18,
+
'offset': [0, 0],
+
'anchor': 'start',
+
'alignment': 'center'}]},
+ 'visualChannels':
{'colorField': {'name': 'AirportCount',
+
'type': 'integer'},
+
'colorScale': 'quantize',
+
'strokeColorField': None,
+
'strokeColorScale': 'quantile',
+
'sizeField': None,
+
'sizeScale': 'linear',
+
'heightField': None,
+
'heightScale': 'linear',
+
'radiusField': None,
+
'radiusScale': 'linear'}}],
+ 'interactionConfig': {'tooltip':
{'fieldsToShow': {'AirportCount': [{'name': 'NAME_EN',
+
'format': None},
+
{'name': 'AirportCount', 'format': None}]},
+
'compareMode': False,
+
'compareType': 'absolute',
+
'enabled': True},
+ 'brush': {'size':
0.5, 'enabled': False},
+ 'geocoder':
{'enabled': False},
+ 'coordinate':
{'enabled': False}},
+ 'layerBlending': 'normal',
+ 'splitMaps': [],
+ 'animationConfig': {'currentTime': None,
'speed': 1}},
+ 'mapState': {'bearing': 0,
+ 'dragRotate': False,
+ 'latitude': 56.422456606624316,
+ 'longitude': 9.778836615231771,
+ 'pitch': 0,
+ 'zoom': 0.4214991225736964,
+ 'isSplit': False},
+ 'mapStyle': {'styleType': 'dark',
+ 'topLayerGroups': {},
+ 'visibleLayerGroups': {'label': True,
+ 'road': True,
+ 'border': False,
+ 'building': True,
+ 'water': True,
+ 'land': True,
+ '3d building':
False},
+ 'threeDBuildingColor':
[9.665468314072013,
+
17.18305478057247,
+
31.1442867897876],
+ 'mapStyles': {}}}}
+ return config
\ No newline at end of file