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

Christopher Condit condit at sdsc.edu
Thu Jan 10 17:38:57 EST 2008


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>

Even - I think the documentation is straightforward...

-Chris


-----Original Message-----
From: gdal-dev-bounces at lists.osgeo.org [mailto:gdal-dev-bounces at lists.osgeo.org] On Behalf Of Even Rouault
Sent: Thursday, January 10, 2008 14:32
To: Dane Springmeyer
Cc: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] converting csv to kml: locations displaced in GoogleEarth

Dane,

I'm the one who wrote that part of the CSV doc indeed... 
Sorry that it's not clearer. What I meant by "You can write the associated VRT 
file (test.vrt)" is indeed "You must create at hand an associated VRT file 
(test.vrt)". You create it at hand, and then gives it as an input to OGR, so 
it can understand the structure of the underlying CSV file. I hope it makes 
things clearer...
If people have suggestions to formulate it more clearly in the docs, let me 
know.

Best regards

Le Thursday 10 January 2008 23:09:01, vous avez écrit :
> Hi Even,
>
> the csv to vrt docs here: http://www.gdal.org/ogr/drv_csv.html
>
> say to "write" a vrt but from the format's list and the error message
> I get it seems VRT is still read-only in Gdal 1.5
>
> Am I missing something?
>
> I get:
> ____
>
> [tropicana]$ ogr2ogr -f VRT test.vrt test.csv
> VRT driver does not support data source creation.
> ____
>
> - dane
>
> On Jan 10, 2008, at 1:19 PM, Even Rouault wrote:
> > 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.
> >
> > _______________________________________________
> > gdal-dev mailing list
> > gdal-dev at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/gdal-dev


_______________________________________________
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