I have a quite many feature classes in a filegdb and they all have same data schema (same field names and etc).

I wanted to apply a single sqlite query and I am having hard time to make a loop command

ogr2ogr -f "filegdb" -a_srs epsg:3857 -dialect sqlite -sql "select scalecoords(geometry,0.0000000002), field1, field2, field3 from "FEATURE_CLASSES_WITHIN_A_FILEGDB" "inputGDB_Dir" "outputGDB_Dir"

what I did was simply applying

For /R %g in (inputGDB_Dir) do ogr2ogr -f "filegdb" -a_srs epsg:3857 -dialect sqlite -sql "select scalecoords(geometry,0.0000000002), field1, field2, field3" "inputGDB_Dir %g" "outputGDB_Dir"

and obviously, it does not work. I would like to know how to make a loop command using OGR2OGR

  • Assuming your units are degrees, you're scaling your coordinates to twenty nanometers. If the value is applied to SRID, then you're scaling to subatomic precision (in Mercator, which is unreliable for distance even at kilometer scale).
    – Vince
    May 8, 2018 at 12:30
  • You should get what you want by using UNION in your SQL sqlitetutorial.net/sqlite-union. It may be somehow tricky to create the complete SQL with a script, though. It could be easier to make a script that runs ogr2ogr with -update and -update and -nln for each layer in your filegdb. The -nln parameter will be the same all the time for making that layer to gather all the data.
    – user30184
    May 8, 2018 at 21:01

1 Answer 1


You can load your filegdb to python and then you can do something like this

import sys
for g in inputGDB:
    sys.call(Your shell command goes here)

By using sys.call() can execute your shell commands through python. As for loading filegdb to python you can use python libraries like fiona and ogr have a look and them.

  • Can I use OGR2OGR command without using Python? Python seemed to be slower than just simple OGR2OGR command in Windows shell
    – Pil Kwon
    May 8, 2018 at 9:05
  • Yes you can do it using batch file, I never done this myself but you can refer stackoverflow.com/questions/2591758/batch-script-loop to get started with loops in batch script. Hope this answers your question
    – Asad Abbas
    May 8, 2018 at 15:45

Your Answer

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

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