ogr2ogr - working with file geodatabases (.gdb)

ogr2ogr - working with file geodatabases (.gdb) #

import a .gdb into a new, blank .gdb #

ogr2ogr -progress -f "FileGDB" canvec_250K_Hydro.gdb canvec_250K_AB_Hydro.gdb

import a whole folder of .gdb’s to append to the one just created (minus the one used to create): #

for f in *.gdb; do ogr2ogr -update -append -progress canvec_250K_Hydro.gdb $f -f "FileGDB"; done;

import a single gdb into postgis #

ogr2ogr -overwrite -progress -skipfailures -f “PostgreSQL” PG:“dbname=dm106 user=jrobertson port=5432” /Users/jrobertson/data/_Generic/DM10.6/ACA_DataMaps106_base.gdb –config PG_USE_COPY YES

ogr2ogr -overwrite -progress -skipfailures -f “PostgreSQL” PG:“dbname=usgs_pad_v2 user=jrobertson port=5432” /Users/jrobertson/Downloads/PADUS2_0_GDB_Arc10x.zip –config PG_USE_COPY YES

import a specific feature class from a GDB into a postgres database. trails and wilderness in this case #

ogr2ogr -overwrite -progress -skipfailures -f “PostgreSQL” PG:“dbname=dm106 user=jrobertson port=5432” ACA_DataMaps103_base.gdb “trails” –config PG_USE_COPY YES

ogr2ogr -overwrite -progress -skipfailures -f “PostgreSQL” PG:“dbname=dm106 user=jrobertson port=5432” ACA_DataMaps103_base.gdb “trails” –config PG_USE_COPY YES

export a postgis table to a .gdb #

ogr2ogr -progress -f "FileGDB" -sql "SELECT * FROM cn_osm_secondary" cn_secondary_rds.gdb PG:"host=localhost user=jrobertson dbname=osm_chinyc"
Explain this Command
- ```ogr2ogr``` #calling the ogr library - ```-progress``` #show a progress bar
Explain this Command
- ```ogr2ogr``` #calling the ogr library - ```-progress``` #show a progress bar
Download ne-gpkg2postgis.sh

Make a DataMaps 10.X .gdb from a whole bunch of gdb’s each having a single feature class. First, import a single one to make the containing GDB. #

ogr2ogr -progress -f “FileGDB” ACA_DataMaps106_base.gdb urban.gdb

import a whole folder of .gdb’s to append to the one just created (minus the one used to create): #

for f in *.gdb; do ogr2ogr -update -append -progress ACA_DataMaps106_base.gdb $f -f “FileGDB”; done;

append a table from one .gdb into a postgis database #

ogr2ogr -overwrite -progress -skipfailures -f “PostgreSQL” PG:“dbname=dm106 user=jrobertson port=5432” ACA_DataMaps103_base.gdb “wilderness” –config PG_USE_COPY YES

get basic info on table list tables (feature classes) and geometry type: #

ogrinfo ACA_DataMaps10.3.gdb/

get all info including the geom: #

ogrinfo -al ACA_DataMaps10.3.gdb/

get the summary, projection and schema. Must specify layer name #

ogrinfo -so ACA_DataMaps10.3.gdb/ summit

drop a table (feature class) ‘merge’ is the name of the feature class #

ogrinfo -dialect FileGDB -sql “drop table merge” ACA_DataMaps10.3.gdb/

load a geodatabase into another geodatabase #

ogr2ogr -f ‘FileGDB’ -update -append ACA_DataMaps10.3.gdb/ gsummit.gdb/

drop a column in a table/feature class #

ogrinfo -dialect FileGDB -sql “ALTER TABLE gsummit DROP COLUMN ELEV_METER” ACA_DataMaps10.3.gdb

Add a column: #

ogrinfo -dialect FileGDB -sql “ALTER TABLE gsummit ADD COLUMN myfield integer” ACA_DataMaps10.3.gdb

find and replace: #

ogrinfo -dialect FileGDB -sql “UPDATE summit SET NAME = REPLACE(NAME,‘Mountain’,‘Mtn.’) WHERE NAME LIKE ‘%a%’” ACA_DataMaps10.3.gdb

make a database for ACA geodata #

CREATE DATABASE acageo; \c acageo; CREATE EXTENSION postgis; CREATE EXTENSION hstore;

export gdb’s to .shp #

for f in *.gdb; do ogr2ogr -f “ESRI Shapefile” output${f%}.shp $f; done;

dump a folder of .gdb’s into a postgis database #

for f in *.gdb; do ogr2ogr -overwrite -append -progress -skipfailures -f “PostgreSQL” PG:“dbname=acageo user=jrobertson port=5432” $f –config PG_USE_COPY YES; done;

Explain this code
![sql explanation](../../images/mp-attribs-explain.png) 1. If the value in NAME contains “National”... 2. then replace with NAME (ie-leave it alone), 3. if it doesn’t contain “National”, then replace the value with the existing NAME value and append the string “National Park”.