2

I have a shapefile and I loaded it into QGIS using Add vector layer. After that, I can see points in different positions.

I open the Attribute table and I can see columns "X" and "Y" with values such as (151449.965057, 204642.790761). Now I want to convert them to latitude and longitude. How can I do that?

Therefore, I use the option Save as to export the data to csv format using the CRS WGS 84.

However, nothing changes in the CSV file ("X" and "Y" stay the same as the original data).

example

I read and tried several suggestions from this forum without help, e.g., Converting x y coordinates to longitude latitude using QGIS?.

0
4

Before exporting there are several more steps have to be applied.

  1. Create two additional fields, i.e. "lat" and "long" via Open Field Calculator
  2. Apply the following expressions for "lat" and "long" respectively
lat: x(transform($geometry, 'EPSG:4326', 'EPSG:31370'))
long: y(transform($geometry, 'EPSG:4326', 'EPSG:31370'))

or alternatively, you can already use your X and Y fields with

lat: transform("x", 'EPSG:4326', 'EPSG:31370'))
long: transform("y", 'EPSG:4326', 'EPSG:31370'))

Additionally, I may refer you to this article Adding coordinates to attribute table.

0

This is the corresponding programming solution (Python).

import pandas as pd
from pyproj import Proj, transform

data = pd.read_csv('org_canyon_features.csv')

inProj = Proj(init='epsg:31370')
outProj = Proj(init='epsg:4326')

def f(x):
    return transform(inProj, outProj, x['X'], x['Y'])

coordinates = data.apply(lambda x: f(x), result_type='expand', axis=1)
data = pd.concat([data, coordinates], axis=1)

data.to_csv('converted_canyon_features.csv', index=None)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.