When exporting one KML, it's exceeding the Google Fusion Table's max limit of 100mb per upload. Fusion Tables however lets users merge more than one KML for a merged max size of 250mb. Any idea how to export multiple KMLs from QGIS?
2 Answers
It is trivial with ogr2ogr and SQLite SQL dialect. Next examples write 10 first lakes into one KML file and next 10 lakes into another KML file
ogr2ogr -f kml batch_1.kml lakes.shp -dialect sqlite -sql "select * from lakes limit 10"
ogr2ogr -f kml batch_2.kml lakes.shp -dialect sqlite -sql "select * from lakes limit 10 offset 10"
-
very handy! How would you do this if there are thousands of features? Is there a way for iterating over the features and assignig a file-name programmatically?– KayCommented Sep 18, 2014 at 6:02
-
SQL command is using just the same SQL than SQLite/Spatialite and differences to PostgreSQL/PostGIS are small. "limit 100000" takes 100000 features. "offset 100000" will skip 100000 first features before starting to count. Run
ogrinfo -al -so data.shp"
and you can see the total number of features in the shapefile "data.shp". Assigning filenames automatically goes beyond this question but is quite easy to do for example with Windows .bat file or Linux shell script. Commented Sep 18, 2014 at 7:40
The ogr2ogr example is probably the most efficient, but if you prefer to do it without commandline you can just open the attribute table of the layer you're saving as KML, order the table on ID and starting from the top you select a number of records which you think will be within the limit (if the file is 150 megabytes, maybe select half of the records?)
Take note of the ID of the last feature you selected, and right click the layer to save it as KML. Here you tick the box "Save only selected features."
Then repeat the above starting from the feature with the ID that came after those you selected the first time.