/// <summary> /// add a point to the ring /// </summary> /// <param name="longitude"></param> /// <param name="latitude"></param> /// <param name="altitude"></param> public void Add(float longitude, float latitude, float altitude) { kmlPoint pt = new kmlPoint(); pt.longitude = longitude; pt.latitude = latitude; pt.altitude = altitude; Add(pt); }
/// <summary> /// relocate the line at the new position /// </summary> /// <param name="longitude"></param> /// <param name="latitude"></param> public void Relocate(float longitude, float latitude) { // adjust the position of each point relative to the centre for (int i = 0; i < Points.Count; i++) { kmlPoint pt = (kmlPoint)Points[i]; pt.longitude += longitude - centre_longitude; pt.latitude += latitude - centre_latitude; } updateCentrePoint(); }
/// <summary> /// recalculate the centre point of the ring /// </summary> private void updateCentrePoint() { if (Points.Count > 0) { float tot_x = 0; float tot_y = 0; for (int i = 0; i < Points.Count; i++) { kmlPoint pt = (kmlPoint)Points[i]; tot_x += pt.longitude; tot_y += pt.latitude; } centre_longitude = tot_x / Points.Count; centre_latitude = tot_y / Points.Count; } }
/// <summary> /// return an xml element /// </summary> /// <param name="doc">xml document to add the data to</param> /// <returns>an xml element</returns> public XmlElement getXml(XmlDocument doc) { String coords = ""; for (int i = 0; i < Points.Count; i++) { kmlPoint pt = (kmlPoint)Points[i]; coords += "\r\n" + Convert.ToString(pt.longitude) + "," + Convert.ToString(pt.latitude) + "," + Convert.ToString(pt.altitude) + ","; } coords += "\r\n"; XmlElement elem = doc.CreateElement("LinearRing"); doc.DocumentElement.AppendChild(elem); xml.AddTextElement(doc, elem, "coordinates", coords); return(elem); }
/// <summary> /// returns true if the given location is inside the ring /// </summary> /// <param name="longitude"></param> /// <param name="latitude"></param> /// <returns>true if the given location is inside this ring</returns> public bool isInside(float longitude, float latitude) { bool inside = false; int i, j; for (i = 0, j = Points.Count - 1; i < Points.Count; j = i++) { kmlPoint pt1 = (kmlPoint)Points[i]; kmlPoint pt2 = (kmlPoint)Points[j]; if ((((pt1.latitude <= latitude) && (latitude < pt2.latitude)) || ((pt2.latitude <= latitude) && (latitude < pt1.latitude))) && (longitude < (pt2.longitude - pt1.longitude) * (latitude - pt1.latitude) / (pt2.latitude - pt1.latitude) + pt1.longitude)) { inside = !inside; } } return(inside); }
/// <summary> /// add a point to the ring /// </summary> /// <param name="pt"></param> public void Add(kmlPoint pt) { Points.Add(pt); updateCentrePoint(); }