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.

Taras
  • 32,823
  • 4
  • 66
  • 137
JAyenGreen
  • 183
  • 8
  • 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 Mar 24 '22 at 16:40
  • Did tou use "$x" or "$x ( from geometry)" in your expression ? – J.R Mar 24 '22 at 17:30
  • I think it should be $x or x($geometry) – J.R Mar 24 '22 at 17:31
  • I put $x, not $x (from Geometry) – JAyenGreen Mar 24 '22 at 17:32
  • 1
    Are you working with a point layer ? If not you need to convert to points as a first steep – J.R Mar 24 '22 at 18:00
  • Which dataset https://download.qgis.org/downloads/data/ are exactly referring to? – Taras Mar 24 '22 at 18:24
  • I started with the sample data > shapefiles > alaska.shp. I haven't done anything to the layer. – JAyenGreen Mar 24 '22 at 18:35
  • 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 Mar 24 '22 at 20:29
  • Ok. So backing up to my intent, given the sample data, is there any way to generate a list of lat/long coordinates that represent the outline of Alaska? – JAyenGreen Mar 24 '22 at 21:21
  • (Using any of the sample Alaska data…not necessarily the same layer type I chose) – JAyenGreen Mar 24 '22 at 21:43
  • The docs say that when the CRS is converted to EPSG 4326, it is then using a lat/long system. The attribute table still only shows area. And when I add fields, virtual or not, for $x and $y, they are always null rather than showing lat/long. – JAyenGreen Mar 25 '22 at 13:05
  • Right click on the shape file (rather than the layer), 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. – JAyenGreen Mar 28 '22 at 17:31

1 Answers1

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.

nmtoken
  • 13,355
  • 5
  • 38
  • 87
JAyenGreen
  • 183
  • 8