3

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
2

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/ 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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