Notes 12ΒΆ

πŸ—ΊοΈ Python Map Visualization – Key ConceptsΒΆ

πŸ”§ Setup and Libraries GeoPandas: Extension of pandas for geospatial data (points, lines, polygons).

  • Folium: For interactive maps.

  • Shapely: Handles geometric operations (not used here, but good to know).

  • GeoDatasets: Provides built-in geospatial datasets.

πŸ“¦ Getting Started

  • Install & import libraries.

  • Use GeoDatasets.data() to access available datasets.

  • Example dataset: NYC boroughs (used throughout the lesson).

InΒ [4]:
import geopandas as gpd
import folium
import geodatasets

# Load built-in dataset: NYC boroughs
boroughs_path = geodatasets.get_path("nybb")
boroughs = gpd.read_file(boroughs_path)

# Plot NYC boroughs
boroughs.plot(edgecolor='black', color='lightblue', figsize=(10, 6))

# Add centroid and area columns
boroughs['centroid'] = boroughs.geometry.centroid
boroughs['area'] = boroughs.geometry.area

# Load parks GeoJSON file (replace with actual path if needed)
parks = gpd.read_file("nyc_parks.geojson")

# Spatial join: parks matched to boroughs
parks_with_boroughs = gpd.sjoin(parks, boroughs, how="inner", predicate="intersects")

# Plot parks with borough shading
parks_with_boroughs.plot(
    column='BoroName',
    legend=True,
    figsize=(10, 6),
    edgecolor='black',
    cmap='Set2',
    legend_kwds={'loc': 'upper left'}
)

# Filter for Manhattan parks only
manhattan_parks = parks_with_boroughs[parks_with_boroughs['BoroName'] == 'Manhattan']
manhattan_parks.plot(color='green', edgecolor='black', figsize=(10, 6))
---------------------------------------------------------------------------
DataSourceError                           Traceback (most recent call last)
Cell In[4], line 17
     14 boroughs['area'] = boroughs.geometry.area
     16 # Load parks GeoJSON file (replace with actual path if needed)
---> 17 parks = gpd.read_file("nyc_parks.geojson")
     19 # Spatial join: parks matched to boroughs
     20 parks_with_boroughs = gpd.sjoin(parks, boroughs, how="inner", predicate="intersects")

File c:\Users\joshu\anaconda3\Lib\site-packages\geopandas\io\file.py:316, in _read_file(filename, bbox, mask, columns, rows, engine, **kwargs)
    313             filename = response.read()
    315 if engine == "pyogrio":
--> 316     return _read_file_pyogrio(
    317         filename, bbox=bbox, mask=mask, columns=columns, rows=rows, **kwargs
    318     )
    320 elif engine == "fiona":
    321     if pd.api.types.is_file_like(filename):

File c:\Users\joshu\anaconda3\Lib\site-packages\geopandas\io\file.py:576, in _read_file_pyogrio(path_or_bytes, bbox, mask, rows, **kwargs)
    567     warnings.warn(
    568         "The 'include_fields' and 'ignore_fields' keywords are deprecated, and "
    569         "will be removed in a future release. You can use the 'columns' keyword "
   (...)
    572         stacklevel=3,
    573     )
    574     kwargs["columns"] = kwargs.pop("include_fields")
--> 576 return pyogrio.read_dataframe(path_or_bytes, bbox=bbox, **kwargs)

File c:\Users\joshu\anaconda3\Lib\site-packages\pyogrio\geopandas.py:275, in read_dataframe(path_or_buffer, layer, encoding, columns, read_geometry, force_2d, skip_features, max_features, where, bbox, mask, fids, sql, sql_dialect, fid_as_index, use_arrow, on_invalid, arrow_to_pandas_kwargs, **kwargs)
    270 if not use_arrow:
    271     # For arrow, datetimes are read as is.
    272     # For numpy IO, datetimes are read as string values to preserve timezone info
    273     # as numpy does not directly support timezones.
    274     kwargs["datetime_as_string"] = True
