makes sf1 compatible with sf2 by projecting into the projection of 2 and ensuring that the geometry columns are the same name.

st_compatibalize(sf1, sf2)

Arguments

sf1

sf data.frame

sf2

sf data.frame

Examples


source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))

(one <- dplyr::select(sample_flines))
#> Simple feature collection with 707 features and 0 fields
#> Geometry type: MULTILINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -77.16175 ymin: 39.11307 xmax: -76.43622 ymax: 39.64679
#> Geodetic CRS:  WGS 84
#> # A tibble: 707 × 1
#>                                                                             geom
#>                                                            <MULTILINESTRING [°]>
#>  1 ((-76.66157 39.27636, -76.6614 39.27636, -76.66057 39.27545, -76.66051 39.27…
#>  2 ((-76.65498 39.27543, -76.65436 39.27497, -76.65398 39.27431, -76.65386 39.2…
#>  3 ((-76.64835 39.27115, -76.64812 39.27115, -76.64771 39.2709, -76.64662 39.27…
#>  4 ((-76.63034 39.2693, -76.63021 39.26919, -76.62808 39.26881, -76.62708 39.26…
#>  5 ((-76.61201 39.25434, -76.61183 39.25413, -76.61068 39.25344, -76.60962 39.2…
#>  6 ((-76.68668 39.30612, -76.68492 39.30628, -76.6835 39.30608, -76.68218 39.30…
#>  7 ((-76.71434 39.32628, -76.71457 39.32592, -76.7146 39.32432, -76.71425 39.32…
#>  8 ((-76.72432 39.32412, -76.7235 39.32383, -76.72247 39.32387, -76.72152 39.32…
#>  9 ((-76.73594 39.34748, -76.73455 39.34652, -76.73208 39.34574, -76.73143 39.3…
#> 10 ((-76.7446 39.36049, -76.7446 39.35959, -76.74451 39.35934, -76.74424 39.359…
#> # ℹ 697 more rows
(two <- sf::st_transform(one, 5070))
#> Simple feature collection with 707 features and 0 fields
#> Geometry type: MULTILINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: 1597686 ymin: 1956259 xmax: 1663643 ymax: 2010159
#> Projected CRS: NAD83 / Conus Albers
#> # A tibble: 707 × 1
#>                                                                             geom
#>  *                                                         <MULTILINESTRING [m]>
#>  1 ((1641586 1973488, 1641601 1973491, 1641690 1973404, 1641699 1973388, 164172…
#>  2 ((1642159 1973499, 1642221 1973459, 1642268 1973393, 1642289 1973342, 164233…
#>  3 ((1642811 1973144, 1642831 1973148, 1642871 1973127, 1642970 1973109, 164303…
#>  4 ((1644361 1973252, 1644374 1973243, 1644561 1973238, 1644645 1973252, 164474…
#>  5 ((1646235 1971928, 1646255 1971908, 1646367 1971852, 1646465 1971824, 164695…
#>  6 ((1638811 1976321, 1638955 1976369, 1639078 1976371, 1639181 1976429, 163923…
#>  7 ((1636041 1978058, 1636030 1978013, 1636063 1977837, 1636107 1977775, 163625…
#>  8 ((1635254 1977649, 1635330 1977630, 1635415 1977653, 1635482 1977730, 163554…
#>  9 ((1633756 1980012, 1633893 1979931, 1634118 1979888, 1634173 1979894, 163427…
#> 10 ((1632738 1981292, 1632758 1981194, 1632771 1981168, 1632799 1981145, 163287…
#> # ℹ 697 more rows

attr(one, "sf_column") <- "geotest"
names(one)[names(one) == "geom"] <- "geotest"

st_compatibalize(one, two)
#> Simple feature collection with 707 features and 0 fields
#> Geometry type: MULTILINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: 1597686 ymin: 1956259 xmax: 1663643 ymax: 2010159
#> Projected CRS: NAD83 / Conus Albers
#> # A tibble: 707 × 1
#>                                                                             geom
#>  *                                                         <MULTILINESTRING [m]>
#>  1 ((1641586 1973488, 1641601 1973491, 1641690 1973404, 1641699 1973388, 164172…
#>  2 ((1642159 1973499, 1642221 1973459, 1642268 1973393, 1642289 1973342, 164233…
#>  3 ((1642811 1973144, 1642831 1973148, 1642871 1973127, 1642970 1973109, 164303…
#>  4 ((1644361 1973252, 1644374 1973243, 1644561 1973238, 1644645 1973252, 164474…
#>  5 ((1646235 1971928, 1646255 1971908, 1646367 1971852, 1646465 1971824, 164695…
#>  6 ((1638811 1976321, 1638955 1976369, 1639078 1976371, 1639181 1976429, 163923…
#>  7 ((1636041 1978058, 1636030 1978013, 1636063 1977837, 1636107 1977775, 163625…
#>  8 ((1635254 1977649, 1635330 1977630, 1635415 1977653, 1635482 1977730, 163554…
#>  9 ((1633756 1980012, 1633893 1979931, 1634118 1979888, 1634173 1979894, 163427…
#> 10 ((1632738 1981292, 1632758 1981194, 1632771 1981168, 1632799 1981145, 163287…
#> # ℹ 697 more rows