> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# Geopandas

> Geopandas: Work with geospatial data. A Python demo notebook from ganymede.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/geospatial/geopandas/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/geospatial/geopandas/geopandas.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/geospatial/geopandas.ipynb)

Description:
- Work with geospatial data

Resources:
- [GitHub] https://github.com/geopandas/geopandas
- [Docs] https://geopandas.org/en/stable/
- [Examples] https://geopandas.org/en/stable/gallery/index.html

## Environment variables

This notebook reads these environment variables. Set them before you start Jupyter:

- `S3_BUCKET`: name of an S3 bucket you can access. Example 2 reads `ganymede-demo/sample.geojson` from it, so upload any GeoJSON file there first. AWS credentials come from the usual AWS configuration (environment variables, `~/.aws`, or an instance role).

## Example 1

Show version of geopandas

```python
import geopandas

geopandas.show_versions()
```

## Example 2

Download a remote geojson dataset on S3 to local and read it into a dataframe (with different methods) and print the dataframe

```python
import os
import geopandas
from fsspec import filesystem
from pathlib import Path

s3fs = filesystem("s3")

source_path = f"{os.environ['S3_BUCKET']}/ganymede-demo/sample.geojson"
print(f"Working w/ file `{source_path}` w/ the size of {s3fs.du(source_path) / 1024 / 1024:.2f}MBs")

tmp = Path("/tmp/ganymede_demo")
tmp.mkdir(parents=True, exist_ok=True)
local_path = str(tmp / "sample.geojson")
s3fs.get(lpath=local_path, rpath=source_path)

gdf = geopandas.read_file(local_path, engine="fiona") # Note: Strongly discouraged!!
print(gdf.shape)

gdf = geopandas.read_file(local_path, engine="pyogrio") # Note: Strongly encouraged!!
print(gdf.shape)

gdf = geopandas.read_file(local_path, engine="pyogrio", use_arrow=True)
print(gdf.shape)
```
