1

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.

7
  • Did you try : ogr2ogr -f "GMT" file.gmt file.shp ?
    – Pierma
    Commented May 23, 2016 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
    Commented May 23, 2016 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
    Commented May 23, 2016 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
    Commented May 24, 2016 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
    Commented May 24, 2016 at 14:19

1 Answer 1

1
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 and acknowledge you have read our privacy policy.

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