Skip to content

Polar Projection PDF Issue #5895

Closed
Closed

Description

@avipersin

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.

Activity

  1. mdboom commented on Jan 21, 2016

    @mdboom
    Member

    It seems (at least on first read) that this is a basemap, not a matplotlib issue. Would you mind filing this under matplotlib/basemap, and feel free to reopen this issue if there's something on the matplotlib side that needs to be addressed.

  2. WeatherGod commented on Jan 21, 2016

    @WeatherGod
    Member

    but, why would it be a basemap issue in particular? Basemap doesn't have
    any PDF specific code that I am aware of.

    On Thu, Jan 21, 2016 at 3:13 PM, Michael Droettboom <
    notifications@github.com> wrote:

    Closed #5895 #5895.

    —
    Reply to this email directly or view it on GitHub
    #5895 (comment).

  3. mdboom commented on Jan 22, 2016

    @mdboom
    Member

    Sorry -- I missed that it was PDF specific. I'll reopen.

  4. reopened this on Jan 22, 2016
  5. mdboom commented on Jan 22, 2016

    @mdboom
    Member

    Can you provide a complete example (with fake data) so I can reproduce?

  6. avipersin commented on Jan 22, 2016

    @avipersin
    Author

    Can you provide a complete example (with fake data) so I can reproduce?

    Here is a link to the GitHub repo I made to illustrate the issue: https://github.com/avipersin/BasemapPDF.git

    If you run basemap.py and open map.pdf in Adobe Reader you will see the problem.

  7. tacaswell commented on Jan 23, 2016

    @tacaswell
    Member

    but try downloading it and opening it with Adobe Reader

    Can we claim that adobe is not implementing their own spec right? 😈

    With acroread 9.5.5 it looks correct, but gives a cryptic warning in a modal window. Is that the problem?

    The attached file opened fine with chromium, firefox, and okular.

  8. WeatherGod commented on Jan 24, 2016

    @WeatherGod
    Member

    For posterity, what was the cryptic error message?

    On Fri, Jan 22, 2016 at 9:48 PM, Thomas A Caswell notifications@github.com
    wrote:

    but try downloading it and opening it with Adobe Reader

    Can we claim that adobe is not implementing their own spec right? [image:
    😈]

    With acroread 9.5.5 it looks correct, but gives a cryptic warning in a
    modal window. Is that the problem?

    The attached file opened fine with chromium, firefox, and okular.

    —
    Reply to this email directly or view it on GitHub
    #5895 (comment)
    .

  9. tacaswell commented on Jan 24, 2016

    @tacaswell
    Member

    I have since removed acrobat, but from memory it was something like "This PDF is wrong, contact those who created it"

  10. mdboom commented on Jan 25, 2016

    @mdboom
    Member

    Thanks. With this I'm able to reproduce, on both Mac Adobe Reader DC 2015 and Linux 9.5 (which was discontinued and is fairly old at this point). Both pop up a dialog saying there is a problem with the file, but both seem to provide no additional information. This will be a fun puzzle 😱

  11. mdboom commented on Jan 25, 2016

    @mdboom
    Member

    I should add: On Acroread 9.5 on Linux is looks correct. On a Mac with DC 2015, it looks like this:

    screen shot 2016-01-25 at 1 55 04 pm

  12. added a commit that references this issue on Jan 25, 2016
    1d52371
  13. self-assigned this
    on Jan 25, 2016
  14. mdboom commented on Jan 25, 2016

    @mdboom
    Member

    The issue is that some shapes being drawn have shapes that are entirely made up of large numbers (1e30). My best guess is that these are continents entirely on the other side of the projection. These shapes aren't fully clipped by matplotlib's clipping algorithm -- instead a single "MOVETO" operation a location of (1e30, 1e30) is written out. I suspect this is what is tripping up Acrobat Reader. (The PDF spec doesn't really talk about range of numbers, but it's reasonable that they would reject numbers this large given that PDF is optimized for sheets of paper no larger than, say, a small planet).

    Fixing the clipping algorithm to be careful about everything it emits seems to fix the issue. See #5911.

  15. added this to the milestone on Feb 15, 2016
  16. added a commit that references this issue on Feb 22, 2016
    6922209
  17. added a commit that references this issue on Feb 22, 2016
    512c8d0
  18. added a commit that references this issue on May 22, 2016
    6569980
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions