Ok, I finally did this with the base matplotlib library toolkit. I will explain how it works, maybe it will be useful to someone someday.
1. Download and install the matplotlib library on your system. http://matplotlib.org/downloads.html
For Windows binaries, I recommend using this page: http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib Beware of the hint that reads:
Requires numpy, dateutil, pytz, pyparsing, six and possibly a pillow, pycairo, tornado, wxpython, pyside, pyqt, ghostscript, miktex, ffmpeg, mencoder, avconv or imagemagick.
Therefore, if you have not already installed on your system, you need to download and install numpy, dateutil, pytz, pyparsing and six, as well as for matplotlib to work correctly (for Windows users: all of them can be found on the page, for Linux users, the package manager python "pip" should do the trick).
2. Download and install the basemap toolkit for matplotlib. Either from http://matplotlib.org/basemap/users/installing.html or for Windows binaries also from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#basemap
3. Make a projection in Python code:
#Import necessary libraries from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np
Output:
projected_coordinates (10587117.191355567, 14567974.064658936)
Just. Now, when you use the projected coordinates to build a polygon with a beautiful pattern, and then calculate the area using the slender area method, you will get the area in square meter (in accordance with the projection you use). To get square kilometers, divide them by 10 ^ 6.
Edit: I did my best not to convert only single coordinates, but whole geometry objects, such as polygons, when they were already set as beautiful objects, and not through their original coordinates. This meant writing a lot of code in
- get the coordinates of the outer ring of the polygon
- determine if the polygon has holes, and if so, treat each hole separately
- transform each pair of coordinates of the outer ring and any holes
- combine all this and create a polygon object with projected coordinates
- and that only for polygons ... add even more loops for multipolygon and geometric collections.
Then I came across this piece of beautiful documentation that makes things a lot easier: http://toblerity.org/shapely/manual.html#shapely.ops.transform
When a projection map is installed, for example, as done above:
m = Basemap(width=1,height=1, resolution='l',projection='laea',lat_ts=50,lat_0=50,lon_0=-107.)
Then, using this projection, you can transform any slender geometry object through:
from shapely.ops import transform projected_geometry = transform(m,geometry_object)