~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to ogr/ogrsf_frmts/libkml/drv_libkml.html

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 
2
   "http://www.w3.org/TR/html4/loose.dtd">
 
3
<html>
 
4
<head>
 
5
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
 
6
    <title>LIBKML Driver</title>
 
7
</head>
 
8
 
 
9
<body bgcolor="#ffffff">
 
10
 
 
11
  <h1>LIBKML Driver (.kml .kmz)</h1>
 
12
    
 
13
  <p>
 
14
    The LIBKML driver is a client of
 
15
    <a href="http://code.google.com/p/libkml/">Libkml</a> from Google, a
 
16
    reference implementation of
 
17
    <a href="http://www.opengeospatial.org/standards/kml/">KML</a>
 
18
    reading and writing, in the form of a cross platform C++ library.
 
19
    You must build and install Libkml in order to use this OGR driver.
 
20
  </p>
 
21
    
 
22
  <p>
 
23
    Note that if you build and include this LIBKML driver, it will become the
 
24
    default reader of KML for ogr, overriding the previous KML driver. You can
 
25
    still specify either KML or LIBKML as the ouput driver via the command line
 
26
  </p>
 
27
    
 
28
  <p>
 
29
    Libkml from Google provides reading services for any valid KML file.
 
30
    However, please be advised that some KML facilities do not map into the
 
31
    Simple Features specification ogr uses as its internal structure.
 
32
    Therefore, a best effort will be made by the driver to understand the
 
33
    content of a KML file read by libkml into ogr, but your mileage may vary.
 
34
    Please try a few KML files as samples to get a sense of what is understood.
 
35
    In particular, nesting of feature sets more than one deep will be flattened
 
36
    to support ogr's internal format.
 
37
  </p>
 
38
  
 
39
  <h2>Datasource</h2>
 
40
  
 
41
  <p>
 
42
    You may specify a
 
43
    <a href="http://www.gdal.org/ogr/ogr_arch.html#ogr_arch_data_source">datasource </a>
 
44
    as a kml file <code>somefile.kml</code> , 
 
45
    a directory <code>somedir/</code> , or a kmz file <code>somefile.kmz</code> .
 
46
  </p>
 
47
  
 
48
  <p>
 
49
    By default on directory and kmz datasources, an index file of all the
 
50
    layers will be read from or written to doc.kml. It conatains a
 
51
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#networklink">
 
52
    &lt;NetworkLink&gt;</a> to each layer file in the datasource. This feature
 
53
    can be turned off by setting the enviroment variable LIBKML_USE_DOC.KML to
 
54
    "no"
 
55
   </p>
 
56
  
 
57
  <h3>StyleTable</h3>
 
58
  
 
59
  <p>
 
60
    Datasource style tables are written to the
 
61
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#document">
 
62
    &lt;Document&gt;</a> in a .kml, style/style.kml
 
63
    in a kmz file, or style.kml in a directory, as one or more
 
64
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#style">
 
65
    &lt;Style&gt;</a> elements. Not all of
 
66
    <a href="http://www.gdal.org/ogr/ogr_feature_style.html">OGR Feature Style</a>
 
67
    can translate into KML.
 
68
  </p>
 
69
  
 
70
  <h2>Layer</h2>
 
71
  
 
72
  <p>
 
73
    <a href="http://www.gdal.org/ogr/ogr_arch.html#ogr_arch_layer">
 
74
    Layers</a> are mapped to kml files as a
 
75
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#document">
 
76
    &lt;Document&gt;</a>
 
77
    or
 
78
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#folder">
 
79
    &lt;Folder&gt;</a>, and in kmz files or directorys as a seperate kml file.
 
80
  </p>
 
81
  
 
82
  <h3>Style</h3>
 
83
  <p>
 
84
    Layer style tables can not be read from or written to a kml layer that is a 
 
85
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#folder">
 
86
    &lt;Folder&gt;</a>, otherwise they are in the
 
87
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#document">
 
88
    &lt;Document&gt;</a> that is the layer.
 
89
  </p>
 
90
  
 
91
  <h3>Schema</h3>
 
92
  
 
93
  <p>
 
94
    Read and write of
 
95
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#schema">
 
96
    &lt;Schema&gt;</a> is supported for .kml files , .kmz files, and
 
97
    directorys.
 
98
  </p>
 
99
 
 
100
  <h2>Feature</h2>
 
101
  
 
102
  <p>
 
103
    An OGR <a href="http://www.gdal.org/ogr/ogr_arch.html#ogr_arch_feature">feature</a>
 
104
    translates to kml as a
 
105
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#placemark">
 
106
    &lt;Placemark&gt;</a>.
 
107
  </p>
 
108
  
 
109
  <h3>Style</h3>
 
110
  
 
111
  <p>
 
112
    Style Strings at the feature level are Mapped to KML as either a 
 
113
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#style">
 
114
    &lt;Style&gt;</a> or
 
115
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#styleurl">
 
116
    &lt;StyleUrl&gt;</a> in each
 
117
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#placemark">
 
118
    &lt;Placemark&gt;</a>.
 
119
  </p>
 
120
  <p>
 
121
     When reading a kml feature and the enviroment variable LIBKML_RESOLVE_STYLE
 
122
     is set to yes, styleurls are looked up in the style tables and the features
 
123
     style string is set to the style from the table. This is to allow reading 
 
124
     of shared styles by applications, like mapserver, that do not read style
 
125
     tables.
 
126
  </p>
 
127
  
 
128
  <p>
 
129
     When reading a kml feature and the enviroment variable LIBKML_EXTERNAL_STYLE
 
130
     is set to yes, a styleurl that is external to the datasource is read from 
 
131
     disk or fetched from the server and parsed into the datasource style table.
 
132
     If the style kml can not be read or LIBKML_EXTERNAL_STYLE is set to no then
 
133
     the styleurl is copyed to the style string.
 
134
  </p>
 
135
    
 
136
  <h2>Fields</h2>
 
137
  
 
138
  <p> OGR fields (feature atributes) are mapped to kml with
 
139
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#schema">
 
140
    &lt;Schema&gt</a>; and
 
141
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#simpledata">
 
142
    &lt;SimpleData&gt;</a>, except for some special fields as noted below.
 
143
  </p>
 
144
  
 
145
  <p>
 
146
    A rich set of environment variables are available to define how fields in
 
147
    input and output, map to a KML 
 
148
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#placemark">
 
149
    &lt;Placemark&gt;</a>. For example, if you want a field called 'Cities'
 
150
    to map to the
 
151
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#name">
 
152
    &lt;name&gt;</a>; tag in KML, you can set an
 
153
    environment variable. 
 
154
  </p>
 
155
 
 
156
  <dl>
 
157
    <dt>Name</dt>
 
158
    <dd>
 
159
      This String field maps to the kml tag 
 
160
      <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#name">
 
161
      &lt;name&gt;</a>. The name of the ogr field can be changed with the
 
162
      enviroment variable LIBKML_NAME_FIELD .
 
163
    </dd>
 
164
    <dt>description</dt>
 
165
    <dd>This String field maps to the kml tag 
 
166
      <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#description">
 
167
      &lt;description&gt;</a>. The name of the ogr field can be changed with the
 
168
      enviroment variable LIBKML_DESCRIPTION_FIELD .
 
169
    </dd>
 
170
    <dt>timestamp</dt>
 
171
    <dd>This string or datetime or date and/or time field maps to the kml tag 
 
172
      <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#timestamp">
 
173
      &lt;timestamp&gt;</a>. The name of the ogr field can be changed with the
 
174
      enviroment variable LIBKML_TIMESTAMP_FIELD .
 
175
    </dd>
 
176
    <dt>begin</dt>
 
177
    <dd>This string or datetime or date and/or time field maps to the kml tag 
 
178
      <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#begin">
 
179
      &lt;begin&gt;</a>. The name of the ogr field can be changed with the
 
180
      enviroment variable LIBKML_BEGIN_FIELD .
 
181
    </dd>
 
182
    <dt>end</dt>
 
183
    <dd>This string or datetime or date and/or time field maps to the kml tag 
 
184
      <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#end">
 
185
      &lt;end&gt;</a>. The name of the ogr field can be changed with the
 
186
      enviroment variable LIBKML_END_FIELD .
 
187
    </dd>
 
188
    <dt>altitudeMode</dt>
 
189
    <dd>This string field maps to the kml tag 
 
190
      <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#altitudemode">
 
191
      &lt;altitudeMode&gt;</a> or
 
192
      <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#gxaltitudemode">
 
193
      &lt;gx:altitudeMode&gt;</a>. The name of the ogr field can be changed
 
194
      with the enviroment variable LIBKML_ALTITUDEMODE_FIELD .
 
195
    </dd>
 
196
    <dt>tessellate</dt>
 
197
    <dd>This integer field maps to the kml tag 
 
198
      <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#tessellate">
 
199
      &lt;tessellate&gt;</a>. The name of the ogr field can be changed with the
 
200
      enviroment variable LIBKML_TESSELLATE_FIELD .
 
201
    </dd>
 
202
    <dt>extrude</dt>
 
203
    <dd>This integer field maps to the kml tag 
 
204
      <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#extrude">
 
205
      &lt;extrude&gt;</a>. The name of the ogr field can be changed with the
 
206
      enviroment variable LIBKML_EXTRUDE_FIELD .
 
207
    </dd>
 
208
    <dt>visibility</dt>
 
209
    <dd>This integer field maps to the kml tag 
 
210
      <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#visibility">
 
211
      &lt;visibility&gt;</a>. The name of the ogr field can be changed with the
 
212
      enviroment variable LIBKML_VISIBILITY_FIELD .
 
213
    </dd>
 
214
    <dt>OGR_STYLE</dt>
 
215
    <dd>This string feild maps to a features style string, OGR reads this field
 
216
      if there is no style string set on the feature.
 
217
    </dd>
 
218
  </dl>
 
219
  
 
220
  <h2>Geometry</h2>
 
221
  
 
222
  <p>
 
223
    Translation of OGR
 
224
    <a href="http://www.gdal.org/ogr/ogr_arch.html#ogr_arch_geometry">
 
225
    Geometry</a> to KML Geometry is pretty strait forwards with only a couple
 
226
    of exceptions. Point to 
 
227
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#point">
 
228
    &lt;Point&gt;</a>, LineString to
 
229
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#linestring">
 
230
    &lt;LineString&gt;</a>, LinearRing to
 
231
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#linearring">
 
232
    &lt;LinearRing&gt;</a>, and Polygon to
 
233
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#polygon">
 
234
    &lt;Polygon&gt;</a>. In OGR a polygon contains an array of LinearRings,
 
235
    the first one being the outer ring. KML has the tags
 
236
    &nbsp;<a href="http://code.google.com/apis/kml/documentation/kmlreference.html#outerboundaryis">
 
237
    &lt;outerBoundaryIs&gt;</a>&nbsp;and&nbsp; 
 
238
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#innerboundaryis">
 
239
    &lt;innerBoundaryIs&gt;</a>&nbsp;to differentiate between the two. OGR has
 
240
    several Multi types of geometry : GeometryCollection, MultiPolygon,
 
241
    MultiPoint, and MultiLineString. When possible, OGR will try to map 
 
242
    <a href="http://code.google.com/apis/kml/documentation/kmlreference.html#multigeometry">
 
243
    &lt;MultiGeometry&gt;</a> to the more precise OGR geometry type (MultiPoint, MultiLineString or MultiPolygon),
 
244
    and default to GeometryCollection in case of mixed content.
 
245
  </p>
 
246
  
 
247
  <p>
 
248
    Sometimes kml geometry will span the dateline, In applications like qgis or
 
249
    mapserver this will create horizontal lines all the way around the globe.
 
250
    Setting the enviroment variable LIBKML_WRAPDATELINE to "yes" will cause the
 
251
    libkml driver to split the geometry at the dateline when read.
 
252
  </p>
 
253
 
 
254
<h2>VSI Virtual File System API support</h2>
 
255
 
 
256
(Some features below might require OGR >= 1.9.0)<p>
 
257
 
 
258
The driver supports reading and writing to files managed by VSI Virtual File System API, which include
 
259
"regular" files, as well as files in the /vsizip/ (read-write) , /vsigzip/ (read-write) , /vsicurl/ (read-only) domains.<p>
 
260
 
 
261
Writing to /dev/stdout or /vsistdout/ is also supported.<p>
 
262
 
 
263
  <h2>Example</h2>
 
264
 
 
265
  <p>
 
266
    The following bash script will build a
 
267
    <a href="http://www.gdal.org/ogr/drv_csv.html">csv</a> file and a
 
268
    <a href="http://www.gdal.org/ogr/drv_vrt.html">vrt</a> file, and then
 
269
    translate them to KML using 
 
