Skip to content

Instantly share code, notes, and snippets.

@akanik
Created December 6, 2021 23:06
Show Gist options
  • Save akanik/1ba0acd2b02b716348f049b75fd8533e to your computer and use it in GitHub Desktop.
Save akanik/1ba0acd2b02b716348f049b75fd8533e to your computer and use it in GitHub Desktop.
#create two new columns via attribute table
#via: https://gis.stackexchange.com/questions/45243/how-to-determine-the-centroid-of-polygons
long = toreal(regexp_substr(geom_to_wkt(centroid($geometry)), '(-?\\d+\\.?\\d*) -?\\d+\\.?\\d*'))
lat = toreal(regexp_substr(geom_to_wkt(centroid($geometry)), '-?\\d+\\.?\\d* (-?\\d+\\.?\\d*)'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment