Update: I did find the referenced stack discussion but the difference here is:

  • my question is referring to transform .XML to geopackage (not .shape to map info)
  • I would like to include the specification of the driver
  • I explicitly ask for storing the files into another folder than the resource folder.

I have successfully converted a .xml file to a geopackage with the following command:

ogr2ogr -f GPKG "path\to\LoD1.gpkg" GMLAS:"path\to\LoD1.xml" -oo REMOVE_UNUSED_FIELDS=YES

However, I somehow cannot make it to work on a full directory. What I would like is transform all files in one folder into geopackages storing it in another folder.

What I tried is:

ogr2ogr -f "GPKG" "path\to\outputfolder" GMLAS:"path\to\inputfolder" -oo REMOVE_UNUSED_FIELDS=YES

But this throws the error:

Unable to open datasource `GMLAS:path\to\inputfolder' with the following drivers. (then a list of all the driver follows, including GMLAS).

What do I need to change on the command?

  • on windows some trickery is required gis.stackexchange.com/a/25376/276
    – Mapperz
    Commented Mar 6 at 15:58
  • The referenced answer I have found before but didn't answer my question. For example, it doesn't answer how to specify the driver. Further, shapefiles are a different format than XML, and, as far as I have seen, it is not specifying a new directory. Therefore I would be glad if the question would be reopened.
    – i.i.k.
    Commented Mar 6 at 19:51
  • 1
    The shapefile driver can read a directory of shapefiles, and then each shapefile in the directory is seen as a separate layer. It is documented gdal.org/drivers/vector/shapefile.html "Normally the OGR Shapefile driver treats a whole directory of shapefiles as a dataset, and a single shapefile within that directory as a layer. In this case the directory name should be used as the dataset name." GML driver does not behave like this,
    – user30184
    Commented Mar 8 at 14:34

1 Answer 1


This question does not deal with GIS really. It is about generic computing and how to run a command line program in a FOR loop.

If you have input GML files in a directory c:\data\gml1 and you want to store the GeoPackages into directory c:\data\gml2\ run something like this:

for %f in (c:\data\gml1\*.gml) do ogr2ogr -f gpkg "c:\data\gml2\%~nf.gpkg" "GMLAS:%f"
  • Reads the filenames from the input directory into variable %f
  • Opens one by one the file %f with the GMLAS: driver
  • Uses -gpkg driver for output
  • Stores the output into the output directory, uses the "name" part of the input file name together with .gpkg extension
  • Thank you very much! You are right that this is more a question on how to use the command line in Windows, I wasn't aware of it. I still think, this question will help others who want to work with ogr2ogr. Unfortunately I am not able to run it, and I think I have a problem with the paths , as they have spaces, - , : , and German signs (like ä)). I will need to dig here deeper what it is with the paths
    – i.i.k.
    Commented Mar 11 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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