<div dir="ltr"><div><div><div>Hi KC, <br><br></div>I believe it is the right place for your question, maybe no one could really check it out. <br></div>While I have not relied on OGR_STYLE on the command line, I have read a lot of practical examples looking for how to create a geoPDF a few days ago.<br></div>So check out this guides and try to change only the format from PDF to KML<br><br><a href="https://spatialthoughts.com/2015/10/25/geopdf-gdal/">https://spatialthoughts.com/2015/10/25/geopdf-gdal/</a><div><div><a href="http://latuviitta.org/documents/Geospatial_PDF_maps_from_OSM_with_GDAL.pdf">http://latuviitta.org/documents/Geospatial_PDF_maps_from_OSM_with_GDAL.pdf</a><br><br></div><div>For me what worked for PDF was to use feature.<span style="color:rgb(0,0,0)">SetStyleString</span>(style_string) and add to output data source using python, may work for KML too below a minimal example.<br></div><div>I created a KMZ on the project but I used another library for it, not gdal itself but I will provide it here also if it helps .</div><div><br></div><div>Also I noticed that the PDF Label is not showing up on the result as I expected neither I used the label on the KML so cannot help you on this for now, just the styling and popup on the kml, but if I get any progress I report to you.</div><div><br></div><div>My Best,</div><div>Cainã K. Campos<br></div><div><br><div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(86,156,214)">import json<br></span><div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(197,134,192)">from</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">osgeo</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">import</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">ogr</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(78,201,176)">osr</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(78,201,176)">gdal</span></div><div><span style="color:rgb(197,134,192)"></span></div><div><span style="color:rgb(197,134,192)">import</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">matplotlib</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(78,201,176)">colors</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">as</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">mcolors</span></div><div><span style="color:rgb(197,134,192)">import</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">simplekml</span></div></div><br><span style="color:rgb(86,156,214)">def</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">get_style_rules</span><span style="color:rgb(204,204,204)">():</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">return</span><span style="color:rgb(204,204,204)"> {</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">"hidrografia"</span><span style="color:rgb(204,204,204)">: {</span><span style="color:rgb(206,145,120)">"color"</span><span style="color:rgb(204,204,204)">: </span><span style="color:rgb(206,145,120)">"blue"</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"fillColor"</span><span style="color:rgb(204,204,204)">: </span><span style="color:rgb(206,145,120)">"blue"</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"fillOpacity"</span><span style="color:rgb(204,204,204)">: </span><span style="color:rgb(181,206,168)">0.6</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"opacity"</span><span style="color:rgb(204,204,204)">:</span><span style="color:rgb(181,206,168)">0.5</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"weight"</span><span style="color:rgb(204,204,204)">:</span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(204,204,204)">},</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">"area_imovel"</span><span style="color:rgb(204,204,204)">: {</span><span style="color:rgb(206,145,120)">"color"</span><span style="color:rgb(204,204,204)">: </span><span style="color:rgb(206,145,120)">"yellow"</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"fillColor"</span><span style="color:rgb(204,204,204)">: </span><span style="color:rgb(206,145,120)">"white"</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"fillOpacity"</span><span style="color:rgb(204,204,204)">:</span><span style="color:rgb(181,206,168)">0.01</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"weight"</span><span style="color:rgb(204,204,204)">:</span><span style="color:rgb(181,206,168)">3</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"opacity"</span><span style="color:rgb(204,204,204)">:</span><span style="color:rgb(181,206,168)">0.8</span><span style="color:rgb(204,204,204)">},</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">"apps"</span><span style="color:rgb(204,204,204)">: {</span><span style="color:rgb(206,145,120)">"color"</span><span style="color:rgb(204,204,204)">: </span><span style="color:rgb(206,145,120)">"red"</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"fillColor"</span><span style="color:rgb(204,204,204)">: </span><span style="color:rgb(206,145,120)">"red"</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"fillOpacity"</span><span style="color:rgb(204,204,204)">: </span><span style="color:rgb(181,206,168)">0.3</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"opacity"</span><span style="color:rgb(204,204,204)">:</span><span style="color:rgb(181,206,168)">0.5</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">"weight"</span><span style="color:rgb(204,204,204)">:</span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(204,204,204)">}</span></div><div><span style="color:rgb(204,204,204)"> }<br></span></div><div><span style="color:rgb(204,204,204)"><br></span></div></div></div><div><span style="color:rgb(86,156,214)">def</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">color_name_to_hex_with_alpha</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">color_name</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">alpha</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(181,206,168)">1.0</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">invert_alpha</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(86,156,214)">False</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">bgr</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(86,156,214)">False</span><span style="color:rgb(204,204,204)">):</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">"""</span></div><div><span style="color:rgb(206,145,120)"> Convert a color name to a hex value with alpha (transparency).</span></div><div><span style="color:rgb(206,145,120)"> Alpha should be a float between 0.0 (fully transparent) and 1.0 (fully opaque).</span></div><div><span style="color:rgb(206,145,120)"> """</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">try</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Get the hex color code without the '#' and convert to RGBA</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">hex_color</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">mcolors</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">to_hex</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">color_name</span><span style="color:rgb(204,204,204)">)[</span><span style="color:rgb(181,206,168)">1</span><span style="color:rgb(204,204,204)">:]</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Scale alpha to 255 and convert to hex</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">alpha_hex</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">f</span><span style="color:rgb(206,145,120)">"</span><span style="color:rgb(86,156,214)">{</span><span style="color:rgb(78,201,176)">int</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">alpha</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">*</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(181,206,168)">255</span><span style="color:rgb(204,204,204)">)</span><span style="color:rgb(86,156,214)">:02X}</span><span style="color:rgb(206,145,120)">"</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">bgr</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">hex_color</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">f</span><span style="color:rgb(206,145,120)">"</span><span style="color:rgb(86,156,214)">{</span><span style="color:rgb(156,220,254)">hex_color</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(212,212,212)">-</span><span style="color:rgb(181,206,168)">2</span><span style="color:rgb(204,204,204)">:]</span><span style="color:rgb(86,156,214)">}{</span><span style="color:rgb(156,220,254)">hex_color</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(181,206,168)">2</span><span style="color:rgb(204,204,204)">:</span><span style="color:rgb(181,206,168)">4</span><span style="color:rgb(204,204,204)">]</span><span style="color:rgb(86,156,214)">}{</span><span style="color:rgb(156,220,254)">hex_color</span><span style="color:rgb(204,204,204)">[:</span><span style="color:rgb(181,206,168)">2</span><span style="color:rgb(204,204,204)">]</span><span style="color:rgb(86,156,214)">}</span><span style="color:rgb(206,145,120)">"</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">invert_alpha</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">return</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">f</span><span style="color:rgb(206,145,120)">"#</span><span style="color:rgb(86,156,214)">{</span><span style="color:rgb(156,220,254)">alpha_hex</span><span style="color:rgb(86,156,214)">}{</span><span style="color:rgb(156,220,254)">hex_color</span><span style="color:rgb(86,156,214)">}</span><span style="color:rgb(206,145,120)">"</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">return</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">f</span><span style="color:rgb(206,145,120)">"#</span><span style="color:rgb(86,156,214)">{</span><span style="color:rgb(156,220,254)">hex_color</span><span style="color:rgb(86,156,214)">}{</span><span style="color:rgb(156,220,254)">alpha_hex</span><span style="color:rgb(86,156,214)">}</span><span style="color:rgb(206,145,120)">"</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">except</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">ValueError</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">return</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">"#000000FF"</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Default to black with full opacity if color name not found</span></div></div><span style="color:rgb(86,156,214)"><br>def</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">create_styled_layer_from_geojson</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">geojson_data</span><span style="color:rgb(204,204,204)">, output_pdf</span><span style="color:rgb(204,204,204)">):</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Create a temporary file to store the GeoJSON data</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">temp_geojson_file</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">'/tmp/temp_geojson.json'</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">with</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">open</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">temp_geojson_file</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">'w'</span><span style="color:rgb(204,204,204)">) </span><span style="color:rgb(197,134,192)">as</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">f</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">json</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">dump</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">geojson_data</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">f</span><span style="color:rgb(204,204,204)">)</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Open the GeoJSON file with OGR</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">driver</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">ogr</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">GetDriverByName</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">'GeoJSON'</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">dataSource</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">driver</span><span style="color:rgb(204,204,204)">.Open(</span><span style="color:rgb(156,220,254)">temp_geojson_file</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(204,204,204)">) </span><span style="color:rgb(106,153,85)"># 0 means read-only</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">dataSource</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">is</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">None</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">print</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">'Could not open file'</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">return</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Create a spatial reference</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">spatialRef</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">osr</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(78,201,176)">SpatialReference</span><span style="color:rgb(204,204,204)">()</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">spatialRef</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">ImportFromEPSG</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(181,206,168)">4326</span><span style="color:rgb(204,204,204)">) </span><span style="color:rgb(106,153,85)"># Assuming WGS84</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Create the output PDF driver</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">driver_pdf</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">gdal</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">GetDriverByName</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">'PDF'</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">driver_pdf</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">is</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">None</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">print</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">'PDF driver is not available.'</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">return</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Create the PDF file</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">output_ds</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">driver_pdf</span><span style="color:rgb(204,204,204)">.Create(</span><span style="color:rgb(156,220,254)">output_pdf</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(78,201,176)">gdal</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">GDT_Unknown</span><span style="color:rgb(204,204,204)">)</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">output_ds</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">is</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">None</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">print</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">'Could not create PDF file'</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">return</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">output_layer</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">output_ds</span><span style="color:rgb(204,204,204)">.CreateLayer(</span><span style="color:rgb(206,145,120)">'layer'</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">srs</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(156,220,254)">spatialRef</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">geom_type</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(78,201,176)">ogr</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">wkbUnknown</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">in_lyr</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">dataSource</span><span style="color:rgb(204,204,204)">.GetLayerByIndex(</span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">lyr_def</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">in_lyr</span><span style="color:rgb(204,204,204)">.GetLayerDefn ()</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">for</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">i</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">in</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">range</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">lyr_def</span><span style="color:rgb(204,204,204)">.GetFieldCount()):</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">output_layer</span><span style="color:rgb(204,204,204)">.CreateField ( </span><span style="color:rgb(156,220,254)">lyr_def</span><span style="color:rgb(204,204,204)">.GetFieldDefn(</span><span style="color:rgb(156,220,254)">i</span><span style="color:rgb(204,204,204)">) )</span></div><div><span style="color:rgb(204,204,204)"><br></span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Iterate through features and style them</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">for</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">in</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">dataSource</span><span style="color:rgb(204,204,204)">.GetLayer():</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">geom</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)">.GetGeometryRef()</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">cod_tema</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)">.GetField(</span><span style="color:rgb(206,145,120)">'cod_tema'</span><span style="color:rgb(204,204,204)">)</span></div><div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">car_code</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)">.GetField(</span><span style="color:rgb(206,145,120)">'cod_imovel'</span><span style="color:rgb(204,204,204)">)</span></div></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">get_style_cod_theme</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">cod_tema</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">fillOpacity</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">get</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">'fillOpacity'</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(181,206,168)">0.5</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Apply the style to the feature</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">color</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">color_name_to_hex_with_alpha</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(206,145,120)">'color'</span><span style="color:rgb(204,204,204)">], </span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">get</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">"opacity"</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(181,206,168)">0.5</span><span style="color:rgb(204,204,204)">))</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">fillColor</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">color_name_to_hex_with_alpha</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">get</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">'fillColor'</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">'none'</span><span style="color:rgb(204,204,204)">), </span><span style="color:rgb(156,220,254)">fillOpacity</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">line_width</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">get</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">"weight"</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(181,206,168)">1</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Create a new feature with the same geometry</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">new_feature</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">ogr</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(78,201,176)">Feature</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">output_layer</span><span style="color:rgb(204,204,204)">.GetLayerDefn())</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">new_feature</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">SetGeometry</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">geom</span><span style="color:rgb(204,204,204)">.Clone())</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Set the style of the new feature</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style_string</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">f</span><span style="color:rgb(206,145,120)">"PEN(c:</span><span style="color:rgb(86,156,214)">{</span><span style="color:rgb(156,220,254)">color</span><span style="color:rgb(86,156,214)">}</span><span style="color:rgb(206,145,120)">,w:</span><span style="color:rgb(86,156,214)">{</span><span style="color:rgb(156,220,254)">line_width</span><span style="color:rgb(86,156,214)">}</span><span style="color:rgb(206,145,120)">mm)"</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">fillColor</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">!=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">'none'</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style_string</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">+=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">f</span><span style="color:rgb(206,145,120)">";BRUSH(fc:</span><span style="color:rgb(86,156,214)">{</span><span style="color:rgb(156,220,254)">fillColor</span><span style="color:rgb(86,156,214)">}</span><span style="color:rgb(206,145,120)">)"</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style_string</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">+=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">f</span><span style="color:rgb(206,145,120)">';LABEL(f:"Arial, Helvetica", s:26pt, t:"</span><span style="color:rgb(86,156,214)">{car_code</span><span style="color:rgb(86,156,214)">}</span><span style="color:rgb(206,145,120)">")'</span></div><div><span style="color:rgb(204,204,204)"> </span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">new_feature</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">SetStyleString</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">style_string</span><span style="color:rgb(204,204,204)">)</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Add all attributes to the feature</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">for</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">i</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">in</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">range</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)">.GetFieldCount()):</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">field_name</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)">.GetFieldDefnRef(</span><span style="color:rgb(156,220,254)">i</span><span style="color:rgb(204,204,204)">).GetName()</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">field_value</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)">.GetField(</span><span style="color:rgb(156,220,254)">field_name</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">new_feature</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">SetField</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">field_name</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">field_value</span><span style="color:rgb(204,204,204)">)</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">output_layer</span><span style="color:rgb(204,204,204)">.CreateFeature(</span><span style="color:rgb(156,220,254)">new_feature</span><span style="color:rgb(204,204,204)">)</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Destroy the feature to free resources</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">new_feature</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">None</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Close the data sources</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">dataSource</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">None</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">output_ds</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(86,156,214)">None<br><br></span><div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(86,156,214)">def</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">create_kmz_from_geojson</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">geojson_data</span><span style="color:rgb(204,204,204)">, output_kmz</span><span style="color:rgb(204,204,204)">):</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Create a KML object</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">kml</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">simplekml</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(78,201,176)">Kml</span><span style="color:rgb(204,204,204)">()</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Iterate through features and style them</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">for</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">in</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">geojson_data</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(206,145,120)">'features'</span><span style="color:rgb(204,204,204)">]:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">cod_tema</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(206,145,120)">'properties'</span><span style="color:rgb(204,204,204)">].get(</span><span style="color:rgb(206,145,120)">'cod_tema'</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">get_style_cod_theme</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">cod_tema</span><span style="color:rgb(204,204,204)">)</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Extract geometry and properties</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">geom</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(206,145,120)">'geometry'</span><span style="color:rgb(204,204,204)">]</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">properties</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">feature</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(206,145,120)">'properties'</span><span style="color:rgb(204,204,204)">]</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Create a KML placemark for the feature</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">placemark</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">kml</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">newmultigeometry</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">name</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(156,220,254)">cod_tema</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">for</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">coords</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">in</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">geom</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(206,145,120)">'coordinates'</span><span style="color:rgb(204,204,204)">]:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">geom</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(206,145,120)">'type'</span><span style="color:rgb(204,204,204)">] </span><span style="color:rgb(212,212,212)">==</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">'Polygon'</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">placemark</span><span style="color:rgb(204,204,204)">.newpolygon(</span><span style="color:rgb(156,220,254)">outerboundaryis</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(156,220,254)">coords</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">elif</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">geom</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(206,145,120)">'type'</span><span style="color:rgb(204,204,204)">] </span><span style="color:rgb(212,212,212)">==</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">'MultiPolygon'</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">for</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">polygon_coords</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">in</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">coords</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">placemark</span><span style="color:rgb(204,204,204)">.newpolygon(</span><span style="color:rgb(156,220,254)">outerboundaryis</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(156,220,254)">polygon_coords</span><span style="color:rgb(204,204,204)">)</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Apply style to the placemark</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">color</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">color_name_to_hex_with_alpha</span><span style="color:rgb(204,204,204)">(</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">[</span><span style="color:rgb(206,145,120)">'color'</span><span style="color:rgb(204,204,204)">],</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">get</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">"opacity"</span><span style="color:rgb(204,204,204)">,</span><span style="color:rgb(181,206,168)">0.5</span><span style="color:rgb(204,204,204)">),</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">invert_alpha</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(86,156,214)">True</span><span style="color:rgb(204,204,204)">,</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">bgr</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(86,156,214)">True</span></div><div><span style="color:rgb(204,204,204)"> ).</span><span style="color:rgb(220,220,170)">upper</span><span style="color:rgb(204,204,204)">()</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">fillColor</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">get</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">'fillColor'</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(206,145,120)">'none'</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">fillColor</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">!=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">'none'</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">fillColor</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(220,220,170)">color_name_to_hex_with_alpha</span><span style="color:rgb(204,204,204)">(</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">fillColor</span><span style="color:rgb(204,204,204)">,</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">get</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">"fillOpacity"</span><span style="color:rgb(204,204,204)">,</span><span style="color:rgb(181,206,168)">0.5</span><span style="color:rgb(204,204,204)">),</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">invert_alpha</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(86,156,214)">True</span><span style="color:rgb(204,204,204)">,</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">bgr</span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(86,156,214)">True</span></div><div><span style="color:rgb(204,204,204)"> ).</span><span style="color:rgb(220,220,170)">upper</span><span style="color:rgb(204,204,204)">()</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">placemark</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">linestyle</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">color</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">color</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">replace</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">"#"</span><span style="color:rgb(204,204,204)">,</span><span style="color:rgb(206,145,120)">""</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">placemark</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">linestyle</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">width</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">get</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">'weight'</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(181,206,168)">1</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">fillColor</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">!=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">'none'</span><span style="color:rgb(204,204,204)">:</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">placemark</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">style</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">polystyle</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">color</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">fillColor</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">replace</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(206,145,120)">"#"</span><span style="color:rgb(204,204,204)">,</span><span style="color:rgb(206,145,120)">""</span><span style="color:rgb(204,204,204)">)</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Add attributes as description</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">description</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(206,145,120)">"<br>"</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">join</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(86,156,214)">f</span><span style="color:rgb(206,145,120)">"<b></span><span style="color:rgb(86,156,214)">{</span><span style="color:rgb(156,220,254)">key</span><span style="color:rgb(86,156,214)">}</span><span style="color:rgb(206,145,120)"></b>: </span><span style="color:rgb(86,156,214)">{</span><span style="color:rgb(156,220,254)">value</span><span style="color:rgb(86,156,214)">}</span><span style="color:rgb(206,145,120)">"</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">for</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">key</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">value</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(197,134,192)">in</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">properties</span><span style="color:rgb(204,204,204)">.items())</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">placemark</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">description</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">description</span></div><br><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># Save KML to a KMZ file</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">kml</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">savekmz</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">output_kmz</span><span style="color:rgb(204,204,204)">)</span></div></div></div></div></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 18, 2024 at 12:51 PM Open Land LLC via gdal-dev <<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Everyone,<div><br></div><div>I just wanted to ask - Is this the right place to post questions? I put in a post several days ago, and just want to make sure I'm putting it in the right place, because I have not posted to this group before. Thank you - KC <br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">---------- Forwarded message ---------<br>From: <strong class="gmail_sendername" dir="auto">Open Land LLC</strong> <span dir="auto"><<a href="mailto:realoption11@gmail.com" target="_blank">realoption11@gmail.com</a>></span><br>Date: Mon, Jul 15, 2024 at 9:00 PM<br>Subject: How to add labels to DEM contour lines<br>To: <<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>><br></div><br><br><div dir="ltr"><div>Hi everyone, this is my first post. I've also posted this to <a href="https://stackoverflow.com/questions/78751101/labelling-contour-lines-with-ogr-style" target="_blank">https://stackoverflow.com/questions/78751101/labelling-contour-lines-with-ogr-style</a></div><div><br></div>I'm trying to add labels to DEM contour lines.<br><br>I'm working with GDAL 3.6.2. , which I installed using Anaconda . I have some DEM data from USGS which I wrote as a contour map to a KML file using:<br><br> gdal_contour small.tif /home/ubuntu/node/geotools/contour.kml -i 3.0 -f KML -a ELEVATION<br><br>When I open contour.kml in vim, I can see that its made up of features like:<br><br> <Placemark><br> <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style><br> <ExtendedData><SchemaData schemaUrl="#contour"><br> <SimpleData name="ID">39</SimpleData><br> <SimpleData name="ELEVATION">525</SimpleData><br> </SchemaData></ExtendedData><br> <LineString><coordinates>-89.2626638689733,46.1525006611575 -89.262663868958,46.1525469572921 -89.2627325352002,46.152622208059 -89.2628251277396,46.1526266807347 -89.2629177202847,46.1526141000471 -89.2629982621728,46.1525469573863 -89.2629982621882,46.1525006612516</coordinates></LineString><br> </Placemark><br><br>Clearly there is a style component available , but I'm not sure how to work with it to add elevation labels or custom colours. My suspicion is that OGR_STYLE is used to do things like this (<a href="https://github.com/OSGeo/gdal/issues/835)(https://gdal.org/user/ogr_sql_dialect.html#ogr-style" target="_blank">https://github.com/OSGeo/gdal/issues/835)(https://gdal.org/user/ogr_sql_dialect.html#ogr-style</a> ), but I can't find any examples. How can this be done?<div><br></div><div>Thank you very much,</div><div><br></div><div>KC<br> <br></div></div>
</div></div></div>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote></div>