I'm trying to export a matplotlib figure using a kml format. The question is identical to the following:
I've outlined the exact function but I can't get the kml output to work. Conversely, if I export a simplekml
function, it's working fine.
I've attached both outputs below. Output 1 one works but 2 doesn't.
Output 1:
import simplekml
kml = simplekml.Kml()
kml.newpoint(name="Kirstenbosch", coords=[(18.432314,33.988862)])
kml.save("botanicalgarden.kml")
But when trying to pass a matplotlib function to simplekml function, I'm returning the following output. What am I doing wrong?
Output 2:
import matplotlib
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as ppl
from pylab import rcParams
import simplekml
rcParams['figure.figsize'] = (8,8)
# create rectangle over 0 to 10 degrees longitude and 0 to 10 degrees latitude
x = [0, 10, 10, 0, 0]
y = [10, 10, 0, 0, 10]
x1 = range(0,11) # to draw a diagonal line
fig = ppl.figure(1)
ax = fig.add_axes([0,0,1,1])
ax.axis('off')
fig.patch.set_facecolor('blue') # so we can see the true extent
ppl.plot(x, y, 'r', linewidth=3)
ppl.plot(x, y, '.b', linewidth=3)
ppl.plot(x1, x1, 'g', linewidth=3)
ppl.axis('off')
border1 = ppl.axis()
if False:
ppl.show()
else:
pngName = 'Overlay.png'
fig.savefig(pngName, facecolor=fig.get_facecolor(), transparent=False)
bottomleft = (border1[0],border1[2])
bottomright = (border1[1],border1[2])
topright = (border1[1],border1[3])
topleft = (border1[0],border1[3])
kml = simplekml.Kml()
ground = kml.newgroundoverlay(name='GroundOverlay')
ground.icon.href = pngName
ground.gxlatlonquad.coords =[bottomleft, bottomright, topright, topleft]
kml.save("GroundOverlay.kml")
from error exporting matplotlib file to kml - python
No comments:
Post a Comment