smopy icon indicating copy to clipboard operation
smopy copied to clipboard

to_pixels issue

Open balzer82 opened this issue 11 years ago • 6 comments

I have following setup:

import smopy

# bounds via http://boundingbox.klokantech.com/
# copy & paste:
bounds = [14.262150,51.665628,14.502597,51.880444]

maxY = bounds[3]
maxX = bounds[2]
minY = bounds[1]
minX = bounds[0]

mymap = smopy.Map((minY, minX, maxY, maxX), z=10)

X, Y = mymap.to_pixels(51.75,14.325)
ax = mymap.show_mpl(figsize=(23,29.7))

ax.plot(X, Y, 'or', ms=50, mew=2);    

which produces to the following map:

cottbus-hauptbahnhof-1500

Here are two things wrong:

  1. the map is bottom up, maybe because in the def show_mpl the ylim is defined between (self.h, 0) and not from (0, self.h)?
  2. the red dot is not where it is supposed to be. The coordinates are the main station of Cottbus, which is not on this position, even when the map is turned upside-down

Is my code wrong or is the calculation of the lat, lon on the matplotlib image wrong?

balzer82 avatar Jan 22 '14 18:01 balzer82

The exact same code produces the following image on my system:

issue1

I think it is correct?

It may be due to a change in MPL or PIL. Can you run the following code?

import numpy
import matplotlib
import PIL
print "NumPy", numpy.__version__
print "MPL", matplotlib.__version__
print "PIL", PIL.VERSION

On my system: NumPy 1.7.1 MPL 1.3.0 PIL 1.1.7

rossant avatar Jan 22 '14 20:01 rossant

On my system (MacOS X Mountain Lion):

NumPy 1.6.2
MPL 1.1.1
PIL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'VERSION'

If I am doin' something like pip install pil --upgrade it tells me,

Requirement already up-to-date: PIL in /Library/Python/2.7/site-packages/PIL

:(

Maybe this is the problem.

Can you zoom in to your rendering? I changed the ylim() definition in smopy, so that the image is not upside down, but the point was slightly wrong in north direction. I wanna take a look if on your rendering too.

balzer82 avatar Jan 23 '14 10:01 balzer82

Could you try installing Pillow instead of PIL? As far as I understand, PIL is dead, and Pillow is its maintained fork.

I'll try to upload a zoom of the image.

rossant avatar Jan 23 '14 10:01 rossant

If I am doin' mymap.save_png('bg.png') the image is not upside down. So it might be the ylim() definition in show_mpl() ?

balzer82 avatar Jan 23 '14 10:01 balzer82

If I am doin' mymap.save_png('bg.png') the image is not upside down. So it might be the ylim() definition in show_mpl() ?

Possibly. If I change the ylim like you did, I get an upside down image (whereas it is currently correct). I'm wondering how it would work for you if you had the same matplotlib version as me.

rossant avatar Jan 23 '14 10:01 rossant

@sethoscope wrote in his heatmap.py (https://github.com/sethoscope/heatmap)

# If someone wants to use pixel coordinates instead of Lat/Lon, we
# could add an XYProjection.  EquirectangularProjection would work,
# but would be upside-down.

Maybe this is the solution?

balzer82 avatar Jan 28 '14 12:01 balzer82