5

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 ?

  • 2
    Define "can not get it to work". Is there an error message? – user2856 Jul 27 '14 at 22:18
4

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

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.