Skip to content

Commit 68e8626

Browse files
committed
merge a few cells in 01
1 parent 1bb6548 commit 68e8626

File tree

1 file changed

+34
-64
lines changed

1 file changed

+34
-64
lines changed

01_introduction_to_geospatial.ipynb

+34-64
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@
433433
"metadata": {
434434
"scrolled": false,
435435
"slideshow": {
436-
"slide_type": "fragment"
436+
"slide_type": "subslide"
437437
}
438438
},
439439
"outputs": [],
@@ -449,64 +449,23 @@
449449
}
450450
},
451451
"source": [
452-
"## Using GeoDataFrames in SRAI"
453-
]
454-
},
455-
{
456-
"cell_type": "code",
457-
"execution_count": null,
458-
"metadata": {
459-
"slideshow": {
460-
"slide_type": "-"
461-
}
462-
},
463-
"outputs": [],
464-
"source": [
465-
"poland_gdf = countries[countries[\"NAME\"] == \"Poland\"]\n",
466-
"poland_gdf"
467-
]
468-
},
469-
{
470-
"cell_type": "code",
471-
"execution_count": null,
472-
"metadata": {
473-
"slideshow": {
474-
"slide_type": "subslide"
475-
}
476-
},
477-
"outputs": [],
478-
"source": [
479-
"from srai.regionalizers import AdministrativeBoundaryRegionalizer\n",
480-
"\n",
481-
"regionalizer = AdministrativeBoundaryRegionalizer(admin_level=4)\n",
482-
"regions_gdf = regionalizer.transform(poland_gdf)\n",
483-
"regions_gdf.head(5)"
452+
"## Let's go deeper - [Shapely](https://shapely.readthedocs.io/en/stable/manual.html) objects\n",
453+
"- GeoPandas uses Shapely - geometry column\n",
454+
"- geometric operations"
484455
]
485456
},
486457
{
487458
"cell_type": "code",
488459
"execution_count": null,
489460
"metadata": {
490461
"slideshow": {
491-
"slide_type": "subslide"
462+
"slide_type": "fragment"
492463
}
493464
},
494465
"outputs": [],
495466
"source": [
496-
"regions_gdf.explore()"
497-
]
498-
},
499-
{
500-
"cell_type": "markdown",
501-
"metadata": {
502-
"slideshow": {
503-
"slide_type": "slide"
504-
}
505-
},
506-
"source": [
507-
"## Let's go deeper - [Shapely](https://shapely.readthedocs.io/en/stable/manual.html) objects\n",
508-
"- GeoPandas uses Shapely - geometry column\n",
509-
"- geometric operations"
467+
"pl_de_gdf = countries[countries[\"NAME\"].isin([\"Poland\", \"Germany\"])]\n",
468+
"pl_de_gdf"
510469
]
511470
},
512471
{
@@ -519,7 +478,8 @@
519478
},
520479
"outputs": [],
521480
"source": [
522-
"type(regions_gdf.iloc[2].geometry)"
481+
"merged_geom = pl_de_gdf.unary_union\n",
482+
"merged_geom"
523483
]
524484
},
525485
{
@@ -532,10 +492,7 @@
532492
},
533493
"outputs": [],
534494
"source": [
535-
"print(regions_gdf.iloc[2].name)\n",
536-
"voivodeship_region = regions_gdf.iloc[2:3]\n",
537-
"voivodeship_geom = voivodeship_region.geometry[0]\n",
538-
"voivodeship_geom"
495+
"type(merged_geom)"
539496
]
540497
},
541498
{
@@ -559,7 +516,7 @@
559516
},
560517
"outputs": [],
561518
"source": [
562-
"voivodeship_geom.area"
519+
"merged_geom.area"
563520
]
564521
},
565522
{
@@ -573,7 +530,7 @@
573530
"outputs": [],
574531
"source": [
575532
"## minimum bounding region\n",
576-
"voivodeship_geom.bounds"
533+
"merged_geom.bounds"
577534
]
578535
},
579536
{
@@ -584,7 +541,7 @@
584541
}
585542
},
586543
"source": [
587-
"## Let's create a geometry object"
544+
"## Creating a geometry manually"
588545
]
589546
},
590547
{
@@ -598,7 +555,7 @@
598555
"outputs": [],
599556
"source": [
600557
"from shapely.geometry import LineString\n",
601-
"bounds = voivodeship_geom.bounds\n",
558+
"bounds = merged_geom.bounds\n",
602559
"line = LineString(\n",
603560
" [(bounds[0], bounds[1]),\n",
604561
" (bounds[2], bounds[3]),]\n",
@@ -627,7 +584,7 @@
627584
},
628585
"outputs": [],
629586
"source": [
630-
"gpd.GeoSeries([line, voivodeship_geom]).plot(cmap='tab10')"
587+
"gpd.GeoSeries([line, merged_geom]).plot(cmap='tab10')"
631588
]
632589
},
633590
{
@@ -651,7 +608,7 @@
651608
},
652609
"outputs": [],
653610
"source": [
654-
"line.within(voivodeship_geom)"
611+
"line.within(merged_geom)"
655612
]
656613
},
657614
{
@@ -664,7 +621,7 @@
664621
},
665622
"outputs": [],
666623
"source": [
667-
"line.intersects(voivodeship_geom)"
624+
"line.intersects(merged_geom)"
668625
]
669626
},
670627
{
@@ -679,6 +636,15 @@
679636
"You can use the same spatial operations as in Shapely, on entire GeoDataFrames."
680637
]
681638
},
639+
{
640+
"cell_type": "code",
641+
"execution_count": null,
642+
"metadata": {},
643+
"outputs": [],
644+
"source": [
645+
"pl_de_gdf"
646+
]
647+
},
682648
{
683649
"cell_type": "markdown",
684650
"metadata": {
@@ -752,7 +718,7 @@
752718
},
753719
"outputs": [],
754720
"source": [
755-
"gpd.GeoSeries([line, voivodeship_geom]).plot(cmap='tab10')"
721+
"gpd.GeoSeries([line, merged_geom]).plot(cmap='tab10')"
756722
]
757723
},
758724
{
@@ -768,7 +734,7 @@
768734
"from srai.regionalizers import geocode_to_region_gdf, H3Regionalizer\n",
769735
"from utils import CB_SAFE_PALLETE\n",
770736
"\n",
771-
"regionized = H3Regionalizer(resolution=6).transform(voivodeship_region)\n",
737+
"regionized = H3Regionalizer(resolution=3).transform(pl_de_gdf)\n",
772738
"regionized[\"intersects\"] = regionized.intersects(line)\n",
773739
"regionized.explore(\"intersects\")"
774740
]
@@ -816,7 +782,11 @@
816782
{
817783
"cell_type": "code",
818784
"execution_count": null,
819-
"metadata": {},
785+
"metadata": {
786+
"slideshow": {
787+
"slide_type": "fragment"
788+
}
789+
},
820790
"outputs": [],
821791
"source": [
822792
"from srai.loaders import OSMOnlineLoader\n",
@@ -926,7 +896,7 @@
926896
"name": "python",
927897
"nbconvert_exporter": "python",
928898
"pygments_lexer": "ipython3",
929-
"version": "3.10.11"
899+
"version": "3.10.12"
930900
},
931901
"rise": {
932902
"controls": false,

0 commit comments

Comments
 (0)