- Home
- Free tools
- ogr2ogr command builder
ogr2ogr command builder
ogr2ogr is GDAL's command-line tool that converts vector data between formats, reprojects it, filters it and loads it into databases. Fill the form and copy a command that runs.
ogr2ogr -f GeoJSON -t_srs EPSG:4326 parcels.geojson parcels.shp
What each part does
- -f GeoJSON
- Writes with the GDAL driver "GeoJSON".
- -t_srs EPSG:4326
- Reprojects the geometries to EPSG:4326.
- parcels.geojson
- The file to create. It comes before the input.
- parcels.shp
- The file to read.
How it works
- 1
Pick a common job or type your input file. The format is detected from the extension.
- 2
Choose the output format, a CRS if you need to reproject, and any filter or clip.
- 3
Copy the command and run it in a terminal where GDAL is installed, such as the OSGeo4W Shell that comes with QGIS.
The ogr2ogr options used most
The full list is on gdal.org. These cover most daily conversions.
| Option | What it does |
|---|---|
| -f <driver> | Output format, with the GDAL driver name: "ESRI Shapefile", GeoJSON, GPKG, KML, CSV, FlatGeobuf, PostgreSQL, Parquet. |
| -t_srs <crs> | Reproject to this CRS, for example EPSG:4326. |
| -s_srs <crs> | Override the source CRS, when the file has none or a wrong one. |
| -a_srs <crs> | Assign a CRS to the output without reprojecting. |
| -where <sql> | Attribute filter, like a SQL WHERE clause. |
| -select <fields> | Comma separated list of fields to keep. |
| -nln <name> | Name of the output layer or table. |
| -nlt <type> | Output geometry type, often PROMOTE_TO_MULTI. |
| -spat xmin ymin xmax ymax | Spatial filter by bounding box, in the source CRS. |
| -clipdst xmin ymin xmax ymax | Clip geometries to a box, in the output CRS. |
| -lco NAME=VALUE | Layer creation option of the output driver, such as ENCODING=UTF-8. |
| -oo NAME=VALUE | Open option of the input driver, such as X_POSSIBLE_NAMES for CSV. |
| -overwrite / -append | Replace the output layer, or add features to it. |
Do the same in QGIS without the command line
QGIS runs GDAL underneath, so each option above has a place in the interface.
| In QGIS | Covers |
|---|---|
| Processing Toolbox, GDAL, Vector conversion, Convert format | -f, output file, and extra options such as -lco or -nlt in its Additional creation options field |
| Processing Toolbox, Vector general, Reproject layer | -t_srs |
| Layer right click, Export, Save Features As... | -f, -t_srs (CRS), -select (fields to export), -spat (Extent), -lco (Layer options, such as ENCODING), -nln (Layer name), -nlt (Geometry type), -overwrite or -append |
| Layer Properties, Source, Query Builder | -where, before you export |
| Database, DB Manager, Import Layer/File | Loading into PostGIS, with the table name (-nln) and target SRID (-t_srs) |
Or describe it in a sentence: AI Agent runs the conversion for you inside QGIS, for example "export parcels to a GeoPackage in EPSG:4326".
What it does not do
- It does not run anything. It writes a command; your file never leaves your computer.
- It does not read your file, so it cannot check that a field in -where or -select exists.
- It does not cover every option: -sql, -dialect, -fieldmap, -explodecollections, -gt and the rest are on gdal.org.
- It does not check that a CRS code exists. Use the EPSG code from the data provider.
Questions
- How do I install ogr2ogr?
- It ships with QGIS. On Windows, open the OSGeo4W Shell from the QGIS folder in the Start menu and type the command there. On macOS, run brew install gdal. On Debian or Ubuntu, run sudo apt install gdal-bin. Check with ogr2ogr --version.
- What is the difference between ogr2ogr and ogrinfo?
- ogrinfo only reads: it lists the layers, fields, geometry type, CRS and feature count of a dataset. ogr2ogr writes a new dataset. Run ogrinfo -so file.gpkg layer first to find the field names and CRS to put in the command.
- Why does ogr2ogr cut my shapefile field names to 10 characters?
- A shapefile stores its attributes in a .dbf file, and the dbf format allows 10 characters per field name. GDAL shortens longer names and warns. Write to GeoPackage or FlatGeobuf to keep full names.
- Why is the output layer empty or missing geometry?
- For a CSV input, GDAL needs the coordinate column names (X_POSSIBLE_NAMES and Y_POSSIBLE_NAMES, or GEOM_POSSIBLE_NAMES for WKT). For a CSV output, it needs -lco GEOMETRY=AS_WKT or AS_XY, otherwise it writes the attributes only.
- Why do I get an error writing mixed geometries to a shapefile?
- A shapefile holds one geometry type. Add -nlt PROMOTE_TO_MULTI for polygons and multipolygons, or split points, lines and polygons with -where on the geometry type.
- How do I write a single quote inside -where?
- In SQL, double it: name = 'L''Isle'. The builder then quotes the whole condition for your shell. bash passes it unchanged. Windows cmd does too, except %NAME%, which it replaces with an environment variable even inside quotes; the builder warns you when that happens.
Working in QGIS every day?
AI Agent runs conversions, reprojections and geoprocessing from a plain sentence inside QGIS.