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

Tim Michelsen timmichelsen at gmx-topmail.de
Thu Jan 10 18:06:22 EST 2008


Hello,
well Even was a little bit right: I may have read the docs too quickly. 
This is the nearly first or second time I use ogr2ogr on the command 
line. I normally use it indirectly through the programs like GRASS etc.
I am really amazed how simple one can add a geo-value to data with this 
programs once the logic is understood.

rest below.
> Just to clear this up if it isn't already: if the CSV file in question is called "test.csv" and I create a separate VRT file called "test.vrt" (in the same directory as "test.csv") with the following content:
> <OGRVRTDataSource>
>     <OGRVRTLayer name="test">
>         <SrcDataSource>test.csv</SrcDataSource>
>         <GeometryType>wkbPoint</GeometryType>
>         <LayerSRS>WGS84</LayerSRS>
>         <GeometryField encoding="PointFromColumns" x="Longitude" y="Latitude"/>
>     </OGRVRTLayer>
> </OGRVRTDataSource>
> 
> I can then treat the test.vrt file as a read-only OGR data source. And when I run the transform:
> ogr2ogr -f KML test.kml test.vrt
>  I end up with:
> <?xml version="1.0" encoding="utf-8" ?>
> <kml xmlns="http://earth.google.com/kml/2.0">
> <Document><Folder><name>test</name>
>   <Placemark>
>       <name>First point</name>
>       <description>
> <![CDATA[
>       <b>Latitude:</b> <i>48.1</i><br />
>       <b>Longitude:</b> <i>0.25</i><br />
> ]]></description>
>       <Point><coordinates>0.25,48.1,0</coordinates></Point>
>   </Placemark>
>   <Placemark>
>       <name>Second point</name>
>       <description>
> <![CDATA[
>       <b>Latitude:</b> <i>49.2</i><br />
>       <b>Longitude:</b> <i>1.1</i><br />
> ]]></description>
>       <Point><coordinates>1.1,49.200000000000003,0</coordinates></Point>
>   </Placemark>
>   <Placemark>
>       <name>Third point</name>
>       <description>
> <![CDATA[
>       <b>Latitude:</b> <i>47.5</i><br />
>       <b>Longitude:</b> <i>0.75</i><br />
> ]]></description>
>       <Point><coordinates>0.75,47.5,0</coordinates></Point>
>   </Placemark>
> </Folder></Document></kml>
With Evens first response I was able to convert correctly:
.VRT file like above.

csv2kml_test.sh
ogr2ogr -f "KML" test.kml test.vrt -dsco NameField=Name

test.kml displays smoothly some locations in France.

> Even - I think the documentation is straightforward...
I think that the documentation could be updated for things to be 
clearer. Why not writing like you suggested in your Mail 
(http://article.gmane.org/gmane.comp.gis.gdal.devel/14140)?

Why not adding this example we elaborated to the doc?
I could imagine that a lot of people find this useful.

A little off topic:
Does anyone know a good scripting library (preferably in python) which 
can be used to enhance the KML: set special symbols/pin, edit hyper 
links, etc.?

Thank you all for your help!

Kind
regards,
Timmie


More information about the gdal-dev mailing list