Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a folder of GML files that I want to be able to merge to create one GML file that I can then view.

I have tried this using the code described but substuting for GML in this website but to no avail.

http://darrencope.com/2010/05/07/merge-a-directory-of-shapefiles-using-ogr/

The code I used was:

    mkdir merged 
    for %f in (*.gml) do (
    if not exist merged\merged.gml (
    ogr2ogr -f "GML" merged\merged.gml %f) 
    else (
    ogr2ogr -f "GML" -update -append merged\merged.gml %f -nln Merged )
    )

For clarity the files are for the OS mastermap topography data.

Forgot to say I get the following error message several times when I run the code.

C:\OSMM_GMLS>(if not exist merged\merged.gml (ogr2ogr -f "GML" merged\merged.gml M00001177-SX6590-5c296.gml ) else (ogr2ogr -f "GML" -update -append merged\mer ged.gml M00001177-SX6590-5c296.gml -nln Merged ) ) FAILURE: Unable to open existing output datasource `merged\merged.gml'.

share|improve this question
1  
Could you say what happens? OGR should tell you if it's unhappy. –  MerseyViking Jul 26 '12 at 11:59
    
Add the error message now. Sorry about that. –  Matt T Jul 26 '12 at 13:12
    
Matt T: does the merged directory get created? Is there a file in it? –  Darren Cope Jul 26 '12 at 15:50
    
@DarrenCope Matt's responded, but it's in one of the questions below as a comment. –  SaultDon Jul 26 '12 at 20:01

3 Answers 3

up vote 1 down vote accepted

I think I found the answer. The suggested solution (on my website) works great for shapefiles. However, .gml is a bit different, and according to this page, GML does not support the 'update' function. See the first line on that page:

OGR has limited support for GML reading and writing. Update of existing files is not supported.

Shaunak's solution may be best; convert to another format. You could always convert that back to GML when you are done.

share|improve this answer

I wonder if your error is in part beacause -nln Merged may not be a valid layer in the GML file.

Run ogrinfo -ro -so input.gml to see what the layer name(s) are.

Example:

C:\Users\username\Downloads>ogrinfo -ro -so 001l11_5_0.gml
INFO: Open of `001l11_5_0.gml'
      using driver `GML' successful.
1: TR_1750009_1 (Multi Line String)
2: LI_1210009_2 (Multi Polygon)

So in the case of merging several of the above gmls, I would try to use an existing layername, either option 1 ("TR_1750009_1") or 2 ("LI_1210009_2").

share|improve this answer

Because you have not specified the error, I am presenting a alternate approach which may work for you. The blog post you have mentioned in question works on shapefiles. Why not try converting gml to shapefiles, then merge and then write back the gml? here is the tool:

http://www.gdal.org/ogr2ogr.html

share|improve this answer
    
Darren: The folder does get created and there is a gml file created. When I view this in QGIS though it only displays as one the original singular gmls not as a merged version of the original six in the directory. –  Matt T Jul 26 '12 at 15:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.