Difference between revisions of "Vector Format Conversion Using ogr2ogr"
Ellis Symons (talk | contribs) |
Ellis Symons (talk | contribs) |
||
Line 8: | Line 8: | ||
'''MIF to SHP''' - ''assuming only one geometry type exists in the MIF file''<Br> | '''MIF to SHP''' - ''assuming only one geometry type exists in the MIF file''<Br> | ||
<pre>ogr2ogr.exe -f "ESRI Shapefile" 2d_code_M01_R.shp 2d_code_M01.mif</pre> | <pre>ogr2ogr.exe -f "ESRI Shapefile" 2d_code_M01_R.shp 2d_code_M01.mif</pre> | ||
+ | '''SHP to MIF''' - ''TAB and MIF use the same command just with different extensions on the destination file''<br> | ||
+ | <pre>ogr2ogr.exe -f "Mapinfo File" 2d_code_M01_R.mif 2d_code_M01.shp</pre> | ||
==Bulk Format Conversion== | ==Bulk Format Conversion== |
Revision as of 21:07, 11 April 2022
This page lists useful batch file examples for using ogr2ogr.exe. For complete documentation on this tool please visit gdal.org/programs/ogr2ogr
Basic Format Conversion
Format conversion can be done using "-f <format_name>" then specifying the "<destination_filename> <source_filename>".
SHP to GPKG
ogr2ogr.exe -f GPKG 2d_code_M01_R.gpkg 2d_code_M01_R.shp
MIF to SHP - assuming only one geometry type exists in the MIF file
ogr2ogr.exe -f "ESRI Shapefile" 2d_code_M01_R.shp 2d_code_M01.mif
SHP to MIF - TAB and MIF use the same command just with different extensions on the destination file
ogr2ogr.exe -f "Mapinfo File" 2d_code_M01_R.mif 2d_code_M01.shp
Bulk Format Conversion
Convert All Files Within Folder to GPKG
ogr2ogr.exe -f GPKG all_layers.gpkg ./path/to/dir
Convert All Files Within Folder to GPKG with Wildcard
ogr2ogr.exe -f GPKG all_layers.gpkg ./path/to/dir/*.shp
Convert All Files From a GPKG to a SHP
ogr2ogr.exe -f GPKG ./path/to/outdir all_layers.gpkg
Convert Single Layer To/From GPKG
Convert Single Layer From GPKG - Uses an SQL statement to select all features from a given layer
ogr2ogr.exe -f "ESRI Shapefile" -sql "SELECT * FROM '2d_code_M01_R'" 2d_code_M01_R.shp all_layers.gpkg
Convert Single SHP Into a New GPKG Where Layer Name is Different From Database Name
- -nln <layername>: assigns the name of the layer within database
ogr2ogr.exe -f GPKG -nln 2d_code_M01_R new_database.gpkg 2d_code_M01_R.shp
Convert Single SHP Into an Existing GPKG
- -append: appends the layer into an existing database
ogr2ogr.exe -f GPKG -nln 2d_code_M01_R -append existing_database.gpkg 2d_code_M01_R.shp