Skip to content

Description:

  • Work with geospatial data

Resources:

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).

Show version of geopandas

import geopandas
geopandas.show_versions()

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

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)

ganymede is made by Eugo