1ogr2ogr(1)                  General Commands Manual                 ogr2ogr(1)
2
3
4

NAME

6       ogr2ogrConverts simple features data between file formats.
7

SYNOPSIS

9       Usage: 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                      [-addfields] [-unsetFid]
33                      [-relaxedFieldNameMatch] [-forceNullable] [-unsetDefault]
34                      [-fieldTypeToString All|(type1[,type2]*)] [-unsetFieldWidth]
35                      [-mapFieldType type1|All=type2[,type3=type4]*]
36                      [-fieldmap identity | index1[,index2]*]
37                      [-splitlistfields] [-maxsubfields val]
38                      [-explodecollections] [-zfield field_name]
39                      [-gcp ungeoref_x ungeoref_y georef_x georef_y [elevation]]* [-order n | -tps]
40                      [-nomd] [-mo "META-TAG=VALUE"]* [-noNativeData].fi
41

DESCRIPTION

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

PERFORMANCE HINTS

392       When writing into transactional DBMS (SQLite/PostgreSQL,MySQL, etc...),
393       it might be beneficial to increase the number of INSERT statements
394       executed between BEGIN TRANSACTION and COMMIT TRANSACTION statements.
395       This number is specified with the -gt option. For example, for SQLite,
396       explicitly defining -gt 65536 ensures optimal performance while
397       populating some table containing many hundreds of thousands or millions
398       of rows. However, note that -skipfailures overrides -gt and sets the
399       size of transactions to 1.
400
401       For PostgreSQL, the PG_USE_COPY config option can be set to YES for a
402       significant insertion performance boost. See the PG driver
403       documentation page.
404
405       More generally, consult the documentation page of the input and output
406       drivers for performance hints.
407

C API

409       Starting with GDAL 2.1, this utility is also callable from C with
410       GDALVectorTranslate().
411

EXAMPLE

413       Example appending to an existing layer (both flags need to be used):
414
415       % ogr2ogr -update -append -f PostgreSQL PG:dbname=warmerda abc.tab
416
417       Example reprojecting from ETRS_1989_LAEA_52N_10E to EPSG:4326 and
418       clipping to a bounding box
419
420       % ogr2ogr -wrapdateline -t_srs EPSG:4326 -clipdst -5 40 15 55 france_4326.shp europe_laea.shp
421
422       Example for using the -fieldmap setting. The first field of the source
423       layer is used to fill the third field (index 2 = third field) of the
424       target layer, the second field of the source layer is ignored, the
425       third field of the source layer used to fill the fifth field of the
426       target layer.
427
428       % ogr2ogr -append -fieldmap 2,-1,4 dst.shp src.shp
429
430       More examples are given in the individual format pages.
431

AUTHOR

433       Frank Warmerdam warmerdam@pobox.com, Silke Reimer silke@intevation.de
434
435
436
437GDAL                            Tue Mar 3 2020                      ogr2ogr(1)
Impressum