I have a .shp file (downloaded from here), but it is a bunch of pink lines (I expected something like a bunch of dots or something and I have to transform it into gps coordinates (which I guess it's a .gpx file), but I have a lot of trouble finding the tools to do so and understanding what everything means. Right now I'm using QGIS, and I think once I have the coordinates I should dump the values into PostGIS. Could you guys point me in the right direction about which tools I should use, how or tips about how to do things the right way?

Further explanation: I want to get coordinate points that "shape" the coastline, so given a house's position, it can tell you how far away the coast is from the house.

Edit: I managed to get some stuff with QGIS "extract nodes" option, but I don't see any use for this data:


Values repeat a lot and they don't look like map coordinates. What went wrong?

  • why were you expecting a coastline to be dots and not a line?
    – Ian Turton
    May 15, 2017 at 8:22
  • 2
    @iant Because I have absolutely no idea about how anything of this works. Thanks for the typo edits, by the way!
    – Newwt
    May 15, 2017 at 8:27
  • may be you could add a higher level description of what you are trying to do and we could give better advice
    – Ian Turton
    May 15, 2017 at 8:30
  • 1
    @iant The duplicate doesn't have anything to do with what I want...
    – Newwt
    May 15, 2017 at 10:29
  • 1
    @iant I want the coordinates to put on the database.
    – Newwt
    May 15, 2017 at 10:42

2 Answers 2


If you want to extract the vertices go Vector->Geometry Tools->Extract nodes.

However, if you want to simply import a shapefile into PostGIS you can do it in one go (you don't have to convert to points unless you want to). Use shp2pgsql. This tool will be helpful whether you want the points or the lines. Do a search on this site for more information on both topics here.

Following the comments above, have a look here to get you started on 'how things work'. Also - for your situation you will want the line, so do not extract just the points. So simply use shp2pgsql to load your shapefile into postgis. That's all you need to do. Then in PostGIS, ensure you have a spatial index

CREATE INDEX coastline_gidx on coastline USING GIST(geometry)

Then, depending on your exact use-case, consider using ST_DWithin or ST_Distance to test for the distance (other distance tools are also available so check the documentation).

  • I just did the shp2pgsql thing, but it generates an empty sql file (if I use shp2pgsql -s 4236 -I Europe_coastline.shp coastline > coastline.sql), or a table-less database.
    – Newwt
    May 15, 2017 at 9:45
  • 1
    You may need to specify LATIN1 as the encoding. Personally, I'd recommend the GUI for a beginner, rather than the commandline and it will load the data directly into the DB without making an intermediary sql file. But see the link I added above for commandline options to help you with the encoding issue. May 15, 2017 at 10:51

This question breaks down into a few questions questions,

  1. How do I geocode to get a coordinate-POINT from a house's position?

  2. Given an arbitrary POINT and a LINESTRING, what is the nearest point on the string?

    This is answered simply with a ST_Line_Locate_Point followed by a call to ST_Line_Interpolate_Point.

  3. Given two points how do I find the distance between them?

    This is answered with a simple call to ST_Distance(pt1::geography, pt2::geography).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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