Update DuckDB example so it calculates the area of a polygon properly

This commit is contained in:
Diego Ripley
2025-05-30 15:26:22 +00:00
parent a8b05a96f9
commit 6aedfe7c46
+24 -20
View File
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 44,
"id": "56ac906e",
"metadata": {},
"outputs": [],
@@ -14,7 +14,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 45,
"id": "708e293d",
"metadata": {},
"outputs": [],
@@ -35,14 +35,14 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 46,
"id": "580c82ad-f64d-439f-9055-2307fdf7cccd",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8c53af935cf44664a8b493f5133b87e7",
"model_id": "4d154b54d66c48d48637165066492606",
"version_major": 2,
"version_minor": 0
},
@@ -56,10 +56,10 @@
{
"data": {
"text/plain": [
"<duckdb.duckdb.DuckDBPyConnection at 0x7f0654aa5730>"
"<duckdb.duckdb.DuckDBPyConnection at 0x7f0654926530>"
]
},
"execution_count": 42,
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
@@ -71,11 +71,7 @@
"SELECT\n",
" geo.da_dguid,\n",
" cop.count_total_4,\n",
" CAST(\n",
" ROUND(\n",
" (cop.count_total_1 / (ST_AREA_SPHEROID(geo.geom) / 1000000.0)), 0\n",
" ) AS INTEGER\n",
" ) AS count_total_4_per_square_km,\n",
" (cop.count_total_1 / (ST_Area_Spheroid(ST_FlipCoordinates(geo.geom)) / 1000000.0)) AS count_total_4_per_square_km,\n",
" geo.geom\n",
"FROM\n",
" 'https://data.dataforcanada.org/processed/statistics_canada/census_of_population/2021/tabular/da_2021.parquet' AS cop,\n",
@@ -94,17 +90,17 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 47,
"id": "0528eeb4-fb89-4640-94c6-c0eda4cbe764",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<duckdb.duckdb.DuckDBPyConnection at 0x7f0654aa5730>"
"<duckdb.duckdb.DuckDBPyConnection at 0x7f0654926530>"
]
},
"execution_count": 43,
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
@@ -131,17 +127,17 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 48,
"id": "6d38118b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<duckdb.duckdb.DuckDBPyConnection at 0x7f0704bb5e70>"
"<duckdb.duckdb.DuckDBPyConnection at 0x7f0654926530>"
]
},
"execution_count": 38,
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
@@ -168,17 +164,17 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 49,
"id": "c32ab0f8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<duckdb.duckdb.DuckDBPyConnection at 0x7f0704bb5e70>"
"<duckdb.duckdb.DuckDBPyConnection at 0x7f0654926530>"
]
},
"execution_count": 39,
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
@@ -188,6 +184,14 @@
"COPY geo_data TO '{output_data_folder}/da_2021_private_dwellings.parquet' (FORMAT PARQUET);\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f519fe1-b641-4230-b3ed-645f1126e335",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {