[gdal-dev] kml file does not open with ogrinfo but works with GE

Roger Bivand Roger.Bivand at nhh.no
Thu Jan 3 04:08:28 PST 2013


If you change utf-16 in the first line to utf-8, then change line 2:

<Document xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns="http://www.opengis.net/kml/2.2">

to

<kml xmlns="http://www.opengis.net/kml/2.2">

and the final line from </Document> to </kml> to match, gdalinfo recognises
the file.

Then:

> ogrListLayers("test.kml")
[1] "Points"   "Layer #1"
> ogrInfo("test.kml", "Points")
Source: "test.kml", layer: "Points"
Driver: KML number of rows 1293 
Feature type: wkbPoint with 3 dimensions
+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs  
Number of fields: 2 
         name type length typeName
1        Name    4      0   String
2 Description    4      0   String
> summary(readOGR("test.kml", "Points", stringsAsFactors=FALSE))
OGR data source with driver: KML 
Source: "test.kml", layer: "Points"
with 1293 features and 2 fields
Feature type: wkbPoint with 3 dimensions
Object of class SpatialPointsDataFrame
Coordinates:
                  min        max
coords.x1   0.9599367   1.206534
coords.x2  40.8425941  41.017574
coords.x3 -11.7700005 711.090027
Is projected: FALSE 
proj4string :
[+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs]
Number of points: 1293
Data attributes:
     Name           Description       
 Length:1293        Length:1293       
 Class :character   Class :character  
 Mode  :character   Mode  :character  

where Description is a convoluted HTML table. This can be unpacked by:

> library(XML)
> data <- t(unname(sapply(t0$Description, function(x)
> unlist(t(readHTMLTable(substring(x, 11, nchar(x)),
> as.data.frame=FALSE))))))
> str(data)
 chr [1:1293, 1:4] "Roll: -0.05" "Roll: 0.01" "Roll: 0.86" ...

giving a 4-column character matrix that should be easy to convert to the
three numerical colums and one DateTime column needed (probably with
substring to cut out the names, then cast to required type).

Hope this helps,

Roger

PS. Please summarise to R-sig-geo.



Agustin Lobo wrote
> A program (Mission Planner for Ardupilot)
> http://code.google.com/p/ardupilot-mega/wiki/MPTlog
> produces kml files
> with track information that can be represented with the same program
> and GE, but I cannot open them with ogrinfo:
> $ ogrinfo test.kml
> FAILURE:
> Unable to open datasource `test.kml' with the following drivers.
> $ ogrinfo --version
> GDAL 1.9.2, released 2012/10/08
> 
> I cannot open it with QGIS or R (readOGR()) either.
> 
> Is there a newer kml format that is recognized by GE but not by the OGR
> library?
> Any help with this?
> I've uploaded test.kml in case someone could help:
> http://dl.dropbox.com/u/3180464/test.kml
> 
> Thanks!
> Agus
> _______________________________________________
> gdal-dev mailing list

> gdal-dev at .osgeo

> http://lists.osgeo.org/mailman/listinfo/gdal-dev





-----
Roger Bivand
NHH Norwegian School of Economics, Bergen, Norway
--
View this message in context: http://osgeo-org.1560.n6.nabble.com/gdal-dev-kml-file-does-not-open-with-ogrinfo-but-works-with-GE-tp5025428p5025434.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list