1

Could you help me to create long & lat (x and y coordinates in degrees) for polygon shapefile?

When I used directly QGIS export vectors to csv file, it didn't work.

Here is the example file: https://drive.google.com/drive/folders/1lfkwMQADzsiMKCZsOeuFqQAHGUE9Qni8?usp=sharing

10
  • You missed the shp file in your drive shared folder. Otherwise looking at prj file it looks your shapefile is in system using lat long and so when exporting correct shp to csv it should work as expected. – Miro Feb 11 '20 at 3:30
  • Hi miro, l already put shp files in folder. still can't get long lat after export it to csv – billy damanik Feb 11 '20 at 3:34
  • I can't see it there, there are 5 files but not *.shp, which holds the geometry. Apart of dbf, shx, prj (qpj, cpg) you need to have shp file. – Miro Feb 11 '20 at 3:38
  • sorry I wasn't refresh mydrive. please take a look again. Thank you drive.google.com/drive/folders/… – billy damanik Feb 11 '20 at 3:42
  • OK, that works, thank you. Now, you have polygons shapefile. So what coordinates do you want to export into csv? Centroids for these polygons? I see in table you have columns lat and long which are empty. Dou you want to fill these with centroids coordinates and then epxort to csv? – Miro Feb 11 '20 at 3:49
1

In the case you have polygon shapefile, you need to first extract lat and long coordinates for the polygons. This is typically done as coordinates of centroids. But you can also extract minimum, maximum etc.

Your shapefile also must be in some coordinate system which uses degrees (lat, long) - if it is not, you need to first reproject it (Vector / Data management tools / Reproject Layer...).

  1. Select layer in layer list and Open Field Calculator (abacus icon in top menu). Or Right click on layer / Open attribute Table to see all columns and click on abacus icon in top menu of table window.

  2. Select if you want to create new field or update existing (if you use existing field make sure the field type is number type with enough decimals)

  3. As expression write for long: x(centroid($geometry)), for lat y(centroid($geometry))

Once you have both lat and long fields filled in you can export the layer (or better say attribute table) into csv.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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