I have a shapefile with several attributes, for example YEAR
, COUNTY
, and AREA
. I also have a CSV file with more fields that I want in the shapefile, such as POPULATION
. Both the shapefile and the CSV file have a field GISJOIN
. I know how to do a join in QGIS. But how can I make a permanent join and write to a shapefile using ogr2ogr
or one of the other tools in GDAL/OGR?
Answer
The ogr2ogr utility supports a limited sql syntax. You can join your CSV to the shapefile using something like the following:
ogr2ogr -sql "select inshape.*, joincsv.* from inshape left join 'joincsv.csv'.joincsv on inshape.GISJOIN = joincsv.GISJOIN" shape_join.shp inshape.shp
No comments:
Post a Comment