The lack of this functionality annoyed me a bit so I wrote a basic iteration script which stitches the output kmls into a single kmz file. Not sure what edge cases there will be but seems to work fine on basic styles.
https://github.com/zacharlie/effective-dollop/blob/main/pyqgis/qgis-vectors-to-kmz.py On Fri, 13 Aug 2021 at 17:20, Charles Dixon-Paver <char...@kartoza.com> wrote: > I think it would be a lot easier to use the KML Tools algorithms to > iterate over all the layers, then simply drag all the output KMZ files into > Google Earth and export the folder containing them to a consolidated KMZ > file. You can use PyQGIS, e.g: > > layers = [layer for layer in QgsProject.instance().mapLayers().values()] > > out_dir = 'P:/data/kml_output' > > for layer in layers: > if layer.type() == QgsMapLayer.VectorLayer: > try: > layer_src = str(layer.source()).replace('\\','/') > layer_file = os.path.join(out_dir, str(layer.name()) + '.kmz') > processing.run("kmltools:exportkmz", { > 'InputLayer': layer_src, > 'NameField': '', > 'DescriptionField': [], > 'ExportStyle': True, > 'UseGoogleIcon': None, > 'AltitudeInterpretation': 1, > 'AltitudeMode': 0, > 'AltitudeModeField': '', > 'AltitudeField': '', > 'AltitudeAddend': 0, > 'DateTimeStampField': '', > 'DateTimeBeginField': '', > 'DateTimeEndField': '', > 'PhotoField': '', > 'OutputKmz': layer_file, > 'LineWidthFactor': 2, > 'DateStampField': '', > 'TimeStampField': '', > 'DateBeginField': '', > 'TimeBeginField': '', > 'DateEndField': '', > 'TimeEndField': '' > }) > print('Exported: ' + layer_file) > except Exception as err: > print(err) > > > Of course you could try unpack the data and stitch it in python too, but > that's not as easy... But at least the styling etc will be managed for you. > > Regards > > On Fri, 13 Aug 2021 at 16:50, Richard McDonnell <richard.mcdonn...@opw.ie> > wrote: > >> Hi, >> >> You can do this, but it requires a few steps. Open up the Project where >> the Layers are and they are all styled as you want >> >> >> >> *STEP1 Convert all to KMZ* >> >> 1. In the *Processing Tools *under* GDAL, Vector Conversion *highlight >> *Convert format *right click and select* Execute as Batch Process* >> >> 2. Click the* + *symbol to add additional rows and select the >> Layers you want to convert >> >> 3. Click on the three dots on the right for the first layer, set >> the Save as type to KML set a location and in the file name we are just >> going to give it a prefix, type something like 01_ then click save >> >> 4. You will then be presented with the *AutoFill* option, set the >> *Autofill >> mode* to *Fill with parameter values* and set the *Parameter to use* to >> *Input >> Layer*, at this stage you can delete the prefix manually if you wish >> >> 5. Click Run >> >> This should have saved out all Shapefiles as KML’s for you. Now for the >> Styling and fixing of styles >> >> >> >> *STEP2 Apply Styles to KML* >> >> 1. Right click on one of the original Layers in your project, >> select *Styles, Copy Style, All Style Categories* >> >> 2. Right click on the corresponding KML select *Styles, Paste >> Style, All Style Categories* >> >> Repeat for all other Layers >> >> >> >> *STEP3 Final Step* >> >> 1. In the Search baron the Processing Toolbox search for *Package >> Layers* >> >> 2. Select the *KML* Files as your *Input Layers* >> >> 3. Make sure the* Save layer Styles into GeoPackage * >> >> 4. Click on the three dots at *Destination GeoPackage*, selecting *Save >> to File*, set the Location and Name of the GeoPackage, click *Save* and >> then click *Run* >> >> >> >> The result will be a GeoPackage file with the KML’s saved and the Styles >> applied, which means that anyone who opens the GeoPackage in another QGIS >> Project will always have the Styles applied. >> >> >> >> I don’t believe there is an automated process that will do this for you, >> but you could also look at the model builder and using the steps above as a >> guide, build a custom process which will do the three steps I have outlined >> above in a single step for you. >> >> Hope that helps, >> >> >> >> Richard McDonnell >> >> >> >> >> >> >> >> >> >> >> —— >> Richard McDonnell MSc GIS, FME Certified Professional >> *FRM Data Management* >> >> —— >> Oifig na nOibreacha Poiblí >> Office of Public Works >> >> Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36 >> Jonathan Swift Street, Trim, Co Meath, C15 NX36 >> —— >> M +353 87 688 5964 T +353 46 942 2409 >> https://gov.ie/opw >> >> —— >> To send me files larger than 30MB, please use the link below >> https://filetransfer.opw.ie/filedrop/richard.mcdonn...@opw.ie >> >> Email Disclaimer: >> https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/ >> >> *From:* Qgis-user <qgis-user-boun...@lists.osgeo.org> *On Behalf Of *krishna >> Ayyala >> *Sent:* 13 August 2021 14:06 >> *To:* qgis-user <qgis-user@lists.osgeo.org> >> *Subject:* [Qgis-user] Exporting QGIS map to KML/KMZ >> >> >> >> Hello, >> >> I am reposting this question. I have a QGIS map saved >> with ".qgz" extension. This map has four layers. One layer has points, one >> layer has lines and two layers have polygons. Is it possible to convert the >> entire map to kmz without losing the symbology. I know how to convert each >> layer into kmz. But, I am exploring to see if I can convert the entire map >> to kmz? >> >> >> >> Regards. >> _______________________________________________ >> Qgis-user mailing list >> Qgis-user@lists.osgeo.org >> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user >> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user >> >
_______________________________________________ Qgis-user mailing list Qgis-user@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user