2

I have a WGS84 coordinate pair (37.7749295, -122.4194155). I have an image that is a Robinson Map Projection of the world. I'm trying to write a python script to locate my WGS84 coordinate on my Robinson Map.

As an essential step in this, I'm trying to use pyproj, the python-adaption of Proj4, to convert my WGS84 coordinate to a Robinson coordinate. Unfortunately I am new to Proj4, and somewhat confused by the documentation. I hope that someone can help me out.

2
  • Is the image georeferenced already? Aug 14, 2014 at 19:52
  • @Snorfalorpagus I don't think so. What I thought that I would do is to convert WGS84 to some kind of Robinson measurement, and then just scale that to the map by trial and error in order to find the formula for translating Robinson Coordinates to Pixel X/Y. (That's probably not the best method.)
    – Newb
    Aug 14, 2014 at 20:57

1 Answer 1

2

You can do this using cartopy.

#!/usr/bin/env python

import cartopy
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from pylab import imread

im = imread('Robinson-projection.jpg')
ax = plt.axes(projection=ccrs.Robinson())
plt.imshow(im, origin='upper', extent=[-17005833.330525, 17005833.330525, -8622512.772008, 8622512.772008], interpolation='nearest')
ax.coastlines(resolution='110m', color='yellow', linewidth=1, alpha=0.7)
plt.plot(-122.4194155, 37.7749295, marker='o', color='red', transform=ccrs.Geodetic())
plt.show()

To test I used a map in the Robinson projection downloaded from Wikipedia.

http://en.wikipedia.org/wiki/List_of_cartographers#mediaviewer/File:Robinson-projection.jpg

The result is shown below.

output map

To convert coordinates between lnglat and WGS84 using pyproj:

#!/usr/bin/env python
import pyproj
crs_from = pyproj.Proj(init='EPSG:4326')
crs_to = pyproj.Proj('+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
x, y = pyproj.transform(crs_from, crs_to, -122.4194155, 37.7749295)
3
  • Wow! Awesome! I have one follow-up question: do you know of a way to achieve this result by standard image manipulation, rather than by using plt? Is using plt.axes(projection=ccrs.Robinson()) essential, or can this be done by some other means?
    – Newb
    Aug 14, 2014 at 21:13
  • Answer edited to include an example of using pyproj directly to convert the coordinates. You'll have to take a small step further to convert that to pixel coordinates. Aug 15, 2014 at 8:13
  • Any idea why I receive this error? RuntimeError: b'no arguments in initialization list'
    – Stücke
    Jun 13, 2019 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.