How to create a KML

905 views
Skip to first unread message

Lauren

unread,
Jun 4, 2009, 4:49:29 AM6/4/09
to KML Developer Support - Getting Started with KML
Hi,

I'm designing an app in VB.NET that reads in a CSV file and converts
the data in it to a KML file.The user selects different formatting to
be applied to the header and description. I'm new at VB.NET and have
never worked with KML files.

I'd like to know how i would go about applying the selected formatting
to the data and then how to go about converting the CSV file to KML.
The csv file will contain numerous rows of data and I'm unsure how i
would convert all this data and then map it to Google Earth.

PLEASE HELP!!

Lauren

Geospectrum

unread,
Jun 4, 2009, 7:25:29 AM6/4/09
to KML Developer Support - Getting Started with KML
I’m not a programmer but I would have thought that as KML/Z are text
files the formatting would be applied within the app by constructing
the KML file with whatever text manipulation ability you have with
VB.NET. and using a bunch of variables to capture the values selected
by the user and apply them to the text output when you write the KML
file to a file on disk.

Have you looked the KML reference here?
http://code.google.com/apis/kml/documentation/kmlreference.html

To import the csv you’ll have to work out something to loop through
individual lines and column headings and capture those values and wrap
them up in the basic KML tags and the variable values.

I’ve done something like this with VB in EXCEL but nothing fancier.

GS

JerryK

unread,
Jun 4, 2009, 8:25:27 AM6/4/09
to KML Developer Support - Getting Started with KML
Lauren

I have done this using Delphi and it is basically simple
(conceptually) but required attention to detail.
What I did was to develop a kml file template of what I wanted
(searched web for an example
kml file and used it and the online kml reference).

I broke the template file into three parts:
(1) Header part containing all of the kml header information. In
my case this consisted of:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name><![CDATA[2009 China Tour]]></name>
<open>1</open>
<Snippet maxLines="2"></Snippet>
<description><![CDATA[2009 China Tour]]></description>

<Style id="FEATURES">
<IconStyle>
<color>FF699E00</color>
<scale>0.5</scale>
<Icon>
<href>root://icons/palette-4.png</href>
<x>0</x>
<y>0</y>
<w>255</w>
<h>255</h>
</Icon>
</IconStyle>
<LabelStyle>
<color>00FFFFFF</color>
</LabelStyle>
<BalloonStyle>
<text>
</text>
</BalloonStyle>
</Style>


[with a lot of other style information following this}

(2) body of kml file where a data element (point, table, row,
or whatever fits your data model)

(3) a Trailer part, an easy one:

</Document>
</kml>


I wrote a program then that
(1) read in the template and the data
(2) Wrote out the template header to a text file
(3) Wrote out a kml data block for each of my data elements
v

JerryK

unread,
Jun 4, 2009, 8:29:00 AM6/4/09
to KML Developer Support - Getting Started with KML
Lauren

Sorry my previous post terminated early (hit wrong key)

All that was left was to write the trailer template part to the text
file and then
save it with a kml extension.

I am not familiar with VB but in Delphi the actual mechanics of the
program
are pretty simple (memo objects make for easy editing).

hope this helps.

good luck.

Jerry

On Jun 4, 4:49 am, Lauren wrote:

Lauren

unread,
Jun 5, 2009, 3:13:55 AM6/5/09
to KML Developer Support - Getting Started with KML
I've managed to get a template of what I need in the KML file. The
user selects formatting (like font style, italic, font color ect) in
the VB app. I've managed to get these values saved in variables for
each section that I need. I'm just not sure how to move forward now.
One of the aspects I'm struggling with is opening the cvs file and
looping through the records and placing those values in the KML file,
and how to apply the saved formatting aspects to the file. I know that
I can use HTML to apply formatting, but how to apply the values
selected in the the app to the file. I also have to place a table in
the KML, and also have to loop through however many columns the user
selected on the VB side, and once again apply formatting to the header
and row data, and populate the table with the data from the csv. I
feel like I'm going in circles!!
> > Lauren- Hide quoted text -
>
> - Show quoted text -

Lauren

unread,
Jun 12, 2009, 4:21:08 AM6/12/09
to KML Developer Support - Getting Started with KML
Hi,

I've made some progress with the project. The only problem is that the
order of the file is not correct.
I'm not sure why it's coming up this way, as my fields are in the
correct order. Below is the XML file
that is generated:
<?xml version="1.0" encoding="utf-8" ?>
<BEGIN p1:L1="" p2:L2="<point><coordinates>100000, 150000</
coordinates></point>" p3:L3="<!CDATA[<thead><tr><th><font size = 8
face = Arial color = Black> grid header 1 </font>]]></tr></th></
thead><!CDATA[<tbody><tr><td><font size = 8 face = Arial color =
Black> grid data 1 </font>]]></tr></td></tbody></table>]]>" p4:L5=""
xmlns:p4="<name><![CDATA[<font size = 8 face = Arial color = Black>
Footer 1</font>]]></name></placemark>" xmlns:p3="<!CDATA[<table border
= 0><thead><tr><th><font size = 8 face = Arial color = Black> grid
header 1</font>]]></tr></th></thead>" xmlns:p2="<description><![CDATA
[<font size = 8 face = Arial color = Black> Desc 1</font>]]></
description>" xmlns:p1="<placemark><name><![CDATA[<font size = 8 face
= Arial color = Black> Point 1</font>]]></name>" xmlns="<kml xmlns =
"http://www.opengis.net/kml/2.2">" />


And the code (written with VB.Net) used to generate the file.

Could you please take a look at it and maybe point me in the right
direction to get it corrected?

Thanks,
Lauren


Reply all
Reply to author
Forward
0 new messages