Skip to content

Instantly share code, notes, and snippets.

@alexgleith
Created June 27, 2021 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexgleith/f94f3f3da2f43dd6cfab84eb9d8a13f7 to your computer and use it in GitHub Desktop.
Save alexgleith/f94f3f3da2f43dd6cfab84eb9d8a13f7 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"id": "collective-gothic",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.2.6\n"
]
}
],
"source": [
"import rasterio\n",
"from rasterio import warp\n",
"print(rasterio.__version__)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "interior-volunteer",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.0.0.post1\n"
]
}
],
"source": [
"import pyproj\n",
"from pyproj import Transformer\n",
"print(pyproj.__version__)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "possible-cover",
"metadata": {},
"outputs": [],
"source": [
"file = \"https://soilspackage-useast.s3.amazonaws.com/EsriLandCover/01C_20200101-20210101.tif\""
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "quantitative-family",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(-179.9831020235291, -80.51265674820361, 179.81681842082818, -77.57683559445971)\n"
]
}
],
"source": [
"with rasterio.open(file) as f:\n",
" bbox = f.bounds\n",
" bbox_rasterio = warp.transform_bounds(f.crs, \"epsg:4326\", *f.bounds)\n",
" \n",
" transformer = Transformer.from_crs(f.crs, \"EPSG:4326\", always_xy=True)\n",
" bbox_proj = transformer.transform(f.bounds[0], f.bounds[1])\n",
" bbox_proj += transformer.transform(f.bounds[2], f.bounds[3])"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "apart-softball",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"rio: -179.9831020235291 | proj: 175.7142130783133\n",
"rio: -80.51265674820361 | proj: -80.43693672756477\n",
"rio: 179.81681842082818 | proj: -170.9756575751534\n",
"rio: -77.57683559445971 | proj: -77.57683559445971\n"
]
}
],
"source": [
"for i in range(4):\n",
" print(f\"rio: {bbox_rasterio[i]} | proj: {bbox_proj[i]}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "blank-testimony",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment