# What is the difference between projected coordinates and latitude and longitude

Converting projected coordinates to latitude and longitude (lat/lon) means transforming coordinates from a two-dimensional, Cartesian coordinate system to a geographic coordinate system based on a sphere or ellipsoid (such as Earth).

**Projected coordinate system**s are used to represent the Earth’s curved surface on a flat plane. They are especially useful for regional or local mapping, where distortions introduced by the projection are minimal. Examples of projected coordinate systems include Universal Transverse Mercator (UTM), State Plane Coordinate System (SPCS), and Lambert Conformal Conic.

**Latitude and longitude (lat/lon)** are part of a geographic coordinate system that represents points on the Earth’s surface using angles. In this system, latitude is the angle measured from the equator to a point on the Earth’s surface, while longitude is the angle measured from the Prime Meridian (which passes through Greenwich, England) to a point on the Earth’s surface. The most commonly used geographic coordinate system is the World Geodetic System 1984 (WGS84).

When you convert projected coordinates to latitude and longitude, you are transforming coordinates from a flat, Cartesian grid to a curved coordinate system that takes into account the Earth’s shape. This conversion is essential when you need to perform tasks that involve geospatial data in different coordinate systems, such as overlaying data from various sources, calculating distances, or performing spatial analyses.

The conversion process requires knowledge of the source (projected) and destination (geographic) coordinate systems, and sometimes additional parameters, such as the datum or projection parameters. Libraries like `pyproj`

in Python, `sf`

in R, and `proj4js`

in JavaScript are commonly used to perform these conversions.

**Want to stay ahead of the geospatial curve? Listen to our podcast!**

## Converting projected coordinates to lat/lon using Python

To convert projected coordinates to latitude and longitude using Python, you can use the `pyproj`

library, which is a wrapper around the PROJ library. First, you need to install the library if you haven’t done so already:

```
pip install pyproj
```

Next, you can use the following Python script to perform the conversion. Make sure you know the EPSG (European Petroleum Survey Group) codes for both the source and destination coordinate systems. In this example, I am using the UTM Zone 32N (EPSG:32632) as the source coordinate system, and WGS84 (EPSG:4326) as the destination coordinate system. You can change these codes according to your requirements.

```
import pyproj
def convert_projected_to_latlon(x, y, source_epsg, dest_epsg=4326):
source_proj = pyproj.Proj(f'epsg:{source_epsg}')
dest_proj = pyproj.Proj(f'epsg:{dest_epsg}')
lon, lat = pyproj.transform(source_proj, dest_proj, x, y)
return lat, lon
# Example usage:
x, y = 500000, 4649776 # Projected coordinates in UTM Zone 32N
source_epsg = 32632 # UTM Zone 32N
dest_epsg = 4326 # WGS84
lat, lon = convert_projected_to_latlon(x, y, source_epsg, dest_epsg)
print(f'Latitude: {lat}, Longitude: {lon}')
```

Just replace `x`

, `y`

, and `source_epsg`

with your coordinates and EPSG code, respectively. The function `convert_projected_to_latlon`

will return the latitude and longitude in the WGS84 coordinate system.

**19 Python libraries that you should know about!**

## Converting projected coordinates to lat/lon in R

In R, you can use the `sf`

package to convert projected coordinates to latitude and longitude. First, you need to install the package if you haven’t done so already:

```
install.packages("sf")
```

Next, you can use the following R script to perform the conversion. Make sure you know the EPSG (European Petroleum Survey Group) codes for both the source and destination coordinate systems. In this example, I am using the UTM Zone 32N (EPSG:32632) as the source coordinate system, and WGS84 (EPSG:4326) as the destination coordinate system. You can change these codes according to your requirements.

```
library(sf)
convert_projected_to_latlon <- function(x, y, source_epsg, dest_epsg=4326) {
point <- st_point(c(x, y))
source_crs <- st_crs(source_epsg)
dest_crs <- st_crs(dest_epsg)
point_sf <- st_sf(geometry = st_sfc(point, crs = source_crs))
point_sf_transformed <- st_transform(point_sf, dest_crs)
latlon <- st_coordinates(point_sf_transformed)
return(latlon)
}
# Example usage:
x <- 500000
y <- 4649776 # Projected coordinates in UTM Zone 32N
source_epsg <- 32632 # UTM Zone 32N
dest_epsg <- 4326 # WGS84
latlon <- convert_projected_to_latlon(x, y, source_epsg, dest_epsg)
cat("Latitude:", latlon[2], "Longitude:", latlon[1])
```

Just replace `x`

, `y`

, and `source_epsg`

with your coordinates and EPSG code, respectively. The function `convert_projected_to_latlon`

will return the latitude and longitude in the WGS84 coordinate system.

## Converting projected coordinates to lat/lon javascript

To convert projected coordinates to latitude and longitude in JavaScript, you can use the `proj4js`

library. First, you need to install the library if you haven’t done so already:

```
npm install proj4
```

Next, you can use the following JavaScript script to perform the conversion. Make sure you know the EPSG (European Petroleum Survey Group) codes for both the source and destination coordinate systems. In this example, I am using the UTM Zone 32N (EPSG:32632) as the source coordinate system, and WGS84 (EPSG:4326) as the destination coordinate system. You can change these codes according to your requirements.

```
const proj4 = require('proj4');
function convertProjectedToLatLon(x, y, sourceEpsg, destEpsg = 4326) {
const sourceProj = `EPSG:${sourceEpsg}`;
const destProj = `EPSG:${destEpsg}`;
const [lon, lat] = proj4(sourceProj, destProj, [x, y]);
return { lat, lon };
}
// Example usage:
const x = 500000;
const y = 4649776; // Projected coordinates in UTM Zone 32N
const sourceEpsg = 32632; // UTM Zone 32N
const destEpsg = 4326; // WGS84
const { lat, lon } = convertProjectedToLatLon(x, y, sourceEpsg, destEpsg);
console.log(`Latitude: ${lat}, Longitude: ${lon}`);
```

Just replace `x`

, `y`

, and `sourceEpsg`

with your coordinates and EPSG code, respectively. The function `convertProjectedToLatLon`

will return the latitude and longitude in the WGS84 coordinate system.