I'm trying to use gdal/ogr to join a shapefile called myshape.shp with a csv called mycsv.csv. The join field in the shape in joinshp and the join field in the csv is joincsv.

I've found this command on other post(link) :

ogr2ogr -sql "select inshape.*, joincsv.* from inshape left join 'joincsv.csv'.joincsv on inshape.GISJOIN = joincsv.GISJOIN" shape_join.shp inshape.shp

I tried this but I can not get it to work:

ogr2ogr -sql "select myshape.*, mycsv.* from myshape left join 'mycsv.csv'.mycsv on myshape.joinshp = mycsv.joincsv" shape_join.shp myshape.shp

Can someone help me write this command for my example ?

  • 3
    Define "can not get it to work". Is there an error message?
    – user2856
    Jul 27, 2014 at 22:18

1 Answer 1


Seems this question can't be answered with gdal/ogr. Here is another method to join csv and shapefile from linux shell. This method uses a postgres/postgis database :

  • Import your shape in postgres database with shp2pgsql
  • Do the same for the csv (psql)
  • Make a sql join between the shape and the csv (use sql query with Inner join)
  • Export the result as a shapefile with pgsql2shp
  • 4
    Could you say why the original approach didn't work, or what error you received? You link to a (purportedly solved) question for Join a CSV file to shapefile using gdal/ogr?, so it would be helpful to know what the problem was here. Oct 11, 2016 at 19:07

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.