2
votes

I'm working with shapefiles of subdivisions of a number of countries, and for one country (Iceland), the X and Y coordinates appear to be swapped around in the shapefile.

The data can be downloaded here: shapefile data; IS_50V:mork_kjordaemi is the relevant dataset, select the "shape-zip" option in the download dropdown menu. I've been using the "sf" package in R for all the shapefile work, and it has worked flawlessly with all the other shapefile data I have.

library(sf)

ic_2003 <- downloaded_data

st_crs(ic_2003) gives me

Coordinate Reference System:
  User input: ISN2016 
  wkt:
GEOGCRS["ISN2016",
    DATUM["Islands Net 2016",
        ELLIPSOID["GRS 1980",6378137,298.257222101,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    USAGE[
        SCOPE["unknown"],
        AREA["Iceland"],
        BBOX[59.96,-30.87,69.59,-5.55]],
    ID["EPSG",8086]]

head(ic_2003) gives me

Simple feature collection with 6 features and 15 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 63.29577 ymin: -24.53268 xmax: 66.56644 ymax: -13.49462
Geodetic CRS:  ISN2016

I've tried ic_2003 <- st_transform(ic_2003, 4326) but this doesn't fix the problem.

I've also tried ic_2003 <- st_transform(ic_2003, pipeline = "+proj=pipeline +step +proj=axisswap +order=2,1"), as done here , but this also does not solve the issue.

If I plot the data

ggplot(ic_2003) +
 geom_sf() +
 coord_sf() 

I get the right shape, but rotated 90 degrees and in the wrong place on a world map.

Any help you could give me would be greatly appreciated.

1

1 Answers

1
votes

There must be a sf way of doing this easily, but you can also use purrr::modify (which works like map) to swap all of the geometry lat/lon columns (a matrix within a list within a list within a list) without changing the sf attributes...

library(sf)
library(tidyverse)

ic_2003 <- st_read("mork_kjordaemiPolygon.shp") #from link above

ic_2003 <- ic_2003 %>% 
      mutate(geometry = modify(geometry, modify, ~list(.[[1]][,c(2,1)]))) 

ggplot(ic_2003) +
  geom_sf() +
  coord_sf() 

enter image description here