Last active
May 29, 2018 20:30
-
-
Save j08lue/f89c6477735a6abb5622131211ecc534 to your computer and use it in GitHub Desktop.
Fiona issue with transform_geom and rasterio CRS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import rasterio\n", | |
"import fiona.transform\n", | |
"import shapely.geometry" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'1.7.10'" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"fiona.__version__" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"uri = 'https://sentinel-s2-l1c.s3.amazonaws.com/tiles/55/H/BC/2016/10/13/0/B01.jp2'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"dst_crs = {'init': 'epsg:4326'}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"with rasterio.open(uri) as src:\n", | |
" xmin, ymin, xmax, ymax = src.bounds\n", | |
" src_crs = src.crs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"rasterio.crs.CRS" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"type(src_crs)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"geom = shapely.geometry.mapping(\n", | |
" shapely.geometry.box(xmin, ymin, xmax, ymax))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "AttributeError", | |
"evalue": "'CRS' object has no attribute 'encode'", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;31mAttributeError\u001b[0m: 'CRS' object has no attribute 'encode'" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Exception ignored in: 'fiona._transform._crs_from_crs'\n", | |
"AttributeError: 'CRS' object has no attribute 'encode'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"{'coordinates': [[(309780.0, 6190240.0),\n", | |
" (309780.0, 6300040.0),\n", | |
" (199980.0, 6300040.0),\n", | |
" (199980.0, 6190240.0),\n", | |
" (309780.0, 6190240.0)]],\n", | |
" 'type': 'Polygon'}" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"fiona.transform.transform_geom(src_crs, dst_crs, geom)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'coordinates': [[(144.93030119816072, -34.41180718585891),\n", | |
" (144.95410135717518, -33.42215706526496),\n", | |
" (143.77448663451727, -33.39707945023465),\n", | |
" (143.7370120996912, -34.385782261979315),\n", | |
" (144.93030119816072, -34.41180718585891)]],\n", | |
" 'type': 'Polygon'}" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"fiona.transform.transform_geom(dict(src_crs), dst_crs, geom)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python [conda env:py3]", | |
"language": "python", | |
"name": "conda-env-py3-py" | |
}, | |
"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.6.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment