Skip to content

Commit d2ccb2f

Browse files
[pre-commit.ci] pre-commit autoupdate (#15)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black-pre-commit-mirror: 25.12.0 → 26.1.0](psf/black-pre-commit-mirror@25.12.0...26.1.0) - [github.com/kynan/nbstripout: 0.8.2 → 0.9.0](kynan/nbstripout@0.8.2...0.9.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9b43dd9 commit d2ccb2f

File tree

12 files changed

+212
-422
lines changed

12 files changed

+212
-422
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repos:
1212
args: ["--maxkb=3500"]
1313

1414
- repo: https://github.com/psf/black-pre-commit-mirror
15-
rev: 25.12.0
15+
rev: 26.1.0
1616
hooks:
1717
- id: black-jupyter
1818

@@ -27,6 +27,6 @@ repos:
2727
]
2828

2929
- repo: https://github.com/kynan/nbstripout
30-
rev: 0.8.2
30+
rev: 0.9.0
3131
hooks:
3232
- id: nbstripout

book/analytics/buildings.ipynb

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,11 @@
9898
"outputs": [],
9999
"source": [
100100
"# Examine the first few records to understand the schema\n",
101-
"con.sql(\n",
102-
" f\"\"\"\n",
101+
"con.sql(f\"\"\"\n",
103102
"SELECT *\n",
104103
"FROM read_parquet('{url}')\n",
105104
"LIMIT 10\n",
106-
"\"\"\"\n",
107-
")"
105+
"\"\"\")"
108106
]
109107
},
110108
{
@@ -122,12 +120,10 @@
122120
"metadata": {},
123121
"outputs": [],
124122
"source": [
125-
"con.sql(\n",
126-
" f\"\"\"\n",
123+
"con.sql(f\"\"\"\n",
127124
"SELECT COUNT(*) as count\n",
128125
"FROM read_parquet('{url}')\n",
129-
"\"\"\"\n",
130-
")"
126+
"\"\"\")"
131127
]
132128
},
133129
{
@@ -178,8 +174,7 @@
178174
"min_lat, max_lat = 37.0, 41.0\n",
179175
"\n",
180176
"# Create a table for the region's buildings\n",
181-
"con.sql(\n",
182-
" f\"\"\"\n",
177+
"con.sql(f\"\"\"\n",
183178
"CREATE TABLE IF NOT EXISTS buildings AS\n",
184179
"SELECT\n",
185180
" id,\n",
@@ -194,8 +189,7 @@
194189
"FROM read_parquet('{url}')\n",
195190
"WHERE bbox.xmin >= {min_lon} AND bbox.xmax <= {max_lon}\n",
196191
" AND bbox.ymin >= {min_lat} AND bbox.ymax <= {max_lat}\n",
197-
"\"\"\"\n",
198-
")"
192+
"\"\"\")"
199193
]
200194
},
201195
{
@@ -253,8 +247,7 @@
253247
"outputs": [],
254248
"source": [
255249
"# Calculate comprehensive area statistics\n",
256-
"con.sql(\n",
257-
" \"\"\"\n",
250+
"con.sql(\"\"\"\n",
258251
"SELECT\n",
259252
" COUNT(*) as building_count,\n",
260253
" ROUND(SUM(area_sq_meters) / 1000000, 2) as total_area_sq_km,\n",
@@ -263,8 +256,7 @@
263256
" ROUND(MAX(area_sq_meters), 2) as max_area,\n",
264257
" ROUND(MEDIAN(area_sq_meters), 2) as median_area\n",
265258
"FROM buildings\n",
266-
"\"\"\"\n",
267-
")"
259+
"\"\"\")"
268260
]
269261
},
270262
{
@@ -283,8 +275,7 @@
283275
"outputs": [],
284276
"source": [
285277
"# Categorize buildings by size\n",
286-
"con.sql(\n",
287-
" \"\"\"\n",
278+
"con.sql(\"\"\"\n",
288279
"SELECT\n",
289280
" CASE\n",
290281
" WHEN area_sq_meters < 50 THEN 'Small (<50 m²)'\n",
@@ -297,8 +288,7 @@
297288
"FROM buildings\n",
298289
"GROUP BY size_category\n",
299290
"ORDER BY MIN(area_sq_meters)\n",
300-
"\"\"\"\n",
301-
")"
291+
"\"\"\")"
302292
]
303293
},
304294
{
@@ -317,13 +307,11 @@
317307
"outputs": [],
318308
"source": [
319309
"# Sample 10,000 buildings for visualization\n",
320-
"sample_gdf = con.sql(\n",
321-
" \"\"\"\n",
310+
"sample_gdf = con.sql(\"\"\"\n",
322311
"SELECT area_sq_meters, ST_AsText(geometry) as geometry\n",
323312
"FROM buildings\n",
324313
"USING SAMPLE 10000\n",
325-
"\"\"\"\n",
326-
").df()\n",
314+
"\"\"\").df()\n",
327315
"\n",
328316
"# Convert to GeoDataFrame\n",
329317
"gdf = leafmap.df_to_gdf(sample_gdf, src_crs=\"EPSG:4326\")"
@@ -542,20 +530,17 @@
542530
"outputs": [],
543531
"source": [
544532
"# First, create a temporary table with county boundaries\n",
545-
"con.sql(\n",
546-
" \"\"\"\n",
533+
"con.sql(\"\"\"\n",
547534
"CREATE OR REPLACE TABLE counties AS\n",
548535
"SELECT\n",
549536
" NAME as county_name,\n",
550537
" geometry\n",
551538
"FROM read_parquet('https://data.gishub.org/us/us_counties.parquet')\n",
552539
"WHERE STATE = '08'\n",
553-
"\"\"\"\n",
554-
")\n",
540+
"\"\"\")\n",
555541
"\n",
556542
"# Perform spatial join and calculate statistics by county\n",
557-
"comparison_df = con.sql(\n",
558-
" \"\"\"\n",
543+
"comparison_df = con.sql(\"\"\"\n",
559544
"SELECT\n",
560545
" c.county_name,\n",
561546
" COUNT(b.*) as building_count,\n",
@@ -566,8 +551,7 @@
566551
"JOIN counties c ON ST_Intersects(b.geometry, c.geometry)\n",
567552
"GROUP BY c.county_name\n",
568553
"ORDER BY building_count DESC\n",
569-
"\"\"\"\n",
570-
").df()\n",
554+
"\"\"\").df()\n",
571555
"comparison_df.head()"
572556
]
573557
},
@@ -667,8 +651,7 @@
667651
"outputs": [],
668652
"source": [
669653
"# Filter to OSM buildings only\n",
670-
"con.sql(\n",
671-
" \"\"\"\n",
654+
"con.sql(\"\"\"\n",
672655
"SELECT\n",
673656
" COUNT(*) as osm_building_count,\n",
674657
" ROUND(AVG(area_sq_meters), 2) as avg_area,\n",
@@ -677,8 +660,7 @@
677660
" COUNT(CASE WHEN class IS NOT NULL THEN 1 END) as buildings_with_class\n",
678661
"FROM buildings\n",
679662
"WHERE source='OpenStreetMap'\n",
680-
"\"\"\"\n",
681-
").show()"
663+
"\"\"\").show()"
682664
]
683665
},
684666
{
@@ -841,12 +823,10 @@
841823
"metadata": {},
842824
"outputs": [],
843825
"source": [
844-
"con.sql(\n",
845-
" \"\"\"\n",
826+
"con.sql(\"\"\"\n",
846827
"CREATE OR REPLACE TABLE grid AS\n",
847828
"SELECT * FROM ST_Read('grid.geojson')\n",
848-
"\"\"\"\n",
849-
")"
829+
"\"\"\")"
850830
]
851831
},
852832
{
@@ -874,8 +854,7 @@
874854
"metadata": {},
875855
"outputs": [],
876856
"source": [
877-
"con.sql(\n",
878-
" \"\"\"\n",
857+
"con.sql(\"\"\"\n",
879858
"CREATE OR REPLACE TABLE grid_building_counts AS\n",
880859
"SELECT\n",
881860
" g.id,\n",
@@ -897,8 +876,7 @@
897876
" g.geom\n",
898877
"ORDER BY\n",
899878
" g.id;\n",
900-
"\"\"\"\n",
901-
")"
879+
"\"\"\")"
902880
]
903881
},
904882
{
@@ -1047,12 +1025,10 @@
10471025
"metadata": {},
10481026
"outputs": [],
10491027
"source": [
1050-
"con.sql(\n",
1051-
" \"\"\"\n",
1028+
"con.sql(\"\"\"\n",
10521029
"CREATE TABLE IF NOT EXISTS h3_res4_geo AS\n",
10531030
"SELECT * FROM 'https://data.gishub.org/duckdb/h3_res4_geo.parquet';\n",
1054-
"\"\"\"\n",
1055-
")"
1031+
"\"\"\")"
10561032
]
10571033
},
10581034
{

book/analytics/dashboards.ipynb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,10 @@
230230
" output_widget.clear_output()\n",
231231
" if len(m.draw_features_selected) > 0:\n",
232232
" geojson = m.draw_features_selected[0][\"geometry\"]\n",
233-
" df = con.sql(\n",
234-
" f\"\"\"\n",
233+
" df = con.sql(f\"\"\"\n",
235234
" SELECT * EXCLUDE (geometry), ST_AsText(geometry) AS geometry FROM h3_res4_geo\n",
236235
" WHERE ST_Intersects(geometry, ST_GeomFromGeoJSON('{json.dumps(geojson)}'));\n",
237-
" \"\"\"\n",
238-
" ).df()\n",
236+
" \"\"\").df()\n",
239237
" gdf = leafmap.df_to_gdf(df)\n",
240238
" if \"H3 Hexagon\" in m.layer_dict:\n",
241239
" m.remove_layer(\"H3 Hexagon\")\n",

0 commit comments

Comments
 (0)