Last active
January 8, 2019 17:57
-
-
Save migurski/b26e27a7b2f87a6d6f1595f86add7a4b to your computer and use it in GitHub Desktop.
Mercator Projection with GDAL
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": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Downtown Oakland: (-13611145.458784357, 4551774.46736733, 0.0)\n", | |
"MPK 17: (-13597375.237773227, 4506940.905926282, 0.0)\n", | |
"Berlin: (1486126.3340392818, 6893693.664035214, 0.0)\n", | |
"Rio de Janeiro: (-4810115.197177352, -2619929.8004916064, 0.0)\n", | |
"Jakarta: (11893374.396353351, -693771.2752590914, 0.0)\n" | |
] | |
} | |
], | |
"source": [ | |
"from osgeo import osr\n", | |
"\n", | |
"# Unprojected degrees lon/lat - http://epsg.io/4326\n", | |
"sref4326 = osr.SpatialReference()\n", | |
"sref4326.ImportFromEPSG(4326)\n", | |
"\n", | |
"# World spherical mercator - http://epsg.io/3857\n", | |
"sref3857 = osr.SpatialReference()\n", | |
"sref3857.ImportFromEPSG(3857)\n", | |
"\n", | |
"# Transformation from EPSG4326 to EPSG:3857\n", | |
"mercator = osr.CoordinateTransformation(sref4326, sref3857)\n", | |
"\n", | |
"# Transform some sample points\n", | |
"print('Downtown Oakland:', mercator.TransformPoint(-122.271, 37.804))\n", | |
"print('MPK 17:', mercator.TransformPoint(-122.1473, 37.4851))\n", | |
"print('Berlin:', mercator.TransformPoint(13.3501, 52.5145))\n", | |
"print('Rio de Janeiro:', mercator.TransformPoint(-43.21, -22.90))\n", | |
"print('Jakarta:', mercator.TransformPoint(106.84, -6.22))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'PROJCS[\"WGS 84 / Pseudo-Mercator\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]],PROJECTION[\"Mercator_1SP\"],PARAMETER[\"central_meridian\",0],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH],EXTENSION[\"PROJ4\",\"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs\"],AUTHORITY[\"EPSG\",\"3857\"]]'" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sref3857.ExportToWkt()" | |
] | |
} | |
], | |
"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.6.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment