[gdal-dev] converting csv to kml: locations displaced in Google Earth

Dane Springmeyer blake at hailmail.net
Thu Jan 10 16:51:09 EST 2008


Hi Tim,

I was just finishing writing you as Even's email came in... I'm going  
to try what he says about the vrt driver - that's interesting. My  
previous thoughts:

----

It looks like the ogr2ogr command is not forming the xml correctly. I  
have not used ogr2ogr with csv before, but I can help by giving you  
an example of what kind of KML you should be looking for to be output.

The example of:

> Latitude,Longitude,Name
> 48.1,0.25,"First point"
> 49.2,1.1,"Second point"
> 47.5,0.75,"Third point"

should become something like:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
	<name>Timmie's example KML from CSV</name>
		<Placemark>
			<name>First point</name>
			<Point>
				<coordinates>0.25,48.1,0</coordinates>
			</Point>
		</Placemark>
		<Placemark>
			<name>Second point</name>
			<Point>
				<coordinates>1.1,49.2,0</coordinates>
			</Point>
		</Placemark>
		<Placemark>
			<name>Third point</name>
			<Point>
				<coordinates>0.75,47.5,0</coordinates>
			</Point>
		</Placemark>
</Document>
</kml>

Try saving that XML as a .kml file and opening in GE to confirm. What  
is happening in the KML clip you sent before is that the coordinates  
are being placed inside the tag for the balloon or popup window.  
That's fine, but they also need to be placed....  
<Placemark><Point><coordinates> **HERE** </coordinates></Point></ 
Placemark> otherwise GE won't know where to plot them.

Maybe someone else can comment on how to property format your CSV to  
be read by ogr2ogr, or you could try GPSBABEL as a download:
http://www.gpsbabel.org/htmldoc-development/fmt_csv.html

or online:
http://www.gpsvisualizer.com/gpsbabel/


Does that help?

Cheers,

Dane




On Jan 10, 2008, at 12:54 PM, Tim Michelsen wrote:

> Hello,
> I would like to convert a csv file to kml. When I load the  
> resulting KML
> into Googleearth (GE) the generated placemarks inside the file are
> totally displaced.
> What could be the reason?
> Could it be that XML decription is used too old?
>
> When I export my places from GE I read this line:
> <kml xmlns="http://earth.google.com/kml/2.1">
>
> In the generated KML file I can read:
> <kml xmlns="http://earth.google.com/kml/2.0">
>
> Here are the test files:
> Latitude,Longitude,Name
> 48.1,0.25,"First point"
> 49.2,1.1,"Second point"
> 47.5,0.75,"Third point"
>
> the command line I used:
> ogr2ogr -f "KML" test.kml test.csv
>
> the KML:
> <?xml version="1.0" encoding="utf-8" ?>
> <kml xmlns="http://earth.google.com/kml/2.0">
> <Document><Folder><name>test</name>
>     <Placemark>
>       <description><![CDATA[
>         <b>Latitude:</b> <i>48.1</i><br />
>         <b>Longitude:</b> <i>0.25</i><br />
>         <b>Name:</b> <i>First point</i><br />
>      ]]></description>  </Placemark>
>     <Placemark>
>       <description><![CDATA[
>         <b>Latitude:</b> <i>49.2</i><br />
>         <b>Longitude:</b> <i>1.1</i><br />
>         <b>Name:</b> <i>Second point</i><br />
>      ]]></description>  </Placemark>
>     <Placemark>
>       <description><![CDATA[
>         <b>Latitude:</b> <i>47.5</i><br />
>         <b>Longitude:</b> <i>0.75</i><br />
>         <b>Name:</b> <i>Third point</i><br />
>      ]]></description>  </Placemark>
> </Folder></Document></kml>
>
> Attached you find the screenshot from GE.
>
> I would highly appreciate your hints and help.
>
> Kind regards,
> Timmie
>
> P.S. The Mailserver would let my inital mail through. This one  
> comes with a smaller image.<test-kml_google- 
> earth_full_small.jpg>_______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev



More information about the gdal-dev mailing list