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

Even Rouault even.rouault at mines-paris.org
Thu Jan 10 16:19:53 EST 2008


Answers below :

Le Thursday 10 January 2008 21:54:09 Tim Michelsen, vous avez écrit :
> 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">

OGR KML driver exports KML 2.0 for the moment, but that shouldn't be a 
problem.
>
> 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>
>

The generated KML file is obviously not what you would expect (it has output 
all the CSV fields into the description tag, and GE by default put such 
placemark at (0°,0°), which is at the west of Africa) . But that can be 
logically explained. You can't use a CSV file as simply as you do. If you 
read more carefully http://www.gdal.org/ogr/drv_csv.html, you'll see that you 
need to create a VRT file, test.vrt, and do ogr2ogr on that file, not on the 
original CSV file.

> 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.




More information about the gdal-dev mailing list