Simplekml and (geo)pandas

429 views
Skip to first unread message

gper...@gmail.com

unread,
May 13, 2018, 10:16:08 AM5/13/18
to simplekml
I am trying to convert a large number of polygons stored in a (Geo)DataFrame to a KML fils. I'd like to avoid iterating over each row of the DataFrame.
That's why I am trying to use apply method on the entire DataFrame as explained here: https://gist.github.com/tdhopper/5247816
This works fine and is much faster than iterating over each polygon. However, I am not able to apply a custom style to each polygon.
Do you have any suggestion?

Thanks,

Giuseppe

jop...@gmail.com

unread,
Apr 8, 2019, 10:30:36 AM4/8/19
to simplekml
Hello, 
¿you resolve the problem? I have this problem now

Basil Veerman

unread,
Apr 8, 2019, 4:23:22 PM4/8/19
to simp...@googlegroups.com
This is not a problem with simplekml or [geo]pandas. You just need to wrap whatever per-point functionality you want in a single callable to pass to the `apply` method, Consider this psuedocode. It is entirely untested.

```
import simplekml
kml = simplekml.Kml()

def create_point(X):
    pnt = kml.newpoint(name=X["name"], coords=[( X["longitude"],X["latitude"])])
    pnt.style.labelstyle.color = simplekml.Color.red # Make the text red
    pnt.style.labelstyle.scale = 2  # Make the text twice as big
    pnt.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png'

df.apply(create_point)
kml.save(path = "data.kml")
```
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "simplekml" group.
> To unsubscribe from this group and stop receiving emails from it, 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