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
Section titled “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
Section titled “Example 1”Show version of geopandas
import geopandas
geopandas.show_versions()Example 2
Section titled “Example 2”Download a remote geojson dataset on S3 to local and read it into a dataframe (with different methods) and print the dataframe
import osimport geopandasfrom fsspec import filesystemfrom 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