6

With QGIS 3.24.1-Tisler on Mac, I want to get a list of lat/long coordinates for the Alaska sample data that comes with QGIS.

I followed the instructions at https://gis.stackexchange.com/a/64700, with the only difference being that the field calculator only allowed me 3 decimal places rather than the 6 the answer calls for. As per the referenced answer:

  1. Export an Alaska layer as alaska_shape of type ESPG:4326 - WGS 84
  2. Open the Attribute Table for the new layer
  3. Open the Field Calculator
  4. Added field "degx", Decimal (real), Expression $x (from Geometry)
  5. Click Ok. Repeat step 3
  6. Add field "degy", Decimal (real), Expression $y (from Geometry)
  7. Click Ok

I end up with:

Attribute table

with the two added fields being NULL.

When I click to update all, with the hope that this will calculate and update the cells, I get:

An error occurred while evaluating the calculation string: No root node! Parsing failed?

Also, I can't seem to find a way to edit the field definitions once the fields have been created.

12
  • 1
    if these are virtual field you could review and edit them in the layer properties (field tab), if they are "real" field just remove them and create again, if this didn't work update your question with more info (like your exact steeps and the formula you use)
    – J.R
    Commented Mar 24, 2022 at 16:40
  • Did tou use "$x" or "$x ( from geometry)" in your expression ?
    – J.R
    Commented Mar 24, 2022 at 17:30
  • I think it should be $x or x($geometry)
    – J.R
    Commented Mar 24, 2022 at 17:31
  • 1
    Are you working with a point layer ? If not you need to convert to points as a first steep
    – J.R
    Commented Mar 24, 2022 at 18:00
  • 2
    Therein lies the issue. You are working with a polygon layer, whereas the instructions are for a point layer. You can get, for example, the x and y of the centroid of the polygon by using x(centroid($geometry)) and y(centroid($geometry)).
    – Matt
    Commented Mar 24, 2022 at 20:29

1 Answer 1

1
  1. Right click on the shapefile (rather than the layer)
  2. Select Export Layer > to file Format: GeoJSON CRS: Default CRS Geometry: Point

This results in a file with a large array of features that make up the map, in lat/lon. I'll post a separate question about getting the feature collection massaged.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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