Home > Blockchain >  How do I change bounding box in sf object?
How do I change bounding box in sf object?

Time:09-20

I'm reading a geographical json object of election districts in Sweden and I'm a little perplexed by the format.

When reading it I get a bounding box that give a strange output when using ggplot2. How can I change the bouding box or is it something in the reading of the json object?

library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(ggplot2)

url <- "https://www.val.se/download/18.14c1f613181ed0043d560bf/1662820378349/valdistrikt-uppsala-lan.zip"

temp <- tempdir()

download.file(url, paste0(temp, "/uppsala-lan.zip"))

unzip(paste0(temp, "/uppsala-lan.zip"), exdir = "data")

file <- paste0("data/", list.files("data"))

x <- st_read(file)
#> Reading layer `VD_03_20220910_Val_20220911' from data source 
#>   `/private/var/folders/pn/9hhpnpd15_d2k3qp5k814nnh0000gq/T/RtmpMybDSS/reprex-1558b7c32e417-well-mice/data/VD_03_20220910_Val_20220911.json' 
#>   using driver `GeoJSON'
#> Simple feature collection with 238 features and 2 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 594129.6 ymin: 6585241 xmax: 708640.7 ymax: 6728479
#> Geodetic CRS:  WGS 84

x |> 
  ggplot()  
  geom_sf()
#> Warning in st_is_longlat(x): bounding box has potentially an invalid value range
#> for longlat data

Created on 2022-09-19 with enter image description here

You'll get a warning that you are not re-projecting the data; this is OK, since you are fixing the wrong projection rather than transforming the projection.

  • Related