Inserting new fields with the field calculator and the expression $x
and $y
on the layer with your centroids should do the job. If you use the polygon layer of your lakes, you might include there lat/lon in the attribute table directly with x(centroid($geometry))
resp. y(centroid($geometry))
.
If your layer is not in EPSG 4326, you can use this expression to reproject the coordinates and get lat/lon-coordinates (replace XXXX with the EPSG-code of your CRS):. For latitude
xy(transform( make_point (x(centroid($geometry)),y(centroid($geometry))), 'EPSG:XXXX', 'EPSG:4326'))
and for longitude
y(transform( make_point (x(centroid($geometry)),ytransform(centroid($geometry))), 'EPSG:XXXX', 'EPSG:4326'))
Or even better: include the EPSG-code of your project with the corresponding variable, so you don't even have to know about what EPSG you are using and the result is always correct, even when changing the project-CRS CRS. This expressionThese expressions should work without any changes with whatever vector layer you use:
x(transform( make_point (x(centroid($geometry)),y(centroid($geometry))), @map_crs @layer_crs, 'EPSG:4326'))
and
y(transform( make_point (x(centroid($geometry)),y(centroid($geometry))), @map_crs @layer_crs, 'EPSG:4326'))