-1

I have two sf objects, which when plotting are slightly misaligned.

While initially the two objects have different CRS:

  1. the first has: WGS 84
  2. the second has: MGI / Austria GK East

I proceed, as usual with:

sf2 <- st_transform(sf2, crs = st_crs(sf1))

to align the CRS. However still, when plotting this:

ggplot() 
  + geom_sf(sf1)
  + geom_sf(sf2, color = "green", fill = "transparent")       

I get the attached output. Any ideas what I am doing wrong? enter image description here

Datasources are:

sf1: https://data.wien.gv.at/daten/geo?service=WFS&request=GetFeature&version=1.1.0&typeName=ogdwien:BEZIRKSGRENZEOGD&srsName=EPSG:31256&outputFormat=shape-zip

sf2: https://data.wien.gv.at/daten/geo?service=WFS&request=GetFeature&version=1.1.0&typeName=ogdwien:ZAEHLBEZIRKOGD&srsName=EPSG:4326&outputFormat=shape-zip

4
  • Likely red herring, but set ` sf_use_s2(FALSE)` prior to st_transform.
    – Chris
    Commented Jul 2 at 20:44
  • 1
    Where/how did you source your data? Some example data will be helpful here. Subset sf1 and sf2 to only the single most northwestern polygon, run dput() on both subsets, and add the results to a codeblock in your question. The results will look something like structure(list(...)).
    – L Tyrone
    Commented Jul 2 at 23:21
  • 2
    Links to the source/s of your data will also be useful in order to rule out any processing errors you may have accidentally made e.g. the data may have already been corrupted.
    – L Tyrone
    Commented Jul 2 at 23:30
  • many thanks for the comments: I found a "workaround" when exporting a subsample (see Answer). I however still do not understand the problem. I have updated the question by adding the data sources. I couldn't however attach the dput() output, as it was too long.
    – Tom
    Commented Jul 3 at 8:34

1 Answer 1

0

The "solution" to the problem was, that:

  1. I export the misplaced sf2 as gpkg st_write(sf2, dsn = "sf2.gpkg")
  2. and import it again sf2 <- st_read("sf2.gpkg")

all of a sudden the polygons align, even though running identical(st_crs(sf1), st_crs(sf2))gives me FALSE

I still do not understand the issue - but it worked.

enter image description here

1
  • Your "solution" still gives the wrong map, as in your question, for me. Commented Jul 16 at 14:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.