[gdal-dev] change icon of placemark of a kml file
Even Rouault
even.rouault at spatialys.com
Wed Sep 9 01:10:16 PDT 2015
Le mercredi 09 septembre 2015 04:48:13, Cheng Tang a écrit :
> Hi Gdal Developers:
>
> I have a question: Can I change icon of placemark of a kml file through
> code using ogr python? I did not find this function in ogr document.
Tang,
you need to use the LIBML driver of GDAL (not necessarily available in all
builds) : http://gdal.org/drv_libkml.html
You need to attach a style to the OGR feature. The OGR Feature Style
specification is describe here : http://gdal.org/ogr_feature_style.html .
For example :
feat.SetStyleString('SYMBOL(id:"http://gdal.org/gdalicon.png")')
Little demo without code :
Given test.csv with the following content :
id,WKT,OGR_STYLE
1,"POINT(2 49)","SYMBOL(id:""http://gdal.org/gdalicon.png"")"
"ogr2ogr -f libkml out.kml test.csv -select id" generates :
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema id="test.schema">
<SimpleField name="id" type="string"/>
</Schema>
<Document id="test">
<name>test</name>
<Placemark id="test.1">
<Style>
<IconStyle>
<Icon>
<href>http://gdal.org/gdalicon.png</href>
</Icon>
</IconStyle>
</Style>
<ExtendedData>
<SchemaData schemaUrl="#test.schema">
<SimpleData name="id">1</SimpleData>
</SchemaData>
</ExtendedData>
<Point>
<coordinates>
2,49,0
</coordinates>
</Point>
</Placemark>
</Document>
</Document>
</kml>
If you want to see a OGR Python script that explores most possibilities of
KML, you can have a look at
https://svn.osgeo.org/gdal/trunk/autotest/kml_generate_test_files.py . But the
above should be sufficient for your immediate needs.
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list