--> 275 result = read_func(
    276     path_or_buffer,
    277     layer=layer,
    278     encoding=encoding,
    279     columns=columns,
    280     read_geometry=read_geometry,
    281     force_2d=gdal_force_2d,
    282     skip_features=skip_features,
    283     max_features=max_features,
    284     where=where,
    285     bbox=bbox,
    286     mask=mask,
    287     fids=fids,
    288     sql=sql,
    289     sql_dialect=sql_dialect,
    290     return_fids=fid_as_index,
    291     **kwargs,
    292 )
    294 if use_arrow:
    295     import pyarrow as pa

File c:\Users\joshu\anaconda3\Lib\site-packages\pyogrio\raw.py:198, in read(path_or_buffer, layer, encoding, columns, read_geometry, force_2d, skip_features, max_features, where, bbox, mask, fids, sql, sql_dialect, return_fids, datetime_as_string, **kwargs)
     59 """Read OGR data source into numpy arrays.
     60 
     61 IMPORTANT: non-linear geometry types (e.g., MultiSurface) are converted
   (...)
    194 
    195 """
    196 dataset_kwargs = _preprocess_options_key_value(kwargs) if kwargs else {}
--> 198 return ogr_read(
    199     get_vsi_path_or_buffer(path_or_buffer),
    200     layer=layer,
    201     encoding=encoding,
    202     columns=columns,
    203     read_geometry=read_geometry,
    204     force_2d=force_2d,
    205     skip_features=skip_features,
    206     max_features=max_features or 0,
    207     where=where,
    208     bbox=bbox,
    209     mask=_mask_to_wkb(mask),
    210     fids=fids,
    211     sql=sql,
    212     sql_dialect=sql_dialect,
    213     return_fids=return_fids,
    214     dataset_kwargs=dataset_kwargs,
    215     datetime_as_string=datetime_as_string,
    216 )

File pyogrio\\_io.pyx:1293, in pyogrio._io.ogr_read()

File pyogrio\\_io.pyx:232, in pyogrio._io.ogr_open()

DataSourceError: nyc_parks.geojson: No such file or directory
No description has been provided for this image

TableauΒΆ

πŸ—ΊοΈ Tableau Map Visualization – Key Notes 🧩 Map Types Symbol Maps: Dots represent geographic data points (e.g. parks via zip codes).

Filled (Field) Maps: Geographic areas are filled with color based on data values.

Density (Heat) Maps: Show concentration of data using color intensity.

βš™οΈ Workflow Upload Data: Use park.geojson in Tableau Public.

Recognize Location Data:

Tableau auto-detects fields like zip codes.

If not, right-click β†’ Change Data Role β†’ set as geographic role.

πŸ”΅ Symbol Map Double-click zip code field β†’ map with points appears.

Drag borough to Color to color-code points by borough.

πŸŸͺ Filled Map Change Marks type to Map.

Area color represents data at the region level.

Hover displays info like zip code and borough.

πŸ”’ Count Parks per Zip Code Right-click zip code β†’ Create Calculated Field.

Count number of parks: use a COUNT formula.

Add count to Tooltip via the Marks card.

πŸ”₯ Density Map Change Marks type to Density.

Add numeric field (e.g., park count) to visualize concentration.

Use color scale to emphasize dense areas.

πŸ—ΊοΈ Customize Background Map Go to Map β†’ Background Map β†’ choose type (e.g., Outdoor, Normal).

Use Map β†’ Map Layers to toggle visibility of layers (e.g., cities, labels).

Use Washout to reduce background emphasis.

Tableau InteractiveΒΆ

πŸ—ΊοΈ Interactivity in Tableau & Python Maps – Key Notes πŸ“ Interactivity in Tableau Maps Add interactivity via dashboards using actions:

Types: Filter, Highlight, Go to Sheet

Actions can be triggered by selection, hover, or menu

Steps:

Create dashboard

Add sheets (e.g., Map + Borough List)

Go to Dashboard β†’ Actions β†’ Add filter

Link source sheet (e.g., borough list) to target map

Clicking a borough filters the map

🧭 Publishing Save by publishing (e.g., as β€œNYC Parks”)

View and interact with the published dashboard from your profile