[gdal-dev] Proposed ogrmerge.py utility script

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[gdal-dev] Proposed ogrmerge.py utility script

Even Rouault-2

Hi,

 

I've worked on a script to merge several OGR datasources into a single one.

Nothing that can't be done with ogr2ogr with some loops around, but I think this can be convenient.

 

There are basically 2 modes :

- Default one: each layer of each source datasource is written as a separate

layer in the target datasource.

- 'Single' mode: all layers from all source datasources are written into a single

layer in the target datasource. This assumes that the schemas of those source

layers are more or less compatible.

 

I've not yet committed the script. You can grab it from

https://gist.github.com/rouault/3b49bffd67fb18e23cd4c5bcc10d3103

 

Short usage:

 

ogrmerge.py -o out_dsname src_dsname [src_dsname]*

[-f format] [-single] [-nln layer_name_template]

[-update | -overwrite_ds] [-append | -overwrite_lyr]

[-src_geom_type geom_type_name[,geom_type_name]*]

[-dsco NAME=VALUE]* [-lco NAME=VALUE]*

[-s_srs srs_def] [-t_srs srs_def | -a_srs srs_def]

[-progress] [-skip] [--help-general]

 

Options specific to -single:

[-field_strategy FirstLayer|Union|Intersection]

[-src_layer_field_name name]

[-src_layer_field_content layer_name_template]

 

* layer_name_template can contain the following substituable variables:

{AUTO_NAME} : {DS_BASENAME}_{LAYER_NAME} if they are different

or {LAYER_NAME} if they are identical

{DS_NAME} : name of the source dataset

{DS_BASENAME}: base name of the source dataset

{DS_INDEX} : index of the source dataset

{LAYER_NAME} : name of the source layer

{LAYER_IDX} : index of the source layer

 

 

Examples:

 

* ogrmerge.py -f VRT -o merged.vrt *.shp

 

Creates a VRT with a layer for each input shapefiles

 

* ogrmerge.py -f GPKG -o merged.gpkg *.shp

 

Same, but creates a GeoPackage file

 

* ogrmerge.py -single -o merged.shp france.shp germany.shp -src_layer_field_name country

 

Concatenate the content of france.shp and germany.shp in merged.shp, and adds a 'country'

field to each feature whose value is 'france' or 'germany' depending where it comes from

 

 

Internally this generates a VRT file, and if the output format is not VRT,

final translation is done with ogr2ogr / gdal.VectorTranslate. So for advanced uses, output

to VRT, potential manual editing of it and ogr2ogr can be done.

 

Opinions on script naming (I also tought to ogrcat.py to reflect the similarity with the Unix cat

utility used to concatenate files), option naming, etc.. are welcome

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [gdal-dev] Proposed ogrmerge.py utility script

jratike80
Even Rouault-2 wrote
Opinions on script naming (I also tought to ogrcat.py to reflect the similarity with the Unix cat
utility used to concatenate files), option naming, etc.. are welcome
Hi,

ogrmerge.py is good name for the script.
I would rename  -overwrite_lyr into -overwrite_layer. It pays only two letters, "layer" is already used in other parameters, and users would understand with less thinking what it means.

-Jukka Rahkonen-
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Proposed ogrmerge.py utility script

Even Rouault-2

On samedi 4 mars 2017 04:42:54 CET jratike80 wrote:

> Even Rouault-2 wrote

>

> > Opinions on script naming (I also tought to ogrcat.py to reflect the

> > similarity with the Unix cat

> > utility used to concatenate files), option naming, etc.. are welcome

>

> Hi,

>

> ogrmerge.py is good name for the script.

> I would rename -overwrite_lyr into -overwrite_layer. It pays only two

> letters, "layer" is already used in other parameters, and users would

> understand with less thinking what it means.

 

 

Committed into trunk with your remark taken into account.

https://svn.osgeo.org/gdal/trunk/gdal/swig/python/scripts/ogrmerge.py

 

Note: it can be used with GDAL 2.1 as well.

 

Online help page at :

http://gdal.org/ogrmerge.html

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Loading...