1OGR2OGR(1) GDAL OGR2OGR(1)
2
3
4
6 ogr2ogr - Converts simple features data between file formats.
7
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 [[-s_coord_epoch epoch] | [-t_coord_epoch epoch] | [-a_coord_epoch epoch]]
43 [-nomd] [-mo "META-TAG=VALUE"]* [-noNativeData]
44
46 ogr2ogr can be used to convert simple features data between file for‐
47 mats. It can also perform various operations during the process, such
48 as spatial or attribute selection, reducing the set of attributes, set‐
49 ting the output coordinate system or even reprojecting the features
50 during translation.
51
52 -f <format_name>
53 Output file format name, e.g. ESRI Shapefile, MapInfo File,
54 PostgreSQL. Starting with GDAL 2.3, if not specified, the for‐
55 mat is guessed from the extension (previously was ESRI Shape‐
56 file).
57
58 -append
59 Append to existing layer instead of creating new
60
61 -overwrite
62 Delete the output layer and recreate it empty
63
64 -update
65 Open existing output datasource in update mode rather than try‐
66 ing to create a new one
67
68 -select <field_list>
69 Comma-delimited list of fields from input layer to copy to the
70 new layer. A field is skipped if mentioned previously in the
71 list even if the input layer has duplicate field names. (De‐
72 faults to all; any field is skipped if a subsequent field with
73 same name is found.) Geometry fields can also be specified in
74 the list.
75
76 Note this setting cannot be used together with -append. To con‐
77 trol the selection of fields when appending to a layer, use
78 -fieldmap or -sql.
79
80 -progress
81 Display progress on terminal. Only works if input layers have
82 the "fast feature count" capability.
83
84 -sql <sql_statement>
85 SQL statement to execute. The resulting table/layer will be
86 saved to the output. Starting with GDAL 2.1, the @filename syn‐
87 tax can be used to indicate that the content is in the pointed
88 filename.
89
90 -dialect <dialect>
91 SQL dialect. In some cases can be used to use (unoptimized) OGR
92 SQL dialect instead of the native SQL of an RDBMS by passing the
93 OGRSQL dialect value. The SQL SQLite dialect dialect can be se‐
94 lect with the SQLITE and INDIRECT_SQLITE dialect values, and
95 this can be used with any 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
100 the 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 in‐
108 tersects the extents will be selected. The geometries will not
109 be clipped unless -clipsrc is specified.
110
111 -spat_srs <srs_def>
112 Override spatial filter SRS.
113
114 -geomfield <field>
115 Name of the geometry field on which the spatial filter operates
116 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, GE‐
129 OMETRY, POINT, LINESTRING, POLYGON, GEOMETRYCOLLECTION, MULTI‐
130 POINT, MULTIPOLYGON, MULTILINESTRING, CIRCULARSTRING, COMPOUND‐
131 CURVE, CURVEPOLYGON, MULTICURVE, and MULTISURFACE non-linear ge‐
132 ometry types. Add Z, M, or ZM to the type name to specify coor‐
133 dinates with elevation, measure, or elevation and measure. PRO‐
134 MOTE_TO_MULTI can be used to automatically promote layers that
135 mix polygon or multipolygons to multipolygons, and layers that
136 mix linestrings or multilinestrings to multilinestrings. Can be
137 useful when converting shapefiles to PostGIS and other target
138 drivers that implement strict checks for geometry types. CON‐
139 VERT_TO_LINEAR can be used to to convert non-linear geometry
140 types into linear geometry types by approximating them, and CON‐
141 VERT_TO_CURVE to promote a non-linear type to its generalized
142 curve type (POLYGON to CURVEPOLYGON, MULTIPOLYGON to MULTISUR‐
143 FACE, LINESTRING to COMPOUNDCURVE, MULTILINESTRING to MULTIC‐
144 URVE). Starting with version 2.1 the type can be defined as mea‐
145 sured ("25D" remains as an alias for single "Z"). Some forced
146 geometry conversions may result in invalid geometries, for exam‐
147 ple when forcing conversion of multi-part multipolygons with
148 -nlt POLYGON, the resulting polygon will break the Simple Fea‐
149 tures rules.
150
151 Starting with GDAL 3.0.5, -nlt CONVERT_TO_LINEAR and -nlt PRO‐
152 MOTE_TO_MULTI can be used simultaneously.
153
154 -dim <val>
155 Force the coordinate dimension to val (valid values are XY, XYZ,
156 XYM, and XYZM - for backwards compatibility 2 is an alias for XY
157 and 3 is an alias for XYZ). This affects both the layer geometry
158 type, and feature geometries. The value can be set to layer_dim
159 to instruct feature geometries to be promoted to the coordinate
160 dimension declared by the layer. Support for M was added in GDAL
161 2.1.
162
163 -a_srs <srs_def>
164 Assign an output SRS, but without reprojecting (use -t_srs to
165 reproject)
166
167 The coordinate reference systems that can be passed are anything
168 supported by the OGRSpatialReference.SetFromUserInput() call,
169 which includes EPSG Projected, Geographic or Compound CRS (i.e.
170 EPSG:4296), a well known text (WKT) CRS definition, PROJ.4 dec‐
171 larations, or the name of a .prj file containing a WKT CRS defi‐
172 nition.
173
174 -a_coord_epoch <epoch>
175 New in version 3.4.
176
177
178 Assign a coordinate epoch, linked with the output SRS. Useful
179 when the output SRS is a dynamic CRS. Only taken into account if
180 -a_srs is used.
181
182 -t_srs <srs_def>
183 Reproject/transform to this SRS on output, and assign it as out‐
184 put SRS.
185
186 A source SRS must be available for reprojection to occur. The
187 source SRS will be by default the one found in the source layer
188 when it is available, or as overridden by the user with -s_srs
189
190 The coordinate reference systems that can be passed are anything
191 supported by the OGRSpatialReference.SetFromUserInput() call,
192 which includes EPSG Projected, Geographic or Compound CRS (i.e.
193 EPSG:4296), a well known text (WKT) CRS definition, PROJ.4 dec‐
194 larations, or the name of a .prj file containing a WKT CRS defi‐
195 nition.
196
197 -t_coord_epoch <epoch>
198 New in version 3.4.
199
200
201 Assign a coordinate epoch, linked with the output SRS. Useful
202 when the output SRS is a dynamic CRS. Only taken into account if
203 -t_srs is used. It is also mutually exclusive with
204 -a_coord_epoch.
205
206 Currently -s_coord_epoch and -t_coord_epoch are mutually exclu‐
207 sive, due to lack of support for transformations between two dy‐
208 namic CRS.
209
210 -s_srs <srs_def>
211 Override source SRS. If not specified the SRS found in the input
212 layer will be used. This option has only an effect if used to‐
213 gether with -t_srs to reproject.
214
215 The coordinate reference systems that can be passed are anything
216 supported by the OGRSpatialReference.SetFromUserInput() call,
217 which includes EPSG Projected, Geographic or Compound CRS (i.e.
218 EPSG:4296), a well known text (WKT) CRS definition, PROJ.4 dec‐
219 larations, or the name of a .prj file containing a WKT CRS defi‐
220 nition.
221
222 -s_coord_epoch <epoch>
223 New in version 3.4.
224
225
226 Assign a coordinate epoch, linked with the source SRS. Useful
227 when the source SRS is a dynamic CRS. Only taken into account if
228 -s_srs is used.
229
230 Currently -s_coord_epoch and -t_coord_epoch are mutually exclu‐
231 sive, due to lack of support for transformations between two dy‐
232 namic CRS.
233
234 -ct <string>
235 A PROJ string (single step operation or multiple step string
236 starting with +proj=pipeline), a WKT2 string describing a Coor‐
237 dinateOperation, or a urn:ogc:def:coordinateOperation:EPSG::XXXX
238 URN overriding the default transformation from the source to the
239 target CRS. It must take into account the axis order of the
240 source and target CRS.
241
242 New in version 3.0.
243
244
245 -preserve_fid
246 Use the FID of the source features instead of letting the output
247 driver automatically assign a new one (for formats that require
248 a FID). If not in append mode, this behavior is the default if
249 the output driver has a FID layer creation option, in which case
250 the name of the source FID column will be used and source fea‐
251 ture IDs will be attempted to be preserved. This behavior can be
252 disabled by setting -unsetFid.
253
254 -fid fid
255 If provided, only the feature with the specified feature id will
256 be processed. Operates exclusive of the spatial or attribute
257 queries. Note: if you want to select several features based on
258 their feature id, you can also use the fact the 'fid' is a spe‐
259 cial field recognized by OGR SQL. So, -where "fid in (1,3,5)"
260 would select features 1, 3 and 5.
261
262 -limit nb_features
263 Limit the number of features per layer.
264
265 -oo NAME=VALUE
266 Input dataset open option (format specific).
267
268 -doo NAME=VALUE
269 Destination dataset open option (format specific), only valid in
270 -update mode.
271
272 -gt n Group n features per transaction (default 100 000). Increase the
273 value for better performance when writing into DBMS drivers that
274 have transaction support. n can be set to unlimited to load the
275 data into a single transaction.
276
277 -ds_transaction
278 Force the use of a dataset level transaction (for drivers that
279 support such mechanism), especially for drivers such as FileGDB
280 that only support dataset level transaction in emulation mode.
281
282 -clipsrc [xmin ymin xmax ymax]|WKT|datasource|spat_extent
283 Clip geometries to the specified bounding box (expressed in
284 source SRS), WKT geometry (POLYGON or MULTIPOLYGON), from a
285 datasource or to the spatial extent of the -spat option if you
286 use the spat_extent keyword. When specifying a datasource, you
287 will generally want to use it in combination of the -clipsr‐
288 clayer, -clipsrcwhere or -clipsrcsql options
289
290 -clipsrcsql <sql_statement>
291 Select desired geometries using an SQL query instead.
292
293 -clipsrclayer <layername>
294 Select the named layer from the source clip datasource.
295
296 -clipsrcwhere <expression>
297 Restrict desired geometries based on attribute query.
298
299 -clipdst <xmin> <ymin> <xmax> <ymax>
300 Clip geometries after reprojection to the specified bounding box
301 (expressed in dest SRS), WKT geometry (POLYGON or MULTIPOLYGON)
302 or from a datasource. When specifying a datasource, you will
303 generally want to use it in combination of the -clipdstlayer,
304 -clipdstwhere or -clipdstsql options
305
306 -clipdstsql <sql_statement>
307 Select desired geometries using an SQL query instead.
308
309 -clipdstlayer <layername>
310 Select the named layer from the destination clip datasource.
311
312 -clipdstwhere <expression>
313 Restrict desired geometries based on attribute query.
314
315 -wrapdateline
316 Split geometries crossing the dateline meridian (long. = +/-
317 180deg)
318
319 -datelineoffset
320 Offset from dateline in degrees (default long. = +/- 10deg, ge‐
321 ometries within 170deg to -170deg will be split)
322
323 -simplify <tolerance>
324 Distance tolerance for simplification. Note: the algorithm used
325 preserves topology per feature, in particular for polygon geome‐
326 tries, but not for a whole layer.
327
328 -segmentize <max_dist>
329 Maximum distance between 2 nodes. Used to create intermediate
330 points.
331
332 -makevalid
333 Run the OGRGeometry::MakeValid() operation, followed by
334 OGRGeometryFactory::removeLowerDimensionSubGeoms(), on geome‐
335 tries to ensure they are valid regarding the rules of the Simple
336 Features specification.
337
338 -fieldTypeToString type1,...
339 Converts any field of the specified type to a field of type
340 string in the destination layer. Valid types are : Integer, In‐
341 teger64, Real, String, Date, Time, DateTime, Binary, Inte‐
342 gerList, Integer64List, RealList, StringList. Special value All
343 can be used to convert all fields to strings. This is an alter‐
344 nate way to using the CAST operator of OGR SQL, that may avoid
345 typing a long SQL query. Note that this does not influence the
346 field types used by the source driver, and is only an afterwards
347 conversion.
348
349 -mapFieldType srctype|All=dsttype,...
350 Converts any field of the specified type to another type. Valid
351 types are : Integer, Integer64, Real, String, Date, Time, Date‐
352 Time, Binary, IntegerList, Integer64List, RealList, StringList.
353 Types can also include subtype between parenthesis, such as In‐
354 teger(Boolean), Real(Float32), ... Special value All can be
355 used to convert all fields to another type. This is an alternate
356 way to using the CAST operator of OGR SQL, that may avoid typing
357 a long SQL query. This is a generalization of -fieldType‐
358 ToString. Note that this does not influence the field types
359 used by the source driver, and is only an afterwards conversion.
360
361 -unsetFieldWidth
362 Set field width and precision to 0.
363
364 -splitlistfields
365 Split fields of type StringList, RealList or IntegerList into as
366 many fields of type String, Real or Integer as necessary.
367
368 -maxsubfields <val>
369 To be combined with -splitlistfields to limit the number of sub‐
370 fields created for each split field.
371
372 -explodecollections
373 Produce one feature for each geometry in any kind of geometry
374 collection in the source file, applied after any -sql option.
375
376 -zfield <field_name>
377 Uses the specified field to fill the Z coordinate of geometries.
378
379 -gcp <ungeoref_x> <ungeoref_y> <georef_x> <georef_y> <elevation>
380 Add the indicated ground control point. This option may be pro‐
381 vided multiple times to provide a set of GCPs.
382
383 -order <n>
384 Order of polynomial used for warping (1 to 3). The default is to
385 select a polynomial order based on the number of GCPs.
386
387 -tps Force use of thin plate spline transformer based on available
388 GCPs.
389
390 -fieldmap
391 Specifies the list of field indexes to be copied from the source
392 to the destination. The (n)th value specified in the list is the
393 index of the field in the target layer definition in which the
394 n(th) field of the source layer must be copied. Index count
395 starts at zero. To omit a field, specify a value of -1. There
396 must be exactly as many values in the list as the count of the
397 fields in the source layer. We can use the 'identity' setting to
398 specify that the fields should be transferred by using the same
399 order. This setting should be used along with the -append set‐
400 ting.
401
402 -addfields
403 This is a specialized version of -append. Contrary to -append,
404 -addfields has the effect of adding, to existing target layers,
405 the new fields found in source layers. This option is useful
406 when merging files that have non-strictly identical structures.
407 This might not work for output formats that don't support adding
408 fields to existing non-empty layers. Note that if you plan to
409 use -addfields, you may need to combine it with -forceNullable,
410 including for the initial import.
411
412 -relaxedFieldNameMatch
413 Do field name matching between source and existing target layer
414 in a more relaxed way if the target driver has an implementation
415 for it.
416
417 -forceNullable
418 Do not propagate not-nullable constraints to target layer if
419 they exist in source layer.
420
421 -unsetDefault
422 Do not propagate default field values to target layer if they
423 exist in source layer.
424
425 -unsetFid
426 Can be specified to prevent the name of the source FID column
427 and source feature IDs from being re-used for the target layer.
428 This option can for example be useful if selecting source fea‐
429 tures with a ORDER BY clause.
430
431 -emptyStrAsNull
432 New in version 3.3.
433
434
435 Treat empty string values as null.
436
437 -resolveDomains
438 New in version 3.3.
439
440
441 When this is specified, any selected field that is linked to a
442 coded field domain will be accompanied by an additional field
443 ({dstfield}_resolved), that will contain the description of the
444 coded value.
445
446 -nomd To disable copying of metadata from source dataset and layers
447 into target dataset and layers, when supported by output driver.
448
449 -mo META-TAG=VALUE
450 Passes a metadata key and value to set on the output dataset,
451 when supported by output driver.
452
453 -noNativeData
454 To disable copying of native data, i.e. details of source format
455 not captured by OGR abstraction, that are otherwise preserved by
456 some drivers (like GeoJSON) when converting to same format.
457
458 New in version 2.1.
459
460
462 When writing into transactional DBMS (SQLite/PostgreSQL,MySQL, etc...),
463 it might be beneficial to increase the number of INSERT statements exe‐
464 cuted between BEGIN TRANSACTION and COMMIT TRANSACTION statements. This
465 number is specified with the -gt option. For example, for SQLite, ex‐
466 plicitly defining -gt 65536 ensures optimal performance while populat‐
467 ing some table containing many hundreds of thousands or millions of
468 rows. However, note that -skipfailures overrides -gt and sets the size
469 of transactions to 1.
470
471 For PostgreSQL, the PG_USE_COPY config option can be set to YES for a
472 significant insertion performance boost. See the PG driver documenta‐
473 tion page.
474
475 More generally, consult the documentation page of the input and output
476 drivers for performance hints.
477
479 This utility is also callable from C with GDALVectorTranslate().
480
482 Basic conversion from Shapefile to GeoPackage:
483
484 ogr2ogr \
485 -f GPKG output.gpkg \
486 input.shp
487
488 Change the coordinate reference system from EPSG:4326 to EPSG:3857:
489
490 ogr2ogr \
491 -s_srs EPSG:4326 \
492 -t_srs EPSG:3857 \
493 -f GPKG output.gpkg \
494 input.gpkg
495
496 Example appending to an existing layer (both -update and -append flags
497 need to be used):
498
499 ogr2ogr -update -append -f PostgreSQL PG:dbname=warmerda abc.tab
500
501 Clip input layer with a bounding box (<xmin> <ymin> <xmax> <ymax>):
502
503 ogr2ogr \
504 -spat -13.931 34.886 46.23 74.12 \
505 -f GPKG output.gpkg \
506 natural_earth_vector.gpkg
507
508 Filter Features by a -where clause:
509
510 ogr2ogr \
511 -where "\"POP_EST\" < 1000000" \
512 -f GPKG output.gpkg \
513 natural_earth_vector.gpkg \
514 ne_10m_admin_0_countries
515
516 Example reprojecting from ETRS_1989_LAEA_52N_10E to EPSG:4326 and clip‐
517 ping to a bounding box:
518
519 ogr2ogr -wrapdateline -t_srs EPSG:4326 -clipdst -5 40 15 55 france_4326.shp europe_laea.shp
520
521 Example for using the -fieldmap setting. The first field of the source
522 layer is used to fill the third field (index 2 = third field) of the
523 target layer, the second field of the source layer is ignored, the
524 third field of the source layer used to fill the fifth field of the
525 target layer.
526
527 ogr2ogr -append -fieldmap 2,-1,4 dst.shp src.shp
528
529 More examples are given in the individual format pages.
530
532 Frank Warmerdam <warmerdam@pobox.com>, Silke Reimer <silke@inteva‐
533 tion.de>
534
536 1998-2022
537
538
539
540
541 Sep 02, 2022 OGR2OGR(1)