Created
March 12, 2018 06:18
-
-
Save joakimsk/4dd653eac28a2d7eee008ad7578a6e3f to your computer and use it in GitHub Desktop.
Get layers from DXF files using ogrinfo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# sh-ogrgetlayers.sh | |
# -i input DXF file | |
# Output all dxf files and their layers to layers.csv. Layers in array format ['a','b'] | |
# | |
# To execute in batch mode: | |
# find . -iname "*.dxf" -print0 | xargs -0 -I {} ./sh-ogrgetlayers.sh -i "{}" | |
# | |
# Requires ogrinfo, uses sed and grep, tested on OS X 10.13.3 | |
# By Joakim Skjefstad | |
while getopts ":i:" opt; do | |
case $opt in | |
i) | |
echo "-i was triggered, Parameter: $OPTARG" >&2 | |
FILENAME=${OPTARG##*/} | |
PATHNAME=`dirname "$OPTARG"` | |
FILE=${FILENAME%.*} | |
echo "Working on $PATHNAME/$FILENAME" | |
LAYERS=$(ogrinfo "$OPTARG" -dialect SQLITE -sql "SELECT group_concat(DISTINCT layer) AS layers FROM entities ORDER BY layer ASC" | grep 'layers (String)' | sed 's/.*= //' | sed s/,/\',\'/g | sed s/^/[\'/ | sed s/$/\']/) | |
echo "$FILENAME,$LAYERS" >> layers.csv | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment