I'm creating kml using the library simplekml. When creating a single one, it works like a charm, but when trying to create one kml per dict entry, returns an error I could not locate. The data have this kind of format:
{12: {900: [(-5.4529673, 4.46),
(-3.4529799, 40.454),
(-3.495, 33),
(-3.45471, 40.437)]},
29: {900: [(-3.452....}
And the script looks like this:
import simplekml
kml = simplekml.Kml()
for key, value in data.items():
pol = kml.newpolygon(name = key)
pol.outerboundaryis = data[key][900]
pol.innerboundaryis = []
print(pol.outerboundaryis)
pol.style.linestyle.color = simplekml.Color.green
pol.style.linestyle.width = 5
pol.style.polystyle.color = simplekml.Color.changealphaint(100, simplekml.Color.green)
print(pol.name)
kml.save(str(pol.name) +".kml")
Returns this error:
AttributeError: 'int' object has no attribute 'count'
I've been converting the boundaries to strings, using kml.save('key' +".kml")...always the same problem. I don't know what is an Int in all this, I'm starting to thing this is a problem from the library itself? Please and thank you
P.E: Also tried iterating over the enst dict, yielded the same error:
import simplekml
kml = simplekml.Kml()
for key, value in data.items():
for key2, value2 in value.items():
pol = kml.newpolygon(name = key)
pol.outerboundaryis = value2
pol.innerboundaryis = []
print(pol.outerboundaryis)
pol.style.linestyle.color = simplekml.Color.green
pol.style.linestyle.width = 5
pol.style.polystyle.color = simplekml.Color.changealphaint(100, simplekml.Color.green)
kml.save(str(pol.name) +".kml")
So as you said it would work outside a loop since you are not iterating through the entire elements of the
datadictionary.The problem is the data held in here.
This cannot be used with this syntax
for key, value in data.items():since this only acceptskey -> valuepairs and your data consists of lists of dictionary.Read more here on the correct use of the
for key, value in data.items():.To iterate through lists of dictionary, see here and incorporate that idea into your code.