19

I am very new to QGIS, so please bear with me.

I have a ".shp" file, which is contains a set of boundaries for suburbs of Australia. I opened it to QGIS and I would like to export it into a CSV file so that the final file would be like following.

POSTCODE, LATITUDE, LONGITUDE

When I select "Layer > Open attribute table" I can see the "postcode" column.

I had a look at a similar question here

Getting list of coordinates for points in layer using QGIS?

Which told me to simply go to "Layer > Save as" and then type "GEOMETRY=AS_XY" or "GEOMETRY=AS_XYZ" in the "Layer" section of the "OGR creation options".

I followed exactly, but the latitude and longitude values are not being returned.

ericbae
  • 293
  • 1
  • 2
  • 5
  • related: http://gis.stackexchange.com/questions/43129/create-a-csv-with-geometry-as-wkt-in-qgis-and-choosing-the-field-delimiter – underdark Jan 14 '14 at 19:52
  • Either these answers are old or you have to know the program to understand what you are saying. I cannot follow any of these answers int eh software. Can someone dumb it down for me on how to create a CSV file with layer data (coordinates)? thanks. –  May 27 '15 at 13:20
  • 1
    @JnOviedo Please be specific about which step causes problems. The answers here are fine. – underdark May 27 '15 at 20:46
  • In this post the issue was resolved by Willy using the MMQGIS suggested by Joe Thompson: http://gis.stackexchange.com/questions/76321/exporting-polygon-shapefile-with-lat-lon-points best regards –  May 02 '16 at 14:46
  • Note that if your geometry has somehow become a multipart geometry, GEOMETRY=AS_XY will silently fail. You can can fix this by processing the layer with 'Multipart to singleparts' – daviewales Aug 11 '21 at 06:12

5 Answers5

14

I see 2 solutions: 1st you could create 2 attributes to store your lon/lat:

  • select your layer
  • toggle to edit mode
  • open the attribute table
  • open the attribute calculator (ctrl+i)
  • name your column, choose the predefined geometry function $x, $y (in that dialog)

second solution (works for all gemetry types)

  • select your shp layer
  • save as ...
  • choose txt format
  • put GEOMETRY=AS_WKT in the OGR layer option

you will end up with a text file with the layer attributes and geometry as WKT

underdark
  • 84,148
  • 21
  • 231
  • 413
user14131
  • 141
  • 1
  • 2
  • I just see the title of the post, so consider only the second solution :-) – user14131 Jan 10 '13 at 15:45
  • These do not seem to work in version 3.03. Following the first solution, QGIS gives only null values in the new field. For the second solution, there seems to be no option for saving as .txt format. – Agus camacho Jun 21 '18 at 23:15
11

You're looking at the right question, just not the right answer! The reason that that worked for the answer you were looking at is that the data was only in points. Since your data is in polygons, it won't work.

BWill's answer further down is what you need. It will copy all the co-ordinates describing each polygon into WKT format, which is a standard format, although you may need to do some cleaning up depending on your purpose.

Stev_k
  • 6,689
  • 2
  • 34
  • 46
8

Now there is a great plugin produced by Michael Minn that does exactly what you're looking for. Just update your plugin repository and install MMQGIS. I just tried it out and it worked great.

Joe Thompson
  • 81
  • 1
  • 1
4

to provide a visual guidance(applicable to QGIS version 3.10.1-A:)

  • Navigate to Layer --> Save As
  • On the Format dropdown, select 'comma Separated Value [CSV]'
  • Provide the filename to save to
  • In the lower section, expand 'Layer Options' if not expanded (scroll down if required
  • Select 'AS_WKT' for 'Geometry'
  • Click OK

(You may want to play around withthe many options based on your needs) Save geometry as CSV

dntrplytch
  • 41
  • 2
3

You could also use the MMQGIS plugin to export the geometry and the other layer attributes to a CSV file.

moutsinasg
  • 79
  • 6
  • This answer seems to be near identical to your only other one at https://gis.stackexchange.com/a/245507/115 – PolyGeo Jun 27 '17 at 11:19