1 : /******************************************************************************
2 : *
3 : * Project: KML Translator
4 : * Purpose: Implements OGRLIBKMLDriver
5 : * Author: Brian Case, rush at winkey dot org
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2010, Brian Case
9 : *
10 : * Permission is hereby granted, free of charge, to any person obtaining a
11 : * copy of this software and associated documentation files (the "Software"),
12 : * to deal in the Software without restriction, including without limitation
13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 : * and/or sell copies of the Software, and to permit persons to whom the
15 : * Software is furnished to do so, subject to the following conditions:
16 : *
17 : * The above copyright notice and this permission notice shall be included
18 : * in all copies or substantial portions of the Software.
19 : *
20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 : * DEALINGS IN THE SOFTWARE.
27 : *****************************************************************************/
28 :
29 : #include <ogr_featurestyle.h>
30 :
31 : #include <kml/dom.h>
32 : #include <kml/base/color32.h>
33 :
34 : using kmldom::KmlFactory;;
35 : using kmldom::ElementPtr;
36 : using kmldom::ObjectPtr;
37 : using kmldom::FeaturePtr;
38 : using kmldom::StylePtr;
39 : using kmldom::StyleSelectorPtr;
40 : using kmldom::LineStylePtr;
41 : using kmldom::PolyStylePtr;
42 : using kmldom::IconStylePtr;
43 : using kmldom::IconStyleIconPtr;
44 : using kmldom::LabelStylePtr;
45 : using kmldom::HotSpotPtr;
46 : using kmlbase::Color32;
47 :
48 : #include "ogrlibkmlstyle.h"
49 :
50 : /******************************************************************************
51 : generic function to parse a stylestring and add to a kml style
52 :
53 : args:
54 : pszStyleString the stylestring to parse
55 : poKmlStyle the kml style to add to
56 : poKmlFactory the kml dom factory
57 :
58 : returns:
59 : nothing
60 :
61 : ******************************************************************************/
62 :
63 : void addstylestring2kml (
64 : const char *pszStyleString,
65 : StylePtr poKmlStyle,
66 : KmlFactory * poKmlFactory,
67 : PlacemarkPtr poKmlPlacemark,
68 0 : OGRFeature * poOgrFeat )
69 : {
70 :
71 0 : LineStylePtr poKmlLineStyle = NULL;
72 0 : PolyStylePtr poKmlPolyStyle = NULL;
73 0 : IconStylePtr poKmlIconStyle = NULL;
74 0 : LabelStylePtr poKmlLabelStyle = NULL;
75 :
76 : /***** just bail now if stylestring is empty *****/
77 :
78 0 : if ( !pszStyleString || !*pszStyleString ) {
79 0 : return;
80 : }
81 :
82 : /***** create and init a style mamager with the style string *****/
83 :
84 0 : OGRStyleMgr *poOgrSM = new OGRStyleMgr;
85 :
86 0 : poOgrSM->InitStyleString ( pszStyleString );
87 :
88 : /***** loop though the style parts *****/
89 :
90 : int i;
91 :
92 0 : for ( i = 0; i < poOgrSM->GetPartCount ( NULL ); i++ ) {
93 0 : OGRStyleTool *poOgrST = poOgrSM->GetPart ( i, NULL );
94 :
95 0 : if ( !poOgrST ) {
96 0 : continue;
97 : }
98 :
99 0 : switch ( poOgrST->GetType ( ) ) {
100 : case OGRSTCPen:
101 : {
102 : GBool nullcheck;
103 :
104 0 : poKmlLineStyle = poKmlFactory->CreateLineStyle ( );
105 :
106 0 : OGRStylePen *poStylePen = ( OGRStylePen * ) poOgrST;
107 :
108 : /***** pen color *****/
109 :
110 : int nR,
111 : nG,
112 : nB,
113 : nA;
114 :
115 0 : const char *pszcolor = poStylePen->Color ( nullcheck );
116 :
117 0 : if ( !nullcheck
118 : && poStylePen->GetRGBFromString ( pszcolor, nR, nG, nB, nA ) ) {
119 0 : poKmlLineStyle->set_color ( Color32 ( nA, nB, nG, nR ) );
120 : }
121 0 : double dfWidth = poStylePen->Width ( nullcheck );
122 :
123 0 : if ( nullcheck )
124 0 : dfWidth = 1.0;
125 :
126 0 : poKmlLineStyle->set_width ( dfWidth );
127 :
128 0 : break;
129 : }
130 : case OGRSTCBrush:
131 : {
132 : GBool nullcheck;
133 :
134 0 : poKmlPolyStyle = poKmlFactory->CreatePolyStyle ( );
135 :
136 0 : OGRStyleBrush *poStyleBrush = ( OGRStyleBrush * ) poOgrST;
137 :
138 : /***** brush color *****/
139 :
140 : int nR,
141 : nG,
142 : nB,
143 : nA;
144 :
145 0 : const char *pszcolor = poStyleBrush->ForeColor ( nullcheck );
146 :
147 0 : if ( !nullcheck
148 : && poStyleBrush->GetRGBFromString ( pszcolor, nR, nG, nB, nA ) ) {
149 0 : poKmlPolyStyle->set_color ( Color32 ( nA, nB, nG, nR ) );
150 : }
151 :
152 :
153 0 : break;
154 : }
155 : case OGRSTCSymbol:
156 : {
157 : GBool nullcheck;
158 : GBool nullcheck2;
159 :
160 0 : OGRStyleSymbol *poStyleSymbol = ( OGRStyleSymbol * ) poOgrST;
161 :
162 : /***** id (kml icon) *****/
163 :
164 0 : const char *pszId = poStyleSymbol->Id ( nullcheck );
165 :
166 0 : if ( !nullcheck ) {
167 0 : if ( !poKmlIconStyle)
168 0 : poKmlIconStyle = poKmlFactory->CreateIconStyle ( );
169 :
170 : /***** split it at the ,'s *****/
171 :
172 : char **papszTokens =
173 : CSLTokenizeString2 ( pszId, ",",
174 : CSLT_HONOURSTRINGS | CSLT_STRIPLEADSPACES |
175 0 : CSLT_STRIPENDSPACES );
176 :
177 0 : if ( papszTokens ) {
178 :
179 : /***** for lack of a better solution just take the first one *****/
180 : //todo come up with a better idea
181 :
182 0 : if ( papszTokens[0] ) {
183 : IconStyleIconPtr poKmlIcon =
184 0 : poKmlFactory->CreateIconStyleIcon ( );
185 0 : poKmlIcon->set_href ( papszTokens[0] );
186 0 : poKmlIconStyle->set_icon ( poKmlIcon );
187 : }
188 :
189 0 : CSLDestroy ( papszTokens );
190 :
191 : }
192 :
193 :
194 : }
195 :
196 : /***** heading *****/
197 :
198 0 : double heading = poStyleSymbol->Angle ( nullcheck );
199 :
200 0 : if ( !nullcheck ) {
201 0 : if ( !poKmlIconStyle)
202 0 : poKmlIconStyle = poKmlFactory->CreateIconStyle ( );
203 0 : poKmlIconStyle->set_heading ( heading );
204 : }
205 :
206 : /***** scale *****/
207 :
208 0 : double dfScale = poStyleSymbol->Size ( nullcheck );
209 :
210 0 : if ( !nullcheck ) {
211 0 : if ( !poKmlIconStyle)
212 0 : poKmlIconStyle = poKmlFactory->CreateIconStyle ( );
213 :
214 0 : poKmlIconStyle->set_scale ( dfScale );
215 : }
216 :
217 : /***** color *****/
218 :
219 : int nR,
220 : nG,
221 : nB,
222 : nA;
223 :
224 0 : const char *pszcolor = poStyleSymbol->Color ( nullcheck );
225 :
226 0 : if ( !nullcheck && poOgrST->GetRGBFromString ( pszcolor, nR, nG, nB, nA ) ) {
227 0 : poKmlIconStyle->set_color ( Color32 ( nA, nB, nG, nR ) );
228 : }
229 :
230 : /***** hotspot *****/
231 :
232 0 : double dfDx = poStyleSymbol->SpacingX ( nullcheck );
233 0 : double dfDy = poStyleSymbol->SpacingY ( nullcheck2 );
234 :
235 0 : if ( !nullcheck && !nullcheck2 ) {
236 0 : if ( !poKmlIconStyle)
237 0 : poKmlIconStyle = poKmlFactory->CreateIconStyle ( );
238 :
239 0 : HotSpotPtr poKmlHotSpot = poKmlFactory->CreateHotSpot ( );
240 :
241 0 : poKmlHotSpot->set_x ( dfDx );
242 0 : poKmlHotSpot->set_y ( dfDy );
243 :
244 0 : poKmlIconStyle->set_hotspot ( poKmlHotSpot );
245 : }
246 :
247 0 : break;
248 : }
249 : case OGRSTCLabel:
250 : {
251 : GBool nullcheck;
252 : GBool nullcheck2;
253 :
254 0 : poKmlLabelStyle = poKmlFactory->CreateLabelStyle ( );
255 :
256 0 : OGRStyleLabel *poStyleLabel = ( OGRStyleLabel * ) poOgrST;
257 :
258 : /***** color *****/
259 :
260 : int nR,
261 : nG,
262 : nB,
263 : nA;
264 :
265 0 : const char *pszcolor = poStyleLabel->ForeColor ( nullcheck );
266 :
267 0 : if ( !nullcheck
268 : && poStyleLabel->GetRGBFromString ( pszcolor, nR, nG, nB, nA ) ) {
269 0 : poKmlLabelStyle->set_color ( Color32 ( nA, nB, nG, nR ) );
270 : }
271 :
272 : /***** scale *****/
273 :
274 0 : double dfScale = poStyleLabel->Size ( nullcheck );
275 :
276 0 : if ( !nullcheck ) {
277 0 : poKmlLabelStyle->set_scale ( dfScale );
278 : }
279 :
280 : /***** heading *****/
281 :
282 0 : double heading = poStyleLabel->Angle ( nullcheck );
283 :
284 0 : if ( !nullcheck ) {
285 0 : if ( !poKmlIconStyle) {
286 0 : poKmlIconStyle = poKmlFactory->CreateIconStyle ( );
287 0 : IconStyleIconPtr poKmlIcon = poKmlFactory->CreateIconStyleIcon ( );
288 0 : poKmlIconStyle->set_icon ( poKmlIcon );
289 : }
290 :
291 0 : poKmlIconStyle->set_heading ( heading );
292 : }
293 :
294 : /***** hotspot *****/
295 :
296 0 : double dfDx = poStyleLabel->SpacingX ( nullcheck );
297 0 : double dfDy = poStyleLabel->SpacingY ( nullcheck2 );
298 :
299 0 : if ( !nullcheck && !nullcheck2 ) {
300 0 : if ( !poKmlIconStyle) {
301 0 : poKmlIconStyle = poKmlFactory->CreateIconStyle ( );
302 0 : IconStyleIconPtr poKmlIcon = poKmlFactory->CreateIconStyleIcon ( );
303 0 : poKmlIconStyle->set_icon ( poKmlIcon );
304 : }
305 :
306 0 : HotSpotPtr poKmlHotSpot = poKmlFactory->CreateHotSpot ( );
307 :
308 0 : poKmlHotSpot->set_x ( dfDx );
309 0 : poKmlHotSpot->set_y ( dfDy );
310 :
311 0 : poKmlIconStyle->set_hotspot ( poKmlHotSpot );
312 : }
313 :
314 : /***** label text *****/
315 :
316 0 : const char *pszText = poStyleLabel->TextString ( nullcheck );
317 :
318 0 : if ( !nullcheck ) {
319 0 : if ( poKmlPlacemark ) {
320 :
321 0 : poKmlPlacemark->set_name( pszText );
322 : }
323 : }
324 :
325 : break;
326 : }
327 : case OGRSTCNone:
328 : default:
329 : break;
330 : }
331 :
332 0 : delete poOgrST;
333 : }
334 :
335 0 : if ( poKmlLineStyle )
336 0 : poKmlStyle->set_linestyle ( poKmlLineStyle );
337 :
338 0 : if ( poKmlPolyStyle )
339 0 : poKmlStyle->set_polystyle ( poKmlPolyStyle );
340 :
341 0 : if ( poKmlIconStyle )
342 0 : poKmlStyle->set_iconstyle ( poKmlIconStyle );
343 :
344 0 : if ( poKmlLabelStyle )
345 0 : poKmlStyle->set_labelstyle ( poKmlLabelStyle );
346 :
347 0 : delete poOgrSM;
348 : }
349 :
350 : /******************************************************************************
351 : kml2pen
352 : ******************************************************************************/
353 :
354 : OGRStylePen *kml2pen (
355 : LineStylePtr poKmlLineStyle );
356 :
357 : /******************************************************************************
358 : kml2brush
359 : ******************************************************************************/
360 :
361 : OGRStyleBrush *kml2brush (
362 : PolyStylePtr poKmlPolyStyle );
363 :
364 : /******************************************************************************
365 : kml2brush
366 : ******************************************************************************/
367 :
368 : OGRStyleSymbol *kml2symbol (
369 : IconStylePtr poKmlIconStyle );
370 :
371 : /******************************************************************************
372 : kml2label
373 : ******************************************************************************/
374 :
375 : OGRStyleLabel *kml2label (
376 : LabelStylePtr poKmlLabelStyle );
377 :
378 : /******************************************************************************
379 : kml2stylemgr
380 : ******************************************************************************/
381 :
382 : void kml2stylestring (
383 : StylePtr poKmlStyle,
384 14 : OGRStyleMgr * poOgrSM )
385 : {
386 :
387 : /***** linestyle / pen *****/
388 :
389 14 : if ( poKmlStyle->has_linestyle ( ) ) {
390 10 : LineStylePtr poKmlLineStyle = poKmlStyle->get_linestyle ( );
391 :
392 10 : OGRStylePen *poOgrStylePen = kml2pen ( poKmlLineStyle );
393 :
394 10 : poOgrSM->AddPart ( poOgrStylePen );
395 :
396 10 : delete poOgrStylePen;
397 : }
398 :
399 : /***** polystyle / brush *****/
400 :
401 14 : if ( poKmlStyle->has_polystyle ( ) ) {
402 8 : PolyStylePtr poKmlPolyStyle = poKmlStyle->get_polystyle ( );
403 :
404 8 : OGRStyleBrush *poOgrStyleBrush = kml2brush ( poKmlPolyStyle );
405 :
406 8 : poOgrSM->AddPart ( poOgrStyleBrush );
407 :
408 8 : delete poOgrStyleBrush;
409 : }
410 :
411 : /***** iconstyle / symbol *****/
412 :
413 14 : if ( poKmlStyle->has_iconstyle ( ) ) {
414 4 : IconStylePtr poKmlIconStyle = poKmlStyle->get_iconstyle ( );
415 :
416 4 : OGRStyleSymbol *poOgrStyleSymbol = kml2symbol ( poKmlIconStyle );
417 :
418 4 : poOgrSM->AddPart ( poOgrStyleSymbol );
419 :
420 4 : delete poOgrStyleSymbol;
421 : }
422 :
423 : /***** labelstyle / label *****/
424 :
425 14 : if ( poKmlStyle->has_labelstyle ( ) ) {
426 0 : LabelStylePtr poKmlLabelStyle = poKmlStyle->get_labelstyle ( );
427 :
428 0 : OGRStyleLabel *poOgrStyleLabel = kml2label ( poKmlLabelStyle );
429 :
430 0 : poOgrSM->AddPart ( poOgrStyleLabel );
431 :
432 0 : delete poOgrStyleLabel;
433 : }
434 :
435 14 : }
436 :
437 :
438 :
439 : /******************************************************************************
440 : kml2pen
441 : ******************************************************************************/
442 :
443 : OGRStylePen *kml2pen (
444 10 : LineStylePtr poKmlLineStyle )
445 : {
446 :
447 10 : OGRStylePen *poOgrStylePen = new OGRStylePen ( );
448 :
449 : /***** width *****/
450 :
451 10 : if ( poKmlLineStyle->has_width ( ) )
452 8 : poOgrStylePen->SetWidth ( poKmlLineStyle->get_width ( ) );
453 :
454 : /***** color *****/
455 :
456 10 : if ( poKmlLineStyle->has_color ( ) ) {
457 5 : Color32 poKmlColor = poKmlLineStyle->get_color ( );
458 5 : char szColor[10] = { };
459 : snprintf ( szColor, sizeof ( szColor ), "#%02X%02X%02X%02X",
460 : poKmlColor.get_red ( ),
461 : poKmlColor.get_green ( ),
462 5 : poKmlColor.get_blue ( ), poKmlColor.get_alpha ( ) );
463 5 : poOgrStylePen->SetColor ( szColor );
464 : }
465 :
466 10 : return poOgrStylePen;
467 : }
468 :
469 : /******************************************************************************
470 : kml2brush
471 : ******************************************************************************/
472 :
473 : OGRStyleBrush *kml2brush (
474 8 : PolyStylePtr poKmlPolyStyle )
475 : {
476 :
477 8 : OGRStyleBrush *poOgrStyleBrush = new OGRStyleBrush ( );
478 :
479 : /***** color *****/
480 :
481 8 : if ( poKmlPolyStyle->has_color ( ) ) {
482 8 : Color32 poKmlColor = poKmlPolyStyle->get_color ( );
483 8 : char szColor[10] = { };
484 : snprintf ( szColor, sizeof ( szColor ), "#%02X%02X%02X%02X",
485 : poKmlColor.get_red ( ),
486 : poKmlColor.get_green ( ),
487 8 : poKmlColor.get_blue ( ), poKmlColor.get_alpha ( ) );
488 8 : poOgrStyleBrush->SetForeColor ( szColor );
489 : }
490 :
491 8 : return poOgrStyleBrush;
492 : }
493 :
494 : /******************************************************************************
495 : kml2symbol
496 : ******************************************************************************/
497 :
498 : OGRStyleSymbol *kml2symbol (
499 4 : IconStylePtr poKmlIconStyle )
500 : {
501 :
502 4 : OGRStyleSymbol *poOgrStyleSymbol = new OGRStyleSymbol ( );
503 :
504 : /***** id (kml icon) *****/
505 :
506 4 : if ( poKmlIconStyle->has_icon ( ) ) {
507 4 : IconStyleIconPtr poKmlIcon = poKmlIconStyle->get_icon ( );
508 :
509 4 : if ( poKmlIcon->has_href ( ) ) {
510 4 : std::string oIcon = "\"";
511 8 : oIcon.append ( poKmlIcon->get_href ( ).c_str ( ) );
512 4 : oIcon.append ( "\"" );
513 4 : poOgrStyleSymbol->SetId ( oIcon.c_str ( ) );
514 :
515 4 : }
516 : }
517 :
518 : /***** heading *****/
519 :
520 4 : if ( poKmlIconStyle->has_heading ( ) )
521 0 : poOgrStyleSymbol->SetAngle ( poKmlIconStyle->get_heading ( ) );
522 :
523 : /***** scale *****/
524 :
525 4 : if ( poKmlIconStyle->has_scale ( ) )
526 0 : poOgrStyleSymbol->SetSize ( poKmlIconStyle->get_scale ( ) );
527 :
528 : /***** color *****/
529 :
530 4 : if ( poKmlIconStyle->has_color ( ) ) {
531 0 : Color32 poKmlColor = poKmlIconStyle->get_color ( );
532 0 : char szColor[10] = { };
533 : snprintf ( szColor, sizeof ( szColor ), "#%02X%02X%02X%02X",
534 : poKmlColor.get_red ( ),
535 : poKmlColor.get_green ( ),
536 0 : poKmlColor.get_blue ( ), poKmlColor.get_alpha ( ) );
537 0 : poOgrStyleSymbol->SetColor ( szColor );
538 : }
539 :
540 : /***** hotspot *****/
541 :
542 4 : if ( poKmlIconStyle->has_hotspot ( ) ) {
543 0 : HotSpotPtr poKmlHotSpot = poKmlIconStyle->get_hotspot ( );
544 :
545 0 : if ( poKmlHotSpot->has_x ( ) )
546 0 : poOgrStyleSymbol->SetSpacingX ( poKmlHotSpot->get_x ( ) );
547 0 : if ( poKmlHotSpot->has_y ( ) )
548 0 : poOgrStyleSymbol->SetSpacingY ( poKmlHotSpot->get_y ( ) );
549 :
550 : }
551 :
552 4 : return poOgrStyleSymbol;
553 : }
554 :
555 : /******************************************************************************
556 : kml2label
557 : ******************************************************************************/
558 :
559 : OGRStyleLabel *kml2label (
560 0 : LabelStylePtr poKmlLabelStyle )
561 : {
562 :
563 0 : OGRStyleLabel *poOgrStyleLabel = new OGRStyleLabel ( );
564 :
565 : /***** color *****/
566 :
567 0 : if ( poKmlLabelStyle->has_color ( ) ) {
568 0 : Color32 poKmlColor = poKmlLabelStyle->get_color ( );
569 0 : char szColor[10] = { };
570 : snprintf ( szColor, sizeof ( szColor ), "#%02X%02X%02X%02X",
571 : poKmlColor.get_red ( ),
572 : poKmlColor.get_green ( ),
573 0 : poKmlColor.get_blue ( ), poKmlColor.get_alpha ( ) );
574 0 : poOgrStyleLabel->SetForColor ( szColor );
575 : }
576 :
577 0 : return poOgrStyleLabel;
578 : }
579 :
580 : /******************************************************************************
581 : function to add a kml style to a style table
582 : ******************************************************************************/
583 :
584 : void kml2styletable (
585 : OGRStyleTable * poOgrStyleTable,
586 14 : StylePtr poKmlStyle )
587 : {
588 :
589 :
590 : /***** no reason to add it if it don't have an id *****/
591 :
592 14 : if ( poKmlStyle->has_id ( ) ) {
593 :
594 14 : OGRStyleMgr *poOgrSM = new OGRStyleMgr ( poOgrStyleTable );
595 :
596 14 : poOgrSM->InitStyleString ( NULL );
597 :
598 : /***** read the style *****/
599 :
600 28 : kml2stylestring ( poKmlStyle, poOgrSM );
601 :
602 : /***** add the style to the style table *****/
603 :
604 14 : const std::string oName = poKmlStyle->get_id ( );
605 :
606 :
607 : poOgrSM->AddStyle ( CPLString ( ).Printf ( "@%s",
608 28 : oName.c_str ( ) ), NULL );
609 :
610 : /***** cleanup the style manager *****/
611 :
612 14 : delete poOgrSM;
613 : }
614 :
615 : else {
616 : CPLError ( CE_Failure, CPLE_AppDefined,
617 0 : "ERROR Parseing kml Style: No id" );
618 : }
619 :
620 : return;
621 : }
622 :
623 : /******************************************************************************
624 : function to parse a style table out of a document
625 : ******************************************************************************/
626 :
627 : void ParseStyles (
628 : DocumentPtr poKmlDocument,
629 6 : OGRStyleTable ** poStyleTable )
630 : {
631 :
632 : /***** if document is null just bail now *****/
633 :
634 6 : if ( !poKmlDocument )
635 0 : return;
636 :
637 : /***** loop over the Styles *****/
638 :
639 6 : size_t nKmlStyles = poKmlDocument->get_styleselector_array_size ( );
640 : size_t iKmlStyle;
641 :
642 35 : for ( iKmlStyle = 0; iKmlStyle < nKmlStyles; iKmlStyle++ ) {
643 :
644 : StyleSelectorPtr poKmlStyle =
645 15 : poKmlDocument->get_styleselector_array_at ( iKmlStyle );
646 :
647 15 : if ( !poKmlStyle->IsA ( kmldom::Type_Style ) )
648 1 : continue;
649 :
650 14 : if ( !*poStyleTable )
651 2 : *poStyleTable = new OGRStyleTable ( );
652 :
653 14 : ElementPtr poKmlElement = AsElement ( poKmlStyle );
654 :
655 14 : kml2styletable ( *poStyleTable, AsStyle ( poKmlElement ) );
656 : }
657 :
658 6 : return;
659 : }
660 :
661 : /******************************************************************************
662 : function to add a style table to a kml container
663 : ******************************************************************************/
664 :
665 : void styletable2kml (
666 : OGRStyleTable * poOgrStyleTable,
667 : KmlFactory * poKmlFactory,
668 0 : ContainerPtr poKmlContainer )
669 : {
670 :
671 : /***** just return if the styletable is null *****/
672 :
673 0 : if ( !poOgrStyleTable )
674 0 : return;
675 :
676 : /***** parse the style table *****/
677 :
678 0 : poOgrStyleTable->ResetStyleStringReading ( );
679 : const char *pszStyleString;
680 :
681 0 : while ( ( pszStyleString = poOgrStyleTable->GetNextStyle ( ) ) ) {
682 0 : const char *pszStyleName = poOgrStyleTable->GetLastStyleName ( );
683 :
684 : /***** add the style header to the kml *****/
685 :
686 0 : StylePtr poKmlStyle = poKmlFactory->CreateStyle ( );
687 :
688 0 : poKmlStyle->set_id ( pszStyleName + 1 );
689 :
690 : /***** parse the style string *****/
691 :
692 0 : addstylestring2kml ( pszStyleString, poKmlStyle, poKmlFactory, NULL, NULL );
693 :
694 : /***** add the style to the container *****/
695 :
696 0 : DocumentPtr poKmlDocument = AsDocument ( poKmlContainer );
697 :
698 : //ObjectPtr pokmlObject = boost::static_pointer_cast <kmldom::Object> () ;
699 : //poKmlContainer->add_feature ( AsFeature( poKmlStyle) );
700 0 : poKmlDocument->add_styleselector ( poKmlStyle );
701 :
702 : }
703 :
704 0 : return;
705 : }
|