I have several line text-files of (used in GMT) saved in the format (this is a small sample):

-111.29 42.28
-111.29 42.31
-111.29 42.33
-111.37 41.99
-111.38 42.02

I am trying to convert this to a Shapefile to use in QGIS. I know people convert from shp to GMT with ogr2ogr can you do this in reverse GMT to Shp? I tried using ogr2ogr and had no luck. Maybe I did something wrong or it is not possible with that tool.

I have tried to import this format in QGIS via the delimited text layer tool, but can only figure out how to get points when I need lines.

  • Did you try : ogr2ogr -f "GMT" file.gmt file.shp ? – Pierma May 23 '16 at 22:15
  • I tried ogr2ogr -f ""ESRI Shapefile" thrusts.shp thrusts.gmt and got it to create at least a shapefile, but it was still points and didn't work past the first line's worth of data.. the code you posted would be the reverse from shapfile to GMT. Thanks for trying! – AlexGeorge May 23 '16 at 22:30
  • I never used GMT but when I create a text file with your exemple, I can load the file in qgis with lines (just with "Add vector layer"). – Pierma May 23 '16 at 22:40
  • Alternatively to Delimited text, you can add the data with the MMQGIS plugin as well. It asks for the geometry type as well. – AndreJ May 24 '16 at 5:52
  • @Pierma when I try the add vector layer, It says I have an invalid data source. in the add vector box did you input "source type" as "File" and "encoding" as "system" and was your file a .txt extension. If i can get your method to work, it would be really easy! thanks – AlexGeorge May 24 '16 at 14:19
ogr2ogr -F "ESRI Shapefile" data.shp data.gmt

should do the trick. Note that if you want to create a 'proper' OGR/GMT file you should include header information - see GMT Cookbook - OGR/GMT-format chapter. Thus, you might need to add a > on the first line to make sure that ogr2ogr understands that there are multiple line segments.

Good luck.

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.