270
    <a href="http://www.gdal.org/ogr2ogr.html">ogr2ogr</a> into a .kml file with
 
271
    timestamps and styling.
 
272
  </p>
 
273
 
 
274
  <pre>
 
275
 
 
276
 
 
277
#!/bin/bash
 
278
# Copyright (c) 2010, Brian Case
 
279
#
 
280
# Permission is hereby granted, free of charge, to any person obtaining a
 
281
# copy of this software and associated documentation files (the "Software"),
 
282
# to deal in the Software without restriction, including without limitation
 
283
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
284
# and/or sell copies of the Software, and to permit persons to whom the
 
285
# Software is furnished to do so, subject to the following conditions:
 
286
#
 
287
# The above copyright notice and this permission notice shall be included
 
288
# in all copies or substantial portions of the Software.
 
289
#
 
290
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
291
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
292
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
293
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
294
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
295
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
296
# DEALINGS IN THE SOFTWARE.
 
297
 
 
298
 
 
299
icon="http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png"
 
300
rgba33="#FF9900"
 
301
rgba70="#FFFF00"
 
302
rgba150="#00FF00"
 
303
rgba300="#0000FF"
 
304
rgba500="#9900FF"
 
305
rgba800="#FF0000"
 
306
 
 
307
function docsv {
 
308
 
 
309
    IFS=','
 
310
    
 
311
    while read Date Time Lat Lon Mag Dep
 
312
    do
 
313
        ts=$(echo $Date | sed 's:/:-:g')T${Time%%.*}Z
 
314
        rgba=""
 
315
        
 
316
        if [[ $rgba == "" ]] && [[ $Dep -lt 33 ]]
 
317
        then
 
318
            rgba=$rgba33
 
319
        fi
 
320
        
 
321
        if [[ $rgba == "" ]] && [[ $Dep -lt 70 ]]
 
322
        then
 
323
            rgba=$rgba70
 
324
        fi
 
325
        
 
326
        if [[ $rgba == "" ]] && [[ $Dep -lt 150 ]]
 
327
        then
 
328
            rgba=$rgba150
 
329
        fi
 
330
        
 
331
        if [[ $rgba == "" ]] && [[ $Dep -lt 300 ]]
 
332
        then
 
333
            rgba=$rgba300
 
334
        fi
 
335
        
 
336
        if [[ $rgba == "" ]] && [[ $Dep -lt 500 ]]
 
337
        then
 
338
            rgba=$rgba500
 
339
        fi
 
340
        
 
341
        if [[ $rgba == "" ]]
 
342
        then
 
343
            rgba=$rgba800
 
344
        fi
 
345
        
 
346
        
 
347
        
 
348
        style="\"SYMBOL(s:$Mag,id:\"\"$icon\"\",c:$rgba)\""
 
349
        
 
350
        echo $Date,$Time,$Lat,$Lon,$Mag,$Dep,$ts,"$style"
 
351
    done
 
352
        
 
353
}
 
354
 
 
355
 
 
356
wget http://neic.usgs.gov/neis/gis/qed.asc -O /dev/stdout |\
 
357
 tail -n +2 &gt; qed.asc
 
358
 
 
359
echo Date,TimeUTC,Latitude,Longitude,Magnitude,Depth,timestamp,OGR_STYLE &gt; qed.csv
 
360
 
 
361
docsv &lt; qed.asc &gt;&gt; qed.csv
 
362
 
 
363
cat &gt; qed.vrt &lt;&lt; EOF
 
364
&lt;OGRVRTDataSource&gt;
 
365
    &lt;OGRVRTLayer name="qed"&gt;
 
366
        &lt;SrcDataSource&gt;qed.csv&lt;/SrcDataSource&gt;
 
367
        &lt;GeometryType&gt;wkbPoint&lt;/GeometryType&gt;
 
368
        &lt;LayerSRS&gt;WGS84&lt;/LayerSRS&gt;
 
369
        &lt;GeometryField encoding="PointFromColumns" x="Longitude" y="Latitude"/&gt;
 
370
    &lt;/OGRVRTLayer&gt;
 
371
&lt;/OGRVRTDataSource&gt;
 
372
 
 
373
EOF
 
374
 
 
375
ogr2ogr -f libkml qed.kml qed.vrt
 
376
 
 
377
  </pre>
 
378
 
 
379
</body>
 
380
</html>