3. Loading Geospatial Data : Load Data with GDAL/OGR Tools
 
Share this page                  
Load Data with GDAL/OGR Tools
In this example, we load into an Ingres database the on_geoname dataset from the Canadian GeoBase project. This dataset contains geographic names and point locations in Ontario. It is downloaded as a 3 MB zip file from the Canadian GeoBase project (http://geobase.ca).
To load data with GDAL/OGR tools
1. Create a database that will hold the data.
For example, this command creates a database named canada:
createdb canada
2. Convert and load the data into the database.
Use a command with a format like the following:
ogr2ogr -f [format] -a_srs [srs_info] [destination database] [source_shapefile]
where:
-a_srs [srs info]
Assigns an output Spatial Reference System (SRS). Some ways of specifying the SRS are:
EPSG number
For example:
"epsg:4326"
SRS web lookup
For example:
http://spatialreference.org/ref/epsg/4326/
OGC WKT
For example:
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563, AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0, AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]], AUTHORITY["EPSG","4326"]]'
Details of spatial reference systems, including the OGC WKT syntax shown previously, can be found at http://spatialreference.org/.
For example, the following command converts the data and creates a table in the canada database with the same name as the input dataset (on_geoname):
ogr2ogr -f ingres -a_srs http://spatialreference.org/ref/epsg/4326/ @driver=ingres,dbname=canada on_geoname.shp
Other ogr2ogr Command Options
Other ogr2ogr command options applicable to loading data are as follows. For complete options, see http://gdal.org/ogr2ogr.html.
-select [fieldname],[fieldname]...
Lets you provide a comma separated list of field names that you want to load. All other fields are ignored and will not appear in the resulting table. This option is useful if you have an extreme number of fields in your input data.
Depending on the default page size setting (in config.dat) used for your Ingres instance, you may get notices while running ogr2ogr. In such a case, you can specify only the most important fields instead:
ogr2ogr -select roadclass,nbrlanes,pavstatus ...
-skipfailures
Continues to load after encountering a record that gives a failure. Default behavior is to stop processing entirely, which means you have to start again from the beginning after you have fixed the problem. If you do not want to use the -select option workaround, then try ‑skipfailures.
-overwrite
Gives permission to drop and recreate the table during data loading. If your process stopped due to errors and you want to try loading again, this is the easiest way to force it to clean up from the past process and start fresh.