[GIS] How to get, then export as .csv the lat lon centroids from shapefile layer

centroidsexportlatitude longitudeqgisshapefile

I have a shapefile with a whole lot of regions on it. I need to find the centroids for each of these regions in the shapefile (as latlons) and export this as a .csv

I have done extensive research, but no luck yet.

So far: I select the layer. I go to "Vector/Geometry Tools/Polygon centroids". hurrah, the centroids show up. BUT they are not yet added to my layer as lat lons. (although the info must be there because they are, you know, located.)

To get the lat lons added to my layer I go "Vector/Geometry Tools/ExportAdd Geometry Columns" BUT THEN when I look in my attribute table for this layer, some of the column headings have been changed (weird!) :(( The good news is that there ARE the lat lons added.

To be more descriptive:

  • The first 16 column headings remain unchanged. That's good.
  • The 17th gets truncated from SA1_testData_SA1_AREA_SQM to SA1_testDa
  • The 18th column gets changed from SA1_testData_SA1_Dwellings to SA1_test_1
  • The 19th, 20th etc columns keep incrementing by one: SA1_test_2, SA1_test_3, SA1_test_4, etc
  • And then right at the end, the last 2 columns are XCOORD and YCOORD with the lat lons in them.

Yes, I have tried both "adding to this shapefile" AND also "saving as a new shapefile"… same outcome. Why do the column headings get scrambled?

Best Answer

The answer is that you seem have to need your column headers to have <10 characters before doing the operation. I used Table Manger Plugin to rename the headers with shorter descriptions for each column and then the headers in the table don't get scrambled. Who knew?

Related Question