Skip to content
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

UTM Zone conversion #139

Merged
merged 13 commits into from
Nov 20, 2023
Merged

UTM Zone conversion #139

merged 13 commits into from
Nov 20, 2023

Conversation

ateucher
Copy link
Collaborator

@ateucher ateucher commented Nov 17, 2023

This adds a function utm_convert() to convert tabular data in UTM zones to a standard CRS (default BC Albers). This is especially useful for field studies with data collected over a wide area that spans UTM zones.

The location data is expected to be in two columns with x and y, and the zone can be either in a column (when the data set spans multiple UTM zones), or can be specified for the whole data set. E.g.:

# Data with multiple zones, and a column denoting the zone
df <- data.frame(
 animalid = c("a", "b", "c"),
 zone = c(10, 11, 11),
 easting = c(500000, 800000, 700000),
 northing = c(5000000, 3000000, 1000000)
)

utm_convert(df, xcol = "easting", ycol = "northing", zone = "zone")
#> Simple feature collection with 3 features and 6 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 1237767 ymin: -3576605 xmax: 2418043 ymax: 21953.96
#> Projected CRS: NAD83 / BC Albers
#>      animalid zone       X           Y easting northing
#> 10          a   10 1237767    21953.96   5e+05    5e+06
#> 11.2        b   11 2275642 -1807950.91   8e+05    3e+06
#> 11.3        c   11 2418043 -3576604.70   7e+05    1e+06
#>                      geometry
#> 10   POINT (1237767 21953.96)
#> 11.2 POINT (2275642 -1807951)
#> 11.3 POINT (2418043 -3576605)

# Data all in one zone, specify a single zone:
df <- data.frame(
 animalid = c("a", "b"),
 easting = c(500000, 800000),
 northing = c(5000000, 3000000)
)

utm_convert(df, xcol = "easting", ycol = "northing", zone = 11)
#> Simple feature collection with 2 features and 5 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 1711595 ymin: -1807951 xmax: 2275642 ymax: 62209.93
#> Projected CRS: NAD83 / BC Albers
#>   animalid       X           Y easting northing                 geometry
#> 1        a 1711595    62209.93   5e+05    5e+06 POINT (1711595 62209.93)
#> 2        b 2275642 -1807950.91   8e+05    3e+06 POINT (2275642 -1807951)

Created on 2023-11-17 with reprex v2.0.2

Copy link
Collaborator

@boshek boshek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. One comment about argument naming though.

R/utm-convert.R Outdated Show resolved Hide resolved
R/utm-convert.R Show resolved Hide resolved
Copy link
Collaborator

@boshek boshek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Great addition. Ship it!

@ateucher ateucher merged commit 9578067 into main Nov 20, 2023
6 checks passed
@ateucher ateucher deleted the utm-convert branch November 20, 2023 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants