1OGR2OGR(1)                           GDAL                           OGR2OGR(1)
2
3
4

NAME

6       ogr2ogr - Converts simple features data between file formats.
7

SYNOPSIS

9          ogr2ogr [--help-general] [-skipfailures] [-append] [-update]
10                  [-select field_list] [-where restricted_where|\@filename]
11                  [-progress] [-sql <sql statement>|\@filename] [-dialect dialect]
12                  [-preserve_fid] [-fid FID] [-limit nb_features]
13                  [-spat xmin ymin xmax ymax] [-spat_srs srs_def] [-geomfield field]
14                  [-a_srs srs_def] [-t_srs srs_def] [-s_srs srs_def] [-ct string]
15                  [-f format_name] [-overwrite] [[-dsco NAME=VALUE] ...]
16                  dst_datasource_name src_datasource_name
17                  [-lco NAME=VALUE] [-nln name]
18                  [-nlt type|PROMOTE_TO_MULTI|CONVERT_TO_LINEAR|CONVERT_TO_CURVE]
19                  [-dim XY|XYZ|XYM|XYZM|2|3|layer_dim] [layer [layer ...]]
20
21                  # Advanced options
22                  [-gt n]
23                  [[-oo NAME=VALUE] ...] [[-doo NAME=VALUE] ...]
24                  [-clipsrc [xmin ymin xmax ymax]|WKT|datasource|spat_extent]
25                  [-clipsrcsql sql_statement] [-clipsrclayer layer]
26                  [-clipsrcwhere expression]
27                  [-clipdst [xmin ymin xmax ymax]|WKT|datasource]
28                  [-clipdstsql sql_statement] [-clipdstlayer layer]
29                  [-clipdstwhere expression]
30                  [-wrapdateline] [-datelineoffset val]
31                  [[-simplify tolerance] | [-segmentize max_dist]]
32                  [-makevalid]
33                  [-addfields] [-unsetFid] [-emptyStrAsNull]
34                  [-relaxedFieldNameMatch] [-forceNullable] [-unsetDefault]
35                  [-fieldTypeToString All|(type1[,type2]*)] [-unsetFieldWidth]
36                  [-mapFieldType type1|All=type2[,type3=type4]*]
37                  [-fieldmap identity | index1[,index2]*]
38                  [-splitlistfields] [-maxsubfields val]
39                  [-resolveDomains]
40                  [-explodecollections] [-zfield field_name]
41                  [-gcp ungeoref_x ungeoref_y georef_x georef_y [elevation]]* [-order n | -tps]
42                  [-nomd] [-mo "META-TAG=VALUE"]* [-noNativeData]
43

DESCRIPTION

45       ogr2ogr  can  be used to convert simple features data between file for‐
46       mats. It can also perform various operations during the  process,  such
47       as spatial or attribute selection, reducing the set of attributes, set‐
48       ting the output coordinate system or  even  reprojecting  the  features
49       during translation.
50
51       -f <format_name>
52              Output  file  format  name,  e.g.  ESRI Shapefile, MapInfo File,
53              PostgreSQL.  Starting with GDAL 2.3, if not specified, the  for‐
54              mat  is  guessed  from the extension (previously was ESRI Shape‐
55              file).
56
57       -append
58              Append to existing layer instead of creating new
59
60       -overwrite
61              Delete the output layer and recreate it empty
62
63       -update
64              Open existing output datasource in update mode rather than  try‐
65              ing to create a new one
66
67       -select <field_list>
68              Comma-delimited  list  of fields from input layer to copy to the
69              new layer. A field is skipped if  mentioned  previously  in  the
70              list  even  if  the  input layer has duplicate field names. (De‐
71              faults to all; any field is skipped if a subsequent  field  with
72              same  name  is  found.) Geometry fields can also be specified in
73              the list.
74
75              Note this setting cannot be used together with -append. To  con‐
76              trol  the  selection  of  fields  when appending to a layer, use
77              -fieldmap or -sql.
78
79       -progress
80              Display progress on terminal. Only works if  input  layers  have
81              the "fast feature count" capability.
82
83       -sql <sql_statement>
84              SQL  statement  to  execute.  The  resulting table/layer will be
85              saved to the output. Starting with GDAL 2.1, the @filename  syn‐
86              tax  can  be used to indicate that the content is in the pointed
87              filename.
88
89       -dialect <dialect>
90              SQL dialect. In some cases can  be  used  to  use  (unoptimized)
91              ogr_sql_dialect instead of the native SQL of an RDBMS by passing
92              the OGRSQL dialect value.  The sql_sqlite_dialect dialect can be
93              select  with  the SQLITE and INDIRECT_SQLITE dialect values, and
94              this can be used with any datasource.
95
96       -where restricted_where
97              Attribute query (like SQL WHERE). Starting with  GDAL  2.1,  the
98              @filename  syntax can be used to indicate that the content is in
99              the pointed filename.
100
101       -skipfailures
102              Continue after a failure, skipping the failed feature.
103
104       -spat <xmin> <ymin> <xmax> <ymax>
105              spatial query extents, in the SRS of the source layer(s) (or the
106              one  specified with -spat_srs). Only features whose geometry in‐
107              tersects the extents will be selected. The geometries  will  not
108              be clipped unless -clipsrc is specified.
109
110       -spat_srs <srs_def>
111              Override spatial filter SRS.
112
113       -geomfield <field>
114              Name  of the geometry field on which the spatial filter operates
115              on.
116
117       -dsco NAME=VALUE
118              Dataset creation option (format specific)
119
120       -lco NAME=VALUE
121              Layer creation option (format specific)
122
123       -nln <name>
124              Assign an alternate name to the new layer
125
126       -nlt <type>
127              Define the geometry type for the created layer. One of NONE, GE‐
128              OMETRY,  POINT,  LINESTRING, POLYGON, GEOMETRYCOLLECTION, MULTI‐
129              POINT, MULTIPOLYGON, MULTILINESTRING, CIRCULARSTRING,  COMPOUND‐
130              CURVE, CURVEPOLYGON, MULTICURVE, and MULTISURFACE non-linear ge‐
131              ometry types. Add Z, M, or ZM to the type name to specify  coor‐
132              dinates  with elevation, measure, or elevation and measure. PRO‐
133              MOTE_TO_MULTI can be used to automatically promote  layers  that
134              mix  polygon  or multipolygons to multipolygons, and layers that
135              mix linestrings or multilinestrings to multilinestrings. Can  be
136              useful  when  converting  shapefiles to PostGIS and other target
137              drivers that implement strict checks for geometry  types.   CON‐
138              VERT_TO_LINEAR  can  be  used  to to convert non-linear geometry
139              types into linear geometry types by approximating them, and CON‐
140              VERT_TO_CURVE  to  promote  a non-linear type to its generalized
141              curve type (POLYGON to CURVEPOLYGON, MULTIPOLYGON  to  MULTISUR‐
142              FACE,  LINESTRING  to  COMPOUNDCURVE, MULTILINESTRING to MULTIC‐
143              URVE). Starting with version 2.1 the type can be defined as mea‐
144              sured  ("25D"  remains  as an alias for single "Z"). Some forced
145              geometry conversions may result in invalid geometries, for exam‐
146              ple  when  forcing  conversion  of multi-part multipolygons with
147              -nlt POLYGON, the resulting polygon will break the  Simple  Fea‐
148              tures rules.
149
150              Starting  with  GDAL 3.0.5, -nlt CONVERT_TO_LINEAR and -nlt PRO‐
151              MOTE_TO_MULTI can be used simultaneously.
152
153       -dim <val>
154              Force the coordinate dimension to val (valid values are XY, XYZ,
155              XYM, and XYZM - for backwards compatibility 2 is an alias for XY
156              and 3 is an alias for XYZ). This affects both the layer geometry
157              type,  and feature geometries. The value can be set to layer_dim
158              to instruct feature geometries to be promoted to the  coordinate
159              dimension declared by the layer. Support for M was added in GDAL
160              2.1.
161
162       -a_srs <srs_def>
163              Assign an output SRS, but without reprojecting  (use  -t_srs  to
164              reproject)
165
166              The coordinate reference systems that can be passed are anything
167              supported by  the  OGRSpatialReference.SetFromUserInput()  call,
168              which  includes EPSG Projected, Geographic or Compound CRS (i.e.
169              EPSG:4296), a well known text (WKT) CRS definition, PROJ.4  dec‐
170              larations, or the name of a .prj file containing a WKT CRS defi‐
171              nition.
172
173       -t_srs <srs_def>
174              Reproject/transform to this SRS on output, and assign it as out‐
175              put SRS.
176
177              A  source  SRS  must be available for reprojection to occur. The
178              source SRS will be by default the one found in the source  layer
179              when it is available, or as overridden by the user with -s_srs
180
181              The coordinate reference systems that can be passed are anything
182              supported by  the  OGRSpatialReference.SetFromUserInput()  call,
183              which  includes EPSG Projected, Geographic or Compound CRS (i.e.
184              EPSG:4296), a well known text (WKT) CRS definition, PROJ.4  dec‐
185              larations, or the name of a .prj file containing a WKT CRS defi‐
186              nition.
187
188       -s_srs <srs_def>
189              Override source SRS. If not specified the SRS found in the input
190              layer  will  be used. This option has only an effect if used to‐
191              gether with -t_srs to reproject.
192
193              The coordinate reference systems that can be passed are anything
194              supported  by  the  OGRSpatialReference.SetFromUserInput() call,
195              which includes EPSG Projected, Geographic or Compound CRS  (i.e.
196              EPSG:4296),  a well known text (WKT) CRS definition, PROJ.4 dec‐
197              larations, or the name of a .prj file containing a WKT CRS defi‐
198              nition.
199
200       -ct <string>
201              A  PROJ  string  (single  step operation or multiple step string
202              starting with +proj=pipeline), a WKT2 string describing a  Coor‐
203              dinateOperation, or a urn:ogc:def:coordinateOperation:EPSG::XXXX
204              URN overriding the default transformation from the source to the
205              target  CRS.  It  must  take  into account the axis order of the
206              source and target CRS.
207
208              New in version 3.0.
209
210
211       -preserve_fid
212              Use the FID of the source features instead of letting the output
213              driver  automatically assign a new one (for formats that require
214              a FID). If not in append mode, this behavior is the  default  if
215              the output driver has a FID layer creation option, in which case
216              the name of the source FID column will be used and  source  fea‐
217              ture IDs will be attempted to be preserved. This behavior can be
218              disabled by setting -unsetFid.
219
220       -fid fid
221              If provided, only the feature with the specified feature id will
222              be  processed.   Operates  exclusive of the spatial or attribute
223              queries. Note: if you want to select several features  based  on
224              their  feature id, you can also use the fact the 'fid' is a spe‐
225              cial field recognized by OGR SQL. So, -where  "fid  in  (1,3,5)"
226              would select features 1, 3 and 5.
227
228       -limit nb_features
229              Limit the number of features per layer.
230
231       -oo NAME=VALUE
232              Input dataset open option (format specific).
233
234       -doo NAME=VALUE
235              Destination dataset open option (format specific), only valid in
236              -update mode.
237
238       -gt n  Group n features per transaction (default 100 000). Increase the
239              value for better performance when writing into DBMS drivers that
240              have transaction support. n can be set to unlimited to load  the
241              data into a single transaction.
242
243       -ds_transaction
244              Force  the  use of a dataset level transaction (for drivers that
245              support such mechanism), especially for drivers such as  FileGDB
246              that only support dataset level transaction in emulation mode.
247
248       -clipsrc [xmin ymin xmax ymax]|WKT|datasource|spat_extent
249              Clip  geometries  to  the  specified  bounding box (expressed in
250              source SRS), WKT geometry  (POLYGON  or  MULTIPOLYGON),  from  a
251              datasource  or to the spatial extent of the -spa.. option if you
252              use the spat_extent keyword. When specifying a  datasource,  you
253              will  generally  want  to  use it in combination of the -clipsr‐
254              clayer, -clipsrcwhere or -clipsrcsql options
255
256       -clipsrcsql <sql_statement>
257              Select desired geometries using an SQL query instead.
258
259       -clipsrclayer <layername>
260              Select the named layer from the source clip datasource.
261
262       -clipsrcwhere <expression>
263              Restrict desired geometries based on attribute query.
264
265       -clipdst <xmin> <ymin> <xmax> <ymax>
266              Clip geometries after reprojection to the specified bounding box
267              (expressed  in dest SRS), WKT geometry (POLYGON or MULTIPOLYGON)
268              or from a datasource.  When specifying a  datasource,  you  will
269              generally  want  to  use it in combination of the -clipdstlayer,
270              -clipdstwhere or -clipdstsq.. options
271
272       -clipdstsql <sql_statement>
273              Select desired geometries using an SQL query instead.
274
275       -clipdstlayer <layername>
276              Select the named layer from the destination clip datasource.
277
278       -clipdstwhere <expression>
279              Restrict desired geometries based on attribute query.
280
281       -wrapdateline
282              Split geometries crossing the dateline  meridian  (long.  =  +/-
283              180deg)
284
285       -datelineoffset
286              Offset  from dateline in degrees (default long. = +/- 10deg, ge‐
287              ometries within 170deg to -170deg will be split)
288
289       -simplify <tolerance>
290              Distance tolerance for simplification. Note: the algorithm  used
291              preserves topology per feature, in particular for polygon geome‐
292              tries, but not for a whole layer.
293
294       -segmentize <max_dist>
295              Maximum distance between 2 nodes. Used  to  create  intermediate
296              points.
297
298       -makevalid
299              Run the OGRGeometry::MakeValid() operation, followed by OGRGeom‐
300              etryFactory::removeLowerDimensionSubGeoms(),  on  geometries  to
301              ensure they are valid regarding the rules of the Simple Features
302              specification.
303
304       -fieldTypeToString type1,...
305              Converts any field of the specified type  to  a  field  of  type
306              string  in the destination layer. Valid types are : Integer, In‐
307              teger64, Real,  String,  Date,  Time,  DateTime,  Binary,  Inte‐
308              gerList,  Integer64List, RealList, StringList. Special value All
309              can be used to convert all fields to strings.  This is an alter‐
310              nate  way  to using the CAST operator of OGR SQL, that may avoid
311              typing a long SQL query. Note that this does not  influence  the
312              field types used by the source driver, and is only an afterwards
313              conversion.
314
315       -mapFieldType srctype|All=dsttype,...
316              Converts any field of the specified type to another type.  Valid
317              types  are : Integer, Integer64, Real, String, Date, Time, Date‐
318              Time, Binary, IntegerList, Integer64List, RealList,  StringList.
319              Types  can also include subtype between parenthesis, such as In‐
320              teger(Boolean), Real(Float32), ...  Special  value  All  can  be
321              used to convert all fields to another type. This is an alternate
322              way to using the CAST operator of OGR SQL, that may avoid typing
323              a  long  SQL  query.  This  is  a  generalization of -fieldType‐
324              ToString.  Note that this does not  influence  the  field  types
325              used by the source driver, and is only an afterwards conversion.
326
327       -unsetFieldWidth
328              Set field width and precision to 0.
329
330       -splitlistfields
331              Split fields of type StringList, RealList or IntegerList into as
332              many fields of type String, Real or Integer as necessary.
333
334       -maxsubfields <val>
335              To be combined with -splitlistfields to limit the number of sub‐
336              fields created for each split field.
337
338       -explodecollections
339              Produce  one  feature  for each geometry in any kind of geometry
340              collection in the source file, applied after any -sql option.
341
342       -zfield <field_name>
343              Uses the specified field to fill the Z coordinate of geometries.
344
345       -gcp <ungeoref_x> <ungeoref_y> <georef_x> <georef_y> <elevation>
346              Add the indicated ground control point. This option may be  pro‐
347              vided multiple times to provide a set of GCPs.
348
349       -order <n>
350              Order of polynomial used for warping (1 to 3). The default is to
351              select a polynomial order based on the number of GCPs.
352
353       -tps   Force use of thin plate spline transformer  based  on  available
354              GCPs.
355
356       -fieldmap
357              Specifies the list of field indexes to be copied from the source
358              to the destination. The (n)th value specified in the list is the
359              index  of  the field in the target layer definition in which the
360              n(th) field of the source layer  must  be  copied.  Index  count
361              starts  at  zero.  To omit a field, specify a value of -1. There
362              must be exactly as many values in the list as the count  of  the
363              fields in the source layer. We can use the 'identity' setting to
364              specify that the fields should be transferred by using the  same
365              order.   This setting should be used along with the -append set‐
366              ting.
367
368       -addfields
369              This is a specialized version of -append. Contrary  to  -append,
370              -addfields  has the effect of adding, to existing target layers,
371              the new fields found in source layers.  This  option  is  useful
372              when  merging files that have non-strictly identical structures.
373              This might not work for output formats that don't support adding
374              fields  to  existing  non-empty layers. Note that if you plan to
375              use -addfields, you may need to combine it with  -forceNullable,
376              including for the initial import.
377
378       -relaxedFieldNameMatch
379              Do  field name matching between source and existing target layer
380              in a more relaxed way if the target driver has an implementation
381              for it.
382
383       -forceNullable
384              Do  not  propagate  not-nullable  constraints to target layer if
385              they exist in source layer.
386
387       -unsetDefault
388              Do not propagate default field values to target  layer  if  they
389              exist in source layer.
390
391       -unsetFid
392              Can  be  specified  to prevent the name of the source FID column
393              and source feature IDs from being re-used for the target  layer.
394              This  option  can for example be useful if selecting source fea‐
395              tures with a ORDER BY clause.
396
397       -emptyStrAsNull
398              New in version 3.3.
399
400
401              Treat empty string values as null.
402
403       -resolveDomains
404              New in version 3.3.
405
406
407              When this is specified, any selected field that is linked  to  a
408              coded  field  domain  will be accompanied by an additional field
409              ({dstfield}_resolved), that will contain the description of  the
410              coded value.
411
412       -nomd  To  disable  copying  of metadata from source dataset and layers
413              into target dataset and layers, when supported by output driver.
414
415       -mo META-TAG=VALUE
416              Passes a metadata key and value to set on  the  output  dataset,
417              when supported by output driver.
418
419       -noNativeData
420              To disable copying of native data, i.e. details of source format
421              not captured by OGR abstraction, that are otherwise preserved by
422              some drivers (like GeoJSON) when converting to same format.
423
424              New in version 2.1.
425
426

PERFORMANCE HINTS

428       When writing into transactional DBMS (SQLite/PostgreSQL,MySQL, etc...),
429       it might be beneficial to increase the number of INSERT statements exe‐
430       cuted between BEGIN TRANSACTION and COMMIT TRANSACTION statements. This
431       number is specified with the -gt option. For example, for  SQLite,  ex‐
432       plicitly  defining -gt 65536 ensures optimal performance while populat‐
433       ing some table containing many hundreds of  thousands  or  millions  of
434       rows.  However, note that -skipfailures overrides -gt and sets the size
435       of transactions to 1.
436
437       For PostgreSQL, the PG_USE_COPY config option can be set to YES  for  a
438       significant  insertion  performance boost. See the PG driver documenta‐
439       tion page.
440
441       More generally, consult the documentation page of the input and  output
442       drivers for performance hints.
443

C API

445       This utility is also callable from C with GDALVectorTranslate().
446

EXAMPLES

448       Basic conversion from Shapefile to GeoPackage:
449
450          ogr2ogr \
451            -f GPKG output.gpkg \
452            input.shp
453
454       Change the coordinate reference system from EPSG:4326 to EPSG:3857:
455
456          ogr2ogr \
457            -s_srs EPSG:4326 \
458            -t_srs EPSG:3857 \
459            -f GPKG output.gpkg \
460            input.gpkg
461
462       Example  appending to an existing layer (both -update and -append flags
463       need to be used):
464
465          ogr2ogr -update -append -f PostgreSQL PG:dbname=warmerda abc.tab
466
467       Clip input layer with a bounding box (<xmin> <ymin> <xmax> <ymax>):
468
469          ogr2ogr \
470            -spat -13.931 34.886 46.23 74.12 \
471            -f GPKG output.gpkg \
472            natural_earth_vector.gpkg
473
474       Filter Features by a -where clause:
475
476          ogr2ogr \
477            -where "\"POP_EST\" < 1000000" \
478            -f GPKG output.gpkg \
479            natural_earth_vector.gpkg \
480            ne_10m_admin_0_countries
481
482       Example reprojecting from ETRS_1989_LAEA_52N_10E to EPSG:4326 and clip‐
483       ping to a bounding box:
484
485          ogr2ogr -wrapdateline -t_srs EPSG:4326 -clipdst -5 40 15 55 france_4326.shp europe_laea.shp
486
487       Example  for using the -fieldmap setting. The first field of the source
488       layer is used to fill the third field (index 2 = third  field)  of  the
489       target  layer,  the  second  field  of the source layer is ignored, the
490       third field of the source layer used to fill the  fifth  field  of  the
491       target layer.
492
493          ogr2ogr -append -fieldmap 2,-1,4 dst.shp src.shp
494
495       More examples are given in the individual format pages.
496

AUTHOR

498       Frank  Warmerdam  <warmerdam@pobox.com>,  Silke  Reimer  <silke@inteva‐
499       tion.de>
500
502       1998-2021
503
504
505
506
507                                 Sep 07, 2021                       OGR2OGR(1)
Impressum