6

I have a very large GDB file with about 5000 polygon features, several GB in size, that takes a very long time to load into memory. I want to reduce the number of polygons to something I can work with more easily. The polygons have an attribute SCINAME and I have a .csv file with a list of a few hundred SCINAMEs. How can I construct a call to ogr2ogr to create a new .shp file that is a subset of the original GDB only including the polygons that have a SCINAME found in my .csv file? Or is there a better command-line way to do it?

Edit: I made a shell script with a while loop to do this, but it is running extremely slowly. Please take a look and see why it might be so slow.

while read line; do
    echo $line
    ogr2ogr -append -where SCINAME="'$line'" -f "ESRI Shapefile" ./output input.gdb/ "Feature_class_name"
done < scinames.txt

1 Answer 1

5

I solved this by creating a text file with all the names separated by commas, then got what I wanted with a single ogr2ogr call.

The contents of the text file (single line) look like:

'Abeillia abeillei','Acanthidops bairdi','Acanthis flammea',
'Accipiter bicolor','Accipiter cooperii' ... and so on

The subset is created with this code:

scinamestring=$(cat scinames.txt)
ogr2ogr -f "ESRI Shapefile" -sql "SELECT * FROM Feature_class_name WHERE SCINAME IN ($scinamestring)" ./output input.gdb/ 
5
  • Hi I am doing the same thing. But I am a bit confused - what does "Feature_class_name" mean here? I am getting this error ERROR 1: SELECT from table Feature_class_name failed, no such table/featureclass
    – rm167
    Commented Feb 10, 2022 at 16:00
  • 1
    I think maybe the Feature_class_name was something specific to the .gdb file I was working with... you might need to replace it with a different name? Not sure as it's been a while.
    – qdread
    Commented Feb 10, 2022 at 16:03
  • Okay. It's the name of the selected layer. Just one more question. I am getting an error with ./output. I was wondering how does the dynamic naming of the output shapefiles works without any dynamic variable in this argument?
    – rm167
    Commented Feb 10, 2022 at 22:49
  • I guess try replacing output with the desired name of your shapefile, with shp extension?
    – qdread
    Commented Feb 11, 2022 at 1:47
  • @rm167 I am assuming this answered the question? gis.stackexchange.com/questions/423552/…
    – qdread
    Commented Mar 1, 2022 at 18:52

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.