-
Notifications
You must be signed in to change notification settings - Fork 12
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
ms_simplify produces clockwise instead of counterclockwise coordinates #167
Comments
Interesting, it seems to be due to the fact the D3 requires rotation different to the simple features specification. Same issue reported here in the mapshaper repo. I've simplified your example here: library(plotly)
library(rmapshaper)
library(readr)
geojson <- read_file('https://geodata.ucdavis.edu/gadm/gadm4.1/json/gadm41_DEU_0.json') |>
ms_simplify(keep = 0.01)
g <- list(
fitbounds = "locations",
projection = list(type = 'mercator'),
visible = FALSE
)
fig <- plot_ly()
fig <- fig %>% add_trace(
type="choropleth",
geojson=jsonlite::fromJSON(geojson, simplifyDataFrame = FALSE),
locations="Germany",
text="Germany",
z=0,
colors = c('white','#ed6a12'),
showscale=T,
marker = list(line=list(color='grey',width=0.25)),
featureidkey = 'properties.COUNTRY'
)
fig <- fig %>% layout(
geo = g
)
fig |
I'll see about adding the |
@gittybobomber this works for me now. Please install from: remotes::install_github("ateucher/rmapshaper@gj-2008") and try again, setting # remotes::install_github("ateucher/rmapshaper@gj-2008")
library(plotly)
library(rmapshaper)
library(readr)
geojson <- read_file('https://geodata.ucdavis.edu/gadm/gadm4.1/json/gadm41_DEU_0.json') |>
ms_simplify(keep = 0.01, gj2008 = TRUE)
g <- list(
fitbounds = "locations",
projection = list(type = 'mercator'),
visible = FALSE
)
fig <- plot_ly()
fig <- fig %>% add_trace(
type="choropleth",
geojson=jsonlite::fromJSON(geojson, simplifyDataFrame = FALSE),
locations="Germany",
text="Germany",
z=0,
colors = c('white','#ed6a12'),
showscale=T,
marker = list(line=list(color='grey',width=0.25)),
featureidkey = 'properties.COUNTRY'
)
fig <- fig %>% layout(
geo = g
)
fig |
Thanks a lot, but unfortunately I have problems installing it. I uninstall/unload first (otherwise R Warning: Paket rmapshaper wird gerade benutzt und deshab nicht installiert"): Then I install from your github: Then run I get error: Or if I run I get error: I don't get these errors when I use the "normal" install.packages('rmapshaper'). |
Oh, sorry! I think the installation was fine, but I accidentally pasted the wrong geosf_simpl <- ms_simplify(geojson, keep = 0.01, gj2008 = TRUE) |
When you tried it on the sf object, that error is expected as it doesn't make sense for Edit: I did implement the |
Thank you very much, it works now! Just another question: In the webservice https://mapshaper.org/ it is possible to tranform in the console via $ -proj from=EPSG:25833 crs=EPSG:4326 from the coordinate system used by the official German statistical office https://regionalatlas.statistikportal.de/ to the GeoJSON standard coordinations Is this possible with rmapshaper, too? Could not find it yet. |
Not directly, because I try not to replicate what's already available in existing tools (I.e., You can perform pretty much any mapshaper command on geojson objects in R with |
* Add gj2008 flag to allow reverse winding order * Expose gj2008 flag in dots arguments * Ensure all -o flags are passed together * Add test for #167 * Update NEWS for #167, #168 * Add gj2008 to sf and sp methods * Remove spurious argument to fc_command() * Add gj2008 to clip and erase * Ensure quiet flag is passed through appropriately * Update documenation for gj2008 flag * Update snapshot * quiet flag only apply when sys = TRUE * Test gj2008 with sf
At least for R Plotly choropleth geo plots, the coordinates need to be counterclockwise, otherwise the outside area instead of the inside area gets colored. But ms_simplify produces clockwise instead of counterclockwise coordinates.
I have described the problem and a solution in detail here:
https://stackoverflow.com/questions/77289351/choropleth-plot-gets-inverted-after-simplifying-geojson-with-rmapshaper
Could you change it or offer an option to chose between clockwise and counterclockwise?
The text was updated successfully, but these errors were encountered: