Re: [R-sig-Geo] Did I correctly convert my data from UTM zone 12 to 11?

2023-08-08 Thread Alexander Ilich
If the vast majority of your data was within one UTM zone and only a small 
amount bled over into the adjacent UTM zone then it'd probably just be ok to 
choose the one that contains the majority of your data and accept that there 
will be some distortion. Since it's roughly 50/50 though, you should either 
split the data into two data sets and perform calculations separately for each 
one, or transform them to a common projection (e.g. EPSG:4326 aka WGS84 aka 
lat/lon) and then perform the analysis. Most of this has been stated already, 
but I figured I'd point you to some tools as well that may help you. Rather 
than doing some work arounds that seem to get it to look right it'd be better 
to use tools specifically to transform between different projections. Based on 
what you wrote it seems like you're working with vector data. For vector data, 
the sf package in R is very comprehensive (though terra also has vector 
capabilities). The st_crs will let you check or manually set a projection for a 
data set, and the st_transform function will let you transform from one 
projection to another. Note the difference here is that st_crs will not change 
the coordinates, it will just assign the name of the coordinate system whereas 
st_transform will convert from one to the other. UTM is convenient in certain 
cases because it can make calculations simpler since you can assume the area is 
essentially flat over the space considered. That being said, the sf package 
many calculations can now be done using spherical 
geometry which will be more 
accurate (I'm not sure about google earth engine though as I haven't used it). 
Below is some R code to take a dataframe of coordinates (like from your CSV), 
define the projection as UTM 11 or UTM 12 in separate objects, and how to 
transform them to lat/lon and combine them into a single object.

``` r
library(sf)
#> Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.1; sf_use_s2() is TRUE

# Create Data frames of points (Here you would use read.csv)
UTM11<- data.frame(X = c(358334, 571173, 446818, 576082, 331892),
   Y = c(5128282, 5105900, 4730385, 4667181, 4811548))

UTM12<- data.frame(X = c(405776, 614821, 428211, 602751, 366593),
   Y = c(5132654, 5117139, 4841550, 4704516, 4625745))

#Have 2 separate objects with different crs
UTM11<- st_as_sf(UTM11, coords = c("X", "Y"))
st_crs(UTM11)<- "EPSG:32611" #Set crs (https://epsg.io/32611)

UTM12<- st_as_sf(UTM12, coords = c("X", "Y"))
st_crs(UTM12)<- "EPSG:32612" #Set crs (https://epsg.io/32612)

#Transform to common crs and merge
WGS84<- rbind(st_transform(UTM11, crs = "EPSG:4326"),
  st_transform(UTM12, crs = "EPSG:4326"))
```

