Request: gx:labelVisibility for LineString

256 views
Skip to first unread message

Michael Hirsch

unread,
Feb 2, 2015, 1:48:09 AM2/2/15
to simp...@googlegroups.com
KML syntax allows for automatically placing a text label at the midpoint of a LineString, which requires the phrase
<gx:labelVisibility>1</gx:labelVisibility> 
within the relevant <LineStyle> element.

however, there does not currently (simplekml v. 1.2.5) appear to be a way to set this gx:labelVisibility value in simplekml.
Example code fragment:
import simplekml
k = simplekml.Kml()
ls = k.newlinestring(name='My Line', coords=([(0,0),(1,1)]))
ls.style.linestyle.width=5
ls.style.linestyle.color=simplekml.Color.yellow
ls.style.labelstyle.scale=2
ls.style.labelstyle.color = simplekml.Color.blue
k.save('blah.kml')

Produces the KML
<?xml version="1.0" encoding="UTF-8"?>
    <Document id="feat_1">
        <Style id="stylesel_0">
            <LabelStyle id="substyle_1">
                <color>ffff0000</color>
                <colorMode>normal</colorMode>
                <scale>2</scale>
            </LabelStyle>
            <LineStyle id="substyle_0">
                <color>ff00ffff</color>
                <colorMode>normal</colorMode>
                <width>5</width>
            </LineStyle>
        </Style>
        <Placemark id="feat_2">
            <name>My Line</name>
            <styleUrl>#stylesel_0</styleUrl>
            <LineString id="geom_0">
                <coordinates>0,0,0.0 1,1,0.0</coordinates>
            </LineString>
        </Placemark>
    </Document>
</kml>

but if I add the line
<gx:labelVisibility>1</gx:labelVisibility> 
within the 
<LineStyle id="substyle_0"> tag, I see a label "My Line"

is it possible to add this gxlabelvisibility parameter in simplekml so that I don't have to hand-edit the KML files?

E.g. it would be 

ls.style.labelstyle.gxlabelvisibility=1


Thanks.

Kyle Lancaster

unread,
Feb 2, 2015, 1:55:01 AM2/2/15
to simp...@googlegroups.com, mhi...@bu.edu
Hi Michael,

Thanks for letting me know about the missing property. I will try my best to add it to simplekml within a week.

Regards,

Kyle

Kyle Lancaster

unread,
Feb 8, 2015, 5:38:07 AM2/8/15
to simp...@googlegroups.com, mhi...@bu.edu
Hi Michael,

I have released version 1.2.6 with the property gxlabelvisibility added. Below is your example that I have updated to include the new property:

import simplekml
k = simplekml.Kml()
ls = k.newlinestring(name='My Line', coords=([(0,0),(1,1)]))
ls.style.linestyle.width=5
ls.style.linestyle.color=simplekml.Color.yellow
ls.style.labelstyle.scale=2
ls.style.labelstyle.color = simplekml.Color.blue
ls.style.linestyle.gxlabelvisibility = 1
k.save('blah.kml')

Please note that the gxlabelvisibility property was added to the linestyle and not to the labelstyle as you suggested. The KML Reference indicates that gx:labelVisibility is part of the linestyle.

Hope this makes your life a little bit easier!

Regards,

Kyle

Kyle Lancaster

unread,
Feb 8, 2015, 5:40:30 AM2/8/15
to simp...@googlegroups.com, mhi...@bu.edu
Hi again,

Just released 1.2.7 :)

In 1.2.6 I made it so that the tag gx:labelVisibility was always included in the output KML, I have changed that in 1.2.7 so that if the value of gxlabelvisibility is not supplied it is not added to the output KML.

Regards,

Kyle

Hirsch, Michael, Arthur

unread,
Feb 8, 2015, 2:37:15 PM2/8/15
to simp...@googlegroups.com

Thanks very much Kyle!

From: simp...@googlegroups.com [simp...@googlegroups.com] on behalf of Kyle Lancaster [kyle...@gmail.com]
Sent: Sunday, February 08, 2015 05:40
To: simp...@googlegroups.com
Cc: Hirsch, Michael, Arthur
Subject: Re: Request: gx:labelVisibility for LineString

--

---
You received this message because you are subscribed to a topic in the Google Groups "simplekml" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simplekml/erEecaXKGAQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simplekml+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages