To address this issue,
ogr2ogr command line does not provide out of the box function to quickly create multiple output (for each layer) for the input file.
I came up with a solution (using PHP in my case) which is split in 2 steps :
ogrinfo to get all the layers
- Retrieve all the layer, and for each layer use
I first launch
ogrinfo plan.dxf -sql "SELECT DISTINCT Layer FROM entities" (all my dxf files begin with
entities element wrapper). You will need to extract only the name of the layers (in php, for each lines, I used the following regex :
u flag because sometimes my layers names can contain accents).
Then, once I have my array of layers, for each layers I apply this command :
ogr2ogr -f "KML" <layer_name>-fond.kml fond.dxf -s_srs EPSG:27562 EPSG:4326 -where "Layer='<layer_name>'", with
<layer_name> to be replaced by the name of the current layer name in your loop.
To inject the layer name, I used PHP string injection :
exec("ogr2ogr -f \"KML\" $layerName-fond.kml fond.dxf -s_srs EPSG:27562 -t_srs EPSG:4326 -where \"Layer='$layerName'\"");