geoviews icon indicating copy to clipboard operation
geoviews copied to clipboard

Improvement of annotators

Open hoxbro opened this issue 1 year ago • 6 comments

Fixes #576 Fixes problems seen in Annotators.

Things done:

  • Added function transform_shapely_to_wsg84 as large coordinates shows a blank shapely figure. Also visible on the website.
Before After
image image
  • Converted string to pathlib. image

  • Update hover and link code with correct projection functions. Used this example.

  • Changed .opts to .options, though I'm not entirely sure if this is the correct fix.

Things not done:

  • I did not see this error mentioned in #526 when running the notebook.
  • I did see the error mentioned in #526 on a clean installed virtual machine.
  • When moving a point around an annotation, the annotations logic disappears. See #584.

TODO

  • [ ] Make unit test for transform_shapely_to_wsg84

hoxbro avatar Jul 19 '22 11:07 hoxbro

The geometry not being visible is definitely an issue but I'm not sure I love the fix. I would expect the geometry returned by the element to match the crs of that element. Is this a known issue in shapely or do large coordinate values actually get stored incorrectly causing the issue?

philippjfr avatar Jul 25 '22 00:07 philippjfr

The SVG created by shapely doesn't show up in the notebook. It seems to be related to Jupyter as far as I can see:

If I open the saved file in Inkscape, it renders correctly:

It seems to be a known issue: https://github.com/shapely/shapely/issues/574

Code
from IPython.display import SVG, display
from shapely.geometry import MultiPoint, Point

yy = [-10131185, -10131943, -10131766, -10131032]
xx = [3805587, 3803182, 3801073, 3799778]

points = [Point(x, y) for (x, y) in zip(xx, yy)]
multi = MultiPoint(points)

multi._repr_svg_()

with open("tmp.svg", "w") as f:
    f.write(multi._repr_svg_())

hoxbro avatar Jul 26 '22 10:07 hoxbro

Thanks for investigating that. If it's a known bug in shapely I'm a strong -1 in changing our behavior. What I would be in favor of is to add a projection argument to the geom methods that lets you easily project the geometry to some other coordinate system, e.g. WGS84. Then we can update the notebooks so they don't look broken while maintaining the existing correct default behavior.

philippjfr avatar Jul 26 '22 11:07 philippjfr

Completely agree with you.

I have implemented this suggestion. I have removed the flip from transform_shapely, which means that the output of .geom() is rotated compared to the bokeh plot. I can add this back.

image

Another thing is I added an extra point in the first example to avoid #584.

hoxbro avatar Jul 26 '22 12:07 hoxbro

Hmm, I guess I'm confused about that. Why is the svg rotated? When I load shapely objects via geopandas for example they use the same convention for storing x/y that we do and do not appear to be flipped.

philippjfr avatar Jul 26 '22 12:07 philippjfr

After some digging this is because I use wgs84 instead of PlateCarree(), which I thought was the same thing. Should an option of setting projection=True use PlateCarree or will this be too complicated?

image

hoxbro avatar Jul 26 '22 18:07 hoxbro

Issue https://github.com/holoviz/geoviews/issues/584 is also a problem with 5 points. I will update the issue with more information.

hoxbro avatar Jan 06 '23 10:01 hoxbro