0

simplekml module makes multiple polygons instead of a single one. Is there any way to merge the polygons into a single polygon, rather than multiple ones??

import simplekml, pandas as pd
tuples=tuple([(72.852333, 29.807333), (73.131333, 29.6055), (72.84733299999999, 29.587667), (73.568833, 30.1625), (72.8633, 29.2014), (73.1385, 29.614), (72.863667, 29.206667), (73.7015, 30.246667), (72.87169, 29.803279999999997), (72.8665, 29.794666999999997), (72.85826999999999, 29.79843), (72.847, 29.596166999999998), (73.0363238, 29.9029902), (73.035667, 29.466167), (72.8405, 29.587833000000003), (73.258333, 30.007167), (72.85779000000001, 29.79529), (73.022667, 29.478167), (72.84916700000001, 29.4135), (72.9155, 29.269000000000002), (72.840333, 29.620833), (73.2535, 29.992666999999997), (73.2535, 29.992666999999997), (72.86291999999999, 29.79293), (73.253, 29.997667), (73.25366700000001, 29.982667), (72.86233299999999, 29.798167), (73.253, 29.998666999999998), (72.939167, 29.331333), (73.04566700000001, 29.475), (72.84899999999999, 29.791999999999998), (73.131333, 29.6055), (73.565833, 30.164167), (73.14183299999999, 29.606167), (72.946833, 29.500333), (73.13766700000001, 29.615333000000003), (72.922, 29.418667), (72.830667, 29.683000000000003), (73.559774, 30.163674), (73.572, 30.165667), (73.258333, 30.006999999999998), (72.401833, 29.222833), (73.5695, 30.159000000000002), (72.859, 29.197333), (72.839833, 29.596333), (72.9516, 29.5113), (73.25365699999999, 29.992668), (72.866333, 29.803167), (72.9469, 29.6002), (73.2535, 29.992666999999997), (73.252167, 30.003833), (73.0400358, 29.4768821), (73.241233, 29.753483000000003), (73.24731700000001, 29.753967), (72.93329920000001, 29.276225), (72.8875, 29.413333), (72.8565, 29.195166999999998), (73.142333, 29.6125), (73.258333, 29.994166999999997), (72.97783299999999, 29.5), (72.901167, 29.414833), (72.9615, 29.3285), (72.852333, 29.807333), (73.135333, 29.606333000000003), (73.26016700000001, 30.002833000000003), (72.85883299999999, 29.197333), (72.859833, 29.193666999999998), (72.840333, 29.600666999999998), (73.131333, 29.6055), (73.738667, 30.157667), (72.41816700000001, 29.225167), (72.85448000000001, 29.79598), (72.85249, 29.803440000000002), (72.70944399999999, 29.735556), (72.857833, 29.199833), (73.0722, 29.5486), (73.14844000000001, 29.602040000000002), (73.260333, 29.996833000000002), (73.266667, 30.006666999999997), (73.039333, 29.4745), (73.252167, 30.003667), (72.836, 29.784333), (72.88833299999999, 29.203833000000003), (72.4266, 29.2262), (73.697333, 30.245833), (73.0158, 29.8002), (73.036833, 29.9015), (73.241167, 29.974), (73.266667, 30.006666999999997), (73.24255, 29.753517), (73.0365, 29.469666999999998), (73.259833, 30.002667), (73.25783299999999, 29.995833), (73.241167, 29.974), (73.13600000000001, 29.610333), (73.25483299999999, 29.999333), (73.135333, 29.606333000000003), (73.18933299999999, 29.531333), (72.958833, 29.330667), (72.8615, 29.1965), (72.8545, 29.596333), (73.7336, 30.1558), (73.25366700000001, 29.982667), (72.668667, 29.254), (73.25374000000001, 29.98262), (72.7566, 29.6736), (73.03, 29.457333000000002), (72.8581, 29.7985), (72.8602, 29.797690000000003), (72.83716700000001, 29.669666999999997), (72.8615, 29.1965), (73.257667, 29.995833), (73.26083299999999, 30.000833), (73.2535, 29.992666999999997), (73.125833, 29.6025), (72.66883299999999, 29.2475), (73.258333, 29.994166999999997), (73.14015, 29.619529999999997), (73.1386584, 29.613507399999996), (72.86265, 29.78945), (73.561167, 30.163833), (72.86129, 29.795740000000002), (73.2391, 29.7552), (72.841833, 29.598167)])
kml = simplekml.Kml()
pol = kml.newpolygon(name="Atrium Garden",
outerboundaryis=tuples)         
pol.style.polystyle.color = simplekml.Color.red
pol.style.polystyle.outline = 1
pol.style.polystyle.fill = 1
kml.save(r"C:\Users\user\Desktop\PolyStyle.kml")
Asad Ullah
  • 43
  • 1
  • 3
  • 7
  • Can you provide some code and a reproducible example? It's hard to answer your question without some kind of starting point as to where you are and what you're doing. – Avery Mar 20 '19 at 15:11
  • I want all polygons to form a single image. I'm getting the following image which contains voids. [link](https://i.stack.imgur.com/OSOY5.png) – Asad Ullah Mar 20 '19 at 16:06
  • I've added the code as well :) ! – Asad Ullah Mar 20 '19 at 16:16
  • I'm not familiar with simplekml, so not sure exactly what it's doing, but it appears to be making a polygon with a single linestring, where the vertices are not in the correct order. If you share your output KML, we could confirm this. I'm not sure if simplekml supports it, but you might be able to get what you want by combining the polygons into a KML "multigeometry", or a single Polygon with multiple outerBoundary sections. – Christiaan Adams Mar 20 '19 at 21:04
  • The file is available here Christiaan. Thank you for the support : https://drive.google.com/open?id=11Ds3oZmOWNHt9GPKnZhRlmu4gERjGZtM – Asad Ullah Mar 21 '19 at 04:14
  • @Asad Ullah, is your polygons are connected each other? If yes, you could make one by following its outer and inner boundaries. Otherwise, you have to make them separately. – Cloud Cho Oct 08 '19 at 00:26
  • If you run this [tool](http://kml4earth.appspot.com/numbers.html), paste in your KML, you'll see where the points are connected then you'll see dots criss crossing each other. KML has [longitude followed by latitude](https://developers.google.com/kml/documentation/kmlreference#coordinates). Are the lon,lat coords reversed? – CodeMonkey Jul 31 '20 at 15:55

1 Answers1

0

It is important the sequence of tuples. I think to sort tuples in code. For example,

import simplekml, pandas as pd
tuples=tuple([(72.852333, 29.807333), (73.131333, 29.6055), (72.84733299999999, 29.587667), (73.568833, 30.1625), (72.8633, 29.2014), (73.1385, 29.614), (72.863667, 29.206667), (73.7015, 30.246667), (72.87169, 29.803279999999997), (72.8665, 29.794666999999997), (72.85826999999999, 29.79843), (72.847, 29.596166999999998), (73.0363238, 29.9029902), (73.035667, 29.466167), (72.8405, 29.587833000000003), (73.258333, 30.007167), (72.85779000000001, 29.79529), (73.022667, 29.478167), (72.84916700000001, 29.4135), (72.9155, 29.269000000000002), (72.840333, 29.620833), (73.2535, 29.992666999999997), (73.2535, 29.992666999999997), (72.86291999999999, 29.79293), (73.253, 29.997667), (73.25366700000001, 29.982667), (72.86233299999999, 29.798167), (73.253, 29.998666999999998), (72.939167, 29.331333), (73.04566700000001, 29.475), (72.84899999999999, 29.791999999999998), (73.131333, 29.6055), (73.565833, 30.164167), (73.14183299999999, 29.606167), (72.946833, 29.500333), (73.13766700000001, 29.615333000000003), (72.922, 29.418667), (72.830667, 29.683000000000003), (73.559774, 30.163674), (73.572, 30.165667), (73.258333, 30.006999999999998), (72.401833, 29.222833), (73.5695, 30.159000000000002), (72.859, 29.197333), (72.839833, 29.596333), (72.9516, 29.5113), (73.25365699999999, 29.992668), (72.866333, 29.803167), (72.9469, 29.6002), (73.2535, 29.992666999999997), (73.252167, 30.003833), (73.0400358, 29.4768821), (73.241233, 29.753483000000003), (73.24731700000001, 29.753967), (72.93329920000001, 29.276225), (72.8875, 29.413333), (72.8565, 29.195166999999998), (73.142333, 29.6125), (73.258333, 29.994166999999997), (72.97783299999999, 29.5), (72.901167, 29.414833), (72.9615, 29.3285), (72.852333, 29.807333), (73.135333, 29.606333000000003), (73.26016700000001, 30.002833000000003), (72.85883299999999, 29.197333), (72.859833, 29.193666999999998), (72.840333, 29.600666999999998), (73.131333, 29.6055), (73.738667, 30.157667), (72.41816700000001, 29.225167), (72.85448000000001, 29.79598), (72.85249, 29.803440000000002), (72.70944399999999, 29.735556), (72.857833, 29.199833), (73.0722, 29.5486), (73.14844000000001, 29.602040000000002), (73.260333, 29.996833000000002), (73.266667, 30.006666999999997), (73.039333, 29.4745), (73.252167, 30.003667), (72.836, 29.784333), (72.88833299999999, 29.203833000000003), (72.4266, 29.2262), (73.697333, 30.245833), (73.0158, 29.8002), (73.036833, 29.9015), (73.241167, 29.974), (73.266667, 30.006666999999997), (73.24255, 29.753517), (73.0365, 29.469666999999998), (73.259833, 30.002667), (73.25783299999999, 29.995833), (73.241167, 29.974), (73.13600000000001, 29.610333), (73.25483299999999, 29.999333), (73.135333, 29.606333000000003), (73.18933299999999, 29.531333), (72.958833, 29.330667), (72.8615, 29.1965), (72.8545, 29.596333), (73.7336, 30.1558), (73.25366700000001, 29.982667), (72.668667, 29.254), (73.25374000000001, 29.98262), (72.7566, 29.6736), (73.03, 29.457333000000002), (72.8581, 29.7985), (72.8602, 29.797690000000003), (72.83716700000001, 29.669666999999997), (72.8615, 29.1965), (73.257667, 29.995833), (73.26083299999999, 30.000833), (73.2535, 29.992666999999997), (73.125833, 29.6025), (72.66883299999999, 29.2475), (73.258333, 29.994166999999997), (73.14015, 29.619529999999997), (73.1386584, 29.613507399999996), (72.86265, 29.78945), (73.561167, 30.163833), (72.86129, 29.795740000000002), (73.2391, 29.7552), (72.841833, 29.598167)])
tuples = sorted(tuples, key=lambda x: (x[0], x[1]))
kml = simplekml.Kml()
pol = kml.newpolygon(name="Atrium Garden",
outerboundaryis=tuples)         
pol.style.polystyle.color = simplekml.Color.red
pol.style.polystyle.outline = 1
pol.style.polystyle.fill = 1
kml.save(r"C:\Users\user\Desktop\PolyStyle.kml")

Does it nearly you hope? More untie needs to check the sequence.

And this link might be useful for your aim, isn't it?

https://developers.google.com/kml/documentation/altitudemode#clamptoground

Regulus
  • 11
  • 4