Created on 2023-08-08 with [reprex 
v2.0.2](https://reprex.tidyverse.org)



From: R-sig-Geo  on behalf of Jason Edelkind 
via R-sig-Geo 
Sent: Sunday, August 6, 2023 4:23 PM
To: [email protected] 
Subject: [R-sig-Geo] Did I correctly convert my data from UTM zone 12 to 11?

hello, first time user here and aspiring grad student. I have a set of location 
data that I�ve been trying to import into google earth engine from R as a CSV 
file. The problem is that about half of my data is from utm zone 12, and the 
other half is from utm zone 11. When I import my original data into google 
earth engine, the zone 11 data is shifted over to the right because I use utm 
zone 12 as the crs in R. After some reading into the definition of a utm zone, 
I tried to just subtract 6 from the zone 11 latitude values after first 
converting them to a lon/lat format. This appears to have worked as on first 
glance all of the zone 11 points are where they should be, however it feels 
like too easy a fix for me after struggling with this for several days. So my 
question is, is this an acceptable way to convert my data, or am I doing 
something wrong that could result in inaccurate location data? Thanks!
___
R-sig-Geo mailing list
[email protected]
https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&data=05%7C01%7Cailich%40usf.edu%7Cf73b5985c9d543c03e7508db96bb0824%7C741bf7dee2e546df8d6782607df9deaa%7C0%7C0%7C638269502289723854%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=T2BxWF1rCQPJmqKsVkbFR4%2F8xXrEh5iXM0XjhO634gc%3D&reserved=0
[EXTERNAL EMAIL] DO NOT CLICK links or attachments unless you recognize the 
sender and know the content is safe.

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Did I correctly convert my data from UTM zone 12 to 11?

2023-08-07 Thread MAURIZIO MARCHI
 I strongly agree with Michael Sumner. Mathematical adjustments may work but 
are heavily discouraged. The right way to work is to create two different 
spatial objects (I recommend to use the vect function of terra package) and 
then to reproject one of them in the other reference system or both in a common 
projection as for example EPSG:4326 or something like that. After that you can 
merge the two spatial objects in a single one or extract the new spatial 
coordinates to rewrite a new .csv file to be used outside R

--
Maurizio Marchi,
PhD Forest Science - Ecological Modelling
Researcher
CNR - Institute of Biosciences and BioResources (IBBR), Florence Research Area, 
Sesto Fiorentino (Italy)
SkypeID: maurizioxyz

https://scholar.google.com/citations?user=_2X6fu8J&hl=en

#--#
EUFGIS National Focal Point for Italy (www.eufgis.org<http://www.eufgis.org/>)
Scopus Author ID: 57188626512
ResearcherID: T-3813-2019
https://ibbr.cnr.it/climate-dt/

Il giorno 7 ago 2023, alle ore 12:02, [email protected] ha 
scritto:

Send R-sig-Geo mailing list submissions to
   [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
   https://stat.ethz.ch/mailman/listinfo/r-sig-geo
or, via email, send a message with subject or body 'help' to
   [email protected]

You can reach the person managing the list at
   [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of R-sig-Geo digest..."


Today's Topics:

  1. Did I correctly convert my data from UTM zone 12 to 11?
 (Jason Edelkind)
  2. Re:  Did I correctly convert my data from UTM zone 12 to 11?
 (Michael Sumner)

--

Message: 1
Date: Sun, 6 Aug 2023 15:23:08 -0500
From: Jason Edelkind 
To: [email protected]
Subject: [R-sig-Geo] Did I correctly convert my data from UTM zone 12
   to 11?
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

hello, first time user here and aspiring grad student. I have a set of 
location data that I’ve been trying to import into google earth engine from R 
as a CSV file. The problem is that about half of my data is from utm zone 12, 
and the other half is from utm zone 11. When I import my original data into 
google earth engine, the zone 11 data is shifted over to the right because I 
use utm zone 12 as the crs in R. After some reading into the definition of a 
utm zone, I tried to just subtract 6 from the zone 11 latitude values after 
first converting them to a lon/lat format. This appears to have worked as on 
first glance all of the zone 11 points are where they should be, however it 
feels like too easy a fix for me after struggling with this for several days. 
So my question is, is this an acceptable way to convert my data, or am I doing 
something wrong that could result in inaccurate location data? Thanks!



--

Message: 2
Date: Mon, 7 Aug 2023 09:26:32 +1000
From: Michael Sumner 
To: Jason Edelkind 
Cc: [email protected]
Subject: Re: [R-sig-Geo]  Did I correctly convert my data from UTM
   zone 12 to 11?
Message-ID:
   
Content-Type: text/plain; charset="utf-8"

You should treat the different sets of coordinates (from Zone 11 and Zone
12) completely separately. You cannot have mixed crs (of projected
coordinates) in a dataset. When you plot in R (generally, even with popular
spatial formats) there is no account taken of crs, the graphics doesn't
know that you plot Zone 11 and then (say) add coordinates from Zone 12,
they will be "shifted" as you say.  (There are exceptions to this plotting
rule but apart from ggplot2::coord_sf they are in dusty corners not front
and centre of plotting code in R).

Some level of coordinate hackery (arithmetic shifting) *can work*  in
limited circumstances, but I would highly recommend against that. Separate
your coordinates into two objects, set the source crs appropriately of the
zone for each, transform each to a common crs.

(UTM is generally a bad idea but comes with a very popular usage culture
which is a shame, there's no single right choice but you always need to put
thought into the overall region of your data, the properties of the
coordinate space that make sense for your work, and whether you will need
smaller or larger regions in the future for related work ... I would advise
a common crs that is *not UTM* but advice there really depends on the
details of your situation).

It's hard to be more specific without details of your flow, e.g. code
examples.

HTH, Mike





On Mon, Aug 7, 2023 at 6:23 AM Jason Edelkind via R-sig-Geo <
[email protected]> wrote:

hello, first time user here and aspiring grad student. I have a set of
location data that I’ve been trying to import into google earth eng

Re: [R-sig-Geo] Did I correctly convert my data from UTM zone 12 to 11?

2023-08-06 Thread Michael Sumner
You should treat the different sets of coordinates (from Zone 11 and Zone
12) completely separately. You cannot have mixed crs (of projected
coordinates) in a dataset. When you plot in R (generally, even with popular
spatial formats) there is no account taken of crs, the graphics doesn't
know that you plot Zone 11 and then (say) add coordinates from Zone 12,
they will be "shifted" as you say.  (There are exceptions to this plotting
rule but apart from ggplot2::coord_sf they are in dusty corners not front
and centre of plotting code in R).

Some level of coordinate hackery (arithmetic shifting) *can work*  in
limited circumstances, but I would highly recommend against that. Separate
your coordinates into two objects, set the source crs appropriately of the
zone for each, transform each to a common crs.

 (UTM is generally a bad idea but comes with a very popular usage culture
which is a shame, there's no single right choice but you always need to put
thought into the overall region of your data, the properties of the
coordinate space that make sense for your work, and whether you will need
smaller or larger regions in the future for related work ... I would advise
a common crs that is *not UTM* but advice there really depends on the
details of your situation).

It's hard to be more specific without details of your flow, e.g. code
examples.

HTH, Mike





On Mon, Aug 7, 2023 at 6:23 AM Jason Edelkind via R-sig-Geo <
[email protected]> wrote:

> hello, first time user here and aspiring grad student. I have a set of
> location data that I’ve been trying to import into google earth engine from
> R as a CSV file. The problem is that about half of my data is from utm zone
> 12, and the other half is from utm zone 11. When I import my original data
> into google earth engine, the zone 11 data is shifted over to the right
> because I use utm zone 12 as the crs in R. After some reading into the
> definition of a utm zone, I tried to just subtract 6 from the zone 11
> latitude values after first converting them to a lon/lat format. This
> appears to have worked as on first glance all of the zone 11 points are
> where they should be, however it feels like too easy a fix for me after
> struggling with this for several days. So my question is, is this an
> acceptable way to convert my data, or am I doing something wrong that could
> result in inaccurate location data? Thanks!
> ___
> R-sig-Geo mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>


-- 
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: [email protected]

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo