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 readsganymede-demo/sample.geojsonfrom 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
In [ ]:
Copied!
import geopandas
geopandas.show_versions()
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
In [ ]:
Copied!
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)
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)