[Qgis-developer] Vector equivalent of a VRT - Linux bash script
Zoltan Szecsei
zoltans at geograph.co.za
Sun Oct 26 08:11:00 PDT 2014
On 2014/10/24 18:49, Andre Joost wrote:
>
> +100 from me if you promise to build a QGIS plugin for the purpose ;-)
>
Right.... with a little help on the VRT syntax, from Even, this script
will create you a vrt file (ie: in a simple case, 'ogrbuildvrt' :-) )
#!/bin/bash
#
# Bash script to generate a VRT for SHP files
#
# Author: Zoltan Szecsei zoltans at geograph.co.za
# Date: 26 October 2014
#
# Notes:
# 'find' is used instead of 'ls -1' as find descends nicely into
subdirectories
# WLC is the wildcard for 'find' to find the shapefiles you want
# DIR is the parent directory, above the shapefiles you want to
add into this VRT
# NAM is the name you want to see in your QGIS 'Legend' sidebar
# VRT is the me of the vrt file that will (must) be
#
#
WLC="*build*point*.shp"
DIR="."
NAM="MyVRT"
VRT="${DIR}/${NAM}.vrt"
echo "<OGRVRTDataSource>" > $VRT
echo " <OGRVRTUnionLayer name=\"${NAM}\">" >> $VRT
for shp in `find $DIR -iname $WLC`
do
lay="`ogrinfo -al -so $shp | grep -i "layer name:" | awk '{print $3}'`"
echo " <OGRVRTLayer name=\"$lay\">" >> $VRT
echo " <SrcDataSource relativeToVRT=\"1\">${shp}</SrcDataSource>
" >> $VRT
echo " </OGRVRTLayer>" >> $VRT
done
echo " </OGRVRTUnionLayer>" >> $VRT
echo "</OGRVRTDataSource>" >> $VRT
Hope it's useful to some.
Regards,
Zoltan
--
===========================================
Zoltan Szecsei PrGISc [PGP0031]
Geograph (Pty) Ltd.
GIS and Photogrammetric Services
P.O. Box 7, Muizenberg 7950, South Africa.
Mobile: +27-83-6004028
Fax: +27-86-6115323 www.geograph.co.za
===========================================
More information about the Qgis-developer
mailing list