3

I'm very new to this application so bear with me. I hope that I am missing something very elementary.

I have a shapefile supplied by my customer. I need to get the latitude and longitude for each of the points. From the export it appears there are 140 points.

I looked at the attribute table and only the OBJECTID, Shape_Leng are defined.

I have tried to do the steps in this post but I only get a file that looks like:

OBJECTID,Shape_Leng
1,17715.43075900000
2,20656.19732000000

What I was hoping to get a a file that looks like:

OBJECTID, latitude, longitude

The customer sent me a zip file with all of this data:

customer_x.dbf
customer_x.qix
customer_x.shp.xml
customer_x.prj
customer_x.shp
customer_x.shx

I have been opening the .shp file and haven't been able to open any of the other files with QGIS.

  • 1
    Are you sure the Shapefile contains points? Shape_Leng is a common attribute for lines. Perhaps your question is how to extract points from those lines? – Germán Carrillo Apr 6 '15 at 22:39
  • @gcarrillo that might be what's causing me so many problems. I'm struggling from being a complete novice with this. – Ed McKee Apr 7 '15 at 11:12
  • I was able to export the coordinates as a geojson. It was line coordinates which was my problem. Thank you – Ed McKee Apr 7 '15 at 11:58
  • Great! I'll post the comment as an answer, according to this site recommendations. – Germán Carrillo Apr 7 '15 at 12:38
3

Are you sure the Shapefile contains points? Shape_Leng is a common attribute for lines. That could be the reason why you can't export X and Y coordinates from your Shapefile.

In that case the new question would be how to extract points from those lines. For that, you could go to Processing->ToolBox->QGIS geoalgorithms->Vector geometry tools->Extract nodes. This will give you a point layer where each point is a vertex of your original lines.

On this point layer you can repeat the steps you mentioned in your question to get a CSV file listing latitude and longitude coordinates.

  • 1
    This worked perfectly. I needed to save as GCS WGS84 before I ran the points but then it was perfect. This might be the most helpful group on stackexchange you guys are great. – Ed McKee Apr 8 '15 at 12:27
2

You first need to establish what coordinate system the file sent to you is in. The presence of a .prj file indicates it does have one. If it isn't GCS WGS84, you'll need to reproject it to that (or an alternative geographic coordinate system [GCS] if another better suites your requirements). In QGIS you can do this by right-clicking the layer and choosing Save As, and specifying the desired coordinate system.

Once you have the layer in a GCS, you'll need to add two fields to the attribute table under Properties > Attributes. You can call them latitude and longitude or similar. With them added you can use the Field calculator to calculate the two values for each point to the new fields.

For more details refer to:

Note that a shapefile is actually composed of several files - at bare minimum three, and usually more than that. The .shp file is the one you open and work with except in special circumstances. For more info on the format, as well as possible included files and what they are, see http://en.wikipedia.org/wiki/Shapefile

  • This is great information and really clear instructions. Unfortunately it didn't work for me. I created the $x, and $y fields but they say NULL when I view them on the table and are blank when exported to csv. The CRS for the reprojected file is the WGS84 (epsg:4326). I believe that it knows these coordinates because it will overlay the openstreetmap properly. – Ed McKee Apr 6 '15 at 23:13
  • @EdMcKee You don't want to name your fields $x and $y, that's just the syntax for the field calculation. There are restrictions on field names, particularly so with shapefiles. They generally need to start with a letter, have no spaces or special characters other than underscore, not use spaces, and be under 13 characters long. You'll also want to make sure the field you create are the right data-type (ie doubles or floats, not strings). – Chris W Apr 7 '15 at 0:49
  • I've tried different names and I have to think I'm still doing something wrong because based on your comments and the others on the site this process should work. I did a quick screen recording i hope you can take a look at it. Thank you. portal.hubcastsolutions.com/tmp/qgis.mp4 – Ed McKee Apr 7 '15 at 11:04
  • I was able to export the coordinates as a geojson. It was line coordinates which was my problem. Thank you for your help – Ed McKee Apr 7 '15 at 11:59
  • So if you have lines, as gcarrillo mentions you'd need to extract the vertices to points before doing anything in my answer since lines don't have a single coordinate. But I'm not quite sure what this gets you (or rather what you're trying to do) since you'll get coordinate pairs for every vertex on the lines. If you're doing routing I suppose, but if you're wanting store locations or something similar you end up with a lot of extra points. Sounds like you got what you needed though. – Chris W Apr 7 '15 at 19:12

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.