0
votes

I have a problem with visualising polygon on google earth. I'm reading .xlsx file from the top to the bottom (in java) and I have a set of coordinates (x,y). My app is producing .kml file using JAK lib. After that when I import this .kml file into google earth I have wrong polygon shapes. Here is the example:

wrong polygon shape

The thing is that in kml file coordinates are in the sequence as they appear on the image. Last coordinate is by default connected to the first one and this is the problem. How can I sort the coordinates that this shape will be a rectagle? Of course this is the simplest example. I have much more complicated polygons (in the file) than the rectangle one.

2

2 Answers

1
votes

KML's LinearRing structure that you'd use in the Polygon is a ring, so the polygon is drawn linearly in the order that you specify in the ring. So if you want to draw a rectangle, they'd need to be ordered 1, 2, 4 3.

There's nothing within KML to tell it to interpret the ring differently. You'll need to either sort them in your java application when you're reading the XSLX, or have whoever is providing you the data send you the list of points in the correct order. I'm not sure what the domain is of what you're doing, but it doesn't make sense to me to send them in any way to you other than as a linear ring of points int he order you'd draw the lines.

0
votes

If your polygons are convex you can implement any convex-hull algorithm. This will work for your example but not with more complex polygons.