Hi!
As I said in a previous message, I use qgis to put together many geographic
information sources prior to downloading the data as kmz to my mobile.
That's the reason I wrote a small script to generate kmz icons from a
qgis-generated kml.
That script is a "sed" script, meaning it has to be processed with the
"sed" utility included in Linux. If you have a Windows version of qgis
bundled with Msys (such as osgeo4win), you could probably execute it from
the msys command line.
Someone could try to adapt it to python, but I don't know how to make
python scripts.
Please note: Lines are long and they could be wrapped when sendind as
email. I will use an empty line (two carriage returns) to mark new line.
---
SCRIPT 1 Generate icons from "name" field
This script takes a qgis-generated kml file, and adds an icon (called
"Cueva.png") to every feature with a name containing "Cueva" or "Sima",
another icon (called ."Icnitas.png") to every feature with a name
containing "icnita" or "Icnita",
another icon (called "Fosil.png") to every feature with a name like
"Fosil", "Fósil", "fosil" or "fósil", and another icon (called "Mina.png")
to every feature with a name containing "Mina".
The icons should be placed in a folder called "images", and zipped along
with the modified kml file in a file with kmz extension.
The script should be invoked like this:
sed mykmlfile.kml -f kmzfromname.sed > newkmlfile.kml
After that, you should use your preferred zip manager to zip together the
files. I use this:
7z -a -tzip newkmlfile.kmz newkmlfilekml images/*.png
but the syntax would be different if you use a different zip manager.
kmziconfromname.sed--CUT
HERE--
#!/bin/sed
#Replace name tag with Cueva or cueva with icon and name tag
/name>[^>]*[Cc]ueva/{;s//images\/Cueva.png<\/href><\/icon>/;};
#Replace name tag with Sima or sima with icon and name tag
/name>[^>]*[Ss]ima/{;s//images\/Cueva.png<\/href><\/icon>/;};
#Replace name tag with Icnita or icnita with icon and name tag
/name>[^>]*[Ii]cnita/{;s//images\/Icnitas.png<\/href><\/icon>/;}
#Replace name tag with F?sil or f?sil (probably, fosil or fósil) with icon
and name tag
/name>[^>]*[Ff].sil/{;s//images\/Fosil.png<\/href><\/icon>/;}
#Replace name tag with Mina or mina with icon and name tag
/name>[^>]*[Mm]ina/{;s//images\/Mina.png<\/href><\/icon>/;}
#Previous code for icons was a pseudocode. Replace it with the real code.
s!!1.0!;
s!!1.01,0!
#I don't know why, but replacing folder with document allows oruxmaps put a
name (instead of a date) to this layer.
s!Folder>!Document>!
kmziconfromname.sed---END OF
FILE---
SCRIPT 2 - Generate icons from a custom field (not "name")
This is a skeleton script. In the previous sample, I used the name to
detect the class of each feature, but my kml file has a field caled
T006_006_C that stores the actual feature class.
So I could use that field instead.
But, in order to do that, I have to read the field inside the
tag and, after that, put a new flag outside that tag.
Doing that with SED is tricky, because SED uses to read one line at a time.
We have to tell it to group the whole group in a single line.
Please notice you should adapt this script to your needs, i.e., replace
T006_006_C with the field name you want, add code to replace the tags with your preferred icon, and so on.
The usage would be again,
sed mykmlfile.kml -f kmzfromfield.sed > newkmlfile.kml
After that, you should use your preferred zip manager to zip together the
files. I use this:
7z -a -tzip newkmlfile.kmz newkmlfilekml images/*.png
but the syntax would be different if you use a different zip manager.
---kmziconfromfield.sed--CUT
HERE--
#!/usr/bin/sed
#Example: how to make icon from field using SED
#Replace T006_006_C with fieldname
:a
N
#Do not put spaces after the backslash in the next line:
s/\
/ /g
/\/ExtendedData/!ba
s/\(\)\([^<]*\)\(.*<\/ExtendedData>\)/\1\2\3/
#Step 2: Replace with code for icon
(/Cueva.png<\/icon>/
#Now we change pseudocode with real icon code.
s!!