5

I am frustrated by the seeming difficulty of calculating x,y coordinates in QGIS 3. As a longtime user of ArcGIS I find Esri much easier for this. However, I like QGIS and think in many ways it is more powerful. So, how does one easily enter x,y coordinates in a shapefile attribute table with QGIS 3, and furthermore be able to select units, e.g. decimal degree, lat/long, etc.?

4

To calculate coordinates of features, open the attribute table of your layer and then the field calculator. Create a new field and make sure to choose the correct field type (E.g. float with precision 8). Enter $x for x-coordinates and $y to calculate the y-coordinate for each feature. Units, by default are specified by the layers CRS.

But of course you can transform them. You can use this universal expression for that:

x(transform($geometry, layer_property(@layer_name, 'crs'), 'EPSG:4326')) and

y(transform($geometry, layer_property(@layer_name, 'crs'), 'EPSG:4326'))

This will transform x and y coordinates of any source CRS to WGS84 with unit degree. Just enter another EPSG-Code if you want a different one (e.g. to get units in meters, like UTM).

Using expressions in QGIS you can do almost everything you want to. So for example you can create a combined string field of x and y coordinates by using the concatenator ||. E.g. $x || ',' || $y. Or create a WKT string and stuff like that.

4

As your question is about overall QGIS 3, the answer by MrXsquared is the best.

If you have access to QGIS 3.8 or later, try Add X/Y fields to layer (see visual changelog "New Feature: Add X/Y fields to layer". It can be found in the Processing Toolbox > Vector table).

You can add X/Y fields calculated in the CRS of your choice.

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.