Wednesday, 19 May 2010

KML Overlapping Features: Revisited

In a previous post about overlapping features I expressed the difficulty with selecting LineStrings in Google Earth that lie completely within a Polygon.

I've tried altering the Altitude relative to the Ground .. with clampedToGround but cannot get them to work.

It appears that the only thing you can click inside a Polygon is a Point with an Icon attached to it (whether or not it is active)

The only solution therefore, is to use a <multigeometry> element around the <linestring> element.  Then for every point along the LineString, you add a Point to the Multigeometry.  For example:

-1.689192,53.348771,2 -1.689188,53.348688,2 -1.689071,53.348596,2 -1.688909,53.348642,2 


Define an IconStyle that is not too obstrusive... and then you can select any of the above Points in the Line, whether or not it is in a Polygon.

Unfortunately we can't always control the separation of the points... a line generated by Google MyTracks can have a large number of points all bunched up together... it would look pretty bad to make them all visible... so perhaps when generating the KML I could work through the collection of Points that makes the whole LineString and every 50m or so I can calculate the Point location and drop one into the KML...

We start with Northings and Eastings.  PointA would be something like N:540244 E:384222 and PointB N:540233 E:384243.   So PointB lies south and east of PointB.  Simple trigonometry tells us that the distance between A and B is the root of 562 [121 + 441] = 23.7m.  If we want to drop a Point (into the MultiGeometry markup) every 50m then we skip PointB... and calculate the distance to PointC.

PointC is N:540213 E:384223 - which is south and west of Point B.  The distance is 28.3m making a total distance along the path of 28.3+23.7 = 52m.  We could either drop PointC into the MultiGeometry ... or if you want exact 50m points, you calculate the Northing and Easting of the point that lies 26.3m from PointB along the line towards PointC.

So all the sides of the triangle must be reduced by 92.93%.  Thus we require a point that is 18.59m (-ish) south and 18.59m west of PointB -> N:540214.41 E:384224.41.  This point can then be dropped into the KML after PointA.  From this point there is about 2m to PointC.  So our next KML Point will be 48m from PointC along the LineString.

These calculations are fairly straightforward to build into code, especially if you have to work through each point in a line and convert Northings and Eastings into Lat/Lon coordinates (using Grid Inquest from Quest Geo Solutions Ltd).

No comments:

Post a Comment