3

I want to get the coordinates for a line shapefile as csv or gmt files.

I click create "new layer" - "new shapefile layer" - I check the "line" box and then "OK". Then I make my shapefile. When I move the cursor I can see the coordinates at the lower bar but when I create a new shapefile and look in the attribute table there is no coordinates.

How to get the all the coordinates for the shapefile?

  • Where is your shapefile located? It may be in a protected folder, in which case you can copy/paste the shapefile (and it's associated files) into another location such as a folder in your desktop. You should be able to load this shapefile and do a Save As.... – Joseph Dec 10 '14 at 15:37
  • I have tried to copy/paste the files but I still get the "premission denied". I need the coordinates for the shapefiles which I can read manually if I use the identifying tool. Is it possible to extract just the coordinates? – Johnston Dec 11 '14 at 11:31
  • I opened the .dbf and the only thing showed was the id, no coordinates. – Johnston Dec 11 '14 at 11:47
  • 1
    Yes, I should have asked if the shapefile already had coordinates stored in it. Apologies, my mistake. In QGIS, click the Edit icon for the shapefile and open up the Field Calculator. Create a new column with a name like "X-Coor" or something and in the expression box, type $x. Repeat for the "Y-Coor" with the expression $y. Open up the Attributes table, select all rows and then select the option "Copy selected rows to clipboard". Open up Excel or Notepad etc and paste the values. – Joseph Dec 11 '14 at 11:52
  • 1
    Please detail the steps you used to add the shapefile, and if it is displaying properly. What kind of a geometry is it (point, line, etc)? – Simbamangu Dec 11 '14 at 13:27
3

You can use the Geometry Export to CSV function on your shapefile to obtain coordinates via:

MMQGIS > Import/Export > Geometry Export to CSV

Make sure it is enabled in Plugins > Manage and Install Plugins...

  • This seems to be a good way, unfortunately I get: "Failure opening //temp-nodes.csv" Something seems wrong with my shapefile – Johnston Dec 10 '14 at 16:01
3

There is a native (non-plugin) solution within QGIS:

  1. Right-click on your shapefile layer and select "Save as".
  2. Select CSV format;
  3. Deselect "Add saved file to map";
  4. Under "layer options", select GEOMETRY AS_XY (for point files) or GEOMETRY AS_WKT (for points, polygons or lines).

For point files only, this will output a CSV file with an X and Y column in the correct projection.

enter image description here

If AS_WKT is selected, the geometry will be given as a string of coordinates in WKT format, i.e. for a simple line:

LINESTRING (-22.777090612886717 30.458186615233615,14.586239123711941 8.17857147600256)

However, what would be even easier in some cases is just to select the features in the QGIS canvas, click "Copy" then paste into a spreadsheet or text editor, giving you the WKT geometry directly!

  • I have tried this, still no coordinates for X and Y, just the id. – Johnston Dec 11 '14 at 12:11
  • @Johnston, please see my comment in the original post above; there must be something else going on and more information is needed! – Simbamangu Dec 11 '14 at 14:42
  • @Johnston, see my edit - XY works for points only, but you can select WKT and get a file with all the coordinates for the geometry listed; alternatively, copy-and-paste as indicated! – Simbamangu Dec 14 '14 at 15:43
  • @Johnston, did this work? – Simbamangu Dec 18 '14 at 13:58

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.