OGR2OGR(1)
π NAME π
okay so first things first β this is the manual page for ogr2ogr, straight outta GDAL (yes, the OGR2OGR(1) page, hi bestie π). And what does it do?? It converts simple features data between file formats. That's it. That's the whole job. Iconic behavior honestly. π¦
πΈ SYNOPSIS πΈ
here's the whole menu of ways you can call it, laid out exactly as the universe intended:
Usage: ogr2ogr [--help] [--long-usage] [--help-general]
[-of <output_format>] [-dsco <NAME>=<VALUE>]...
[-lco <NAME>=<VALUE>]...
[[-append]|[-upsert]|[-overwrite]]
[-update] [-sql <statement>|@<filename>] [-dialect <dialect>]
[-spat <xmin> <ymin> <xmax> <ymax>]
[-where <restricted_where>|@<filename>] [-select <field_list>]
[-nln <name>] [-nlt <type>]... [-s_srs <srs_def>]
[[-a_srs <srs_def>]|[-t_srs <srs_def>]]
<dst_dataset_name> <src_dataset_name> [<layer_name>]...
Field related options:
[-addfields] [-relaxedFieldNameMatch]
[-fieldTypeToString All|<type1>[,<type2>]...]
[-mapFieldType <srctype>|All=<dsttype>[,<srctype2>=<dsttype2>]...]
[-fieldmap <field_1>[,<field_2>]...] [-splitlistfields]
[-maxsubfields <n>] [-emptyStrAsNull] [-forceNullable]
[-unsetFieldWidth] [-unsetDefault] [-resolveDomains]
[-dateTimeTo UTC|UTC(+|-)<HH>|UTC(+|-)<HH>:<MM>] [-noNativeData]
Advanced geometry and SRS related options:
[-dim layer_dim|2|XY|3|XYZ|XYM|XYZM] [-s_coord_epoch <epoch>]
[-a_coord_epoch <epoch>] [-t_coord_epoch <epoch>]
[-ct <pipeline_def>] [-ct_opt <NAME>=<VALUE>]...
[-spat_srs <srs_def>] [-geomfield <name>]
[-segmentize <max_dist>] [-simplify <tolerance>] [-makevalid]
[-skipinvalid] [-wrapdateline] [-datelineoffset <val_in_degree>]
[-clipsrc [<xmin> <ymin> <xmax> <ymax>]|<WKT>|<datasource>|spat_extent]
[-clipsrcsql <sql_statement>] [-clipsrclayer <layername>]
[-clipsrcwhere <expression>]
[-clipdst [<xmin> <ymin> <xmax> <ymax>]|<WKT>|<datasource>]
[-clipdstsql <sql_statement>] [-clipdstlayer <layername>]
[-clipdstwhere <expression>] [-explodecollections]
[-zfield <name>]
[-gcp <ungeoref_x> <ungeoref_y> <georef_x> <georef_y> [<elevation>]]...
[-tps] [-order 1|2|3] [-xyRes <val>[ m|mm|deg]]
[-zRes <val>[ m|mm]] [-mRes <val>] [-unsetCoordPrecision]
Other options:
[--quiet] [-progress] [-if <format>]... [-oo <NAME>=<VALUE>]...
[-doo <NAME>=<VALUE>]...
[-fid <FID>] [-preserve_fid] [-unsetFid]
[[-skipfailures]|[-gt <n>|unlimited]]
[-limit <nb_features>] [-ds_transaction] [-mo <NAME>=<VALUE>]...
[-nomd]
π DESCRIPTION π
so ogr2ogr can be used to convert simple features data between file formats. but bestie that's literally just the appetizer π because it can ALSO do a whole bunch of operations while it's doing the converting, like:
- spatial or attribute selection
- reducing the set of attributes
- setting the output coordinate system
- or even reprojecting the features during translation
main character energy, truly. π
π TIP π
there's an equivalent way to do all this in the new "gdal" command line interface, and here's the map:
gdal vector clipfor spatial subsettinggdal vector convertfor format translationgdal vector explode-collectionsto explode geometries of type collectiongdal vector make-validto fix geometry validitygdal vector reprojectfor reprojectiongdal vector segmentizeto segmentize geometriesgdal vector selectto select a subset of fieldsgdal vector set-field-typeto change the type of an attribute fieldgdal vector set-geom-typeto change the type of a geometry fieldgdal vector simplifyto simplify geometriesgdal vector sqlto run SQL query
and now, the options, in the exact order they showed up, no skips no cuts π«Ά
--helpβ Show this help message and exit--help-generalβ Gives a brief usage message for the generic GDAL commandline options and exit.-q,--quietβ Suppress progress messages and other non-error output. (the silent treatment, but productive β¨)-if <format>β Format/driver name to be attempted to open the input file(s). It is generally not necessary to specify it, but it can be used to skip automatic driver detection, when it fails to select the appropriate driver. This option can be repeated several times to specify several candidate drivers. Note that it does not force those drivers to open the dataset. In particular, some drivers have requirements on file extensions.
Added in version 3.2.
-of <format_name>,-f <format_name>β Output file format name, e.g.ESRI Shapefile,MapInfo File,PostgreSQL. If not specified, the format is guessed from the extension.-appendβ Append to existing layer instead of creating new. This option also enables-update.-upsertβ Variant of-appendwhere theOGRLayer::UpsertFeature()operation is used to insert or update features instead of appending withOGRLayer::CreateFeature().
Added in version 3.6.
This is currently implemented only in a few drivers: GPKG -- GeoPackage vector, Elasticsearch: Geographically Encoded Objects for Elasticsearch and MongoDBv3 (drivers that implement upsert expose the GDAL_DCAP_UPSERT capability).
The upsert operation uses the FID of the input feature, when it is set and is a "significant" (that is the FID column name is not the empty string), as the key to update existing features. It is crucial to make sure that the FID in the source and target layers are consistent. (like, crucial crucial, no cap π)
For the GPKG driver, it is also possible to upsert features whose FID is unset or non-significant (-unsetFid can be used to ignore the FID from the source feature), when there is a UNIQUE column that is not the integer primary key.
-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-select <field_list>β Comma-delimited list of fields from input layer to copy to the new layer.
Starting with GDAL 3.9, field names with spaces, commas or double-quote should be surrounded with a starting and ending double-quote character, and double-quote characters in a field name should be escaped with backslash.
Depending on the shell used, this might require further quoting. For example, to select regular_field, a_field_with space, and comma and a field with " double quote with a Unix shell:
-select "regular_field,\"a_field_with space, and comma\",\"a field with \\\" double quote\""
A field is only selected once, even if mentioned several times in the list and if the input layer has duplicate field names.
Geometry fields can also be specified in the list.
All fields are selected when -select is not specified. Specifying the empty string can be used to disable selecting any attribute field, and only keep geometries.
Note this setting cannot be used together with -append. To control the selection of fields when appending to a layer, use -fieldmap or -sql.
-progressβ Display progress on terminal. Only works if input layers have the "fast feature count" capability.-sql <sql_statement>|@<filename>β SQL statement to execute. The resulting table/layer will be saved to the output. The@filenamesyntax can be used to indicate that the content is in the pointed filename. (Cannot be used with-spat_srs.)-dialect <dialect>β SQL dialect. In some cases can be used to use the (unoptimized) OGR SQL dialect instead of the native SQL of an RDBMS by passing theOGRSQLdialect value. The SQL SQLite dialect dialect can be chosen with theSQLITEandINDIRECT_SQLITEdialect values, and this can be used with any datasource. (-dialectis ignored with-where. Use-sqlinstead.)-where <restricted_where>|@<filename>β Attribute query (like SQL WHERE). The@filenamesyntax can be used to indicate that the content is in the pointed filename. (-dialectis ignored with-where. Use-sqlinstead.)-skipfailuresβ Continue after a failure, skipping the failed feature. Note that this option overrides the value of-gtto 1, which may cause severe slowdown when inserting into databases. (rip your runtime π)-spat <xmin> <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_srs <srs_def>β Override spatial filter SRS. (Cannot be used with-sql.)-geomfield <field>β Name of the geometry field on which the spatial filter operates on.-dsco <NAME>=<VALUE>β Dataset creation option (format specific)-lco <NAME>=<VALUE>β Layer creation option (format specific)-nln <name>β Assign an alternate name to the new layer-nlt <type>β okay bestie, this one sets the geometry type for the layer you're creating π . Pick one of:NONE,GEOMETRY,POINT,LINESTRING,POLYGON,GEOMETRYCOLLECTION,MULTIPOINT,MULTIPOLYGON,MULTILINESTRING,CIRCULARSTRING,COMPOUNDCURVE,CURVEPOLYGON,MULTICURVE, andMULTISURFACEβ those last few are the non-linear geometry types β¨. Wanna do heights or measurements? Just addZ,M, orZMto the type name and it'll give you coords with elevation, measure, or elevation and measure π. There's alsoPROMOTE_TO_MULTI, which auto-promotes layers that mix polygon or multipolygons into multipolygons, and layers that mix linestrings or multilinestrings into multilinestrings β so useful when you're converting shapefiles to PostGIS and other target drivers that do strict geometry type checks, no cap. And thenCONVERT_TO_LINEARconverts non-linear geometry types into linear ones by approximating them, whileCONVERT_TO_CURVEpromotes a non-linear type to its generalized curve type β specificallyPOLYGONtoCURVEPOLYGON,MULTIPOLYGONtoMULTISURFACE,LINESTRINGtoCOMPOUNDCURVE, andMULTILINESTRINGtoMULTICURVEπ. Since version 2.1 the type can be defined as measured (and head's up,"25D"still lives on as an alias for single"Z"). β οΈ Some forced geometry conversions can produce invalid geometries β like when you force conversion of multi-part multipolygons with-nlt POLYGON, the resulting polygon will break the Simple Features rules, periodt.
Also since GDAL 3.0.5, you can use -nlt CONVERT_TO_LINEAR and -nlt PROMOTE_TO_MULTI at the same time π«Ά.
-dim <val>β forces the coordinate dimension to val. Valid values areXY,XYZ,XYM, andXYZM(and for backwards compatibility,2is an alias forXYand3is an alias forXYZβ the legacy crumbs π). This hits both the layer geometry type and the feature geometries. You can also set it tolayer_dimto tell feature geometries to get promoted to the coordinate dimension declared by the layer π.-a_srs <srs_def>β assigns an output SRS, but without reprojecting (if you actually want the reprojection, that's-t_srs's job, bestie). The CRS you can pass is anything supported by theOGRSpatialReference::SetFromUserInput()call β that 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.prjfile containing a WKT CRS definition π.-a_coord_epoch <epoch>β β¨ Added in version 3.4. Assigns a coordinate epoch that's linked with the output SRS. Super handy when your output SRS is a dynamic CRS. Only taken into account if-a_srsis used, iykyk.-t_srs <srs_def>β reprojects/transforms to this SRS on output, and assigns it as the output SRS π₯. For reprojection to actually happen, a source SRS has to be available β it'll default to the one found in the source layer when it's available, or to whatever the user overrides with-s_srs. The CRS you can pass is, again, anything supported by theOGRSpatialReference::SetFromUserInput()call β EPSG Projected, Geographic or Compound CRS (i.e.EPSG:4296), a WKT CRS definition, PROJ.4 declarations, or the name of a.prjfile containing a WKT CRS definition π«.-t_coord_epoch <epoch>β β¨ Added in version 3.4. Assigns a coordinate epoch linked with the output SRS β ideal when the output SRS is a dynamic CRS. Only taken into account if-t_srsis used. It's mutually exclusive with-a_coord_epoch, so pick a lane π« .
Before PROJ 9.4, -s_coord_epoch and -t_coord_epoch were mutually exclusive too, because there was no support for transformations between two dynamic CRS. Rude, but okay.
-s_srs <srs_def>β overrides the source SRS π. If you don't specify it, the SRS found in the input layer gets used. This option only does anything if it's used together with-t_srsto reproject β otherwise it's just vibes. The CRS you can pass is, once more, anything supported by theOGRSpatialReference::SetFromUserInput()call β EPSG Projected, Geographic or Compound CRS (i.e.EPSG:4296), a WKT CRS definition, PROJ.4 declarations, or the name of a.prjfile containing a WKT CRS definition πΈ.-xyRes "<val>[ m|mm|deg]"β β¨ Added in version 3.9. Sets/overrides the geometry X/Y coordinate resolution. If you only give a numeric value, it's assumed to be expressed in the units of the target SRS. Them,mmordegsuffixes tell it to interpret that value as meter, millimeter or degree π. When you specify this option, theOGRGeometry::SetPrecision()method gets run on geometries (that are not curves) before they're handed to the output driver β that's to avoid generating invalid geometries from the potentially reduced precision, unless theOGR_APPLY_GEOM_SET_PRECISIONconfiguration option is set toNO. And if neither this option nor-unsetCoordPrecisionis specified, the coordinate resolution of the source layer gets used, if it's available π .-zRes "<val>[ m|mm]"β β¨ Added in version 3.9. Sets/overrides the geometry Z coordinate resolution. If you only give a numeric value, it's assumed to be expressed in the units of the target SRS. Themormmsuffixes tell it the value means meter or millimeter. If neither this option nor-unsetCoordPrecisionis specified, the coordinate resolution of the source layer gets used, if available π¦.-mRes <val>β β¨ Added in version 3.9. Sets/overrides the geometry M coordinate resolution. If neither this option nor-unsetCoordPrecisionis specified, the coordinate resolution of the source layer gets used, if available π«.-unsetCoordPrecisionβ β¨ Added in version 3.9. Stops the geometry coordinate resolution from being set on the target layer(s). Simple as that, bestie π.-s_coord_epoch <epoch>β β¨ Added in version 3.4. Assigns 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. Before PROJ 9.4,-s_coord_epochand-t_coord_epochwere mutually exclusive, due to lack of support for transformations between two dynamic CRS π.-ct <string>β β¨ Added in version 3.0. This lets you override the default transformation from the source to the target CRS with either a PROJ string (a single step operation, or a multiple step string starting with+proj=pipeline), a WKT2 string describing aCoordinateOperation, or aurn:ogc:def:coordinateOperation:EPSG::XXXXURN π. Important: it must take into account the axis order of the source and target CRS β which typically means including a stepproj=axisswap order=2,1at the beginning of the pipeline if the source CRS has northing/easting axis order, and/or at the end of the pipeline if the target CRS has northing/easting axis order. Don't skip that part fr fr.-ct_opt <NAME>=<VALUE>β β¨ Added in version 3.11. Specifies a coordinate operation option that influences how PROJ selects coordinate operations when-ctis not set. Here are the options available:ONLY_BEST=YES/NO. By default (at least in the PROJ 9.x series), PROJ may use coordinate operations that are not the "best" if resources (typically grids) needed to use them are missing π¬. It'll then fall back to other coordinate operations with lesser accuracy β for example using Helmert transformations β or, in the absence of such operations, to ones with potentially very rough accuracy using "ballpark" transformations (seehttps://proj.org/glossary.html). When you call this withYES, PROJ will only consider the "best" operation, and error out (atTransform()time) if they can't be used. It can be combined withALLOW_BALLPARK=NOto only allow best operations that have a known accuracy. Heads up: this has no effect on PROJ versions before 9.2. The default value for this option can also be set with thePROJ_ONLY_BEST_DEFAULTenvironment variable, or with theonly_best_defaultsetting ofproj.ini. SettingONLY_BEST=YES/NOoverrides that default value π.ALLOW_BALLPARK=YES/NO. Whether ballpark coordinate operations are allowed. Default isYES.WARN_ABOUT_DIFFERENT_COORD_OP=YES/NO. Can be set toNOto avoid the GDAL warning when different coordinate operations are used to transform the different geometries of the dataset (or part of the same geometry). Default isYES.
-preserve_fidβ uses the FID of the source features instead of letting the output driver automatically assign a new one (for formats that require a FID) π«Ά. If you're not in append mode, this behavior is already the default when the output driver has a FID layer creation option β in that case the name of the source FID column gets used and source feature IDs will be attempted to be preserved. You can turn that off by setting-unsetFid. And psst, this option is not compatible with-explodecollectionsπ.-fid <fid>β if you provide it, only the feature with that specified feature id will be processed β¨. It operates exclusive of the spatial or attribute queries, just so you know. Note: if you wanna select several features based on their feature id, you can also use the fact that '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>β limits the number of features per layer. Cute little cap π.-oo <NAME>=<VALUE>β Dataset open option (format specific) π§. If a driver supports theOGR_SCHEMAopen option, it can be used to partially or completely override the auto-detected schema of the dataset β i.e. which fields are read, with which types, subtypes, length, precision, etc. π The value of this option is a JSON string or a path to a JSON file that complies with theOGR_SCHEMAopen option schema definition.-doo <NAME>=<VALUE>β Destination dataset open option (format specific), and it's <hottpink>only</hottpink> valid in-updatemode π.-gt <n>β ok so this one groups n features per transaction, and the default is 100 000 π. Crank that number up if you're writing into DBMS drivers that have transaction support, because bigger groups = better performance, no cap. And get this: n can literally be set tounlimitedto load ALL the data into a single transaction. one transaction. iconic.-ds_transactionβ forces the use of a dataset level transaction (for drivers that support that kind of mechanism) β¨. It's especially for drivers like FileGDB that only support dataset level transaction in emulation mode. bestie it's giving "we make it work anyway".-clipsrc [<xmin> <ymin> <xmax> <ymax>]|WKT|<datasource>|spat_extentβ clips geometries (before any potential reprojection, so watch the order) to one of these:- the bounding box you specified, expressed in source SRS π¦
- a WKT geometry β
POLYGONorMULTIPOLYGON, expressed in source SRS π¦ - one or more geometries selected from a datasource ποΈ
- the spatial extent of the
-spatoption, if you use thespat_extentkeyword β¨
And when you're specifying a datasource, you'll generally want to pair -clipsrc with the -clipsrclayer, -clipsrcwhere or -clipsrcsql options. trio of besties fr fr.
-clipsrcsql <sql_statement>β selects the geometries you want from the source clip datasource using an SQL query π-clipsrclayer <layername>β picks the named layer from the source clip datasource π-clipsrcwhere <expression>β restricts the geometries you want from the source clip layer based on an attribute query π-clipdst [<xmin> <ymin> <xmax> <ymax>]|<WKT>|<datasource>β this one clips geometries (after any potential reprojection, opposite energy of-clipsrc) to one of:- the bounding box you specified, and here it's expressed in destination SRS π¦
- a WKT geometry β
POLYGONorMULTIPOLYGON, expressed in destination SRS πΈ - one or more geometries selected from a datasource ποΈ
And again, when specifying a datasource, you'll generally want -clipdst in combination with the -clipdstlayer, -clipdstwhere or -clipdstsql options π
-clipdstsql <sql_statement>β selects the geometries you want from the destination clip datasource using an SQL query β¨-clipdstlayer <layername>β picks the named layer from the destination clip datasource π-clipdstwhere <expression>β restricts the geometries you want from the destination clip layer based on an attribute query π-wrapdatelineβ splits geometries that are crossing the dateline meridian (that's long. = +/- 180deg) π-datelineoffsetβ the offset from the dateline, in degrees. Default is long. = +/- 10deg, meaning geometries within 170deg to -170deg will get split π§-simplify <tolerance>β distance tolerance for simplification. Heads up bestie: the algorithm used preserves topology per feature, in particular for polygon geometries, but not for a whole layer π. The value you specify is the tolerance used to merge consecutive points of the output geometry using theOGRGeometry::SimplifyPreserveTopology()method. The unit of the distance is in georeferenced units of the source vector dataset π. And important β this option is applied before the reprojection implied by-t_srs.-segmentize <max_dist>β the value you give is the maximum distance between two consecutive points of the output geometry before intermediate points get added β¨. The unit of the distance is georeferenced units of the source layer π. Same deal as above: this option is applied before the reprojection implied by-t_srs.-makevalidβ runs theOGRGeometry::MakeValid()operation, followed byOGRGeometryFactory::removeLowerDimensionSubGeoms(), on geometries so they're valid regarding the rules of the Simple Features specification π
Added in version 3.1: (requires GEOS)
-skipinvalidβ runs theOGRGeometry::IsValid()operation on geometries to check if they're valid regarding the rules of the Simple Features specification. If they're not, the feature gets skipped π. This check is done after all other geometry operations.
Added in version 3.10: (requires GEOS)
-fieldTypeToString All|<type1>[,<type2>]...β converts any field of the specified type into 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 valueAllconverts everything to strings π. This is an alternate way to using theCASToperator of OGR SQL, and it may save you from typing out a long SQL query. Note that this does not influence the field types used by the source driver β it's only an afterwards conversion, iykyk. Also note this option is without effects on fields whose presence and type is hard-coded in the output driver (e.g KML, GPX) π« . For an alternative way to manipulate field types earlier in the process while they're read from the input dataset, see-oo OGR_SCHEMA(only available for a limited set of formats).-mapFieldType {<srctype>|All=<dsttype>[,<srctype2>=<dsttype2>]...}β 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 a subtype between parenthesis, such asInteger(Boolean),Real(Float32), ... Special valueAllconverts all fields to another type β¨. Just like the one above, this is an alternate way to using theCASToperator of OGR SQL that may save you from typing a long SQL query β and it's actually a generalization of-fieldTypeToStringπ. Note again: this does not influence the field types used by the source driver, it's only an afterwards conversion. Also note this option is without effects on fields whose presence and type is hard-coded in the output driver (e.g KML, GPX). For an alternative way to manipulate field types earlier in the process while they're read from the input dataset, see-oo OGR_SCHEMA(only available for a limited set of formats).-dateTimeTo {UTC|UTC(+|-)<HH>|UTC(+|-)<HH>:<MM>}β converts date time values from the timezone specified in the source value to the target timezone expressed with-dateTimeToπ°οΈ. Datetimes whose timezone is unknown or localtime are not modified π.HHmust be in the[0,14]range andMM=00,15,30or45.
Added in version 3.7.
-unsetFieldWidthβ sets field width and precision to0π-splitlistfieldsβ splits fields of typeStringList,RealListorIntegerListinto as many fields of typeString,RealorIntegeras necessary βοΈ-maxsubfields <val>β to be combined with-splitlistfields, it limits the number of subfields created for each split field π’-explodecollectionsβ produces one feature for each geometry in any kind of geometry collection in the source file, applied after any-sqloption π₯. This option is not compatible with-preserve_fid, but-sql "SELECT fid AS original_fid, * FROM ..."can be used to store the original FID if you need it. periodt.-zfield <field_name>β uses the specified field to fill the Z coordinate of geometries π§-gcp <ungeoref_x> <ungeoref_y> <georef_x> <georef_y> [<elevation>]β uses the indicated ground control point to compute a coordinate transformation π. The transformation method can be selected by specifying the-orderor-tpsoptions. Note that β unlike raster tools such asgdal_editorgdal_translateβ GCPs are not added to the output dataset π . This option may be provided multiple times to give a set of GCPs (and at least 2 GCPs are needed).-order <n>β order of polynomial used for warping,1to3π. The default is to select a polynomial order based on the number of GCPs.-tpsβ forces use of the 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)th value specified in the list is the index of the field in the target layer definition in which the n(th) field of the source layer must be copied. Index count starts at zero. Want 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. You can use theidentitysetting 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β does field name matching between source and existing target layer in a more relaxed way, if the target driver has an implementation for it π§-forceNullableβ does not propagate not-nullable constraints to the target layer if they exist in the source layer π«-unsetDefaultβ does not propagate default field values to the target layer if they exist in the source layer π-unsetFidβ can be specified to prevent the name of the source FID column and source feature IDs from being reused for the target layer π. This option can, for example, be useful if you're selecting source features with aORDER BYclause.-emptyStrAsNullβ treats empty string values as null π³οΈ
Added in version 3.3.
-resolveDomainsβ when this is specified, any selected field that is linked to a coded field domain will be accompanied by an additional field ({dstfield}_resolved), which will contain the description of the coded value π·οΈ
Added in version 3.3.
-nomdβ to disable copying of metadata from source dataset and layers into target dataset and layers, when supported by the output driver π«-mo <META-TAG>=<VALUE>β passes a metadata key and value to set on the output dataset, when supported by the output driver β¨-noNativeDataβ bestie, this one turns OFF copying of native data π€ like, the lil details of the source format that the OGR abstraction just doesn't capture? Those. Normally some drivers (hi GeoJSON π) keep them around when you're converting to the same format. This flag says nah π<dst_dataset_name>β the output dataset name, aka where your stuff is going π<src_dataset_name>β the source dataset name, aka where your stuff is coming from π<layer_name>β one or more source layer names to copy over to the output dataset. And if you pass no layer names at all? Then all source layers get copied, no cap β¨
π₯ PERFORMANCE HINTS π₯
Okay so when you're writing into a transactional DBMS (SQLite/PostgreSQL, MySQL, etc...), it might lowkey be a massive glow-up to increase the number of INSERT statements executed between BEGIN TRANSACTION and COMMIT TRANSACTION statements π
That magic number is set 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. Fr fr that's a lotta rows π«Ά
But heads up bestie β οΈ β-skipfailuresoverrides-gtand sets the size of transactions to1. So like, pick your fighter π
For PostgreSQL, the PG_USE_COPY config option can be set to YES for a significant insertion performance boost. Peep the PG driver documentation page for that one πΈ
And more generally? Consult the documentation page of the input and output drivers for performance hints. They know things, iykyk π
π KNOWN ISSUES π
Starting with GDAL 3.8, ogr2ogr uses internally an Arrow array based API (cf RFC 86: Column-oriented read API for vector layers) for some source formats (in particular GeoPackage or FlatGeoBuf), and for the most basic types of operations, to improve performance β¨
This substantial change in the ogr2ogr internal logic has required a number of fixes throughout the GDAL 3.8.x bugfix releases to fully stabilize it, and we believe most issues are resolved with GDAL 3.9 π
If you hit errors not met with earlier GDAL versions, you may specify --config OGR2OGR_USE_ARROW_API NO on the ogr2ogr command line to opt for the classic algorithm using an iterative feature based approach. And if that flag is needed with GDAL >= 3.9, please file an issue on the GDAL issue tracker π
π RETURN STATUS CODE π
The program returns status code 0 in case of success, and non-zero in case of error (non-blocking errors emitted as warnings are considered as a successful execution) πβ¨
π§ C API π§
This utility is also callable from C with GDALVectorTranslate(). Slay, she's bilingual π
πΈ EXAMPLES πΈ
Example 1: Appending to an existing layer
ogr2ogr -append -f PostgreSQL PG:dbname=warmerda abc.tab
Example 2: Clip input layer with a bounding box
The bounding box is specified as <xmin> <ymin> <xmax> <ymax>:
ogr2ogr -spat -13.931 34.886 46.23 74.12 output.gpkg natural_earth_vector.gpkg
Example 3: Filter Features by a -where clause
ogr2ogr -where "\"POP_EST\" < 1000000" \
output.gpkg natural_earth_vector.gpkg ne_10m_admin_0_countries
More examples are given in the individual format pages π (go read them, they eat fr)
π ADVANCED EXAMPLES π
Example 4: Reprojecting from ETRS_1989_LAEA_52N_10E to EPSG:4326 and clipping to a bounding box
ogr2ogr -wrapdateline -t_srs EPSG:4326 -clipdst -5 40 15 55 france_4326.shp europe_laea.shp
Example 5: Outputting geometries with the CSV driver.
By default this driver does not preserve geometries upon layer creation. So an explicit layer creation option is needed, bestie:
ogr2ogr -lco GEOMETRY=AS_XYZ TrackWaypoint.csv TrackWaypoint.kml
Example 6: Extracting only geometries
There are different situations, depending if the input layer has a named geometry column, or not. First check, with ogrinfo if there is a reported geometry column.
$ ogrinfo -so CadNSDI.gdb.zip PLSSPoint | grep 'Geometry Column'
Geometry Column = SHAPE
In that situation where the input format is a FileGeodatabase, it is called SHAPE and can thus be referenced directly in a SELECT statement.
ogr2ogr -sql "SELECT SHAPE FROM PLSSPoint" \
-lco GEOMETRY=AS_XY -f CSV /vsistdout/ CadNSDI.gdb.zip
For a shapefile with a unnamed geometry column, _ogr_geometry_ can be used as a special name to designate the implicit geometry column, when using the default OGR SQL dialect. The name begins with an underscore and SQL syntax requires that it must appear between double quotes. In addition the command line interpreter may require that double quotes are escaped and the final SELECT statement could look like:
ogr2ogr -sql "SELECT \"_ogr_geometry_\" FROM PLSSPoint" \
-lco GEOMETRY=AS_XY -f CSV /vsistdout/ CadNSDI.shp
If using the SQL SQLite dialect, the special geometry name is geometry when the source geometry column has no name.
ogr2ogr -sql "SELECT geometry FROM PLSSPoint" -dialect SQLite \
-lco GEOMETRY=AS_XY -f CSV /vsistdout/ CadNSDI.shp
π«Ά AUTHOR π«Ά
Frank Warmerdam <warmerdam@pobox.com>, Silke Reimer <silke@intevation.de>
π COPYRIGHT π
1998-2026
And that's the whole page, bestie, we made it to the end together ππ This one's the Aug 18, 2026 drop of the OGR2OGR(1) manual page β go forth and translate some vectors, you absolute icon πβ¨
π¦ where this page comes from
- alpine 3.24: gdal-doc 3.13.3-r0 Β· MIT
- arch rolling: gdal 3.13.3-6 Β· MIT
- ubuntu stonking: gdal-bin 3.13.3+dfsg-1ubuntu4 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms