Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange results on reading KML/KMZ with elements that go through the International Date Line (longitude 180) #1508

Closed
arthurwelle opened this issue Oct 11, 2020 · 1 comment

Comments

@arthurwelle
Copy link

I'm reading a KMZ file that has solar eclipse paths. I'm using sf::sf_read() on Linux/Ubuntu 18 and the driver is the default LIBKML. Everything works fine until some paths go through the International Date Line (longitude 180). In this case the transformation to an sf object gives unexpected results, as seen in the image below.

sf_image

Since github does not provide support for .KMZ files I share it in my Drive (only 100Kb):

https://drive.google.com/file/d/1dp21nRucVlaEL2RAhxJsHcpQQpY3QJce/view?usp=sharing

The minimum code I used is:

library(tidyverse)
library(sf)
library(rnaturalearth)

# retrive a list of every layer of the kmz file 
l_layers <- sf::st_layers("./test.kmz")$name

# read a given layer of interest
f <- sf::st_read("./test.kmz", layer = l_layers[3])

# download world map as sf
worldmap <- rnaturalearth::ne_countries(returnclass = 'sf')

# plot results
ggplot2::ggplot() +
        geom_sf(data = worldmap, mapping = aes(geometry = geometry)) +
        geom_sf(data = f, mapping = aes(geometry = geometry))

Does anyone knows what is happening here? Is there other custom drivers that I could use? Is the s2 in the future a solution to this?

Thanks!

@edzer
Copy link
Member

edzer commented Oct 11, 2020

It's (I.M.O.) not the transformation to an sf object, but the assumption made by plotting it on Plate Carree; for this type of plot you need to pull it through st_wrap_dateline first, as in

f = st_wrap_dateline(f)

then we see
x

Other projections need other manipulations, e.g. to crop to the visible part of the Earth before doing an orthographic projection. see e.g. here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants