Vector Format Conversion Using ogr2ogr: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 10:
'''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>
'''MIF to SHP Force Overwrite an Existing File'''<br>
:* ''<tt>-overwrite</tt>'': overwrite the output file if it exists
<pre>ogr2ogr.exe -f "ESRI Shapefile" -overwrite 2d_code_M01_R.shp 2d_code_M01.mif</pre>
 
==Bulk Format Conversion==
Line 33 ⟶ 36:
==Converting MIF File With Multiple Geometry Types==
<Br>
'''MIF With Multiple Geometry Types To SHP'''<br>
:* ''<tt>-where <clause></tt>'': "-where" can be used to specify a clause to only select a given geometry type
<pre>
ogr2ogr.exe -f "ESRI Shapefile" -where ""OGR_GEOMETRY='Point'"" 2d_zsh_P.shp 2d_zsh.mif
ogr2ogr.exe -f "ESRI Shapefile" -where ""OGR_GEOMETRY='LineString'"" 2d_zsh_L.shp 2d_zsh.mif
ogr2ogr.exe -f "ESRI Shapefile" -where ""OGR_GEOMETRY='Polygon'"" 2d_zsh_R.shp 2d_zsh.mif
</pre>
'''MIF With Multiple Geometry Types To a Single GPKG'''<Br>
:* ''<tt>-nlt <geometry_type></tt>'': Defines geometry type for output layer. Useful when converting to formats that implement strict checks for geometry types (e.g. Don't allow "Singlepart" geometry and "Multipart" geometry in the same layer.
<pre>
ogr2ogr.exe -f GPKG -nln 2d_zsh_P -where ""OGR_GEOMETRY='Point'" -nlt POINT 2d_zsh.gpkg 2d_zsh.mif
ogr2ogr.exe -f GPKG -nln 2d_zsh_L -where ""OGR_GEOMETRY='LineString'" -nlt LINESTRING -append 2d_zsh.gpkg 2d_zsh.mif
ogr2ogr.exe -f GPKG -nln 2d_zsh_R -where ""OGR_GEOMETRY='Polygon'" -nlt POLYGON -append 2d_zsh.gpkg 2d_zsh.mif
</pre>