holoviz / geoviews

Simple, concise geographical visualization in Python
http://geoviews.org
BSD 3-Clause "New" or "Revised" License
592 stars 76 forks source link

polygon rendering bug with Geostationary projection #108

Open rabernat opened 6 years ago

rabernat commented 6 years ago

I have found a mysterious bug that only appears with Geostationary projections.

import holoviews as hv
import geoviews as gv
import geoviews.feature as gf
from cartopy import ccrs
hv.notebook_extension()

# create two polygons

# this one works fine
good_tri = np.array(
 [[161.10399999999998, -50.62000000000003],
 [156.569, -52.84800000000001],
 [158.563, -48.80600000000001]]
)

# this one renders strangely ... what could the difference be?
bad_tri = np.array(
 [[150.388, -63.71100000000001],
 [143.041, -63.62899999999999],
 [179.209, -65.34300000000002]])

# turn these into geoviews shapes
extents = (-180, -90, 180, 90)
bad_tri_shape = gv.Shape(shapely.geometry.Polygon(bad_tri), extents=extents)
good_tri_shape = gv.Shape(shapely.geometry.Polygon(good_tri), extents=extents)

# define a projection: Orthographic works
projection = ccrs.Orthographic(central_longitude=180)

# <--- new cell --->
%%opts Feature (facecolor='0.9' edgecolor='0.2')  [projection=projection]
%%opts Shape (facecolor='red') [projection=projection]
gf.land() * bad_tri_shape * good_tri_shape

# now use Geostationary
projection = ccrs.Geostationary(central_longitude=180)

# <--- new cell --->
%%opts Feature (facecolor='0.9' edgecolor='0.2')  [projection=projection]
%%opts Shape (facecolor='red') [projection=projection]
gf.land() * bad_tri_shape * good_tri_shape

The output of Orthographic is this: (The polygons are small but visible in the lower left part of the globe.) image

The output of Geostationary is this: image The bad_tri_shape is somehow covering the whole globe.

philippjfr commented 5 years ago

This seems related to https://github.com/pyviz/geoviews/issues/214, in that case tiny slivers are blowing up to cover the whole globe. Something similar seems to be happening here but the sliver in this case is much bigger than in that example.

philippjfr commented 5 years ago

In fact it seems to invert the polygon, the sliver becomes the interior of a huge polygon covering the globe.

jbednar commented 5 years ago

Maybe it's not a slight gap in the original data, but a slight overlap.