# Converting a shapefile from decimal degrees to UTM (km) in R

The code that I have below seems like it works in converting my vector `roads` which is in decimal degrees into a UTM CRS so that I can more easily work on the data in kilometers rather than decimal degrees.

However, upon inspecting `roads.UTM` I can see that the extent of the SpatialLinesDataFrame is still in decimal degrees, `extent: 24.41195, 32.79441, -17.92888, -9.358345 (xmin, xmax, ymin, ymax)`, and yet the CRS says it's in `+proj=UTM`.

How can I convert `roads` into UTM so that the extent is in UTM and not decimal degrees?

Here is the code I have:

``````rm(list=ls())
library(sf)
proj4string(roads) <- "+init=epsg:32735 +proj=utm +zone=35 +south +datum=WGS84 +units=m +no_defs
+ellps=WGS84 +towgs84=0,0,0"
+ellps=WGS84 +towgs84=0,0,0"))
``````
• It seems as if the wrong projection was assigned. You should be able to replace the defective .prj with a correct one, then project it to UTM. – Vince Nov 30 '20 at 4:06
• @Vince I'm not sure what you mean.. is there something wrong with the code as I've written it or something that I need to add? – JAG2024 Nov 30 '20 at 4:08
• Assigning the desired projection instead of the correct one is the cause one of the most common questions here in GIS SE. – Vince Nov 30 '20 at 4:11
• Ok, I'm still not sure what you mean though. – JAG2024 Nov 30 '20 at 4:35
• Note that UTM has length unit meters — not kilometers. – Mike T Dec 1 '20 at 3:59

After reading through the comments I figured out that I needed to set `proj4string(roads)<-" +init=epsg:4326 +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"` instead of the CRS I wanted to project to.

It looks like you are using maptools to read in the roads file and it seems that the particular function is not being maintained. If you are using library(sf) you can read the data directly into a simple features data.frame

Try:

``````library (sf)
``````library (sf)