Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'd like to open a USGS KML file of bedrock geology for an entire county, but there are over 2,000 individual polygon layers. Does anyone know if there is a way to merge all of these layers together into one file before opening in QGIS?

share|improve this question
2  
Your initial statement is a bit confusing. Do you have one kml file with multiple polygons in it, or do you have 2000 individual kml files representing the bedrock geology types? –  Get Spatial Jul 22 '12 at 20:31
1  
One thing you might do is use python and the QGIS API to do it. This question and answer provides a means to get started: How to write standalone Python scripts using QGIS –  Get Spatial Jul 22 '12 at 20:32
    
Yes it is one kml file with multiple polygon files. I was hoping for a plugin, because I know nothing about programming with python, but maybe now is a good time to start learning! Thanks. –  Patrick Jul 23 '12 at 15:55
    
I am not sure I understand, if I have a kml file with multiple lines, that would just open as one layer with multiple lines in QGIS. If on the other hand you have multiple kml files, you can open them all in Google earth, put them in one folder and export the folder as a new kml. –  Paulo Aug 1 '12 at 7:38
add comment

2 Answers

One option would be to write a "wrapper" KML file and include links to each file in the wrapper, using the KML NetworkLink. Although it says "network", the Link element can contain a local file path instead. You can also use this in a KMZ structure

share|improve this answer
add comment

Here a simple shell script ("ogr_kml_merge.sh") which uses ogr2ogr:

#!/bin/sh

# Markus Neteler, 2008
# merge KML files

PROG=`basename $0`

if [ $# -lt 1 ] ; then
 echo "Merges KML files together (mosaik)"
 echo "Usage:"
 echo "  $PROG *.kml"
 echo "  $PROG a.kml b.kml c.kml"
 echo "At then end of the merge you can select a new name"
 exit 1
fi

LIST="$@"
OUT=file_merged

rm -f $OUT.kml

ogr2ogr -f KML $OUT.kml $1
shift

for i in `seq 1 $#` ; do
  echo "Appending #$i: $1"
  ogr2ogr -f KML -update -append $OUT.kml $1 -nln $OUT `basename $1 .kml`
  shift
done

echo "Written: $OUT.kml"

echo -n "Enter file name for new KML (or CTRL-C): "
read NEW
NEW=`basename $NEW .kml`
mv $OUT.kml $NEW.kml

echo "Written as: $NEW.kml"

Hope this gives the idea.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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