import geopandas as gp
import geodatasets
from plotnine import (
ggplot,
aes,
coord_fixed,
facet_wrap,
geom_map,
geom_text,
labs,
scale_fill_brewer,
scale_fill_continuous,
scale_x_continuous,
scale_y_continuous,
scale_size_continuous,
stage,
coord_cartesian,
element_line,
element_rect,
element_text,
theme_void,
theme, )
Define some useful functions
def good_centroid(geometry):
"""
Calculate "good" centroids for polygons in the geometry
The polygon is projected onto the Equal Area Cylindrical projection,
the centroids are computed, then mapped back onto the original
coordinate system.
"""
return geometry.to_crs("+proj=cea").centroid.to_crs(geometry.crs)
def overlay_color(rgb_hex_colors, light="white", dark="black", threshold=0.5):
"""
Decide which color is suitable to write onto the given colors
"""
def luminance(rgb_hex):
"""
Calculate the Luminance ([0, 1]) of a hex color
"""
= int(rgb_hex[1:3], 16)
r = int(rgb_hex[3:5], 16)
g = int(rgb_hex[5:], 16)
b = (r*0.299 + g*0.587 + b*0.0722) / 256
luma return luma
return [light if luminance(x) < threshold else dark for x in rgb_hex_colors]
A Map from geodatasets
We are going to use a dataset from the geodatasets package. We can explore the dataset providers at geodatasets.data
, each of which has one or more datasets:
geodatasets.data
-
geodatasets.Bunch53 items
-
geodatasets.Datasetgeoda.airbnb
- url
- https://geodacenter.github.io/data-and-lab//data/airbnb.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Airbnb rentals, socioeconomics, and crime in Chicago
- geometry_type
- Polygon
- nrows
- 77
- ncols
- 21
- details
- https://geodacenter.github.io/data-and-lab//airbnb/
- hash
- a2ab1e3f938226d287dd76cde18c00e2d3a260640dd826da7131827d9e76c824
- filename
- airbnb.zip
-
geodatasets.Datasetgeoda.atlanta
- url
- https://geodacenter.github.io/data-and-lab//data/atlanta_hom.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Atlanta, GA region homicide counts and rates
- geometry_type
- Polygon
- nrows
- 90
- ncols
- 24
- details
- https://geodacenter.github.io/data-and-lab//atlanta_old/
- hash
- a33a76e12168fe84361e60c88a9df4856730487305846c559715c89b1a2b5e09
- filename
- atlanta_hom.zip
- members
- ['atlanta_hom/atl_hom.geojson']
-
geodatasets.Datasetgeoda.cars
- url
- https://geodacenter.github.io/data-and-lab//data/Abandoned_Vehicles_Map.csv
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2011 abandoned vehicles in Chicago (311 complaints).
- geometry_type
- Point
- nrows
- 137867
- ncols
- 21
- details
- https://geodacenter.github.io/data-and-lab//1-source-and-description/
- hash
- 6a0b23bc7eda2dcf1af02d43ccf506b24ca8d8c6dc2fe86a2a1cc051b03aae9e
- filename
- Abandoned_Vehicles_Map.csv
-
geodatasets.Datasetgeoda.charleston1
- url
- https://geodacenter.github.io/data-and-lab//data/CharlestonMSA.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2000 Census Tract Data for Charleston, SC MSA and counties
- geometry_type
- Polygon
- nrows
- 117
- ncols
- 31
- details
- https://geodacenter.github.io/data-and-lab//charleston-1_old/
- hash
- 4a4fa9c8dd4231ae0b2f12f24895b8336bcab0c28c48653a967cffe011f63a7c
- filename
- CharlestonMSA.zip
- members
- ['CharlestonMSA/sc_final_census2.gpkg']
-
geodatasets.Datasetgeoda.charleston2
- url
- https://geodacenter.github.io/data-and-lab//data/CharlestonMSA2.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 1998 and 2001 Zip Code Business Patterns (Census Bureau) for Charleston, SC MSA
- geometry_type
- Polygon
- nrows
- 42
- ncols
- 60
- details
- https://geodacenter.github.io/data-and-lab//charleston2/
- hash
- 056d5d6e236b5bd95f5aee26c77bbe7d61bd07db5aaf72866c2f545205c1d8d7
- filename
- CharlestonMSA2.zip
- members
- ['CharlestonMSA2/CharlestonMSA2.gpkg']
-
geodatasets.Datasetgeoda.chicago_health
- url
- https://geodacenter.github.io/data-and-lab//data/comarea.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Chicago Health + Socio-Economics
- geometry_type
- Polygon
- nrows
- 77
- ncols
- 87
- details
- https://geodacenter.github.io/data-and-lab//comarea_vars/
- hash
- 4e872adb552786eae2fcd745524696e5e4cd33cc9a6c032471c0e75328871401
- filename
- comarea.zip
-
geodatasets.Datasetgeoda.chicago_commpop
- url
- https://geodacenter.github.io/data-and-lab//data/chicago_commpop.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Chicago Community Area Population Percent Change for 2000 and 2010
- geometry_type
- Polygon
- nrows
- 77
- ncols
- 9
- details
- https://geodacenter.github.io/data-and-lab//commpop/
- hash
- 1dbebb50c8ea47e2279ea819ef64ba793bdee2b88e4716bd6c6ec0e0d8e0e05b
- filename
- chicago_commpop.zip
- members
- ['chicago_commpop/chicago_commpop.geojson']
-
geodatasets.Datasetgeoda.chile_labor
- url
- https://geodacenter.github.io/data-and-lab//data/flma.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Labor Markets in Chile (1982-2002)
- geometry_type
- Polygon
- nrows
- 64
- ncols
- 140
- details
- https://geodacenter.github.io/data-and-lab//FLMA/
- hash
- 4777072268d0127b3d0be774f51d0f66c15885e9d3c92bc72c641a72f220796c
- filename
- flma.zip
- members
- ['flma/FLMA.geojson']
-
geodatasets.Datasetgeoda.cincinnati
- url
- https://geodacenter.github.io/data-and-lab//data/walnuthills_updated.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2008 Cincinnati Crime + Socio-Demographics
- geometry_type
- Polygon
- nrows
- 457
- ncols
- 73
- details
- https://geodacenter.github.io/data-and-lab//walnut_hills/
- hash
- d6871dd688bd14cf4710a218d721d34f6574456f2a14d5c5cfe5a92054ee9763
- filename
- walnuthills_updated.zip
- members
- ['walnuthills_updated']
-
geodatasets.Datasetgeoda.cleveland
- url
- https://geodacenter.github.io/data-and-lab//data/cleveland.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2015 sales prices of homes in Cleveland, OH.
- geometry_type
- Point
- nrows
- 205
- ncols
- 10
- details
- https://geodacenter.github.io/data-and-lab//clev_sls_154_core/
- hash
- 49aeba03eb06bf9b0d9cddd6507eb4a226b7c7a7561145562885c5cddfaeaadf
- filename
- cleveland.zip
-
geodatasets.Datasetgeoda.grid100
- url
- https://geodacenter.github.io/data-and-lab//data/grid100.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Grid with simulated variables
- geometry_type
- Polygon
- nrows
- 100
- ncols
- 37
- details
- https://geodacenter.github.io/data-and-lab//grid100/
- hash
- 5702ba39606044f71d53ae6a83758b81332bd3aa216b7b7b6e1c60dd0e72f476
- filename
- grid100.zip
- members
- ['grid100/grid100s.gpkg']
-
geodatasets.Datasetgeoda.groceries
- url
- https://geodacenter.github.io/data-and-lab//data/grocery.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2015 Chicago supermarkets
- geometry_type
- Point
- nrows
- 148
- ncols
- 8
- details
- https://geodacenter.github.io/data-and-lab//chicago_sup_vars/
- hash
- ead10e53b21efcaa29b798428b93ba2a1c0ba1b28f046265c1737712fa83f88a
- filename
- grocery.zip
- members
- ['grocery/chicago_sup.shp', 'grocery/chicago_sup.dbf', 'grocery/chicago_sup.shx', 'grocery/chicago_sup.prj']
-
geodatasets.Datasetgeoda.guerry
- url
- https://geodacenter.github.io/data-and-lab//data/guerry.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Mortal statistics of France (Guerry, 1833)
- geometry_type
- Polygon
- nrows
- 85
- ncols
- 24
- details
- https://geodacenter.github.io/data-and-lab//Guerry/
- hash
- 80d2b355ad3340fcffa0a28e5cec0698af01067f8059b1a60388d200a653b3e8
- filename
- guerry.zip
- members
- ['guerry/guerry.shp', 'guerry/guerry.dbf', 'guerry/guerry.shx', 'guerry/guerry.prj']
-
geodatasets.Datasetgeoda.health
- url
- https://geodacenter.github.io/data-and-lab//data/income_diversity.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2000 Health, Income + Diversity
- geometry_type
- Polygon
- nrows
- 3984
- ncols
- 65
- details
- https://geodacenter.github.io/data-and-lab//co_income_diversity_variables/
- hash
- eafee1063040258bc080e7b501bdf1438d6e45ba208954d8c2e1a7562142d0a7
- filename
- income_diversity.zip
- members
- ['income_diversity/income_diversity.shp', 'income_diversity/income_diversity.dbf', 'income_diversity/income_diversity.shx', 'income_diversity/income_diversity.prj']
-
geodatasets.Datasetgeoda.health_indicators
- url
- https://geodacenter.github.io/data-and-lab//data/healthIndicators.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Chicago Health Indicators (2005-11)
- geometry_type
- Polygon
- nrows
- 77
- ncols
- 32
- details
- https://geodacenter.github.io/data-and-lab//healthindicators-variables/
- hash
- b43683245f8fc3b4ab69ffa75d2064920a1a91dc76b9dcc08e288765ba0c94f3
- filename
- healthIndicators.zip
-
geodatasets.Datasetgeoda.hickory1
- url
- https://geodacenter.github.io/data-and-lab//data/HickoryMSA.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2000 Census Tract Data for Hickory, NC MSA and counties
- geometry_type
- Polygon
- nrows
- 68
- ncols
- 31
- details
- https://geodacenter.github.io/data-and-lab//hickory1/
- hash
- 4c0804608d303e6e44d51966bb8927b1f5f9e060a9b91055a66478b9039d2b44
- filename
- HickoryMSA.zip
- members
- ['HickoryMSA/nc_final_census2.geojson']
-
geodatasets.Datasetgeoda.hickory2
- url
- https://geodacenter.github.io/data-and-lab//data/HickoryMSA2.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 1998 and 2001 Zip Code Business Patterns (Census Bureau) for Hickory, NC MSA
- geometry_type
- Polygon
- nrows
- 29
- ncols
- 56
- details
- https://geodacenter.github.io/data-and-lab//hickory2/
- hash
- 5e9498e1ff036297c3eea3cc42ac31501680a43b50c71b486799ef9021679d07
- filename
- HickoryMSA2.zip
- members
- ['HickoryMSA2/HickoryMSA2.geojson']
-
geodatasets.Datasetgeoda.home_sales
- url
- https://geodacenter.github.io/data-and-lab//data/kingcounty.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2014-15 Home Sales in King County, WA
- geometry_type
- Point
- nrows
- 21613
- ncols
- 22
- details
- https://geodacenter.github.io/data-and-lab//KingCounty-HouseSales2015/
- hash
- b979f0eb2cef6ebd2c761d552821353f795635eb8db53a95f2815fc46e1f644c
- filename
- kingcounty.zip
- members
- ['kingcounty/kc_house.shp', 'kingcounty/kc_house.dbf', 'kingcounty/kc_house.shx', 'kingcounty/kc_house.prj']
-
geodatasets.Datasetgeoda.houston
- url
- https://geodacenter.github.io/data-and-lab//data/houston_hom.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Houston, TX region homicide counts and rates
- geometry_type
- Polygon
- nrows
- 52
- ncols
- 24
- details
- https://geodacenter.github.io/data-and-lab//houston/
- hash
- d3167fd150a1369d9a32b892d3b2a8747043d3d382c3dd81e51f696b191d0d15
- filename
- houston_hom.zip
- members
- ['houston_hom/hou_hom.geojson']
-
geodatasets.Datasetgeoda.juvenile
- url
- https://geodacenter.github.io/data-and-lab//data/juvenile.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Cardiff juvenile delinquent residences
- geometry_type
- Point
- nrows
- 168
- ncols
- 4
- details
- https://geodacenter.github.io/data-and-lab//juvenile/
- hash
- 811cfcfa613578214d907bfbdd396c6e02261e5cda6d56b25a6f961148de961c
- filename
- juvenile.zip
- members
- ['juvenile/juvenile.shp', 'juvenile/juvenile.shx', 'juvenile/juvenile.dbf']
-
geodatasets.Datasetgeoda.lansing1
- url
- https://geodacenter.github.io/data-and-lab//data/LansingMSA.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2000 Census Tract Data for Lansing, MI MSA and counties
- geometry_type
- Polygon
- nrows
- 117
- ncols
- 31
- details
- https://geodacenter.github.io/data-and-lab//lansing1/
- hash
- 724ce3d889fa50e7632d16200cf588d40168d49adaf5bca45049dc1b3758bde1
- filename
- LansingMSA.zip
- members
- ['LansingMSA/mi_final_census2.geojson']
-
geodatasets.Datasetgeoda.lansing2
- url
- https://geodacenter.github.io/data-and-lab//data/LansingMSA2.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 1998 and 2001 Zip Code Business Patterns (Census Bureau) for Lansing, MI MSA
- geometry_type
- Polygon
- nrows
- 46
- ncols
- 56
- details
- https://geodacenter.github.io/data-and-lab//lansing2/
- hash
- 7657c05d3bd6090c4d5914cfe5aaf01f694601c1e0c29bc3ecbe9bc523662303
- filename
- LansingMSA2.zip
- members
- ['LansingMSA2/LansingMSA2.geojson']
-
geodatasets.Datasetgeoda.lasrosas
- url
- https://geodacenter.github.io/data-and-lab//data/lasrosas.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Corn yield, fertilizer and field data for precision agriculture, Argentina, 1999
- geometry_type
- Polygon
- nrows
- 1738
- ncols
- 35
- details
- https://geodacenter.github.io/data-and-lab//lasrosas/
- hash
- 038d0e82203f2875b50499dbd8498ca9c762ebd8003b2f2203ebc6acada8f8fd
- filename
- lasrosas.zip
- members
- ['lasrosas/rosas1999.gpkg']
-
geodatasets.Datasetgeoda.liquor_stores
- url
- https://geodacenter.github.io/data-and-lab//data/liquor.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2015 Chicago Liquor Stores
- geometry_type
- Point
- nrows
- 571
- ncols
- 3
- details
- https://geodacenter.github.io/data-and-lab//liq_chicago/
- hash
- 6a483a6a7066a000bc97bfe71596cf28834d3088fbc958455b903a0938b3b530
- filename
- liquor.zip
- members
- ['liq_Chicago.shp', 'liq_Chicago.dbf', 'liq_Chicago.shx', 'liq_Chicago.prj']
-
geodatasets.Datasetgeoda.malaria
- url
- https://geodacenter.github.io/data-and-lab//data/malariacolomb.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Malaria incidence and population (1973, 95, 93 censuses and projections until 2005)
- geometry_type
- Polygon
- nrows
- 1068
- ncols
- 51
- details
- https://geodacenter.github.io/data-and-lab//colomb_malaria/
- hash
- ca77477656829833a4e3e384b02439632fa28bb577610fe5aef9e0b094c41a95
- filename
- malariacolomb.zip
- members
- ['malariacolomb/colmunic.gpkg']
-
geodatasets.Datasetgeoda.milwaukee1
- url
- https://geodacenter.github.io/data-and-lab//data/MilwaukeeMSA.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2000 Census Tract Data for Milwaukee, WI MSA
- geometry_type
- Polygon
- nrows
- 417
- ncols
- 35
- details
- https://geodacenter.github.io/data-and-lab//milwaukee1/
- hash
- bf3c9617c872db26ea56f20e82a449f18bb04d8fb76a653a2d3842d465bc122c
- filename
- MilwaukeeMSA.zip
- members
- ['MilwaukeeMSA/wi_final_census2_random4.gpkg']
-
geodatasets.Datasetgeoda.milwaukee2
- url
- https://geodacenter.github.io/data-and-lab//data/MilwaukeeMSA2.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 1998 and 2001 Zip Code Business Patterns (Census Bureau) for Milwaukee, WI MSA
- geometry_type
- Polygon
- nrows
- 83
- ncols
- 60
- details
- https://geodacenter.github.io/data-and-lab//milwaukee2/
- hash
- 7f74212d63addb9ab84fac9447ee898498c8fafc284edcffe1f1ac79c2175d60
- filename
- MilwaukeeMSA2.zip
- members
- ['MilwaukeeMSA2/MilwaukeeMSA2.gpkg']
-
geodatasets.Datasetgeoda.ncovr
- url
- https://geodacenter.github.io/data-and-lab//data/ncovr.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- US county homicides 1960-1990
- geometry_type
- Polygon
- nrows
- 3085
- ncols
- 70
- details
- https://geodacenter.github.io/data-and-lab//ncovr/
- hash
- e8cb04e6da634c6cd21808bd8cfe4dad6e295b22e8d40cc628e666887719cfe9
- filename
- ncovr.zip
- members
- ['ncovr/NAT.gpkg']
-
geodatasets.Datasetgeoda.natregimes
- url
- https://geodacenter.github.io/data-and-lab//data/natregimes.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- NCOVR with regimes (book/PySAL)
- geometry_type
- Polygon
- nrows
- 3085
- ncols
- 74
- details
- https://geodacenter.github.io/data-and-lab//natregimes/
- hash
- 431d0d95ffa000692da9319e6bd28701b1156f7b8e716d4bfcd1e09b6e357918
- filename
- natregimes.zip
-
geodatasets.Datasetgeoda.ndvi
- url
- https://geodacenter.github.io/data-and-lab//data/ndvi.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Normalized Difference Vegetation Index grid
- geometry_type
- Polygon
- nrows
- 49
- ncols
- 8
- details
- https://geodacenter.github.io/data-and-lab//ndvi/
- hash
- a89459e50a4495c24ead1d284930467ed10eb94829de16a693a9fa89dea2fe22
- filename
- ndvi.zip
- members
- ['ndvi/ndvigrid.gpkg']
-
geodatasets.Datasetgeoda.nepal
- url
- https://geodacenter.github.io/data-and-lab//data/nepal.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Health, poverty and education indicators for Nepal districts
- geometry_type
- Polygon
- nrows
- 75
- ncols
- 62
- details
- https://geodacenter.github.io/data-and-lab//nepal/
- hash
- d7916568fe49ff258d0f03ac115e68f64cdac572a9fd2b29de2d70554ac2b20d
- filename
- nepal.zip
-
geodatasets.Datasetgeoda.nyc
- url
- https://geodacenter.github.io/data-and-lab///data/nyc.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Demographic and housing data for New York City subboroughs, 2002-09
- geometry_type
- Polygon
- nrows
- 55
- ncols
- 35
- details
- https://geodacenter.github.io/data-and-lab//nyc/
- hash
- a67dff2f9e6da9e11737e6be5a16e1bc33954e2c954332d68bcbf6ff7203702b
- filename
- nyc.zip
-
geodatasets.Datasetgeoda.nyc_earnings
- url
- https://geodacenter.github.io/data-and-lab//data/lehd.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Block-level Earnings in NYC (2002-14)
- geometry_type
- Polygon
- nrows
- 108487
- ncols
- 71
- details
- https://geodacenter.github.io/data-and-lab//LEHD_Data/
- hash
- 771fe11e59a16d4c15c6471d9a81df5e9c9bda5ef0a207e77d8ff21b2c16891b
- filename
- lehd.zip
-
geodatasets.Datasetgeoda.nyc_education
- url
- https://geodacenter.github.io/data-and-lab//data/nyc_2000Census.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- NYC Education (2000)
- geometry_type
- Polygon
- nrows
- 2216
- ncols
- 57
- details
- https://geodacenter.github.io/data-and-lab//NYC-Census-2000/
- hash
- ecdf342654415107911291a8076c1685bd2c8a08d8eaed3ce9c3e9401ef714f2
- filename
- nyc_2000Census.zip
-
geodatasets.Datasetgeoda.nyc_neighborhoods
- url
- https://geodacenter.github.io/data-and-lab//data/nycnhood_acs.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Demographics for New York City neighborhoods
- geometry_type
- Polygon
- nrows
- 195
- ncols
- 99
- details
- https://geodacenter.github.io/data-and-lab//NYC-Nhood-ACS-2008-12/
- hash
- aeb75fc5c95fae1088093827fca69928cee3ad27039441bb35c03013d2ee403f
- filename
- nycnhood_acs.zip
-
geodatasets.Datasetgeoda.orlando1
- url
- https://geodacenter.github.io/data-and-lab//data/OrlandoMSA.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2000 Census Tract Data for Orlando, FL MSA and counties
- geometry_type
- Polygon
- nrows
- 328
- ncols
- 31
- details
- https://geodacenter.github.io/data-and-lab//orlando1/
- hash
- e98ea5b9ffaf3e421ed437f665c739d1e92d9908e2b121c75ac02ecf7de2e254
- filename
- OrlandoMSA.zip
- members
- ['OrlandoMSA/orlando_final_census2.gpkg']
-
geodatasets.Datasetgeoda.orlando2
- url
- https://geodacenter.github.io/data-and-lab//data/OrlandoMSA2.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 1998 and 2001 Zip Code Business Patterns (Census Bureau) for Orlando, FL MSA
- geometry_type
- Polygon
- nrows
- 94
- ncols
- 60
- details
- https://geodacenter.github.io/data-and-lab//orlando2/
- hash
- 4cd8c3469cb7edea5f0fb615026192e12b1d4b50c22b28345adf476bc85d0f03
- filename
- OrlandoMSA2.zip
- members
- ['OrlandoMSA2/OrlandoMSA2.gpkg']
-
geodatasets.Datasetgeoda.oz9799
- url
- https://geodacenter.github.io/data-and-lab//data/oz9799.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Monthly ozone data, 1997-99
- geometry_type
- Point
- nrows
- 30
- ncols
- 78
- details
- https://geodacenter.github.io/data-and-lab//oz96/
- hash
- 1ecc7c46f5f42af6057dedc1b73f56b576cb9716d2c08d23cba98f639dfddb82
- filename
- oz9799.zip
- members
- ['oz9799/oz9799.csv']
-
geodatasets.Datasetgeoda.phoenix_acs
- url
- https://geodacenter.github.io/data-and-lab//data/phx2.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Phoenix American Community Survey Data (2010, 5-year averages)
- geometry_type
- Polygon
- nrows
- 985
- ncols
- 18
- details
- https://geodacenter.github.io/data-and-lab//phx/
- hash
- b2f6e196bacb6f3fe1fc909af482e7e75b83d1f8363fc73038286364c13334ee
- filename
- phx2.zip
- members
- ['phx/phx.gpkg']
-
geodatasets.Datasetgeoda.police
- url
- https://geodacenter.github.io/data-and-lab//data/police.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Police expenditures Mississippi counties
- geometry_type
- Polygon
- nrows
- 82
- ncols
- 22
- details
- https://geodacenter.github.io/data-and-lab//police/
- hash
- 596270d62dea8207001da84883ac265591e5de053f981c7491e7b5c738e9e9ff
- filename
- police.zip
- members
- ['police/police.gpkg']
-
geodatasets.Datasetgeoda.sacramento1
- url
- https://geodacenter.github.io/data-and-lab//data/sacramento.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2000 Census Tract Data for Sacramento MSA
- geometry_type
- Polygon
- nrows
- 403
- ncols
- 32
- details
- https://geodacenter.github.io/data-and-lab//sacramento1/
- hash
- 72ddeb533cf2917dc1f458add7c6042b93c79b31316ae2d22f1c855a9da275f9
- filename
- sacramento.zip
- members
- ['sacramento/sacramentot2.gpkg']
-
geodatasets.Datasetgeoda.sacramento2
- url
- https://geodacenter.github.io/data-and-lab//data/SacramentoMSA2.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 1998 and 2001 Zip Code Business Patterns (Census Bureau) for Sacramento MSA
- geometry_type
- Polygon
- nrows
- 125
- ncols
- 59
- details
- https://geodacenter.github.io/data-and-lab//sacramento2/
- hash
- 3f6899efd371804ea8bfaf3cdfd3ed4753ea4d009fed38a57c5bbf442ab9468b
- filename
- SacramentoMSA2.zip
- members
- ['SacramentoMSA2/SacramentoMSA2.gpkg']
-
geodatasets.Datasetgeoda.savannah1
- url
- https://geodacenter.github.io/data-and-lab//data/SavannahMSA.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2000 Census Tract Data for Savannah, GA MSA and counties
- geometry_type
- Polygon
- nrows
- 77
- ncols
- 31
- details
- https://geodacenter.github.io/data-and-lab//savannah1/
- hash
- df48c228776d2122c38935b2ebbf4cbb90c0bacc68df01161e653aab960e4208
- filename
- SavannahMSA.zip
- members
- ['SavannahMSA/ga_final_census2.gpkg']
-
geodatasets.Datasetgeoda.savannah2
- url
- https://geodacenter.github.io/data-and-lab//data/SavannahMSA2.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 1998 and 2001 Zip Code Business Patterns (Census Bureau) for Savannah, GA MSA
- geometry_type
- Polygon
- nrows
- 24
- ncols
- 60
- details
- https://geodacenter.github.io/data-and-lab//savannah2/
- hash
- 5b22b84a8665434cb91e800a039337f028b888082b8ef7a26d77eb6cc9aea8c1
- filename
- SavannahMSA2.zip
- members
- ['SavannahMSA2/SavannahMSA2.gpkg']
-
geodatasets.Datasetgeoda.seattle1
- url
- https://geodacenter.github.io/data-and-lab//data/SeattleMSA.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2000 Census Tract Data for Seattle, WA MSA and counties
- geometry_type
- Polygon
- nrows
- 664
- ncols
- 31
- details
- https://geodacenter.github.io/data-and-lab//seattle1/
- hash
- 46fb75a30f0e7963e6108bdb19af4d7db4c72c3d5a020025cafa528c96e09daa
- filename
- SeattleMSA.zip
- members
- ['SeattleMSA/wa_final_census2.gpkg']
-
geodatasets.Datasetgeoda.seattle2
- url
- https://geodacenter.github.io/data-and-lab//data/SeattleMSA2.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 1998 and 2001 Zip Code Business Patterns (Census Bureau) for Seattle, WA MSA
- geometry_type
- Polygon
- nrows
- 145
- ncols
- 60
- details
- https://geodacenter.github.io/data-and-lab//seattle2/
- hash
- 3dac2fa5b8c8dfa9dd5273a85de7281e06e18ab4f197925607f815f4e44e4d0c
- filename
- SeattleMSA2.zip
- members
- ['SeattleMSA2/SeattleMSA2.gpkg']
-
geodatasets.Datasetgeoda.sids
- url
- https://geodacenter.github.io/data-and-lab//data/sids.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- North Carolina county SIDS death counts
- geometry_type
- Polygon
- nrows
- 100
- ncols
- 15
- details
- https://geodacenter.github.io/data-and-lab//sids/
- hash
- e2f7b210b9a57839423fd170e47c02cf7a2602a480a1036bb0324e1112a4eaab
- filename
- sids.zip
- members
- ['sids/sids.gpkg']
-
geodatasets.Datasetgeoda.sids2
- url
- https://geodacenter.github.io/data-and-lab//data/sids2.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- North Carolina county SIDS death counts and rates
- geometry_type
- Polygon
- nrows
- 100
- ncols
- 19
- details
- https://geodacenter.github.io/data-and-lab//sids2/
- hash
- b5875ffbdb261e6fa75dc4580d67111ef1434203f2d6a5d63ffac16db3a14bd0
- filename
- sids2.zip
- members
- ['sids2/sids2.gpkg']
-
geodatasets.Datasetgeoda.south
- url
- https://geodacenter.github.io/data-and-lab//data/south.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- US Southern county homicides 1960-1990
- geometry_type
- Polygon
- nrows
- 1412
- ncols
- 70
- details
- https://geodacenter.github.io/data-and-lab//south/
- hash
- 8f151d99c643b187aad37cfb5c3212353e1bc82804a4399a63de369490e56a7a
- filename
- south.zip
- members
- ['south/south.gpkg']
-
geodatasets.Datasetgeoda.spirals
- url
- https://geodacenter.github.io/data-and-lab//data/spirals.csv
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- Synthetic spiral points
- geometry_type
- Point
- nrows
- 300
- ncols
- 2
- details
- https://geodacenter.github.io/data-and-lab//spirals/
- hash
- 3203b0a6db37c1207b0f1727c980814f541ce0a222597475f9c91540b1d372f1
- filename
- spirals.csv
-
geodatasets.Datasetgeoda.stlouis
- url
- https://geodacenter.github.io/data-and-lab//data/stlouis.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- St Louis region county homicide counts and rates
- geometry_type
- Polygon
- nrows
- 78
- ncols
- 24
- details
- https://geodacenter.github.io/data-and-lab//stlouis/
- hash
- 181a17a12e9a2b2bfc9013f399e149da935e0d5cb95c3595128f67898c4365f3
- filename
- stlouis.zip
-
geodatasets.Datasetgeoda.tampa1
- url
- https://geodacenter.github.io/data-and-lab//data/TampaMSA.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2000 Census Tract Data for Tampa, FL MSA and counties
- geometry_type
- Polygon
- nrows
- 547
- ncols
- 31
- details
- https://geodacenter.github.io/data-and-lab//tampa1/
- hash
- 9a7ea0746138f62aa589e8377edafea48a7b1be0cdca2b38798ba21665bfb463
- filename
- TampaMSA.zip
- members
- ['TampaMSA/tampa_final_census2.gpkg']
-
geodatasets.Datasetgeoda.us_sdoh
- url
- https://geodacenter.github.io/data-and-lab//data/us-sdoh-2014.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- 2014 US Social Determinants of Health Data
- geometry_type
- Polygon
- nrows
- 71901
- ncols
- 26
- details
- https://geodacenter.github.io/data-and-lab//us-sdoh/
- hash
- 076701725c4b67248f79c8b8a40e74f9ad9e194d3237e1858b3d20176a6562a5
- filename
- us-sdoh-2014.zip
- members
- ['us-sdoh-2014/us-sdoh-2014.shp', 'us-sdoh-2014/us-sdoh-2014.dbf', 'us-sdoh-2014/us-sdoh-2014.shx', 'us-sdoh-2014/us-sdoh-2014.prj']
-
-
geodatasets.Bunch1 items
-
geodatasets.Datasetny.bb
- url
- https://www.nyc.gov/assets/planning/download/zip/data-maps/open-data/nybb_16a.zip
- license
- NA
- attribution
- Department of City Planning (DCP)
- description
- The borough boundaries of New York City clipped to the shoreline at mean high tide for 2016.
- geometry_type
- Polygon
- details
- https://data.cityofnewyork.us/City-Government/Borough-Boundaries/tqmj-j8zm
- nrows
- 5
- ncols
- 5
- hash
- a303be17630990455eb079777a6b31980549e9096d66d41ce0110761a7e2f92a
- filename
- nybb_16a.zip
- members
- ['nybb_16a/nybb.shp', 'nybb_16a/nybb.shx', 'nybb_16a/nybb.dbf', 'nybb_16a/nybb.prj']
-
-
geodatasets.Bunch1 items
-
geodatasets.Dataseteea.large_rivers
- url
- https://www.eea.europa.eu/data-and-maps/data/wise-large-rivers-and-large-lakes/zipped-shapefile-with-wise-large-rivers-vector-line/zipped-shapefile-with-wise-large-rivers-vector-line/at_download/file
- license
- ODC-by
- attribution
- European Environmental Agency
- description
- Large rivers in Europe that have a catchment area large than 50,000 km2.
- geometry_type
- LineString
- details
- https://www.eea.europa.eu/data-and-maps/data/wise-large-rivers-and-large-lakes
- nrows
- 20
- ncols
- 3
- hash
- 97b37b781cba30c2292122ba2bdfe2e156a791cefbdfedf611c8473facc6be50
- filename
- wise_large_rivers.zip
-
-
geodatasets.Bunch2 items
-
geodatasets.Datasetabs.australia
- url
- https://www.abs.gov.au/statistics/standards/australian-statistical-geography-standard-asgs-edition-3/jul2021-jun2026/access-and-downloads/digital-boundary-files/AUS_2021_AUST_SHP_GDA2020.zip
- license
- CC BY 4.0
- attribution
- Australian Bureau of Statistics (ABS)
- description
- Australia land polygon including Norfolk Island, the Territory of Christmas Island, and the Territory of Cocos (Keeling) Islands.
- geometry_type
- Polygon
- nrows
- 2
- ncols
- 7
- details
- https://www.abs.gov.au/statistics/standards/australian-statistical-geography-standard-asgs-edition-3/jul2021-jun2026/access-and-downloads/digital-boundary-files
- hash
- 086752a6b0b3978247be201f02e02cd4e3c4f36d4f4ca74802e6831083b67129
- filename
- AUS_2021_AUST_SHP_GDA2020.zip
-
geodatasets.Datasetabs.australia_states_territories
- url
- https://www.abs.gov.au/statistics/standards/australian-statistical-geography-standard-asgs-edition-3/jul2021-jun2026/access-and-downloads/digital-boundary-files/STE_2021_AUST_SHP_GDA2020.zip
- license
- CC BY 4.0
- attribution
- Australian Bureau of Statistics (ABS)
- description
- Australian state and territory boundaries.
- geometry_type
- Polygon
- nrows
- 10
- ncols
- 9
- details
- https://www.abs.gov.au/statistics/standards/australian-statistical-geography-standard-asgs-edition-3/jul2021-jun2026/access-and-downloads/digital-boundary-files
- hash
- d9b7f735de6085b37414faf011f796dda3c7f768c55e9dce01f96e790f399a21
- filename
- STE_2021_AUST_SHP_GDA2020.zip
-
-
geodatasets.Bunch1 items
-
geodatasets.Datasetnaturalearth.land
- url
- https://naciscdn.org/naturalearth/110m/physical/ne_110m_land.zip
- license
- CC0
- attribution
- Natural Earth
- description
- Land polygons including major islands in a 1:110m resolution.
- geometry_type
- Polygon
- details
- https://www.naturalearthdata.com/downloads/110m-physical-vectors/110m-land/
- nrows
- 127
- ncols
- 4
- hash
- 1926c621afd6ac67c3f36639bb1236134a48d82226dc675d3e3df53d02d2a3de
- filename
- ne_110m_land.zip
-
We choose the dataset of Sudden Infant Death (SIDS) counts from counties in North Carolina. We can see some meta information about that dataset.
geodatasets.data.geoda.sids
- url
- https://geodacenter.github.io/data-and-lab//data/sids.zip
- license
- NA
- attribution
- Center for Spatial Data Science, University of Chicago
- description
- North Carolina county SIDS death counts
- geometry_type
- Polygon
- nrows
- 100
- ncols
- 15
- details
- https://geodacenter.github.io/data-and-lab//sids/
- hash
- e2f7b210b9a57839423fd170e47c02cf7a2602a480a1036bb0324e1112a4eaab
- filename
- sids.zip
- members
- ['sids/sids.gpkg']
Download the dataset we want (it is automatically cached).
"geoda sids") geodatasets.fetch(
Read data
= gp.read_file(geodatasets.get_path("geoda.sids"))
sids sids.head()
AREA | PERIMETER | CNTY_ | CNTY_ID | NAME | FIPS | FIPSNO | CRESS_ID | BIR74 | SID74 | NWBIR74 | BIR79 | SID79 | NWBIR79 | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0.114 | 1.442 | 1825 | 1825 | Ashe | 37009 | 37009 | 5 | 1091.0 | 1.0 | 10.0 | 1364.0 | 0.0 | 19.0 | POLYGON ((-81.47276 36.23436, -81.54084 36.272... |
1 | 0.061 | 1.231 | 1827 | 1827 | Alleghany | 37005 | 37005 | 3 | 487.0 | 0.0 | 10.0 | 542.0 | 3.0 | 12.0 | POLYGON ((-81.23989 36.36536, -81.24069 36.379... |
2 | 0.143 | 1.630 | 1828 | 1828 | Surry | 37171 | 37171 | 86 | 3188.0 | 5.0 | 208.0 | 3616.0 | 6.0 | 260.0 | POLYGON ((-80.45634 36.24256, -80.47639 36.254... |
3 | 0.070 | 2.968 | 1831 | 1831 | Currituck | 37053 | 37053 | 27 | 508.0 | 1.0 | 123.0 | 830.0 | 2.0 | 145.0 | MULTIPOLYGON (((-76.00897 36.3196, -76.01735 3... |
4 | 0.153 | 2.206 | 1832 | 1832 | Northampton | 37131 | 37131 | 66 | 1421.0 | 9.0 | 1066.0 | 1606.0 | 3.0 | 1197.0 | POLYGON ((-77.21767 36.24098, -77.23461 36.214... |
The sids
data has two periods 1974 - 1978
and 1979 - 1985
. For each period there is a number of births and a number of deaths. We want to visually compare the deaths per 1000 in each county for the two periods.
= sids.copy()
data
# Calculate the death per 1000
"1974 - 1978"] = (data["SID74"] / data["BIR74"]) * 1000
data["1979 - 1984"] = (data["SID79"] / data["BIR79"]) * 1000
data[
# Calculate center coordinates for the counties
"center_lon"] = good_centroid(data.geometry).x
data["center_lat"] = good_centroid(data.geometry).y
data[
# Make the data
= data.melt(
data =["NAME", "geometry", "center_lon", "center_lat"],
id_vars=["1974 - 1978", "1979 - 1984"],
value_vars="period",
var_name="deaths_per_1k",
value_name
).rename("NAME": "county"},
{=1
axis
)
data.head()
county | geometry | center_lon | center_lat | period | deaths_per_1k | |
---|---|---|---|---|---|---|
0 | Ashe | POLYGON ((-81.47276 36.23436, -81.54084 36.272... | -81.498245 | 36.431263 | 1974 - 1978 | 0.916590 |
1 | Alleghany | POLYGON ((-81.23989 36.36536, -81.24069 36.379... | -81.125138 | 36.490963 | 1974 - 1978 | 0.000000 |
2 | Surry | POLYGON ((-80.45634 36.24256, -80.47639 36.254... | -80.685736 | 36.412381 | 1974 - 1978 | 1.568381 |
3 | Currituck | MULTIPOLYGON (((-76.00897 36.3196, -76.01735 3... | -76.027392 | 36.407026 | 1974 - 1978 | 1.968504 |
4 | Northampton | POLYGON ((-77.21767 36.24098, -77.23461 36.214... | -77.410484 | 36.422110 | 1974 - 1978 | 6.333568 |
Plot the data
# Gallery, maps
(
ggplot(data)+ geom_map(aes(fill="deaths_per_1k"))
+ geom_text(
aes("center_lon",
"center_lat",
="county",
label=stage("deaths_per_1k", after_scale="overlay_color(color)")
color
),=6,
size=False
show_legend
)+ scale_fill_continuous(
="Deaths Per 1000",
name="plasma",
cmap_name=[0, 2.5, 5, 7.5, 10],
breaks=["0", "2.5", "5", "7.5", "10"],
labels=[0, 10],
limits
)+ facet_wrap(
"period",
=1,
ncol=lambda s: f"Sudden Infant Deaths in the Period {s}"
labeller
)+ coord_fixed(expand=False)
+ theme_void()
+ theme(
=(12, 8),
figure_size=(0, 0),
legend_position="horizontal",
legend_direction="top",
legend_title_position=0.01,
plot_margin=element_rect(fill="white"),
plot_background=0.025,
panel_spacing=element_rect(color="black"),
legend_frame=element_line(color="black"),
legend_ticks=element_text(size=12),
strip_text
) )
The Territories of Westeros
Layering different features on a Map
Read data and select features in Westeros only.
= gp.read_file("data/lands-of-ice-and-fire/continents.shp")
continents = gp.read_file("data/lands-of-ice-and-fire/islands.shp")
islands = gp.read_file("data/lands-of-ice-and-fire/lakes.shp")
lakes = gp.read_file("data/lands-of-ice-and-fire/rivers.shp")
rivers = gp.read_file("data/lands-of-ice-and-fire/political.shp")
political = gp.read_file("data/lands-of-ice-and-fire/wall.shp")
wall = gp.read_file("data/lands-of-ice-and-fire/roads.shp")
roads = gp.read_file("data/lands-of-ice-and-fire/locations.shp")
locations
= continents.query('name=="Westeros"')
westeros = islands.query('continent=="Westeros" and name!="Summer Islands"')
islands = lakes.query('continent=="Westeros"')
lakes = rivers.query('continent=="Westeros"')
rivers = roads.query('continent=="Westeros"')
roads
= westeros.geometry[0]
wg = [wg.contains(g) for g in locations.geometry]
bool_idx = locations[bool_idx]
westeros_locations = westeros_locations[westeros_locations["type"] == "City"].copy() cities
Create map by placing the features in layers in an order that limits obstraction.
The GeoDataFrame.geometry.centroid
property has the center coordinates of polygons, we use these to place the labels of the political regions.
# Gallery, maps
# colors
= "#a3ccff"
water_color = "white"
wall_color = "brown"
road_color
# Create label text by merging the territory name and
# the claimant to the territory
def fmt_labels(names, claimants):
= []
labels for name, claimant in zip(names, claimants):
if name:
"{} ({})".format(name, claimant))
labels.append(else:
"({})".format(claimant))
labels.append(return labels
def calculate_center(df):
"""
Calculate the centre of a geometry
This method first converts to a planar crs, gets the centroid
then converts back to the original crs. This gives a more
accurate
"""
= df.crs
original_crs = "EPSG:3857"
planar_crs return df["geometry"].to_crs(planar_crs).centroid.to_crs(original_crs)
"center"] = calculate_center(political)
political["center"] = calculate_center(cities)
cities[
(
ggplot()+ geom_map(westeros, fill=None)
+ geom_map(islands, fill=None)
+ geom_map(political, aes(fill="ClaimedBy"), color=None, show_legend=False)
+ geom_map(wall, color=wall_color, size=2)
+ geom_map(lakes, fill=water_color, color=None)
+ geom_map(rivers, aes(size="size"), color=water_color, show_legend=False)
+ geom_map(roads, aes(size="size"), color=road_color, alpha=0.5, show_legend=False)
+ geom_map(cities, size=1)
+ geom_text(
political,"center.x", "center.y", label="fmt_labels(name, ClaimedBy)"),
aes(=8,
size="bold",
fontweight
)+ geom_text(
cities,"center.x", "center.y", label="name"),
aes(=8,
size="left",
ha=0.20,
nudge_x
)+ labs(title="The Political Territories of Westeros")
+ scale_fill_brewer(type="qual", palette=8)
+ scale_x_continuous(expand=(0, 0, 0, 1))
+ scale_y_continuous(expand=(0, 1, 0, 0))
+ scale_size_continuous(range=(0.4, 1))
+ coord_cartesian()
+ theme_void()
+ theme(figure_size=(8, 12), panel_background=element_rect(fill=water_color))
)
Credit: cadaei of the cartographersguild website forum.