OGR2OGR(1)
π NAME π
okay so ogr2ogr β and yes, this is the OGR2OGR(1) page from the GDAL manual, bestie β converts simple features data between file formats. β¨
β¨ SYNOPSIS β¨
here's the whole shape of it, fr fr, and every line stays exactly as the manual says:
ogr2ogr [--help-general] [-skipfailures] [-append] [-update]
[-select field_list] [-where restricted_where|\@filename]
[-progress] [-sql <sql statement>|\@filename] [-dialect dialect]
[-preserve_fid] [-fid FID] [-limit nb_features]
[-spat xmin ymin xmax ymax] [-spat_srs srs_def] [-geomfield field]
[-a_srs srs_def] [-t_srs srs_def] [-s_srs srs_def] [-ct string]
[-f format_name] [-overwrite] [[-dsco NAME=VALUE] ...]
dst_datasource_name src_datasource_name
[-lco NAME=VALUE] [-nln name]
[-nlt type|PROMOTE_TO_MULTI|CONVERT_TO_LINEAR|CONVERT_TO_CURVE]
[-dim XY|XYZ|XYM|XYZM|2|3|layer_dim] [layer [layer ...]]
# Advanced options
[-gt n]
[[-oo NAME=VALUE] ...] [[-doo NAME=VALUE] ...]
[-clipsrc [xmin ymin xmax ymax]|WKT|datasource|spat_extent]
[-clipsrcsql sql_statement] [-clipsrclayer layer]
[-clipsrcwhere expression]
[-clipdst [xmin ymin xmax ymax]|WKT|datasource]
[-clipdstsql sql_statement] [-clipdstlayer layer]
[-clipdstwhere expression]
[-wrapdateline] [-datelineoffset val]
[[-simplify tolerance] | [-segmentize max_dist]]
[-makevalid]
[-addfields] [-unsetFid] [-emptyStrAsNull]
[-relaxedFieldNameMatch] [-forceNullable] [-unsetDefault]
[-fieldTypeToString All|(type1[,type2]*)] [-unsetFieldWidth]
[-mapFieldType type1|All=type2[,type3=type4]*]
[-fieldmap identity | index1[,index2]*]
[-splitlistfields] [-maxsubfields val]
[-resolveDomains]
[-explodecollections] [-zfield field_name]
[-gcp ungeoref_x ungeoref_y georef_x georef_y [elevation]]* [-order n | -tps]
[[-s_coord_epoch epoch] | [-t_coord_epoch epoch] | [-a_coord_epoch epoch]]
[-nomd] [-mo "META-TAG=VALUE"]* [-noNativeData]
π¦ DESCRIPTION π¦
okay so ogr2ogr can be used to convert simple features data between file formats. It can also perform various operations during the process, such as spatial or attribute selection, reducing the set of attributes, setting the output coordinate system or even reprojecting the features during translation. iconic behavior, honestly. π
here are the flags, bestie β every single one, no skips:
-fformat_name β output file format name, e.g.ESRI Shapefile,MapInfo File,PostgreSQL. Starting with GDAL 2.3, if not specified, the format is guessed from the extension (previously wasESRI Shapefile). π-appendβ append to existing layer instead of creating new. π«Ά-overwriteβ delete the output layer and recreate it empty. π-updateβ open existing output datasource in update mode rather than trying to create a new one. β¨-selectfield_list β comma-delimited list of fields from input layer to copy to the new layer. A field is skipped if mentioned previously in the list even if the input layer has duplicate field names. (Defaults to all; any field is skipped if a subsequent field with same name is found.) Geometry fields can also be specified in the list. π
note: this setting cannot be used together with-append. To control the selection of fields when appending to a layer, use-fieldmapor-sql.
-progressβ display progress on terminal. Only works if input layers have the"fast feature count"capability. π-sqlsql_statement β SQL statement to execute. The resulting table/layer will be saved to the output. Starting with GDAL 2.1, the@filenamesyntax can be used to indicate that the content is in the pointed filename. π§-dialectdialect β SQL dialect. In some cases can be used to use (unoptimized)ogr_sql_dialectinstead of the native SQL of an RDBMS by passing theOGRSQLdialect value. Thesql_sqlite_dialectdialect can be select with theSQLITEandINDIRECT_SQLITEdialect values, and this can be used with any datasource. π-whererestricted_where β attribute query (like SQL WHERE). Starting with GDAL 2.1, the@filenamesyntax can be used to indicate that the content is in the pointed filename. π«-skipfailuresβ continue after a failure, skipping the failed feature. π-spatxmin ymin xmax ymax β spatial query extents, in the SRS of the source layer(s) (or the one specified with-spat_srs). Only features whose geometry intersects the extents will be selected. The geometries will not be clipped unless-clipsrcis specified. π¦-spat_srssrs_def β override spatial filter SRS. πΈ-geomfieldfield β name of the geometry field on which the spatial filter operates on. π-dscoNAME=VALUE β dataset creation option (format specific). π-lcoNAME=VALUE β layer creation option (format specific). π-nlnname β assign an alternate name to the new layer. β¨-nlttype β define the geometry type for the created layer. One ofNONE,GEOMETRY,POINT,LINESTRING,POLYGON,GEOMETRYCOLLECTION,MULTIPOINT,MULTIPOLYGON,MULTILINESTRING,CIRCULARSTRING,COMPOUNDCURVE,CURVEPOLYGON,MULTICURVE, andMULTISURFACEnon-linear geometry types. AddZ,M, orZMto the type name to specify coordinates with elevation, measure, or elevation and measure.PROMOTE_TO_MULTIcan be used to automatically promote layers that mix polygon or multipolygons to multipolygons, and layers that mix linestrings or multilinestrings to multilinestrings. Can be useful when converting shapefiles to PostGIS and other target drivers that implement strict checks for geometry types.CONVERT_TO_LINEARcan be used to to convert non-linear geometry types into linear geometry types by approximating them, andCONVERT_TO_CURVEto promote a non-linear type to its generalized curve type (POLYGONtoCURVEPOLYGON,MULTIPOLYGONtoMULTISURFACE,LINESTRINGtoCOMPOUNDCURVE,MULTILINESTRINGtoMULTICURVE). Starting with version 2.1 the type can be defined as measured ("25D"remains as an alias for single"Z"). Some forced geometry conversions may result in invalid geometries, for example when forcing conversion of multi-part multipolygons with-nlt POLYGON, the resulting polygon will break the Simple Features rules. π
Starting with GDAL 3.0.5, -nlt CONVERT_TO_LINEAR and -nlt PROMOTE_TO_MULTI can be used simultaneously. π₯
-dimval β force the coordinate dimension to val (valid values areXY,XYZ,XYM, andXYZMβ for backwards compatibility2is an alias forXYand3is an alias forXYZ). This affects both the layer geometry type, and feature geometries. The value can be set tolayer_dimto instruct feature geometries to be promoted to the coordinate dimension declared by the layer. Support forMwas added in GDAL 2.1. π-a_srssrs_def β assign an output SRS, but without reprojecting (use-t_srsto reproject). πΈ
The coordinate reference systems that can be passed are anything supported by the OGRSpatialReference.SetFromUserInput() call, which includes EPSG Projected, Geographic or Compound CRS (i.e. EPSG:4296), a well known text (WKT) CRS definition, PROJ.4 declarations, or the name of a .prj file containing a WKT CRS definition. β¨
-a_coord_epochepoch β new in version 3.4. Assign a coordinate epoch, linked with the output SRS. Useful when the output SRS is a dynamic CRS. Only taken into account if-a_srsis used. π°οΈ-t_srssrs_def β reproject/transform to this SRS on output, and assign it as output SRS. π₯
A source SRS must be available for reprojection to occur. The source SRS will be by default the one found in the source layer when it is available, or as overridden by the user with -s_srs. π«
The coordinate reference systems that can be passed are anything supported by the OGRSpatialReference.SetFromUserInput() call, which includes EPSG Projected, Geographic or Compound CRS (i.e. EPSG:4296), a well known text (WKT) CRS definition, PROJ.4 declarations, or the name of a .prj file containing a WKT CRS definition. π
-t_coord_epochepoch β new in version 3.4. Assign a coordinate epoch, linked with the output SRS. Useful when the output SRS is a dynamic CRS. Only taken into account if-t_srsis used. It is also mutually exclusive with-a_coord_epoch. β οΈ
Currently -s_coord_epoch and -t_coord_epoch are mutually exclusive, due to lack of support for transformations between two dynamic CRS. π
-s_srssrs_def β override source SRS. If not specified the SRS found in the input layer will be used. This option has only an effect if used together with-t_srsto reproject. π
The coordinate reference systems that can be passed are anything supported by the OGRSpatialReference.SetFromUserInput() call, which includes EPSG Projected, Geographic or Compound CRS (i.e. EPSG:4296), a well known text (WKT) CRS definition, PROJ.4 declarations, or the name of a .prj file containing a WKT CRS definition. π«Ά
-s_coord_epochepoch β new in version 3.4. Assign a coordinate epoch, linked with the source SRS. Useful when the source SRS is a dynamic CRS. Only taken into account if-s_srsis used. πΈ
Currently -s_coord_epoch and -t_coord_epoch are mutually exclusive, due to lack of support for transformations between two dynamic CRS. π
-ctstring β a PROJ string (single step operation or multiple step string starting with+proj=pipeline), a WKT2 string describing a CoordinateOperation, or aurn:ogc:def:coordinateOperation:EPSG::XXXXURN overriding the default transformation from the source to the target CRS. It must take into account the axis order of the source and target CRS. π
New in version 3.0. β¨
okay so, continuing the flag tour, bestie β every single one is here:
-preserve_fidβ use the FID of the source features instead of letting the output driver automatically assign a new one (for formats that require a FID). If not in append mode, this behavior is the default if the output driver has a FID layer creation option, in which case the name of the source FID column will be used and source feature IDs will be attempted to be preserved. This behavior can be disabled by setting-unsetFid. π-fid fidβ if provided, only the feature with the specified feature id will be processed. Operates exclusive of the spatial or attribute queries. Note: if you want to select several features based on their feature id, you can also use the fact the'fid'is a special field recognized by OGR SQL. So,-where "fid in (1,3,5)"would select features 1, 3 and 5. β¨-limit nb_featuresβ limit the number of features per layer. π-oo NAME=VALUEβ input dataset open option (format specific). π¦-doo NAME=VALUEβ destination dataset open option (format specific), only valid in-updatemode. πΈ-gt nβ groupnfeatures per transaction (default100 000). Increase the value for better performance when writing into DBMS drivers that have transaction support.ncan be set tounlimitedto load the data into a single transaction. π₯-ds_transactionβ force the use of a dataset level transaction (for drivers that support such mechanism), especially for drivers such as FileGDB that only support dataset level transaction in emulation mode. π-clipsrc [xmin ymin xmax ymax]|WKT|datasource|spat_extentβ clip geometries to the specified bounding box (expressed in source SRS), WKT geometry (POLYGONorMULTIPOLYGON), from a datasource or to the spatial extent of the-spa..option if you use thespat_extentkeyword. When specifying a datasource, you will generally want to use it in combination of the-clipsrclayer,-clipsrcwhereor-clipsrcsqloptions. π-clipsrcsql <sql_statement>β select desired geometries using an SQL query instead. β-clipsrclayer <layername>β select the named layer from the source clip datasource. π-clipsrcwhere <expression>β restrict desired geometries based on attribute query. π«Ά-clipdst <xmin> <ymin> <xmax> <ymax>β clip geometries after reprojection to the specified bounding box (expressed indest SRS), WKT geometry (POLYGONorMULTIPOLYGON) or from a datasource. When specifying a datasource, you will generally want to use it in combination of the-clipdstlayer,-clipdstwhereor-clipdstsq..options. π-clipdstsql <sql_statement>β select desired geometries using an SQL query instead. π-clipdstlayer <layername>β select the named layer from the destination clip datasource. π-clipdstwhere <expression>β restrict desired geometries based on attribute query. π-wrapdatelineβ split geometries crossing the dateline meridian (long. = +/- 180deg). π§-datelineoffsetβ offset from dateline in degrees (defaultlong. = +/- 10deg, geometries within170degto-170degwill be split). π-simplify <tolerance>β distance tolerance for simplification. Note: the algorithm used preserves topology per feature, in particular for polygon geometries, but not for a whole layer. β¨-segmentize <max_dist>β maximum distance between 2 nodes. Used to create intermediate points. π-makevalidβ run theOGRGeometry::MakeValid()operation, followed byOGRGeometryFactory::removeLowerDimensionSubGeoms(), on geometries to ensure they are valid regarding the rules of the Simple Features specification. π¦-fieldTypeToString type1,...β converts any field of the specified type to a field of type string in the destination layer. Valid types are:Integer,Integer64,Real,String,Date,Time,DateTime,Binary,IntegerList,Integer64List,RealList,StringList. Special valueAllcan be used to convert all fields to strings. This is an alternate way to using theCASToperator of OGR SQL, that may avoid typing a long SQL query. Note that this does not influence the field types used by the source driver, and is only an afterwards conversion. πΈ-mapFieldType srctype|All=dsttype,...β converts any field of the specified type to another type. Valid types are:Integer,Integer64,Real,String,Date,Time,DateTime,Binary,IntegerList,Integer64List,RealList,StringList. Types can also include subtype between parenthesis, such asInteger(Boolean),Real(Float32), ... Special valueAllcan be used to convert all fields to another type. This is an alternate way to using theCASToperator of OGR SQL, that may avoid typing a long SQL query. This is a generalization of-fieldTypeToString. Note that this does not influence the field types used by the source driver, and is only an afterwards conversion. π₯-unsetFieldWidthβ set field width and precision to0. π-splitlistfieldsβ split fields of typeStringList,RealListorIntegerListinto as many fields of typeString,RealorIntegeras necessary. π-maxsubfields <val>β to be combined with-splitlistfieldsto limit the number of subfields created for each split field. β-explodecollectionsβ produce one feature for each geometry in any kind of geometry collection in the source file, applied after any-sqloption. π-zfield <field_name>β uses the specified field to fill the Z coordinate of geometries. π«Ά-gcp <ungeoref_x> <ungeoref_y> <georef_x> <georef_y> <elevation>β add the indicated ground control point. This option may be provided multiple times to provide a set of GCPs. π-order <n>β order of polynomial used for warping (1to3). The default is to select a polynomial order based on the number of GCPs. π-tpsβ force use of thin plate spline transformer based on available GCPs. π-fieldmapβ specifies the list of field indexes to be copied from the source to the destination. The(n)thvalue specified in the list is the index of the field in the target layer definition in which then(th)field of the source layer must be copied. Index count starts at zero. To omit a field, specify a value of-1. There must be exactly as many values in the list as the count of the fields in the source layer. We can use the'identity'setting to specify that the fields should be transferred by using the same order. This setting should be used along with the-appendsetting. π-addfieldsβ this is a specialized version of-append. Contrary to-append,-addfieldshas the effect of adding, to existing target layers, the new fields found in source layers. This option is useful when merging files that have non-strictly identical structures. This might not work for output formats that don't support adding fields to existing non-empty layers. Note that if you plan to use-addfields, you may need to combine it with-forceNullable, including for the initial import. π§-relaxedFieldNameMatchβ do field name matching between source and existing target layer in a more relaxed way if the target driver has an implementation for it. π-forceNullableβ do not propagate not-nullable constraints to target layer if they exist in source layer. β¨-unsetDefaultβ do not propagate default field values to target layer if they exist in source layer. π-unsetFidβ can be specified to prevent the name of the source FID column and source feature IDs from being re-used for the target layer. This option can for example be useful if selecting source features with aORDER BYclause. π¦-emptyStrAsNullβ New in version 3.3. Treat empty string values as null. πΈ-resolveDomainsβ New in version 3.3. When this is specified, any selected field that is linked to a coded field domain will be accompanied by an additional field({dstfield}_resolved), that will contain the description of the coded value. π₯-nomdβ to disable copying of metadata from source dataset and layers into target dataset and layers, when supported by output driver. π-mo META-TAG=VALUEβ passes a metadata key and value to set on the output dataset, when supported by output driver. π-noNativeDataβ to disable copying of native data, i.e. details of source format not captured by OGR abstraction, that are otherwise preserved by some drivers (like GeoJSON) when converting to same format. New in version 2.1. β
π« PERFORMANCE HINTS π«
okay so when you're writing into a transactional DBMS (SQLite, PostgreSQL, MySQL, etc...), it might be beneficial to increase the number of INSERT statements executed between BEGIN TRANSACTION and COMMIT TRANSACTION statements. This number is specified with the -gt option. For example, for SQLite, explicitly defining -gt 65536 ensures optimal performance while populating some table containing many hundreds of thousands or millions of rows. However, note that -skipfailures overrides -gt and sets the size of transactions to 1. π
For PostgreSQL, the PG_USE_COPY config option can be set to YES for a significant insertion performance boost. See the PG driver documentation page. π«Ά
More generally, consult the documentation page of the input and output drivers for performance hints. β¨
π C API π
This utility is also callable from C with GDALVectorTranslate(). π
β¨ EXAMPLES β¨
Okay bestie, this is the part where it gets fun π β like, actual hands-on "copy this and go" energy. Every single one of these is real, so type them exactly as shown, mwah.
π The classic glow-up: Shapefile β GeoPackage
Like, the most basic conversion ever, and honestly? It slays:
ogr2ogr \
-f GPKG output.gpkg \
input.shp
That's it. That's the whole vibe. β¨
π¦ Changing the coordinate reference system
Moving from EPSG:4326 to EPSG:3857 β she's evolving, your honor:
ogr2ogr \
-s_srs EPSG:4326 \
-t_srs EPSG:3857 \
-f GPKG output.gpkg \
input.gpkg
Source CRS goes in -s_srs, target CRS goes in -t_srs, and everybody minds their business π«Ά
πΈ Appending to an existing layer
Heads up bestie: this one needs both-updateand-append. Not one. Both. No cap, if you forget one it's giving β¨nothingβ¨.
ogr2ogr -update -append -f PostgreSQL PG:dbname=warmerda abc.tab
π§ Clipping with a bounding box
Clip your input layer with a bounding box, which is written as <xmin> <ymin> <xmax> <ymax>:
ogr2ogr \
-spat -13.931 34.886 46.23 74.12 \
-f GPKG output.gpkg \
natural_earth_vector.gpkg
Four numbers, in that exact order. Iconic. π
β Filtering features with -where
-where clause goes brr:
ogr2ogr \
-where "\"POP_EST\" < 1000000" \
-f GPKG output.gpkg \
natural_earth_vector.gpkg \
ne_10m_admin_0_countries
Notice the escaped quotes around \"POP_EST\" β yes, both of them, she's delicate π
π₯ Reprojecting + clipping, the combo meal
Reprojecting from ETRS_1989_LAEA_52N_10E to EPSG:4326 while clipping to a bounding box, all in one line:
ogr2ogr -wrapdateline -t_srs EPSG:4326 -clipdst -5 40 15 55 france_4326.shp europe_laea.shp
Main character energy fr fr π
π The -fieldmap moment
Lowkey the most misunderstood flag ever, so let's break it down π
For this one:
- the first field of the source layer fills the third field (index
2= third field) of the target layer, - the second field of the source layer gets ignored,
- the third field of the source layer fills the fifth field of the target layer.
ogr2ogr -append -fieldmap 2,-1,4 dst.shp src.shp
See the -1? That's the "ignore this one bestie" slot. π
More examples are given in the individual format pages. So if your format isn't here, go snoop around its own page β she's got lore too π§ββοΈ
π AUTHOR π
- Frank Warmerdam
<warmerdam@pobox.com> - Silke Reimer
<silke@intevation.de>
Legends, both of them π«Ά
π COPYRIGHT π
1998-2026
β¨ that's the whole page, bestie β¨
This little masterpiece comes to you straight from the OGR2OGR(1) source, dated Jan 08, 2026 β so if you're reading this in some distant future where GeoPackages are beamed directly into your brain, just know she was serving facts way back when ππ
Now go convert something. I believe in you. π
π¦ where this page comes from
- epel 9: gdal3.4 3.4.3-5.el9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms