Start a new topic

Creating a shapefile by joining tables from 2 GDB (geodatabase) files programmatically

I have 2 gdb (geodatabase) files, one containing geometry info on(i.e.  catchment table), and the other contain attribute tables.

I would like to join 2 tables from these 2 gdb (or shapefiles) files as below:

select * from catchment_table a

join climate_table b on a.segment = b.segment

I was not able to do the join using ogr2ogr sql option because it only accept one source file and I have 2.

Is there a gdal/ogr command that can do the join from 2 files? Or how can I programmatically join 2 tables from 2 gdb files and output it as a shapefile?

I know that I can manually do that with QGIS Desktop, but I have potentially many tables to join.

Thank you.

1 person likes this idea

Found a way to go around this:

1. Convert gdb files into shapefile using ogr2ogr and output them into a (same) directory (i.e. outdir)

2. You can access all the tables in the shapefiles when the outdir directory is used as the source

i.e.  ogr2ogr -f "ESRI Shapefile" merged.shp outdir -sql "select * from tablea a join tableb b on a.segment = b.segment"

Login to post a comment