GDAL Guru's,

I'm looking at how to apply some sort of predefined style to a dataset coming 
from XLSX and going to KML (LIBKML).

My thoughts are XLSX --> VRT --> KML.

I can successfully add OGR_STYLE at each feature and style the features 
individually, however I'm hoping I can leverage existing styles at the layer / 
folder level of the KML. 
(https://gdal.org/drivers/vector/libkml.html#styletable, 
https://gdal.org/drivers/vector/libkml.html#style)

For the KML file specifically I'd love to be able to append a StyleURL in the 
format 'sharedstyle.kml#Zone' and somehow bundle the ogr2ogr generated file 
with this sharedstyle.kml in a kmz...?

Some data sets:

The XLSX data:
ElementId
Name
WKT
1179
Zone1
POLYGON ((530494.56 6944864.63, 530486.431754 6944883.227494, 530497.919033 
6944897.30242, 530575.4 6944931.94, 530589.075307 6944920.363282, 530608.620897 
6944914.005078, 530494.56 6944864.63))
1180
Zone4
POLYGON ((530640.737164 6944927.90768, 530633.256 6944960.922, 530648.673025 
6944964.552847, 530660.54 6944936.48, 530640.737164 6944927.90768))
1181
Zone2
POLYGON ((530494.56 6944864.63, 530501.34 6944857.63, 530665.986727 
6944919.946257, 530660.54 6944936.48, 530494.56 6944864.63))


The VRT file (Local.vrt):
<OGRVRTDataSource>
  <OGRVRTLayer name="Zone">
    <SrcDataSource relativeToVRT="1">Local.xlsx</SrcDataSource>
    <FID name="ElementId"/>
    <OpenOptions>
      <OOI key="HEADERS">FORCE</OOI>
    </OpenOptions>
    <SrcSQL>Select ElementId, Name, WKT, '@Zone' as OGR_STYLE from Zone</SrcSQL>
    <GeometryType>wkbPolygon</GeometryType>
    <LayerSRS>EPSG:28356</LayerSRS>
    <GeometryField encoding="WKT" name="Geometry" field="WKT" 
reportSrcColumn="FALSE" />
    <Field name="ElementId" type="Integer" />
    <Field name="Name" type="String" />
    <Style>OGR_STYLE</Style>
  </OGRVRTLayer>
</OGRVRTDataSource>

Template KML file (Base.kml):
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns=http://www.opengis.net/kml/2.2>
  <Document id="root_doc">
    <Style id="Zone">
      <LineStyle>
        <color>ff0000ff</color>
        <width>15</width>
      </LineStyle>
      <PolyStyle>
        <color>7f7faaaa</color>
        <colorMode>random</colorMode>
      </PolyStyle>
    </Style>
  </Document>
</kml>

Local.ofs:
#OFS-Version: 1.0
#StyleField: "LayerStyle"

DefaultStyle: BRUSH(fc:#000000);PEN(c:#000000)
Zone:      BRUSH(fc:#0000FF);PEN(c:#000000)

ogr2ogr Local.kml Local.vrt Zone -oo HEADERS=FORCE -t_srs EPSG:4326 -f LIBKML 
-lco FOLDER=NO

How do I append layer level rules to a KML file when using ogr2ogr, things I've 
tried:
'BRUSH(fc:#0000FF);PEN(c:#000000)', writes a style element to each feature 
(this will work but not ideal).
'@Zone', generates '#Zone' in the styleurl, but I don't know how to append the 
style rule to the newly created kml file.
'@styles.kml#Zome', generates '#styles.kml#Zone', just not going to cut it.

https://gdal.org/user/ogr_feature_style.html#styles-table-format
I've tinkered with the .ofs file, documentation on this is a little sparse not 
sure exactly what to do with it?



Note:
This message is for the named person's use only.  It may contain confidential, 
proprietary or legally privileged information.  No confidentiality or privilege 
is waived or lost by any mistransmission.  If you receive this message in 
error, please immediately delete it and all copies of it from your system, 
destroy any hard copies of it and notify the sender.  You must not, directly or 
indirectly, use, disclose, distribute, print, or copy any part of this message 
if you are not the intended recipient. The Port of Brisbane reserves the right 
to monitor all e-mail communications through its networks.
If you have received this transmission in error please let us know by 
contacting us on +61 7 3258 4888 or by reply E-Mail to the sender.
Any views expressed in this message are those of the individual sender, except 
where the message states otherwise and the sender is authorised to state them 
to be the views of any such entity.
 
Thank You.
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to