Maybe I am just loosin' my time struggling to import KML polygons in
GRASS but here is my attempt and my problems. I have read past threads
but I didn't really found the "SOLUTION"
I understand that it should be easy to play with xpath and xslt but
since KML's are XML's but, again, I have no idea about xpath and xslt
and I try do it the way I "know" more or less... ;-p
If there is already a solution... I would be more than greatful since I
am in the last phase of my current work.
Here is my attempt to import coordinates the "hard way":
---
1. Decompress KMZ and get the "KML"
# I was told, and I read, that KML are just XML's. So...
2. Replacing the KMLheader <kml xmlns="http://earth.google.com/kml/2.2">
with
<?xml-stylesheet type="text/xsl" href="kml2html.xsl" ?>
<kml>
3. Saving the KML file in the same folder with an .xsl (in my case
kml2html.xsl given by a friend --- file attached)
4. Open with a browser and either (a) "copy-paste" the coordinates
for which I am interested or (b) "save as" txt file.
5. I choose (a) for my first attempt and save some coordinates in a txt
file and try to import them "sacrificing" the meta-data.
["example.xyz" with coordinates attached.]
The problem is that the coordinates are given in form of x,y,z but
continuously... that is one "x,y,z" field after another separated by
"space" and not in separate lines!
It looks like this:
x1,y1,z1 x2,y2,z2 x3,y3,z3 [...] xi,yi,zi
and NOT like this:
x1,y1,z1
x2,y2,z
x3,y3,z3
[...]
xi,yi,zi
6. I have studied v.out.ascii (since it is the reverse of v.in.ascii)
and I came up with this bash loop which WORKS in the command line. I can
import the desired coordinates in GRASS and I think it should be easy to
"clean" and convert in areas.
["example.grass-ready.xyz" attached]
The problem is that my "solution" DOES NOT work in a script due to an
error in "cut -d ' ' -f$i #### How can I use in -f a variable (stepwise
increasing number) instead of a constant number?
INPUT=example.xyz
OUTPUT= just a name
TYPE=B ### "B" for "boundaries" ...or "L" for lines better?
i=0
PRIMITIVES="`cat $INPUT | wc -w`"
echo "$TYPE $PRIMITIVES" > $OUTPUT.grass-ready; cat $OUTPUT.grass-ready
| echo "\nVERTI:">> $OUTPUT.grass-ready
until [ $i -gt $PRIMITIVES ]; do cat $INPUT | cut -d' ' -f$i | tr ',' '
' >> $OUTPUT.grass-ready; let i=i+1; done ### Note in tr ',' ' ' --
second character is a space
7. If this is going to work I was thinking to "grep" somehow the
metadata out of the "saved as txt file" and force it with a script in
the X.grass-ready ascii
...
Some more questions:
* ogr officially supports "KML" reading and writing. I can't read with
ogrinfo any KML file. I have read about "expat" support... but isn't
this activated by default in ogr coming with FWTools?
Sorry for the QGIS question:
* QGIS suppports GML reading?
(attachments)
kml2html.xsl (511 Bytes)
example.xyz (2.57 KB)
example.grass-ready.xyz (2.67 KB)