basemap icon indicating copy to clipboard operation
basemap copied to clipboard

Polar Projection PDF Issue

Open avipersin opened this issue 9 years ago • 5 comments
trafficstars

Python 3.4 Conda 3.18.3 Matplotlib 1.5.1 basemap 1.0.7 Adobe Reader XI

Trying to plot a polar projection with a custom shapefile results in an error when opening the PDF in Adobe Reader.

I am creating two orthographic projections (a southern and northern hemisphere).

basemaps.append(Basemap(projection='ortho', lon_0=270, lat_0=90., resolution='c', ax=axes[0]))
basemaps.append(Basemap(projection='ortho', lon_0=90, lat_0=-90., resolution='c', ax=axes[1]))

I then draw a full world shapefile on each projection:

basemap.readshapefile('Earth', 'globe')
...
plt.savefig('amaps.pdf')

Everything works fine here and both basemaps display with the proper lines and shapes drawn. However, when downloading the PDF and displaying it in Adobe Acrobat, you will get something like this: amap.pdf (which looks fine if you view it in your browser, but try downloading it and opening it with Adobe Reader). We've determined that the problem arises when the coastline includes lon, lat pairs in the opposite hemisphere from the hemisphere that it is to be drawn in. So if you are drawing the southern hemisphere, you cannot read a shapefile that has lon, lat points in the norther hemisphere, and vise-versa.

Our workaround required creating two separate shapefiles, one for the northern hemisphere and one for the southern. So now it looks like this:

# drawing northern hemisphere
if polar and idx == 0:
    basemap.readshapefile('Earth_north', 'nh')
elif polar and idx == 1:
# drawing southern hemisphere
    basemap.readshapefile('Earth_south', 'sh')
# drawing all other projections
else:
    basemap.readshapefile('Earth', 'globe')

This works fine but shouldn't be necessary.

avipersin avatar Jan 21 '16 20:01 avipersin

Your sample file works in evince (as in doesn't crash/error; I don't know what it should look like).

QuLogic avatar Jan 21 '16 20:01 QuLogic

@QuLogic Yes, it does work in Evince. Try opening it in Adobe Reader.

avipersin avatar Jan 21 '16 20:01 avipersin

Adobe Acrobat X also doesn't render it correctly. Google Chrome seems to render fine.

We've determined that the problem arises when the coastline includes lon, lat pairs in the opposite hemisphere from the hemisphere that it is to be drawn in. So if you are drawing the southern hemisphere, you cannot read a shapefile that has lon, lat points in the norther hemisphere, and vise-versa.

So clipping the lines that are on the other side of the globe might be a fix?

micahcochran avatar Jan 21 '16 22:01 micahcochran

So clipping the lines that are on the other side of the globe might be a fix?

That is exactly what we did with the work-around. We had to create two different shapefiles, one for each side of the globe. It works, but I would imagine this is something that should be patched at some point.

avipersin avatar Jan 21 '16 22:01 avipersin

This issue should be fixed by matplotlib/matplotlib#5911, which just need some final review before merging.

WeatherGod avatar Jan 28 '16 16:01 WeatherGod