Skip to content

Instantly share code, notes, and snippets.

@rutj3
Created March 11, 2016 09:47
Show Gist options
  • Save rutj3/e4e40b1025f7279af430 to your computer and use it in GitHub Desktop.
Save rutj3/e4e40b1025f7279af430 to your computer and use it in GitHub Desktop.
gdal_proj
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import gdal\n",
"import ogr\n",
"import osr"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'2000000'"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdal.VersionInfo()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'PROJCS[\"Africa_Albers_Equal_Area_Conic\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Albers_Conic_Equal_Area\"],PARAMETER[\"False_Easting\",0],PARAMETER[\"False_Northing\",0],PARAMETER[\"longitude_of_center\",25],PARAMETER[\"Standard_Parallel_1\",20],PARAMETER[\"Standard_Parallel_2\",-23],PARAMETER[\"latitude_of_center\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"102022\"]]'"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# init projection from EPSG 102022 (=AEA Africa)\n",
"fromepsg_srs = osr.SpatialReference()\n",
"fromepsg_srs.ImportFromEPSG(102022)\n",
"wktstr = fromepsg_srs.ExportToWkt()\n",
"\n",
"wktstr # show wkt"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs '"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fromepsg_srs.ExportToProj4() # show proj4"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs '"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# init from wkt\n",
"fromwkt_srs = osr.SpatialReference()\n",
"fromwkt_srs.ImportFromWkt(wktstr)\n",
"proj4str = fromwkt_srs.ExportToProj4()\n",
"proj4str # show proj4, still the same"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs '"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# init from proj4\n",
"my_srs = osr.SpatialReference()\n",
"my_srs.ImportFromProj4(proj4str)\n",
"my_srs.ExportToProj4() # show proj4, changed"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"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.4.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment