GDAL commands for importing and exporting spatial layers into SQL Server, PostGres and Spatialite
Batch import shape files by supplying folder path containing shape files rather than individual shape file path
ogr2ogr -progress -lco geometry_name=geom -lco schema=public -f "PostgreSQL"
PG:"host=IPADDRESS dbname=DATABASENAME user=USERNAME password=PASSWORD" SHAPEFILEPATH.shp
-nln TABLENAME --config PG_USE_COPY YES
There are two drivers using in File GeoDatabases
Issue with importing some polygons files producing errors - Error occurred in filegdbtable.cpp at line 2375, ERROR 1: Error occurred in filegdbtable.cpp at line 2703. This appears to result from GDAL not supporting M routing values. Either
ogr2ogr -progress -lco geometry_name=geom -lco schema=public -f "PostgreSQL"
PG:"host=IPADDRESS dbname=DATABASENAME user=USERNAME password=PASSWORD"
GEODATABASEFILEPATH.gdb "TABLENAME"
Unable to rename multiple tables using -nln
ogr2ogr -progress -lco geometry_name=geom -lco schema=public -f "PostgreSQL"
PG:"host=IPADDRESS dbname=DATABASENAME user=USERNAME password=PASSWORD"
SPATIALITEFILEPATH.sqlite "TABLENAME1" "TABLENAME2"
ogr2ogr -progress -f SQLite -dsco SPATIALITE=NO SPATIALITEFILEPATH.sqlite
SHAPEFILEPATH.shp
ogr2ogr -f "ESRI Shapefile" ORIGINAL.shp REPROJECTED.shp -s_srs EPSG:27700
-t_srs EPSG:4326
command | Description |
---|---|
-nln TABLENAME | Name table on import |
-overwrite | Overwrite existing table |
-append | Append to existing table |
-nlt MULTIPOLYGON | Define polygon type if not Polygon |
-lco precision=NO | Turn off guessing at precision for column data types as GDAL |
can incorrectly guess precision for columns leading to obscure errors | |
-lco geometry_name=NAME | Name given to the geometry field |
-lco schemna=NAME | define schema to use |
-s_srs ESPG:xxxx | override the source spatial reference system |
-t_srs EPSG:xxxx | Reproject / transform to spatial reference system |
-a_srs ESPG:xxxx | Assign spatial reference system on output |
-sql SQLQUERY | sql statement to execute |
–config PG_USE_COPY YES | Improve speed importing into PostGres |