# How to convert MTM coordinates to WGS84 with R?

I have MTM coordinates in the following format

``````df <- data.frame(xcentro = c(250605,250770,250871),ycentro = c(5186087,5185610,5186140))
``````

and need them to be converted in the WGS84 format. I expect the rgdal library to be able to do that, but I fail in finding the correct epsg

The only way out I see would be to implement the conversion formulas https://stackoverflow.com/questions/27824732/how-to-convert-mtm-canada-coordinates-to-latitude-and-longitude but I cannot believe it was not already implemented somehow in rgdal.

• Do you know the MTM zone? There do exist EPSG Codes for MTM zones (i.e. EPSG:32189). So it is only a matter of finding the right zone – JonasV Oct 1 '20 at 13:54
• The geographical zone is Eastern Canada (Québec). – Xavier Prudent Oct 1 '20 at 15:02
• Most of the MTM zones cover a portion of Quebec. Here's a url that does a search for MTM zones that contain Quebec in their area of use. – mkennedy Oct 1 '20 at 23:14
• Looks like this might be EPSG:32187 (NAD83 MTM Zone 7) which would correspond to points in Old Quebec City. – FSimardGIS Oct 2 '20 at 2:40
• What would be the consequence if I used an epsg for another zone close by, would the precision sink or would that be negeligible (~1meter). – Xavier Prudent Oct 2 '20 at 17:58

It looks like your points might be in EPSG:32187 (NAD83 MTM Zone 7) which would correspond to points in Old Quebec City.

It is important to tell the system the correct coordinate system and zone that your points are expressed in. Let's take the MTM Zones as an example: In each zone, the x,y coordinates repeat themselves, but 3 longitude degrees apart. Choosing a wrong zone would cause the system to locate your points in a completely different region. Your points would be hundreds of km off if you used another zone. MTM zones are 3 longitude degrees wide, so if your zone number is off by 1, then your point is off by 3 degrees of longitude, or +- 200 km.

More technical details about how to do the conversion in R:

``````library(rgdal)
library(leaflet)

## Given a shapefile with coordinates projected onto MTM-zone 7
myFile <- "/path/to/file.shp"

## Define the projection used for these data
proj4string(data) <- CRS("+init=epsg:32187") # MTM zone 7

## Define the new projection to use (WGS84 for lat-lon)
CRS.wgs84 <- CRS("+init=epsg:4326")

## Tranform to the WGS projection
data <- spTransform(data,CRS.wgs84)

## Look at it on a map